question on class loading behavior on array classes

ravenex ravenex at qq.com
Mon Jan 4 03:03:24 PST 2010


Hi all,


Not sure where to ask, not sure if it's a bug or not so I'm seeking for advice here.


According the the JVM spec, 2nd edition, 5.3.3 Creating Array Classes, both the bootstrap class loader and user-defined class loaders can load array classes, and the corresponding class loaders involved are recorded as initiating class loaders.


But starting from JDK 6, Sun's JDK by default doesn't allow array syntax in ClassLoader.loadClass()/ClassLoader.findSystemClass(); array classes couldn't be created by calling defineClass() anyway, so this effectively bans user-defined class loaders to be initiating class loaders for array classes. Calling Class.forName(className, initialize, classLoader) won't record classLoader as an initiating class loader for an array class either.


Is this an intended behavior?


I'm expecting a call to Class.forName() would mark the loader as an initiating one, for all classes (including array classes). That way I won't have to keep a cache of my own in my custom class loader to keep track of what's been loaded already. I read Bug 6500212 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6500212) and know that I shouldn't call ClassLoader.loadClass() with array syntax, so I switched to Class.forName(). But then when my class loader is asked to load the same array class again, it calls findLoadedClass() and gets a null back. That's pretty bad because I don't won't to get down to SystemDictionary::resolve_array_class_or_null() every time I load an array class. That'll force me to use my own cache to record just about the same info as what the VM already has, plus the array classes loaded, which looks like a bad smell to me.


Any help would be grateful.


Thanks in advance,
Raven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/jdk6-dev/attachments/20100104/31deb892/attachment.html 


More information about the jdk6-dev mailing list