On Mon, 2005-07-25 at 18:20 +0200, Mark Wielaard wrote:
> On Mon, 2005-07-25 at 17:55 +0200, Jeroen Frijters wrote:
> > > This won't work if you make the VM_USE_CACHE field static final. Then
> > > the constant will be compiled into ClassLoader making it impossible to
> > > override for the runtime vm-classes later. It has to be a 
> > > static method for that to work.
> > 
> > Like Archie says, your comment doesn't make sense ;-) If a VM decides
> > not to use the cache in ClassLoader, it replaces VMClassLoader and sets
> > the constant to true.
> 
> Yes, but unfortunately that doesn't change the byte-code of the
> ClassLoader class. static final primitive (and String) field values are
> actually inlined into other classes. So you can replace VMClassLoader
> all you want with a version the has VM_USE_CACHE set to another value,
> that won't actually change the ClassLoader code paths unless ClassLoader
> is also recompiled against this new value. Really, try it out. It is an
> annoying byte code optimization. So for things that can be different at
> runtime like the VMClasses you unfortunately cannot use static final
> fields of primitive types.
> 
> > I haven't looked at jdwp yet, but hopefully jdwp will provide its own
> > VM interface instead of messing around with the internals of other
> > classes.
> 
> Yeah that would be the clean way to do it indeed.

Well if it were decided to have some minor changes to allow VM re-use
this is pretty much how I would alter ClassLoader.

We're not ready to use it anyways but I'll put it out there so people
know what would be required.

Aaron
Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.54
diff -u -p -r1.54 ClassLoader.java
--- java/lang/ClassLoader.java	25 Jul 2005 14:28:42 -0000	1.54
+++ java/lang/ClassLoader.java	25 Jul 2005 18:37:38 -0000
@@ -40,6 +40,7 @@ package java.lang;
 
 import gnu.classpath.SystemProperties;
 import gnu.classpath.VMStackWalker;
+import gnu.classpath.jdwp.Jdwp;
 import gnu.java.util.DoubleEnumeration;
 import gnu.java.util.EmptyEnumeration;
 
@@ -152,6 +153,14 @@ public abstract class ClassLoader
    */
   private final boolean initialized;
 
+  /**
+   * This list is kept around for JDWP. We need a way to know every class
+   * that this ClassLoader has been asked to load, thus they will be added
+   * here. There's no need to do anything else, JDWP is able to sniff out
+   * private fields so we'll just sniff this field as well!  
+   */
+  final ArrayList loadRequests = new ArrayList();
+
   static class StaticData
   {
     /**
@@ -333,23 +342,25 @@ public abstract class ClassLoader
 	  {
 	    if (parent == null)
 	      {
-		c = VMClassLoader.loadClass(name, resolve);
-		if (c != null)
-		  return c;
-	      }
-	    else
-	      {
-		return parent.loadClass(name, resolve);
-	      }
-	  }
-	catch (ClassNotFoundException e)
-	  {
-	  }
-	// Still not found, we have to do it ourself.
-	c = findClass(name);
+			c = VMClassLoader.loadClass(name, resolve);
+          }
+        else
+          {
+       		c =  parent.loadClass(name, resolve);
+          }
+       }
+       catch (ClassNotFoundException e)
+         {
+         }
+      // Still not found, we have to do it ourself.
+      if (c == null)
+        c = findClass(name);
       }
+    }
     if (resolve)
       resolveClass(c);
+    if (Jdwp.isDebugging)
+      loadRequests.add(c);
     return c;
   }
 
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to