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 loader fix


I'm checking this in.

ClassLoaders need to keep a strong reference to the classes they define.
This patch simply pulls in some support for this from Classpath.
A more complete merge of ClassLoader will have to wait for another day.

This fixes the "early gc" class loader bug.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* java/lang/ClassLoader.java (loadedClasses): New field.
	(defineClass): Fixed indentation.  Put new class in
	loadedClasses.
	(findLoadedClass): Implement here.
	* java/lang/natClassLoader.cc (findLoadedClass): Removed.

Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ClassLoader.java,v
retrieving revision 1.21
diff -u -r1.21 ClassLoader.java
--- java/lang/ClassLoader.java 9 Dec 2002 00:03:59 -0000 1.21
+++ java/lang/ClassLoader.java 11 Dec 2002 19:12:17 -0000
@@ -87,6 +87,14 @@
 public abstract class ClassLoader
 {
   /**
+   * All classes loaded by this classloader. VM's may choose to implement
+   * this cache natively; but it is here available for use if necessary. It
+   * is not private in order to allow native code (and trusted subclasses)
+   * access to this field.
+   */
+  final Map loadedClasses = new HashMap();
+
+  /**
    * The desired assertion status of classes loaded by this loader, if not
    * overridden by package or class instructions.
    */
@@ -446,31 +454,32 @@
       throw new java.lang.LinkageError ("class " 
 					+ name 
 					+ " already loaded");
-    
+
     if (protectionDomain == null)
       protectionDomain = defaultProtectionDomain;
 
-    try {
-      // Since we're calling into native code here, 
-      // we better make sure that any generated
-      // exception is to spec!
-
-      return defineClass0 (name, data, off, len, protectionDomain);
-
-    } catch (LinkageError x) {
-      throw x;		// rethrow
-
-    } catch (java.lang.VirtualMachineError x) {
-      throw x;		// rethrow
-
-    } catch (java.lang.Throwable x) {
-      // This should never happen, or we are beyond spec.  
-      
-      throw new InternalError ("Unexpected exception "
-			       + "while defining class "
-			       + name + ": " 
-			       + x.toString ());
-    }
+    try
+      {
+	Class retval = defineClass0 (name, data, off, len, protectionDomain);
+	loadedClasses.put(retval.getName(), retval);
+	return retval;
+      }
+    catch (LinkageError x)
+      {
+	throw x;		// rethrow
+      }
+    catch (java.lang.VirtualMachineError x)
+      {
+	throw x;		// rethrow
+      }
+    catch (java.lang.Throwable x)
+      {
+	// This should never happen, or we are beyond spec.  
+      	throw new InternalError ("Unexpected exception "
+				 + "while defining class "
+				 + name + ": " 
+				 + x.toString ());
+      }
   }
 
   /** This is the entry point of defineClass into the native code */
@@ -722,8 +731,10 @@
    * @param     name  class to find.
    * @return    the class loaded, or null.
    */ 
-  protected final native Class findLoadedClass(String name);
-
+  protected final Class findLoadedClass(String name)
+  {
+    return (Class) loadedClasses.get(name);
+  }
 
   /**
    * Get a resource using the system classloader.
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.54
diff -u -r1.54 natClassLoader.cc
--- java/lang/natClassLoader.cc 11 Dec 2002 03:15:14 -0000 1.54
+++ java/lang/natClassLoader.cc 11 Dec 2002 19:12:17 -0000
@@ -189,12 +189,6 @@
   return _Jv_FindClassFromSignature (sig, NULL);
 }
 
-jclass
-java::lang::ClassLoader::findLoadedClass (jstring name)
-{
-  return _Jv_FindClassInCache (_Jv_makeUtf8Const (name), this);
-}
-
 /** This function does class-preparation for compiled classes.  
     NOTE: It contains replicated functionality from
     _Jv_ResolvePoolEntry, and this is intentional, since that function


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