gcj: disabling synchronization

Alexandre Petit-Bianco apbianco@cygnus.com
Sat Apr 1 00:00:00 GMT 2000


Jeff Sturm writes:

> I didn't completely understand the tree structure created by
> patch_synchronized_statement.  It may be obvious to anyone who
> understands the compiler internals (which I certainly don't).

It basically builds what is documented in the comment found in the
middle of patch_synchronized_statement: surrounding the synchronized
block with a try/catch sequence so that if an exception is thrown
during the execution of the block, the synchronization lock is
released and the exception rethrown.

If you read java-tree.def, you'll find that the SYNCHRONIZED_EXPR
contains two things: first the expression on which we synchronize and
then the synchronized block. I thing something hereafter might work.

./A

Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.133
diff -u -p -r1.133 parse.y
--- parse.y	2000/01/25 18:29:02	1.133
+++ parse.y	2000/01/29 20:06:39
@@ -11720,6 +11724,15 @@ patch_synchronized_statement (node, wfl_
       parse_error_context (wfl_operator, "Incompatible type for `synchronized'. Can't convert `%s' to `java.lang.Object'",
 			   lang_printable_name (TREE_TYPE (expr), 0));
       return error_mark_node;
+    }
+
+  /* If we actually don't synchronize. Simply return a compound
+     expression */
+  if (flag_no_synch)
+    {
+      block = java_complete_tree (block);
+      return (block == error_mark_node ?
+	      block : build (COMPOUND_EXPR, void_type_node, expr, block));
     }
 
   if (flag_emit_xref)


More information about the Java mailing list