tags:

views:

36

answers:

2

Hi all,

imagine a (container-) application is creating multiple classloaders to host a couple of other/sub- applications.

There is a -say- root classloader for the container app. Each time a sub-application is loaded, the container creates a new classloader for this application.

Some sub-applications use the same classes, but they were not loaded by the container's classloader, so each sub-application (better: its classloader) loads the code for e.g. class A. Therefore permspace will be filled twice: once for sub-application #1 and once for sub-app #2.

What does this mean for sun's hot-spot optimization?
Will the same optimizations occur twice on class A, once for each class-loader?
Or, is there some "magic" built-in which avoids this? (Optimizations done once)
Somebody knows a link, were this is explained?

I am referring to a sun (server) vm shipping with jdk 1.6

A: 

I don't have any literature that I can point you to in order to prove this, but I can tell you from experience that if your classes are being re-loaded, your methods will be re-compiled and re-optimized. You can observe this by adding:

-XX:+PrintCompilation

to the Java command line and execute your app. This will tell you exactly what methods are being compiled. If you see the same method output twice, you know it's being re-compiled. If you aren't sure that your classes are being re-loaded, add:

-verbose:class

as well. This will show you all class load events.

Amir Afghani
Thank you for answering - I lack your experience :). However I'll try out the jvm switches you provided.
Martin
Using these switches you could make your own test to check the behavior of HotSpot. And please, report back with your findings! ;-)
Neeme Praks
@Neeme: Guess what? I did! I created a blog! See: http://growninthewild.blogspot.com/2010/09/java-virtual-machine-hotspot.html
Martin
Nice! You misspelled my name, though. :-P
Neeme Praks
A: 

It must. There is no guarantee that the 2nd classloader loaded the same bytecode as the 1st classloader.

EJP