openjdk 21 分层编译功能验证¶
1.JVM 分层编译参数测试¶
功能基本正常,运行时间关系也基本符合预期,int 纯解释执行性能比分层编译运行效果差很多。
[root@localhost ~]# java -version
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment BiSheng (build 21.0.2+12)
OpenJDK 64-Bit Server VM BiSheng (build 21.0.2+12, mixed mode, sharing)
[root@localhost ~]# cd javatest
[root@localhost javatest]# time java -Xcomp -XX:TieredStopAtLevel=0 -Xmx100m -Xms10m -cp . HotCodeTest
cost:4585ms
real 0m6.076s
user 0m5.024s
sys 0m1.013s
[root@localhost javatest]# time java -Xcomp -XX:TieredStopAtLevel=1 -Xmx100m -Xms10m -cp . HotCodeTest
cost:230ms
real 0m5.947s
user 0m3.573s
sys 0m2.264s
[root@localhost javatest]# time java -Xcomp -XX:TieredStopAtLevel=2 -Xmx100m -Xms10m -cp . HotCodeTest
cost:327ms
real 0m6.393s
user 0m4.110s
sys 0m2.148s
[root@localhost javatest]# time java -Xcomp -XX:TieredStopAtLevel=3 -Xmx100m -Xms10m -cp . HotCodeTest
cost:537ms
real 0m7.839s
user 0m5.306s
sys 0m2.396s
[root@localhost javatest]# time java -Xint -Xmx100m -Xms10m -cp . HotCodeTest
cost:4334ms
real 0m6.083s
user 0m4.792s
sys 0m1.253s
[root@localhost javatest]# time java -Xmixed -Xmx100m -Xms10m -cp . HotCodeTest
cost:72ms
real 0m1.923s
user 0m0.799s
sys 0m1.299s
测试代码
HotCodeTest.java
public class HotCodeTest {
public static void main(String[] args){
nlp();
}
public static void nlp(){
int sum=0;
long start = System.currentTimeMillis();
for(int i=0;i<20000000;i++)
{
sum+=i;
}
long end = System.currentTimeMillis();
System.out.println("cost:" + (end - start) + "ms");
}
}
2.JVM 分层编译状态检查¶
[root@localhost javatest]# java -version
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment BiSheng (build 21.0.2+12)
OpenJDK 64-Bit Server VM BiSheng (build 21.0.2+12, mixed mode, sharing)
[root@localhost javatest]# java -Xint -XX:+CITime -XX:+PrintCompilation -Xmx100m -Xms10m fannkuchredux 10
73196
Pfannkuchen(10) = 38
Individual compiler times (for compiled methods only)
------------------------------------------------
Individual compilation Tier times (for compiled methods only)
------------------------------------------------
Accumulated compiler times
----------------------------------------------------------
Total compilation time : 0.000 s
Standard compilation : 0.000 s, Average : 0.000 s
Bailed out compilation : 0.000 s, Average : 0.000 s
On stack replacement : 0.000 s, Average : 0.000 s
Invalidated : 0.000 s, Average : 0.000 s
Total compiled methods : 0 methods
Standard compilation : 0 methods
On stack replacement : 0 methods
Total compiled bytecodes : 0 bytes
Standard compilation : 0 bytes
On stack replacement : 0 bytes
Average compilation speed : 0 bytes/s
nmethod code size : 0 bytes
nmethod total size : 0 bytes
[root@localhost javatest]# java -Xmixed -XX:+CITime -XX:+PrintCompilation -Xmx100m -Xms10m fannkuchredux 10
1258 1 3 java.lang.Object::<init> (1 bytes)
1339 2 3 java.lang.String::coder (15 bytes)
1411 3 3 java.lang.String::hashCode (60 bytes)
1419 4 3 java.lang.String::length (11 bytes)
1443 7 3 fannkuchredux::nextPermutation (112 bytes)
1444 5 n 0 java.lang.System::arraycopy (native) (static)
1455 8 3 fannkuchredux::countFlips (118 bytes)
1463 6 3 java.lang.Math::max (11 bytes)
1467 9 4 fannkuchredux::countFlips (118 bytes)
1552 12 % 3 fannkuchredux::runTask @ 36 (115 bytes)
1588 8 3 fannkuchredux::countFlips (118 bytes) made not entrant
1591 10 4 fannkuchredux::nextPermutation (112 bytes)
1599 13 3 fannkuchredux::runTask (115 bytes)
1677 7 3 fannkuchredux::nextPermutation (112 bytes) made not entrant
1681 14 % 4 fannkuchredux::runTask @ 36 (115 bytes)
1866 12 % 3 fannkuchredux::runTask @ 36 (115 bytes) made not entrant
1873 15 4 fannkuchredux::runTask (115 bytes)
2479 13 3 fannkuchredux::runTask (115 bytes) made not entrant
2483 11 4 java.lang.Math::max (11 bytes)
2501 6 3 java.lang.Math::max (11 bytes) made not entrant
73196
Pfannkuchen(10) = 38
Individual compiler times (for compiled methods only)
------------------------------------------------
C1 {speed: 6438.726 bytes/s; standard: 0.057 s, 499 bytes, 8 methods; osr: 0.041 s, 137 bytes, 1 methods; nmethods_size: 12104 bytes; nmethods_code_size: 8640 bytes}
C2 {speed: 1090.488 bytes/s; standard: 0.824 s, 745 bytes, 4 methods; osr: 0.185 s, 356 bytes, 1 methods; nmethods_size: 11320 bytes; nmethods_code_size: 6040 bytes}
Individual compilation Tier times (for compiled methods only)
------------------------------------------------
Tier1 {speed: 0.000 bytes/s; standard: 0.000 s, 0 bytes, 0 methods; osr: 0.000 s, 0 bytes, 0 methods; nmethods_size: 0 bytes; nmethods_code_size: 0 bytes}
Tier2 {speed: 0.000 bytes/s; standard: 0.000 s, 0 bytes, 0 methods; osr: 0.000 s, 0 bytes, 0 methods; nmethods_size: 0 bytes; nmethods_code_size: 0 bytes}
Tier3 {speed: 6438.726 bytes/s; standard: 0.057 s, 499 bytes, 8 methods; osr: 0.041 s, 137 bytes, 1 methods; nmethods_size: 12104 bytes; nmethods_code_size: 8640 bytes}
Tier4 {speed: 1090.488 bytes/s; standard: 0.824 s, 745 bytes, 4 methods; osr: 0.185 s, 356 bytes, 1 methods; nmethods_size: 11320 bytes; nmethods_code_size: 6040 bytes}
Accumulated compiler times
----------------------------------------------------------
Total compilation time : 1.108 s
Standard compilation : 0.882 s, Average : 0.073 s
Bailed out compilation : 0.000 s, Average : 0.000 s
On stack replacement : 0.227 s, Average : 0.113 s
Invalidated : 0.000 s, Average : 0.000 s
C1 Compile Time: 0.099 s
Setup time: 0.001 s
Build HIR: 0.029 s
Parse: 0.020 s
Optimize blocks: 0.000 s
GVN: 0.006 s
Null checks elim: 0.001 s
Range checks elim: 0.001 s
Other: 0.001 s
Emit LIR: 0.032 s
LIR Gen: 0.012 s
Linear Scan: 0.020 s
Other: 0.000 s
Code Emission: 0.015 s
Code Installation: 0.020 s
Other: 0.001 s
C2 Compile Time: 1.078 s
Parse: 0.107 s
Optimize: 0.483 s
Escape Analysis: 0.000 s
Conn Graph: 0.000 s
Macro Eliminate: 0.000 s
GVN 1: 0.036 s
Incremental Inline: 0.000 s
IdealLoop: 0.000 s
(IGVN: 0.000 s)
(Inline: 0.000 s)
(Prune Useless: 0.000 s)
Other: 0.000 s
Vector: 0.000 s
Box elimination: 0.000 s
IGVN: 0.000 s
Prune Useless: 0.000 s
Renumber Live: 0.000 s
IdealLoop: 0.379 s
IdealLoop Verify: 0.000 s
Cond Const Prop: 0.009 s
GVN 2: 0.003 s
Macro Expand: 0.009 s
Barrier Expand: 0.000 s
Graph Reshape: 0.004 s
Other: 0.043 s
Matcher: 0.067 s
Scheduler: 0.043 s
Regalloc: 0.266 s
Ctor Chaitin: 0.000 s
Build IFG (virt): 0.004 s
Build IFG (phys): 0.064 s
Compute Liveness: 0.071 s
Regalloc Split: 0.016 s
Postalloc Copy Rem: 0.037 s
Merge multidefs: 0.001 s
Fixup Spills: 0.000 s
Compact: 0.000 s
Coalesce 1: 0.005 s
Coalesce 2: 0.002 s
Coalesce 3: 0.006 s
Cache LRG: 0.001 s
Simplify: 0.015 s
Select: 0.019 s
Other: 0.024 s
Block Ordering: 0.004 s
Peephole: 0.000 s
Code Emission: 0.088 s
Insn Scheduling: 0.008 s
Shorten branches: 0.014 s
Build OOP maps: 0.011 s
Fill buffer: 0.018 s
Code Installation: 0.030 s
Other: 0.008 s
Total compiled methods : 14 methods
Standard compilation : 12 methods
On stack replacement : 2 methods
Total compiled bytecodes : 1737 bytes
Standard compilation : 1244 bytes
On stack replacement : 493 bytes
Average compilation speed : 1567 bytes/s
nmethod code size : 14680 bytes
nmethod total size : 23424 bytes