简体   繁体   English

如果一个类是由不同的类加载器加载的,那么(sun-jvm)热点优化会发生多次吗?

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

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. 容器应用有一个-say-根类加载器。 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 eg class A. Therefore permspace will be filled twice: once for sub-application #1 and once for sub-app #2. 一些子应用程序使用相同的类,但是它们不是由容器的类加载器加载的,因此每个子应用程序(更好的是它的类加载器)加载例如A类的代码。因此,永久空间将被填充两次:一次用于子应用程序#1,一次用于子应用程序#2。

What does this mean for sun's hot-spot optimization? 这对于s​​un的热点优化意味着什么?
Will the same optimizations occur twice on class A, once for each class-loader? 是否会对A类进行两次相同的优化,对于每个类加载器一次?
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 我指的是JDK 1.6附带的Sun(Server)VM

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. 到Java命令行并执行您的应用程序。 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. 这将向您显示所有类加载事件。

It must. 它必须。 There is no guarantee that the 2nd classloader loaded the same bytecode as the 1st classloader. 不能保证第二类加载器加载与第一类加载器相同的字节码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM