classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Infinite loop


From: Archie Cobbs
Subject: Re: Infinite loop
Date: Wed, 09 Nov 2005 11:46:06 -0600
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

Jeroen Frijters wrote:
The infinite loop is simple:

Class.getClassLoader() invokes VMStackWalker.getCallingClassLoader() VMStackWalker.getCallingClassLoader() invokes Class.getClassLoader()

It would be nice if VMStackWalker.getCallingClassLoader() could
invoke VMClass.getClassLoader(), but access permissions prevent that.

Any ideas? One idea is to move VMStackWalker into java.lang.

We can't do that, it needs to be public. I guess that VMStackWalker
should have a native method to get the class loader from a Class.

Sounds good.. how about this?

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
Index: VMStackWalker.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/vm/reference/gnu/classpath/VMStackWalker.java,v
retrieving revision 1.5
diff -u -r1.5 VMStackWalker.java
--- VMStackWalker.java  2 Jul 2005 20:33:08 -0000       1.5
+++ VMStackWalker.java  9 Nov 2005 17:44:29 -0000
@@ -88,9 +88,9 @@
 
   /**
    * Get the class loader associated with the Class returned by
-   * <code>getCallingClass()</code>, or <code>null</code> if no
-   * such class exists or it is the boot loader. This method is an optimization
-   * for the expression <code>getClassContext()[1].getClassLoader()</code>
+   * <code>getCallingClass()</code>, or <code>null</code> if no such class
+   * exists or it is the boot loader. This method is an optimization for the
+   * expression <code>VMStackWalker.getClassLoader(getClassContext()[1])</code>
    * and should return the same result.
    *
    * <p>
@@ -102,7 +102,15 @@
     Class[] ctx = getClassContext();
     if (ctx.length < 3)
       return null;
-    return ctx[2].getClassLoader();
+    return getClassLoader(ctx[2]);
   }
+
+  /**
+   * Retrieve the class's ClassLoader, or <code>null</code> if loaded
+   * by the bootstrap loader. I.e., this should return the same thing
+   * as address@hidden java.lang.VMClass#getClassLoader}. This duplicate 
version
+   * is here to work around access permissions.
+   */
+  public static native ClassLoader getClassLoader(Class cl);
 }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]