This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
java: Fix inliner for synchronized methods
- From: Andrew Haley <aph at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Date: Tue, 25 Mar 2003 20:32:20 +0000 (GMT)
- Subject: java: Fix inliner for synchronized methods
This is a longstanding bug in the tree inliner; if you inline
synchronized methods the synchronization gets lost.
As far as I am aware this is the last inlining bug that affects
correctness. I'd like to build libgcj on the trunk with inlining.
Andrew.
* decl.c (complete_start_java_method): Break into two functions,
complete_start_java_method and wrap_synchronized_method. Call
wrap_synchronized_method.
* parse.y (java_expand_method_bodies): Call
wrap_synchronized_method.
Index: java/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.151
diff -c -2 -p -r1.151 decl.c
*** java/decl.c 26 Feb 2003 03:02:14 -0000 1.151
--- java/decl.c 25 Mar 2003 20:31:06 -0000
*************** complete_start_java_method (tree fndecl)
*** 1709,1715 ****
}
if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
{
- /* Wrap function body with a monitorenter plus monitorexit cleanup. */
tree enter, exit, lock;
if (METHOD_STATIC (fndecl))
--- 1709,1725 ----
}
+ /* We already did this for source methods. */
+ if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
+ wrap_synchronized_method (fndecl);
+ }
+
+ /* If a method is synchronized, wrap its body with a monitorenter plus
+ monitorexit cleanup. */
+
+ void
+ wrap_synchronized_method (tree fndecl)
+ {
if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
{
tree enter, exit, lock;
if (METHOD_STATIC (fndecl))
Index: java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.172
diff -c -2 -p -r1.172 java-tree.h
*** java/java-tree.h 24 Feb 2003 02:14:48 -0000 1.172
--- java/java-tree.h 25 Mar 2003 20:31:08 -0000
*************** extern int verify_constant_pool (struct
*** 1245,1248 ****
--- 1245,1249 ----
extern void start_java_method (tree);
extern void end_java_method (void);
+ extern void wrap_synchronized_method (tree);
extern void give_name_to_locals (struct JCF *);
extern void note_instructions (struct JCF *, tree);
Index: java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.425
diff -c -2 -p -r1.425 parse.y
*** java/parse.y 11 Mar 2003 20:37:02 -0000 1.425
--- java/parse.y 25 Mar 2003 20:31:17 -0000
*************** java_expand_method_bodies (tree class)
*** 8006,8010 ****
current_function_decl = decl;
!
/* Save the function for inlining. */
if (flag_inline_trees)
--- 8006,8011 ----
current_function_decl = decl;
! wrap_synchronized_method (decl);
!
/* Save the function for inlining. */
if (flag_inline_trees)