JIT’s profile artifact jitwatch

brief introduction

It seems that the constant use of command-line tools can't keep up with the pace in modern society, especially when doing JIT analysis, the log output using logcompilation is too large and frightening. Is there any easier way to analyze JIT logs? Come and learn jitwatch with younger martial sister.

What is JIT

Junior sister, senior brother F, JIT is just in time compilers. Can you summarize what JIT does?

Of course, no problem. JIT has two main functions. The first function you should already know is to compile byte code into machine code at run time to improve the execution speed of the program.

The second function is to optimize the code at run time, which also improves the performance.

There are two compilers in JIT. C1 represents client compiler and C2 represents server compiler.

C1 is only a simple compilation, while C2 will conduct more in-depth compilation and optimization after collecting more information.

Common optimization methods include: loop unrolling, inlining, dead code elimination, escape analysis, introduction, branch prediction, etc.

Layered compilation will be started by default in jdk8. You can also use - XX: + tieredcompilation to start it manually.

Introduction to jitwatch

Younger martial sister: Senior brother F, the output results of logcompilation and printcompilation you talked about last time are still too complex, especially logcompilation. The output results are more than ten m, which is very difficult to analyze. Is there a simpler way to double my work efficiency?

This must be, there is a demand, there is a market, there is a demand, there is a great God. Today I'll introduce you to a tool called jitwatch.

Jitwatch is a visual analysis tool for JIT logs made by God. Before using it, you may think it is a little powerful, and after using it, you will think it is really powerful.

Run jitwatch

Younger martial sister: Senior brother F, introduce me to use such a powerful tool.

No problem at all, but jitwatch doesn't have a ready-made packaged executable. Yes, you need to download the source code from GitHub.

After downloading, you can execute:

mvn clean compile test exec:java

You can start the jitwatch journey.

Jitwatch details

Younger martial sister: Senior brother F, why don't you pack such a useful tool for everyone to use directly? It's so troublesome to download the source code.

Actually, jitwatch comes with one for your convenience Sand@R_194_2419 @Function, provides some code that can be run directly in jitwatch, and jitwatch can realize the real-time comparison function of source code. So you need to download the source code.

No gossip, let's start the jitwatch journey.

It's such a simple interface that people always feel a little A heavy sword without a blade is a great skill. The UI made by experts is so perfect.

Next, we need to run a program to feel the charm of jitwatch in real time.

See the top left corner sand@R_194_2419 @Are you ready? Open it and you can see the following sand@R_194_2419 @Page:

This page will select one sad@R_194_2419 @The example in shows you. Pay attention to the description of the output box below, which will show whether your disassembler is available. If you want to install disassembler, please refer to my previous article.

If you are not satisfied with this example, or you want to use your own code, there is no problem at all. Click config.

Here you can configure the path of source code, select the language of VM, and various VM options. I believe I have introduced the following options in previous articles.

If there are other partners who don't understand, wechat me, talk to me privately, 1-on-1 on-site teaching.

Everything is ready. I only owe the east wind. Let's start. I'm the man who wants to be the king of java!

Then we enter the tirview interface. Here we can see that the main interface is divided into three parts: source code, bytecode and assembly.

Younger martial sister: tears are in my eyes. Finally, I don't need to add those XX parameters myself. Interface oriented programming, good.

There are several buttons above. Here is a brief introduction to their functions. There are not screenshots for the specific interface, because there are too many

Chain shows the call chain.

Journal is the XML log generated previously using logcompilation.

LNT, full name is line number table--- At present, I don't know what this is for. If you know, please leave me a message.

Then there is the inline into function. This function needs to be described in detail, because it will affect the execution efficiency of the program.

Remember the example of inline?

int a = 1;
int b = 2;
int result = add(a,b);
...
public int add(int x,int y) { return x + y; }
int result = a + b; //内联替换

The above add method can be simply replaced with an inline expression.

Jitwatch can display whether the method is inlined and the reason for inlined.

Click BCI to display the associated inline code. You can experience it yourself.

Now let's go back to the lovely and stylish homepage:

On the left is the source code, including JDK's own code. If you want to analyze the optimization of JDK's own code in detail, this is a very good tool.

The right shows the JIT compiled classes and methods, and shows the compilation level and compilation time.

There is another row of buttons in the upper right corner. Config is used to configure the running code.

Timeline shows the timeline of JIT compilation in graphical form.

Histo is some compilation information displayed by histogram.

Toplist is the sorting of some objects or data generated during compilation.

Cache is the free code cache space.

Nmethod is a native method.

Threads are JIT compiled threads.

Triview is the panel we first showed.

Finally, let's focus on suggestion:

Suggestions are some optimization suggestions for the code.

From the above figure, we can see that when calling the HashMap method of string, it cannot be inlined because the called method is too large and exceeds the maximum inlining size.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>