Patch: FYI: ClassLoader fix

Tom Tromey tromey@redhat.com
Thu Oct 2 15:15:00 GMT 2003


I'm checking this in on the trunk.

First, we could get an error due to circular initialization at startup
(which isn't the problem per se, but it meant that a static field
wasn't initialized at the point where we needed it to be).  This is
fixed by explicitly initializing ClassLoader during startup.

Second, I changed java.lang.VMClassLoader to look up classes
internally as part of its "bootstrap" operation.  This means that
class loaders with a null parent will continue to work.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* java/lang/VMClassLoader.java (loadClass): Now native.
	* java/lang/natClassLoader.cc (loadClass): Implement.
	* prims.cc (_Jv_RunMain): Initialize ClassLoader.

Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.83
diff -u -r1.83 prims.cc
--- prims.cc 1 Oct 2003 16:22:12 -0000 1.83
+++ prims.cc 2 Oct 2003 14:52:19 -0000
@@ -983,6 +983,12 @@
       arg_vec = JvConvertArgv (argc - 1, argv + 1);
 #endif
 
+      // We have to initialize this fairly early, to avoid circular
+      // class initialization.  In particular we want to start the
+      // initialization of ClassLoader before we start the
+      // initialization of VMClassLoader.
+      _Jv_InitClass (&java::lang::ClassLoader::class$);
+
       using namespace gnu::gcj::runtime;
       if (klass)
 	main_thread = new FirstThread (klass, arg_vec);
Index: java/lang/VMClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/VMClassLoader.java,v
retrieving revision 1.8
diff -u -r1.8 VMClassLoader.java
--- java/lang/VMClassLoader.java 25 Sep 2003 07:46:19 -0000 1.8
+++ java/lang/VMClassLoader.java 2 Oct 2003 14:52:20 -0000
@@ -142,20 +142,14 @@
   /**
    * Helper to load a class from the bootstrap class loader.
    *
-   * In libgcj, this does nothing, as the default system loader knows
-   * how to find classes that have been linked in.
-   *
    * @param name the class name to load
    * @param resolve whether to resolve it
    * @return the class, loaded by the bootstrap classloader or null
    * if the class wasn't found. Returning null is equivalent to throwing
    * a ClassNotFoundException (but a possible performance optimization).
    */
-  static final Class loadClass(String name, boolean resolve)
-    throws ClassNotFoundException
-  {
-    return null;
-  }
+  static final native Class loadClass(String name, boolean resolve)
+    throws ClassNotFoundException;
 
   /**
    * Helper to load a resource from the bootstrap class loader.
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.59
diff -u -r1.59 natClassLoader.cc
--- java/lang/natClassLoader.cc 25 Sep 2003 07:46:19 -0000 1.59
+++ java/lang/natClassLoader.cc 2 Oct 2003 14:52:20 -0000
@@ -136,6 +136,17 @@
   return _Jv_FindClassFromSignature (sig, NULL);
 }
 
+jclass
+java::lang::VMClassLoader::loadClass(jstring name, jboolean resolve)
+{
+  _Jv_Utf8Const *utf = _Jv_makeUtf8Const (name);
+  // FIXME: we culd make _Jv_FindClassFromSignature a template.
+  jclass klass = _Jv_FindClassInCache (utf, NULL);
+  if (klass && resolve)
+    _Jv_InitClass (klass);
+  return klass;
+}
+
 void
 _Jv_WaitForState (jclass klass, int state)
 {



More information about the Java-patches mailing list