JVM JIT diagnostic tools and optimization tips

I heard a lot about what the JVM JIT can do, but I don’t see much information about how to profile what JIT really does in this run of your program. There are many tips for using -XX:+PrintCompilation and -XX:+PrintOptoAssembly , but this leads to really low-level information that is difficult to interpret.

In general, during optimization, I like to have a standard set of common operations with allocated JIT warm-up time, etc., but I would like to see which optimizations actually fire my code. Perhaps my JVM considered the question of a specific method call, but something about this decided not to, or maybe the JIT was unable to avoid checking the bounds of the array in my loops, because I formulated my invariants and loop conditions too vaguely. I would expect a tool like YourKit to support some form of β€œwhat's happening with JIT”, but I could not find support for this in YourKit or elsewhere.

Ideally, I would just like to dump the brain of what the JIT optimizer thinks during the launch of my program. Let's say I warmed up my function, and decided to embed the three methods in my inner loop and split the loop into three sections without checking the boundaries of the boundaries in the middle part, I would like to generalize these decisions and the motivation for them.

Did I miss something obvious here? What do JVM-enabled programmers do when optimizing hard inner loops to figure out what is going on? Of course, low-level flags -XX may not be the only option, right? I would appreciate how best to deal with this kind of low-level material on the JVM. And no, this question is not motivated by premature optimization! :)

Edit: I think some of what I need is given -XX:+LogCompilation , but I'm still wondering if people have general tips and tools for this kind of action.

+6
source share
1 answer

If you need a dump for the brain, you can print the resulting assembly code, but this is much lower than what you already have. I suspect that what you are looking for does not exist for the HotSpot JVM. I saw a presentation for something similar based on JRockit, and maybe this will make it in HotSpot one day.

Did I miss something obvious here? What do JVM-enabled programmers do when optimizing hard inner loops to figure out what is going on?

I usually like to minimize garbage production, and it usually does pretty well. for example, for delays of a few seconds.

Such micro-optimization really requires a deep understanding of machine code and how processors work.

Of course, low-level flags -XX may not be the only option, can they?

If only where it is simple, it is much more complicated. To dump machine code, you need an additional native library that does not come with the JVM .;)

I would be grateful for the best way to deal with such low-level material on the JVM.

It seems that you really do not want to work at a low level, if you can avoid this, and I think that this is good, first you need to take care of the high level, because micro-optimization is good for micro, but rarely suitable for real applications, because you need to understand all the delays of your final system, and this can be done without even looking at the code in many cases. that is, the main delay in your database, OS, disk, or network IO.

I’m still wondering if people have general tips and tools for this kind of activity.

Use a profiler, and if you suspect that you need to go lower, it is likely that you missed something much more important.

+3
source

Source: https://habr.com/ru/post/943795/


All Articles