2 Kasım 2021 Salı

Just In Time Compilation - JIT C1 ve C2 Derleyici

Derleyici Seviyeleri
Açıklaması şöyle
C1 compiler is responsible for levels 1, 2, and 3 compilations and optimizations. C2 compiler is responsible for level 4 compilation and optimization.
Eski Kullanım
Açıklaması şöyle. Yani eskiden JDK içinde ya C1 ya da sadece C2 vardı.
During the early days of Java, there were two types of JIT compilers:
  • Client
  • Server

Based on what type of JIT compiler you want to use, appropriate JDKs have to be downloaded and installed. If you are building a desktop application, then JDK with a "client" JIT compiler needs to be downloaded. If you are building a server application, then JDK that has a "server" JIT compiler needs to be downloaded.

Client JIT compiler starts compiling the code as soon as the application starts. Server JIT compiler will observe the code execution for quite some time. Based on the execution knowledge it gains, it will start doing the JIT compilation. Even though server JIT compilation is slow, the code it produces will be far more superior and performant than the one produced by the client JIT compiler.

Today modern JDKs are shipped with both client and server JIT compilers. Both of the compilers try to optimize the application code. During the application startup time, code is compiled using the client JIT compiler. Later as more knowledge is gained, code is compiled using the server JIT compiler. This is called tiered compilation in JVM.

JDK developers were calling them client and server JIT compilers, internally as C1 and C2 compilers. Thus, the threads used by the client JIT compiler are called C1 compiler threads. Threads used by the server JIT compiler are called C2 compiler threads.
JDK içinde artık iki tane derleyici olduğunu belirten bir açıklama şöyle
Additionally, there are two types of compiler optimizations which are part of JDK — a client-side offering (-client), and a VM tuned for server applications (-server). Although the Server and the Client VMs are similar, the Server VM has been specially tuned to maximize peak operating speed. 

The Client VM compiler serves as an upgrade for both the Classic VM and the just-in-time (JIT) compilers used by previous versions of the JDK. The Client VM compiler does not try to execute many of the more complex optimizations performed by the compiler in the Server VM, but in exchange, it requires less time to analyze and compile a piece of code. 

The Server VM contains an advanced adaptive compiler that supports many of the same types of optimizations performed by optimizing C++ compilers, as well as some optimizations that cannot be done by traditional compilers.
Dolayısıyla
-client seçeneği ile C1 Compiler devreye girer ve fazla optimizasyon yapılmaz. 
-server seçeneği ile C2 compiler devreye girer ve daha fazla optimizasyon yapılır.

C2 Neden Hemen Çalışmıyor
Açıklaması şöyle. Amaç uzun vadede kodu gözlemlemek ve en iyi optimizasyonu yapmak
The reason Java does not compile the code at start-up has to do with long-term performance optimisation. By observing the application run and analysing real-time methods invocations and class initialisations, Java compiles frequently called portions of code. It might even make some assumptions based on experience (this portion of code never gets called or this object is always a String).
64 bit HotSpot
Normalde -client seçeneği ile C1 compiler etkinleştirilir. Ancak 64 bit HotSpot  JVM bu seçeneği dikkate almıyor. Kullansak bile bir etkisi olmuyor. Açıklaması şöyle
A 64-bit capable JDK currently ignores this option and instead uses the Java Hotspot Server VM.
Normalde -server seçeneği ile C2 compiler etkinleştirilir.  Ancak 64 bit HotSpot  JVM bu seçeneği kullanmasak bile kendisi örtülü bir şekilde etkinleştiriyor. Açıklaması şöyle
-server

Select the Java HotSpot Server VM. On a 64-bit capable jdk only the Java HotSpot Server VM is supported so the -server option is implicit. This is subject to change in a future release..
Yani neticede  64 bit HotSpot  JVM için ne -client ne de -server seçeneğini kullanmaya gerek yok :)
Bu arada C2 derleyiciyi idame ettirmek bayağı zor deniyor. Açıklaması şöyle
Hotspot is getting old

The JVM traditionally uses the Hotspot JIT compiler, which is made of 2 compilers:
- C1 emits simple native code, but which is still faster than executing bytecode in an interpreter, and
- C2 is a more aggressive compiler that generates better native code based on execution profiles, but it may frequently de-optimize.

C2 is the compiler that gives performance, but it is and older, complex code base written in C++. Very few people on this planet have the ability to maintain it.

Hiç yorum yok:

Yorum Gönder