This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH to lookup_label


I checked the attached patch into mainline.

The function lookup_label generates a LABEL_DECL from a bytecode offset.
It used to do this by mapping a bytecode offset to an identifier
"LJpc=NNN" where NNN is the bytecode offset (pc).  Unfortunately,
different methods may need different labels at the same offset.
This causes confusion - at least when inlining is done.  I fixed
the problem by instead generating (informally) "LJpc=MMMNNN" where
MMM is counter that is incremented for each new method.  This
assumes that all calls to lookup_label for a given method happen
before we call expand_byte_code for the next method.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/
2005-06-13  Per Bothner  <per@bothner.com>

	* expr.c (int highest_label_pc_this_method,
	start_label_pc_this_method): New globals.
	(lookup_label): Add start_label_pc_this_method to pc for label, and
	update highest_label_pc_this_method.  This prevents conflicts between
	labels from different methods.
	* java-tree.h: Declare new globals.
	* jcf-parse.c (parse_class_file): If needed bump
	start_label_pc_this_method and reset highest_label_pc_this_method.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.228
diff -u -p -r1.228 expr.c
--- expr.c	24 May 2005 19:21:59 -0000	1.228
+++ expr.c	13 Jun 2005 19:26:20 -0000
@@ -138,6 +138,12 @@ int stack_pointer;
 const unsigned char *linenumber_table;
 int linenumber_count;
 
+/* Largest pc so far in this method that has been passed to lookup_label. */
+int highest_label_pc_this_method = -1;
+
+/* Base value for this method to add to pc to get generated label. */
+int start_label_pc_this_method = 0;
+
 void
 init_expr_processing (void)
 {
@@ -1766,7 +1772,9 @@ lookup_label (int pc)
 {
   tree name;
   char buf[32];
-  ASM_GENERATE_INTERNAL_LABEL(buf, "LJpc=", pc);
+  if (pc > highest_label_pc_this_method)
+    highest_label_pc_this_method = pc;
+  ASM_GENERATE_INTERNAL_LABEL(buf, "LJpc=", start_label_pc_this_method + pc);
   name = get_identifier (buf);
   if (IDENTIFIER_LOCAL_VALUE (name))
     return IDENTIFIER_LOCAL_VALUE (name);
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.235
diff -u -p -r1.235 java-tree.h
--- java-tree.h	9 Jun 2005 10:54:59 -0000	1.235
+++ java-tree.h	13 Jun 2005 19:26:20 -0000
@@ -234,6 +234,12 @@ extern int always_initialize_class_p;
 
 extern int flag_verify_invocations;
 
+/* Largest pc so far in this method that has been passed to lookup_label. */
+extern int highest_label_pc_this_method;
+
+/* Base value for this method to add to pc to get generated label. */
+extern int start_label_pc_this_method;
+
 typedef struct CPool constant_pool;
 
 #define CONSTANT_ResolvedFlag 16
Index: jcf-parse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-parse.c,v
retrieving revision 1.185
diff -u -p -r1.185 jcf-parse.c
--- jcf-parse.c	23 Apr 2005 21:29:02 -0000	1.185
+++ jcf-parse.c	13 Jun 2005 19:26:21 -0000
@@ -929,6 +929,21 @@ parse_class_file (void)
 
       give_name_to_locals (jcf);
 
+      /* Bump up start_label_pc_this_method so we get a unique label number
+	 and reset highest_label_pc_this_method. */
+      if (highest_label_pc_this_method >= 0)
+	{
+	  /* We adjust to the next multiple of 1000.  This is just a frill
+	     so the last 3 digits of the label number match the bytecode
+	     offset, which might make debugging marginally more convenient. */
+	  start_label_pc_this_method
+	    = ((((start_label_pc_this_method + highest_label_pc_this_method)
+		 / 1000)
+		+ 1)
+	       * 1000);
+	  highest_label_pc_this_method = -1;
+	}
+
       /* Convert bytecode to trees.  */
       expand_byte_code (jcf, method);
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]