[英]HotSpot JIT inlining strategy: top-down or down-top
Suppose we have 3 methods: method 2 is called from method 1, method 3 is called from method 2. Methods 2 and 3 are of size 30 bytecodes each. 假设我们有3种方法:从方法1调用方法2,从方法2调用方法3.方法2和3各自大小为30字节码。 Also, suppose for definiteness method 2 is always called from method 1 exactly once, and method 3 is always called from method 2 exaclty once.
另外,假设确定性方法2总是从方法1中恰好调用一次,并且方法3总是从方法2中调用一次。
If method 2 is inlined first, method 3 will be called from the body of method 1 directly, and could be inlined in its turn. 如果方法2首先被内联,则方法3将直接从方法1的主体调用,并且可以依次内联。 If method 3 is inlined into method 2 first, the size of the latter will become about 60 bytecodes, and it couldn't be inlined, because default
MaxInlineSize
threshold is 35 bytecodes. 如果方法3首先内联到方法2中,则后者的大小将变为大约60个字节码,并且无法内联,因为默认的
MaxInlineSize
阈值是35个字节码。
In which order HotSpot JIT inlines methods: top-down or down-top? HotSpot JIT以哪种顺序内联方法:自上而下或下至上?
The MaxInlineSize
affects compilations of methods executed at least one time but less than MinInliningThreshold
times only. MaxInlineSize
影响至少执行一次但小于MinInliningThreshold
次数的方法的编译。 For methods executed more than MinInliningThreshold
there is a different setting -XX:FreqInlineSize=…
having a far bigger (platform dependent) default value. 对于执行超过
MinInliningThreshold
方法,有一个不同的设置-XX:FreqInlineSize=…
具有更大(平台相关)的默认值。 Hotspots are still inlined regardless of the MaxInlineSize
. 无论
MaxInlineSize
如何,热点仍然是内联的。 You may test it by running an application with -XX:+UnlockDiagnosticVMOptions
-XX:+PrintInlining
-XX:MaxInlineSize=0
. 您可以通过使用
-XX:+UnlockDiagnosticVMOptions
运行应用程序来测试它-XX:+UnlockDiagnosticVMOptions
-XX:+PrintInlining
-XX:MaxInlineSize=0
。 It will still report inlining of hot spots (these with the comment “(hot)”). 它仍将报告热点的内联(这些与评论“(热)”)。 Only methods formerly reported as inlined with the comment “executed < MinInliningThreshold times” might then get the comment to “too big”.
只有以前报告为注释“执行<MinInliningThreshold times”的方法可能会使注释“太大”。 If you set down the
FreqInlineSize
you might receive comments like “hot method too big”. 如果您设置
FreqInlineSize
您可能会收到“hot method too big”之类的评论。 I never saw them with the default setting. 我从未在默认设置下看到它们。
Running the below code with the parameters reveals that both methods m3 is inlined first. 使用参数运行以下代码显示两个方法m3首先内联。 i used the following parameters for jvm:
-XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
. 我对jvm使用了以下参数:
-XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
。 Apparenly the method who's first execution count reaches the inlining threshold is inlined first. 首先,内联首先执行计数达到内联阈值的方法。 In our case m3.
在我们的情况下m3。 So for the hotspot i used for testing is down-top as
m3
is first executed and the m2
execution ends. 因此,我用于测试的热点是首先执行
m3
并且m2
执行结束。
Code was run with jdk7_u40 with TieredCompilation disabled, server mode on windows 8 box. 使用jdk7_u40运行代码,禁用TieredCompilation,在Windows 8框上运行服务器模式。 Output of the command was:
该命令的输出是:
@ 66 java.lang.String::indexOfSupplementary (71 bytes) too big
@ 21 methodTest::m3 (31 bytes) inline (hot)
@ 11 methodTest::m2 (35 bytes) inline (hot)
@ 21 methodTest::m3 (31 bytes) inline (hot)
@ 14 methodTest::m1 (25 bytes) inline (hot)
@ 11 methodTest::m2 (35 bytes) inline (hot)
@ 21 methodTest::m3 (31 bytes) inline (hot)
m1
is 25 bytes
in size, m2
is 35 bytes
and m3
has 31 bytes
. m1
大小为25 bytes
, m2
为35 bytes
, m3
为31 bytes
。
public class methodTest {
public static void main(String[] args) {
doTest();
}
int i = 0;
int j = 0;
int k = 0;
private static void doTest() {
methodTest m = new methodTest();
for (int i = 0; i < 1000000000; i++) {
m.m1();
}
System.out.println(m.i);
System.out.println(m.j);
System.out.println(m.k);
}
private void m1() {
i++;
m2();
j++;
}
private void m2() {
i++;
i++;
m3();
j++;
}
private void m3() {
i++;
j++;
k++;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.