Does (sun-jvm) hotspot optimization take place multiple times, if a class is loaded by different classloaders?

StackOverflow https://stackoverflow.com/questions/3788875

  •  05-10-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top