30 Eylül 2021 Perşembe

Just In Time Compilation - JIT Çıktısını Görmek

Giriş
JIT çalışırken bazı çıktıları görebilmek mümkün. Bu çıktılar için eğer JVM yerel makinede çalışıyorsa farklı uzak makinede çalışıyorsa farklı seçenekler kullanılır

Yerel Makine
PrintCompilation Seçeneği
Açıklaması şöyle
By setting the flag -XX:+PrintCompilation we can enable some simple output regarding the bytecode to native code compilation.
Whenever a method is compiled, a line is printed to the output. Each line consists of (1) a number of milliseconds since VM started, (2) order in which method/code block is compiled, (3) compilation level cache, (4) method name.
Örnek
JIT olan kodu görmek için şöyle yaparız.
java -XX:+PrintCompilation Main
Çıktı olarak şunu alırız. Buradaki 3. sütun önemli, çünkü Compilation Level Cache değerini göster. Bu sütunda 1,2,3,4 sayıları yazar
val 1       
val 2
val 3
...
922  315    3    src.main.BasicHolder::getInstance (4 bytes)   # Method compiled
922  316    3    src.main.BasicHolder::getVALUE    (4 bytes)   # Method compiled
...
val 1563    
val 1563
val 1563
val 1563
...
2. Sütun Code Cache Durumu
Açıklaması şöyle. Yani ikinci sütunda bazen % işareti de bulunur. Yukarıdaki örnekte yok gerçi. Bu işaret kodun Code Cache içinde olduğunu gösterir.
... you can see in the 2nd column, and there is the percentage(%) symbol in front of some code blocks. That means those code blocks are in the code cache. 
3. Sütun JIT Durumu
Buradaki 3. sütun önemli. Bu sütunda 0,1,2,3,4 sayıları yazar. Açıklaması şöyle. 1,2,3 ise C1 tarafından JIT yapılmıştır. C4 ise C2 tarafından JIT yapılmıştır
In the 3rd column, you can see the stages of the code block's compilation process. Some are in level 0, which are not compiled by the JIT compiler. That means code blocks that are not re-occurred. Some code blocks are in levels 1,2, and 3, which are compiled by the C1 compiler, and some are in level 4, which are compiled by the C2 compiler.
Uzak Makine
Açıklaması şöyle
If you want to see the same information on some remote machine where you cannot see the console output you can use the following command:

java -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation <class name>

which will produce log file with compilation results in it.
Açıklaması şöyle-XX:+UnlockDiagnosticVMOptions ve -XX:+PrintInlining seçenekleri kullanılabilir.
You can enable a lot of debug information about how the compiler decides what to do with your code using feature flags like -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining

Hiç yorum yok:

Yorum Gönder