Should I check the bytecode generated by the java compiler?

No,

>The JIT compiler may "convert" bytecode to something completely different. > It will lead you to premature optimization

yes

>You don't know which methods jit will compile, so it's better if you optimize them. > It will make you a better java programmer

What I'm asking is that I don't really know (obviously) so I'm free to redirect to JIT hyperlinks

Solution

Yes, but in a way - as an educational opportunity, it's good to see what's going on behind the scenes, but maybe it should be done moderately

This may be a good thing, because looking at bytecode may help you understand how to compile java source code into Java bytecode In addition, it may give some ideas about what optimizations the compiler will perform and some limitations on the amount of optimizations the compiler can perform

For example, if you perform string concatenation, javac optimizes the concatenation to use StringBuilder and executes an append method to concatenate strings

However, if string concatenation is performed in the loop, a new StringBuilder can be instantiated at each iteration, which may lead to performance degradation compared with manually instantiating StringBuilder outside the loop and performing append only inside the loop

Questions about JIT Just in time compilation will be specific to the JVM implementation, so it is not easy to find out what actually happens to bytecode when converting bytecode to native code. Moreover, we can't tell which parts are JIT (at least there are no JVM specific tools to see what JIT compilation is being performed - I don't know any details in this field, so I'm just guessing.)

That is, in any case, the JVM will execute bytecode in a way that is more or less opaque to developers and is also unique to the JVM One JVM may perform some performance tricks, while the other does not

When it comes to viewing the generated bytecode, it boils down to what actually happens when learning the source code when compiling into bytecode You can see various optimizations performed by the compiler, but you can also understand that there are limited ways in which the compiler can perform optimizations

All in all, I don't think it's a good idea to be allergic to bytecode generation and try to write a program that will emit optimized bytecode More importantly, write java source code that others can read and maintain

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
分享
二维码
< <上一篇
下一篇>>