Attila Szegedi a écrit :
> No can do. java.lang.ClassLoader has a field named "Vector classes"  
> defined as:
>
>      // The classes loaded by this class loader.  The only purpose of this  
> table
>      // is to keep the classes from being GC'ed until the loader is GC'ed.
>      private Vector classes = new Vector();
>
> It also has a method:
>
>      void addClass(Class c) {
>          classes.addElement(c);
>      }
>
> that is invoked by *native* JVM code to add a class to the class loader  
> when it is loaded. It being package-private method, it can't be overridden  
> outside the package, and you also can't define a new class within  
> java.lang.* package since it is sealed. Oh, and it is also pretty much  
> specific to Sun JRE too :-)
>
> Mind you, it *might* be possible to do horrible hackery, like retrieving  
> the "classes" field through reflection, with Field.setAccessible(false),  
> and then clearing it from time to time. Needless to say, it would *not*  
> work in any sane enterprise scenario when JVM runs under a security  
> manager.
>   
The last time, i've tried a similar trick, the VM crash :)
> The other way to get around this would be to run java with a tampered  
> rt.jar in which ClassLoader.addClass() is modified to be a no-op.
>
> Again, all these solutions either require you to run without a security  
> manager, or assume a Sun JRE, or both.
>
> However, also notice that the "classes" field is only used for the sole  
> purpose of preventing GC of the class. I.e. it is not used by  
> findLoadedClass, which actually delegates to native findLoadedClass0()  
> method, hinting that there's further association of loaded class to its  
> class loader somewhere in JVMs native guts. Meaning it might not be a good  
> idea to try to pull the rug out of it, as it could well be assuming that  
> the classes can't be GCed until the loader can be.
>
> You can say I gave some thought to this idea already :-)
>
> Attila.
>   
Rémi

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to