The performance of JVM and Java applications of the same version differs by 30% on X86 and aarch64 platforms. Why?

Song Baohua 2021-09-15 09:51:18

Editor's note : At present, many companies use x86 and AArch64 2 A mainstream server . The computational power of these two environments is equal , With the same memory : The same version of JVM and Java application , same JVM Parameters , The performance of application is different in different platforms 30%,x86 Much better than AArch64 platform . This paper analyzes an application in AArch64 Examples of performance degradation on the platform , Find out JVM Of CodeCache Size is the root cause of this performance problem , And then study what leads to... On different platforms CodeCache Different sizes . Finally, the author gives how to set parameters in different platforms to avoid this problem . I hope this article can give readers some enlightenment : When using different hardware platforms, we need to pay attention to the impact of the underlying hardware on the upper application .

The business is in x86 and AArch64 When deployed simultaneously on ( same JDK and Java Application version ), Find out AArch64 Platform performance degradation is a serious problem . Check the log further , Found in AArch64 The following situations happen occasionally in the platform :

This represents JVM Medium CodeCache Full of , Cause compilation to stop , Uncompiled methods can only interpret and execute , This will seriously affect the application performance . What is CodeCache

CodeCache What is it?

Simply speaking ,CodeCache Used to store compiled methods , It is divided into three parts :

  1. Non-nmethods: Include runtime Stub,Adapter etc. ;

  2. Profiled nmethod: Including methods of collecting information , That is... In layered compilation 2、3 Layer method ;

  3. Non-Profiled nmethods: Including methods that do not collect information , That is... In layered compilation 1、4 Layer method , Also include JNI Methods .

notes : Layered compilation refers to JVM At the same time C1 and C2 Two compilers ,C1 Do some simple compilation optimization , Less time consuming ,C2 Do more complex compilation optimization , Good performance , Compilation takes a lot of time . Layered compilation is triggered in JVM It will be triggered according to the corresponding conditions , For more knowledge about layered compilation, you can refer to relevant resources [1].

stay JDK 9 after [2], These will be assigned to different areas ( Advantages of using different areas : lookup 、 Recycling etc. ),JDK 8 Will be assigned to the same area .

JVM I usually clean up some unreachable methods , For example, dead methods due to backoff optimization , in addition UseCodeCacheFlushing Options ( Default on ), It also cleans up older and less executed methods . once CodeCache After full , Will stop compiling , until CodeCache Space available , If closed UseCodeCacheFlushing Options , Will directly and permanently stop compiling .

Different JVM Version and different parameters , default CodeCache Different sizes .JDK 11 Under the default parameters in CodeCache The size is 240M, If you want to get ( confirm ) By default CodeCache size , It is recommended to use - XX:+PrintFlagsFinal Options get ReservedCodeCache Size .

CodeCache The size is mainly adjusted through the following options :

Option Description
InitialCodeCacheSize Initial CodeCache size ( Unit byte )
ReservedCodeCacheSize Reserved CodeCache size , That is, the biggest CodeCache size ( Unit byte )
CodeCacheExpansionSize CodeCache Each expansion size ( Unit byte )

Use –XX:+PrintCodeCache Option to print the... Used by the application CodeCache situation , as follows :

among max_used Indicates... Used in the application CodeCache size , According to this, you can set the appropriate ReservedCodeCacheSize value .

AArch64 vs x86_64

We all know AArch64 and x86 Respectively RISC and CISC framework , Therefore, there are some differences in code density , In this article [3] The size of handwritten assembly under different instruction sets is compared , You can see AArch64 The code density is RISC Better in the architecture , But compared with x86_64 Still a little worse ( among RISC The worst ,m68k best ).

In addition, the author selects java Test Suite dacapo[4] Compare AArch64 and x86_64 Next CodeCache The size of the occupation .

You can see , stay AArch64 Under the architecture ,CodeCache Average ratio x86_64 Be big , But according to different scenarios , The size gap is different , stay 5%-20% Between . So we found the same application in x86 and AArch64 Upper time ,CodeCache The size needs to be adjusted accordingly .

besides , Attention is also needed InlineSmallCode Options ,JVM It's just inline Methods with code volume smaller than this value .JVM adopt inline Can trigger more optimizations , therefore inline It is also important for performance improvement . stay JDK 11 in ,InlineSmallCode stay x86 The default value under is 2000 byte , stay AArch64 The default value under is 2500 byte . and JDK 8 in ,InlineSmallCode stay x86 and AArch64 The default values are 2000 byte . Therefore, it is recommended to modify it during migration InlineSmallCode Value . Business through to CodeCache Adjustment of relevant parameters , Achieve assistance JIT The best compilation effect .

Postscript

If you encounter related technical problems ( Including but not limited to Bi Sheng JDK), You can enter Bisheng JDK Find relevant resources in the community ( Click on the original Enter official website ), Including binary downloads 、 Code warehouse 、 Use teaching 、 install 、 Learning materials, etc . Bi Sheng JDK The community holds regular technical meetings every two weeks on Tuesdays , At the same time, there is a technical exchange group to discuss GCC、LLVM、JDK and V8 And other related compilation techniques , Interested students can add the following wechat assistant , reply Compiler The group of .

Reference resources

[1]http://cr.openjdk.java.net/~thartmann/talks/2017-hotspot_under_the_hood.pdf

[2]https://bugs.openjdk.java.net/browse/jdk-8015774

[3]http://web.eece.maine.edu/~vweaver/papers/iccd09/ll_document.pdf

[4]http://dacapobench.org/

Please bring the original link to reprint ,thank
Similar articles

2021-09-15

2021-09-15