force inline in java [duplicate]
Asked Answered
A

2

6

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.

Abeabeam answered 12/10, 2011 at 17:41 Comment(2)
Can you add anything to the question that you linked to that changes it in a way that the answers there don't answer your inquiry? If not, then this is simply a duplicate of the other question.Tin
? What is the blame? Sorry, I think I don't understand you in full. It seems to me that your question need more details.Abeabeam
T
11

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.

Thalassic answered 12/10, 2011 at 17:46 Comment(2)
Yeah, I've heard that and I know that. It is pretty good. Thanks to Sun developers. When you work a long time with the casual range of tasks which are aimed to be done with Java Platform, you cannot take care about that. But if you love Java and you are curious or have a task out of the java typical range, you can try to get to know this feature. Eventually, how to do that?Abeabeam
@itun: You should ask: "how to do that in JVM which is produced by XXX and has YYY version?" Whatever XXX and YYY is, I don't know the answer and I don't expect to have to ever know.Liaotung
C
4

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

Corcoran answered 12/6, 2017 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.