PATCH: better inlining in gcjh

Tom Tromey tromey@cygnus.com
Sun Dec 13 16:00:00 GMT 1998


I'm committing the appended patch.  It extends gcjh to recognize a
couple other simple ways to inline a function.

Tom

1998-12-13  Tom Tromey  <tromey@cygnus.com>

	* gjavah.c (decompile_method): Handle all types of `return'
	opcode.  Decompile `return this' and `return'.
	(method_access): New global.
	(print_method_info): Set it.
	(decompile_method): Don't decompile a synchronized method.

Index: gjavah.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/java/gjavah.c,v
retrieving revision 1.22.2.5
diff -u -r1.22.2.5 gjavah.c
--- gjavah.c	1998/12/13 21:32:40	1.22.2.5
+++ gjavah.c	1998/12/13 23:14:37
@@ -124,6 +124,7 @@
 
 #define HANDLE_CONSTANTVALUE(VALUEINDEX) current_field_value = (VALUEINDEX)
 
+static int method_access = 0;
 #define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
   if (out) { decompiled = 0; \
       print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS); \
@@ -398,6 +399,7 @@
   int length, is_init = 0;
   char *override = NULL;
 
+  method_access = flags;
   if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
     fprintf (stream, "<not a UTF8 constant>");
   str = JPOOL_UTF_DATA (jcf, name_index);
@@ -465,12 +467,20 @@
   int index;
   uint16 name_and_type, name;
 
+  /* If the method is synchronized, don't touch it.  */
+  if ((method_access & ACC_SYNCHRONIZED))
+    return;
+
   if (code_len == 5
       && codes[0] == OPCODE_aload_0
       && codes[1] == OPCODE_getfield
-      && codes[4] == OPCODE_areturn)
+      && (codes[4] == OPCODE_areturn
+	  || codes[4] == OPCODE_dreturn
+	  || codes[4] == OPCODE_freturn
+	  || codes[4] == OPCODE_ireturn
+	  || codes[4] == OPCODE_lreturn))
     {
-      /* Found something useful to decompile.  */
+      /* Found code like `return FIELD'.  */
       fputs (" { return ", out);
       index = (codes[2] << 8) | codes[3];
       /* FIXME: ensure that tag is CONSTANT_Fieldref.  */
@@ -480,6 +490,20 @@
       name = JPOOL_USHORT1 (jcf, name_and_type);
       print_name (out, jcf, name);
       fputs ("; }", out);
+      decompiled = 1;
+    }
+  else if (code_len == 2
+	   && codes[0] == OPCODE_aload_0
+	   && codes[1] == OPCODE_areturn)
+    {
+      /* Found `return this'.  */
+      fputs (" { return this; }", out);
+      decompiled = 1;
+    }
+  else if (code_len == 1 && codes[0] == OPCODE_return)
+    {
+      /* Found plain `return'.  */
+      fputs (" { }", out);
       decompiled = 1;
     }
 }



More information about the Gcc-patches mailing list