force inline in java [duplicate]
I looked at this post. It looks nice. However the authors or other aware people will tell me tricks with coding when HotSpot (does not depend on server or client or not Sun version) makes a code inline.
Don't waste your time on unreasonable optimization. Write you code simple, to make it easy to maintain, and let the JIT take care of optimization.
javac
almost never inline anything (which is good). JVM does it often (which is very good). Algorithms to determine when and how to do what optimization by JIT is a rocket science. Don't try to make your code smarter than that.
If you trying to gain performance, then use profiler. If you trying to make your code harder to reverseengineer, use tools like proguard.
I found this link: https://compile-command-annotations.nicoulaj.net/
This library allows you to use annotations on a HotSpot JVM to inline methods.
Thus adding an @Inline
annotation to your method will force inlining.
This is a hotspot specific feature, because Java doesn't allow inlining via the language.
The only other option I can think of is to use compile time annotations and generate the byte code differently (like lombok).
精彩评论