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]

Patch: FYI: class registration cleanup


I'm checking this in.

When I rearranged the internal class cache, I had meant to change how
interpreted classes were registered as well.  Andrew pointed out that
this code was still in there -- causing confusion and inefficiency if
not actual harm.

This cleans up the mess.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* defineclass.cc (handleClassBegin): Use
	_Jv_RegisterInitiatingLoader.
	* java/lang/Class.h (_Jv_UnregisterInitiatingLoader): Declare.
	* java/lang/natVMClassLoader.cc (resolveClass): Don't register
	class.  Use _Jv_UnregisterInitiatingLoader.
	* java/lang/natClassLoader.cc (_Jv_UnregisterInitiatingLoader):
	New function.

Index: defineclass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/defineclass.cc,v
retrieving revision 1.43
diff -u -r1.43 defineclass.cc
--- defineclass.cc 10 Jan 2005 19:39:25 -0000 1.43
+++ defineclass.cc 7 Feb 2005 21:17:09 -0000
@@ -908,16 +908,14 @@
 	throw_no_class_def_found_error ("loading java.lang.Object");
     }
 
-  // In the pre-loading state, it can be looked up in the
-  // cache only by this thread!  This allows the super-class
-  // to include references to this class.
-
   def->state = JV_STATE_PRELOADING;
 
-  {
-    JvSynchronize sync (&java::lang::Class::class$);
-    _Jv_RegisterClass (def);
-  }
+  // Register this class with its defining loader as well (despite the
+  // name of the function we're calling), so that super class lookups
+  // work properly.  If there is an error, our caller will unregister
+  // this class from the class loader.  Also, we don't need to hold a
+  // lock here, as our caller has acquired it.
+  _Jv_RegisterInitiatingLoader (def, def->loader);
 
   if (super_class != 0)
     {
Index: java/lang/Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.76
diff -u -r1.76 Class.h
--- java/lang/Class.h 24 Jan 2005 19:05:34 -0000 1.76
+++ java/lang/Class.h 7 Feb 2005 21:17:09 -0000
@@ -212,6 +212,7 @@
 
 void _Jv_RegisterClassHookDefault (jclass klass);
 void _Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
+void _Jv_UnregisterInitiatingLoader (jclass,java::lang::ClassLoader*);
 void _Jv_UnregisterClass (jclass);
 jclass _Jv_FindClass (_Jv_Utf8Const *name,
 		      java::lang::ClassLoader *loader);
@@ -436,6 +437,7 @@
 					     size_t count);
   friend void ::_Jv_RegisterClassHookDefault (jclass klass);
   friend void ::_Jv_RegisterInitiatingLoader (jclass,java::lang::ClassLoader*);
+  friend void ::_Jv_UnregisterInitiatingLoader (jclass,java::lang::ClassLoader*);
   friend void ::_Jv_UnregisterClass (jclass);
   friend jclass (::_Jv_FindClass) (_Jv_Utf8Const *name,
 				   java::lang::ClassLoader *loader);
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.75
diff -u -r1.75 natClassLoader.cc
--- java/lang/natClassLoader.cc 24 Jan 2005 19:05:34 -0000 1.75
+++ java/lang/natClassLoader.cc 7 Feb 2005 21:17:10 -0000
@@ -110,6 +110,16 @@
   loader->loadedClasses->put(klass->name->toString(), klass);
 }
 
+// If we found an error while defining an interpreted class, we must
+// go back and unregister it.
+void
+_Jv_UnregisterInitiatingLoader (jclass klass, java::lang::ClassLoader *loader)
+{
+  if (! loader)
+    loader = java::lang::ClassLoader::getSystemClassLoader();
+  loader->loadedClasses->remove(klass->name->toString());
+}
+
 // This function is called many times during startup, before main() is
 // run.  At that point in time we know for certain we are running 
 // single-threaded, so we don't need to lock when adding classes to the 
Index: java/lang/natVMClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natVMClassLoader.cc,v
retrieving revision 1.5
diff -u -r1.5 natVMClassLoader.cc
--- java/lang/natVMClassLoader.cc 2 Feb 2005 20:59:41 -0000 1.5
+++ java/lang/natVMClassLoader.cc 7 Feb 2005 21:17:10 -0000
@@ -57,13 +57,8 @@
   jclass klass = VMCompiler::compileClass(loader, name, data,
 					  offset, length, pd);
 
-  if (klass != NULL)
-    {
-      JvSynchronize sync (&java::lang::Class::class$);
-      _Jv_RegisterClass (klass);
-    }
 #ifdef INTERPRETER
-  else
+  if (klass == NULL)
     {
       klass = new java::lang::Class ();
 
@@ -96,7 +91,7 @@
 	  klass->state = JV_STATE_ERROR;
 	  klass->notifyAll ();
 
-	  _Jv_UnregisterClass (klass);
+	  _Jv_UnregisterInitiatingLoader (klass, klass->loader);
 
 	  // If EX is not a ClassNotFoundException, that's ok, because we
 	  // account for the possibility in defineClass().


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