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]

patches to re-direct _Jv_RegisterClass


This patch allows _Jv_RegisterClass to be bypassed using a "hook function".
What does this mean?  The compiler emits calls to _Jv_RegisterClass or
_Jv_RegisterClasses for each class.  These procedures are executed at
start-up ("static constructor") time, i.e. before main() is executed
in most cases, or when a shared library is loaded by dlopen.  The
functions are responsible for entering the new classes into the global
table of classes used by the system class loader.

I have written a class SharedLibLoader, which is a ClassLoader that
wraps a shared library.  In that case the classes in the shared library
should *not* be in the global class table (as these classes are not loaded
by the system class loader), but instead the classes need to entered
in a table local to the SharedLibLoader.  Hence we need to temporarily
bypass the _Jv_RegisterClass during the dlopen call.

It might be useful to include SharedLibLoader in libgcj, if people
think that would be desirable.

Unless there are objections, I'd like to check this into the trunk,
but not the gcc 3.0.1 branch.

        --Per

        Added a hook to allow class registration to be bypassed.
        * gcj/javaprims.h (_Jv_RegisterClassHook, _Jv_RegisterClassHookDefault):
        Add new declarations.
        * java/lang/Class.h (_Jv_RegisterClassHookDefault):  Add as friend.
        * java/lang/natClassLoader.cc (_Jv_RegisterClassHook):  New static.
        (_Jv_RegisterClasses):  Call (*_Jv_RegisterClassHook).
        (_Jv_RegisterClassHookDefault):  Default for _Jv_RegisterClassHook.

Index: gcj/javaprims.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gcj/javaprims.h,v
retrieving revision 1.22
diff -u -p -r1.22 javaprims.h
--- javaprims.h	2001/05/24 05:40:36	1.22
+++ javaprims.h	2001/06/22 23:26:15
@@ -401,6 +401,8 @@ extern "C" void _Jv_Throw (jthrowable) _
 extern "C" void* _Jv_Malloc (jsize) __attribute__((__malloc__));
 extern "C" void* _Jv_Realloc (void *, jsize);
 extern "C" void _Jv_Free (void*);
+extern void (*_Jv_RegisterClassHook) (jclass cl);
+extern "C" void _Jv_RegisterClassHookDefault (jclass);
 
 typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__)));
 typedef unsigned int _Jv_uint __attribute__((__mode__(__SI__)));
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.34
diff -u -p -r1.34 Class.h
--- Class.h	2001/05/24 05:40:37	1.34
+++ Class.h	2001/06/22 23:26:16
@@ -290,6 +290,7 @@ private:   
 
   friend void _Jv_WaitForState (jclass, int);
   friend void _Jv_RegisterClasses (jclass *classes);
+  friend void _Jv_RegisterClassHookDefault (jclass klass);
   friend void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
   friend void _Jv_UnregisterClass (jclass);
   friend jclass _Jv_FindClass (_Jv_Utf8Const *name,
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.32
diff -u -p -r1.32 natClassLoader.cc
--- natClassLoader.cc	2001/04/28 01:39:15	1.32
+++ natClassLoader.cc	2001/06/22 23:26:16
@@ -437,16 +437,24 @@ _Jv_RegisterClasses (jclass *classes)
   for (; *classes; ++classes)
     {
       jclass klass = *classes;
-      jint hash = HASH_UTF (klass->name);
-      klass->next = loaded_classes[hash];
-      loaded_classes[hash] = klass;
 
+      (*_Jv_RegisterClassHook) (klass);
+
       // registering a compiled class causes
       // it to be immediately "prepared".  
       if (klass->state == JV_STATE_NOTHING)
 	klass->state = JV_STATE_COMPILED;
     }
 }
+
+void _Jv_RegisterClassHookDefault (jclass klass)
+{
+  jint hash = HASH_UTF (klass->name);
+  klass->next = loaded_classes[hash];
+  loaded_classes[hash] = klass;
+}
+
+void (*_Jv_RegisterClassHook) (jclass cl) = _Jv_RegisterClassHookDefault;
 
 void
 _Jv_RegisterClass (jclass klass)

-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


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