This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

[java/rfc] cleanup emit_register_classes and friends


This is patch 1 of 3 trying to fix the CNI plt problem currently
causing lots of Java failures.

There are two things in here that seemed unnecessary that warrent review.

First, the decl duplication in register_class.  Why?  Duplicating decls
is always extremely risky buisiness.  In this case I'm particularly 
interested in removing the DECL_RTL invocation here, since I want all
DECL_RTL creation to be delayed until after java_mark_class_local has run.

Second, the call to mark_decl_referenced in emit_register_classes
would seem to be redundant with the one in output_addr_const, which
is eventually called by assemble_integer.  Here, for the sake of 
eventually not referencing rtl anywhere within the java front end,
I've used an output routine that accepts trees instead of playing
with DECL_RTL ourselves.

Tested alone on i686-linux, together with other patches on ia64 
and alpha linux.

Ok?



r~


	* class.c (registered_class): Take it out of class_roots; turn into
	a vec of trees.
	(register_class): Make static.  Don't duplicate decl node.  Use
	VEC_safe_push.
	(emit_register_classes): Use VEC_iterate.  Use output_constant
	instead of assemble_integer.  Don't call mark_decl_referenced
	directly.
	* java-tree.h (register_class): Remove decl.

Index: java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.226
diff -u -p -d -r1.226 class.c
--- java/class.c	10 May 2005 13:23:32 -0000	1.226
+++ java/class.c	24 May 2005 17:36:25 -0000
@@ -64,6 +64,7 @@ static void add_miranda_methods (tree, t
 static int assume_compiled (const char *);
 static tree build_symbol_entry (tree);
 static tree emit_assertion_table (tree);
+static void register_class (void);
 
 struct obstack temporary_obstack;
 
@@ -98,12 +99,13 @@ static class_flag_node *assume_compiled_
 
 static class_flag_node *enable_assert_tree;
 
-static GTY(()) tree class_roots[5];
-#define registered_class class_roots[0]
-#define fields_ident class_roots[1]  /* get_identifier ("fields") */
-#define info_ident class_roots[2]  /* get_identifier ("info") */
-#define class_list class_roots[3]
-#define class_dtable_decl class_roots[4]
+static GTY(()) tree class_roots[4];
+#define fields_ident class_roots[0]  /* get_identifier ("fields") */
+#define info_ident class_roots[1]  /* get_identifier ("info") */
+#define class_list class_roots[2]
+#define class_dtable_decl class_roots[3]
+
+static GTY(()) VEC(tree,gc) *registered_class;
 
 /* Return the node that most closely represents the class whose name
    is IDENT.  Start the search from NODE (followed by its siblings).
@@ -2407,23 +2409,16 @@ layout_class_method (tree this_class, tr
   return dtable_count;
 }
 
-void
+static void
 register_class (void)
 {
-  /* END does not need to be registered with the garbage collector
-     because it always points into the list given by REGISTERED_CLASS,
-     and that variable is registered with the collector.  */
-  static tree end;
-  tree node    = TREE_OPERAND (build_class_ref (current_class), 0);
-  tree current = copy_node (node);
+  tree node;
 
-  XEXP (DECL_RTL (current), 0) = copy_rtx (XEXP (DECL_RTL(node), 0));
   if (!registered_class)
-    registered_class = current;
-  else
-    TREE_CHAIN (end) = current;
+    registered_class = VEC_alloc (tree, gc, 8);
 
-  end = current;
+  node = TREE_OPERAND (build_class_ref (current_class), 0);
+  VEC_safe_push (tree, gc, registered_class, node);
 }
 
 /* Emit something to register classes at start-up time.
@@ -2448,25 +2443,28 @@ emit_register_classes (tree *list_p)
      targets can overide the default in tm.h to use the fallback mechanism.  */
   if (TARGET_USE_JCR_SECTION)
     {
+      tree klass, t;
+      int i;
+
 #ifdef JCR_SECTION_NAME
-      tree t;
       named_section_flags (JCR_SECTION_NAME, SECTION_WRITE);
+#else
+      /* A target has defined TARGET_USE_JCR_SECTION,
+	 but doesn't have a JCR_SECTION_NAME.  */
+      gcc_unreachable ();
+#endif
       assemble_align (POINTER_SIZE);
-      for (t = registered_class; t; t = TREE_CHAIN (t))
+
+      for (i = 0; VEC_iterate (tree, registered_class, i, klass); ++i)
 	{
-	  mark_decl_referenced (t);
-	  assemble_integer (XEXP (DECL_RTL (t), 0),
-			    POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+	  t = build_fold_addr_expr (klass);
+	  output_constant (t, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE);
 	}
-#else
-      /* A target has defined TARGET_USE_JCR_SECTION, but doesn't have a
-	 JCR_SECTION_NAME.  */
-      abort ();
-#endif
     }
   else
     {
       tree klass, t, register_class_fn;
+      int i;
 
       t = build_function_type_list (void_type_node, class_ptr_type, NULL);
       t = build_decl (FUNCTION_DECL, get_identifier ("_Jv_RegisterClass"), t);
@@ -2474,7 +2472,7 @@ emit_register_classes (tree *list_p)
       DECL_EXTERNAL (t) = 1;
       register_class_fn = t;
 
-      for (klass = registered_class; klass; klass = TREE_CHAIN (klass))
+      for (i = 0; VEC_iterate (tree, registered_class, i, klass); ++i)
 	{
 	  t = build_fold_addr_expr (klass);
 	  t = tree_cons (NULL, t, NULL);
Index: java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.230
diff -u -p -d -r1.230 java-tree.h
--- java/java-tree.h	29 Apr 2005 18:42:48 -0000	1.230
+++ java/java-tree.h	24 May 2005 17:36:26 -0000
@@ -1286,7 +1286,6 @@ extern tree build_result_decl (tree);
 extern void set_method_index (tree decl, tree method_index);
 extern tree get_method_index (tree decl);
 extern void make_class_data (tree);
-extern void register_class (void);
 extern int alloc_name_constant (int, tree);
 extern int alloc_constant_fieldref (tree, tree);
 extern void emit_register_classes (tree *);


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