开发者

force inline in java [duplicate]

开发者 https://www.devze.com 2023-04-12 08:54 出处:网络
This question already has answers here: Inlining in Java (8 answers开发者_开发百科) Closed 3 years ago.
This question already has answers here: Inlining in Java (8 answers开发者_开发百科) Closed 3 years ago.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消