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]

Patch: java class registration via .jcr section, take 3



Here's take 3...

Richard - one of your suggestions was to use
targetm.have_named_sections as a test in java/class.c, however I think
we also need to check SUPPORTS_WEAK, like so....
+  if (SUPPORTS_WEAK && targetm.have_named_sections)
Will SUPPORTS_WEAK eventually turn into something like
targetm.supports_weak, or something like that?

Note that _Jv_RegisterClasses is used instead of _Jv_RegisterClass.  

Tested on powerpc-unknown-linux-gnu.  Ok?

Thanks!



2001-08-07  Anthony Green  <green@redhat.com>

	* java/class.c (jcr_section): New function.
        (emit_register_classes): Use assemble_jcr if possible.  Keep the
	original mechanism as a fallback.
	* defaults.h (JCR_SECTION_NAME): Define if we have named section
	and weak symbol support.
	* crtstuff.c (__JCR_LIST__): Define.
	(__JCR_END__): Define.
	(_Jv_RegiserClasses): Define weak symbol if possible.
	(__do_global_ctors_aux): Register classes for ELF targets with
	weak symbol support.


Index: gcc/crtstuff.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/crtstuff.c,v
retrieving revision 1.41
diff -c -u -p -r1.41 crtstuff.c
--- crtstuff.c	2001/08/04 01:31:31	1.41
+++ crtstuff.c	2001/08/07 06:07:05
@@ -415,6 +415,14 @@ char __EH_FRAME_BEGIN__[]
      = { };
 #endif /* EH_FRAME_SECTION_NAME */
 
+#ifdef JCR_SECTION_NAME
+/* Stick a label at the beginning of the java class registration info
+   so we can register them properly.  */
+
+STATIC void *__JCR_LIST__[] __attribute__ ((unused, section(JCR_SECTION_NAME)))
+  = { 0 };
+#endif /* JCR_SECTION_NAME */
+
 #endif /* defined(CRT_BEGIN) */
 
 #ifdef CRT_END
@@ -423,11 +431,25 @@ char __EH_FRAME_BEGIN__[]
 
 #ifdef OBJECT_FORMAT_ELF
 
+#ifdef JCR_SECTION_NAME
+extern void _Jv_RegisterClasses (void *) __attribute__((weak));
+static void *__JCR_END__[];
+#endif
+
 static func_ptr __CTOR_END__[];
 static void
 __do_global_ctors_aux (void)
 {
   func_ptr *p;
+#ifdef JCR_SECTION_NAME
+  void **jcr;
+  if (_Jv_RegisterClasses)
+    {
+      for (jcr = __JCR_END__ - 1; *jcr != NULL; jcr--);
+      if (*(jcr + 1))
+	_Jv_RegisterClasses (jcr + 1);
+    }
+#endif
   for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
     (*p) ();
 }
@@ -542,6 +564,14 @@ STATIC int __FRAME_END__[]
      __attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME)))
      = { 0 };
 #endif /* EH_FRAME_SECTION */
+
+#ifdef JCR_SECTION_NAME
+/* Stick a label at the beginning of the java class registration info
+   so we can register them properly.  */
+
+STATIC void *__JCR_END__[1] 
+     __attribute__ ((unused, section(JCR_SECTION_NAME))) = { 0 };
+#endif /* JCR_SECTION_NAME */
 
 #endif /* defined(CRT_END) */
 
Index: gcc/defaults.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/defaults.h,v
retrieving revision 1.49
diff -c -u -p -r1.49 defaults.h
--- defaults.h	2001/08/04 01:31:31	1.49
+++ defaults.h	2001/08/07 06:07:09
@@ -217,6 +217,15 @@ do { ASM_OUTPUT_LABEL(FILE,LABEL_ALTERNA
 #endif
 #endif
 
+/* If we have named section and we support weak symbols, then use the
+   .jcr section for recording java classes which need to be registered
+   at program start-up time.  */
+#if defined (TARGET_ASM_NAMED_SECTION) && SUPPORTS_WEAK
+#ifndef JCR_SECTION_NAME
+#define JCR_SECTION_NAME ".jcr"
+#endif
+#endif
+
 /* If we have no definition for UNIQUE_SECTION, but do have the 
    ability to generate arbitrary sections, construct something
    reasonable.  */
Index: gcc/java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.102
diff -c -u -p -r1.102 class.c
--- class.c	2001/08/07 00:13:35	1.102
+++ class.c	2001/08/07 06:07:17
@@ -37,6 +37,7 @@ The Free Software Foundation is independ
 #include "output.h"
 #include "parse.h"
 #include "ggc.h"
+#include "target.h"
 
 static tree make_method_value PARAMS ((tree));
 static tree build_java_method_type PARAMS ((tree, tree, int));
@@ -1865,45 +1865,71 @@ register_class ()
   end = current;
 }
 
-/* Generate a function that gets called at start-up (static contructor) time,
-   which calls registerClass for all the compiled classes. */
+/* Given a rtx symbol, emit this symbol into the jcr section (named
+   JCR_SECTION_NAME).  */
 
+static void
+assemble_jcr (symbol)
+     rtx symbol;
+{
+  named_section_flags (JCR_SECTION_NAME, SECTION_WRITE,
+       POINTER_SIZE / BITS_PER_UNIT);
+  assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, 1);
+}
+  
+/* Emit something to register classes at start-up time.
+
+   The preferred mechanism is through the .jcr section, which contain
+   a list of pointers to classes which get registered during
+   constructor invoction time.  The fallback mechanism is to generate
+   a `constructor' function which calls _Jv_RegisterClass for each
+   class in this file.  */
+
 void
 emit_register_classes ()
 {
-  extern tree get_file_function_name PARAMS ((int));
-  tree init_name = get_file_function_name ('I');
-  tree init_type = build_function_type (void_type_node, end_params_node);
-  tree init_decl;
-  tree t;
-
-  init_decl = build_decl (FUNCTION_DECL, init_name, init_type);
-  SET_DECL_ASSEMBLER_NAME (init_decl, init_name);
-  TREE_STATIC (init_decl) = 1;
-  current_function_decl = init_decl;
-  DECL_RESULT (init_decl) = build_decl(RESULT_DECL, NULL_TREE, void_type_node);
-  /*  DECL_EXTERNAL (init_decl) = 1;*/
-  TREE_PUBLIC (init_decl) = 1;
-  pushlevel (0);
-  make_decl_rtl (init_decl, NULL);
-  init_function_start (init_decl, input_filename, 0);
-  expand_function_start (init_decl, 0);
-
-  for ( t = registered_class; t; t = TREE_CHAIN (t))
-    emit_library_call (registerClass_libfunc, 0, VOIDmode, 1,
-		       XEXP (DECL_RTL (t), 0), Pmode);
-
-  expand_function_end (input_filename, 0, 0);
-  poplevel (1, 0, 1);
-  { 
-    /* Force generation, even with -O3 or deeper. Gross hack. FIXME */
-    int saved_flag = flag_inline_functions;
-    flag_inline_functions = 0;	
-    rest_of_compilation (init_decl);
-    flag_inline_functions = saved_flag;
-  }
-  current_function_decl = NULL_TREE;
-  assemble_constructor (XEXP (DECL_RTL (init_decl), 0), DEFAULT_INIT_PRIORITY);
+  if (SUPPORTS_WEAK && targetm.have_named_sections)
+    {
+      tree t;
+      for ( t = registered_class; t; t = TREE_CHAIN (t))
+	assemble_jcr (XEXP (DECL_RTL (t), 0), 0);
+    }
+  else
+    {
+      extern tree get_file_function_name PARAMS ((int));
+      tree init_name = get_file_function_name ('I');
+      tree init_type = build_function_type (void_type_node, end_params_node);
+      tree init_decl;
+      tree t;
+      
+      init_decl = build_decl (FUNCTION_DECL, init_name, init_type);
+      SET_DECL_ASSEMBLER_NAME (init_decl, init_name);
+      TREE_STATIC (init_decl) = 1;
+      current_function_decl = init_decl;
+      DECL_RESULT (init_decl) = build_decl(RESULT_DECL, NULL_TREE, void_type_node);
+      /*  DECL_EXTERNAL (init_decl) = 1;*/
+      TREE_PUBLIC (init_decl) = 1;
+      pushlevel (0);
+      make_decl_rtl (init_decl, NULL);
+      init_function_start (init_decl, input_filename, 0);
+      expand_function_start (init_decl, 0);
+      
+      for ( t = registered_class; t; t = TREE_CHAIN (t))
+	emit_library_call (registerClass_libfunc, 0, VOIDmode, 1,
+			   XEXP (DECL_RTL (t), 0), Pmode);
+      
+      expand_function_end (input_filename, 0, 0);
+      poplevel (1, 0, 1);
+      { 
+	/* Force generation, even with -O3 or deeper. Gross hack. FIXME */
+	int saved_flag = flag_inline_functions;
+	flag_inline_functions = 0;	
+	rest_of_compilation (init_decl);
+	flag_inline_functions = saved_flag;
+      }
+      current_function_decl = NULL_TREE;
+      assemble_constructor (XEXP (DECL_RTL (init_decl), 0), DEFAULT_INIT_PRIORITY);
+    }
 }
 
 void


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