Let's say I have a code like this:
public class InlineTest {
private String test() {
return "test";
}
public static void main(String[] args) {
System.out.println(
new InlineTest().test()
);
}
}
I know that Java HotSpot is smart enough to inline object creation and method call for new InlineTest().test()
.
However I can't check if the inlining was really applied!
Q 1: Is it possible to verify inlining by inspecting only byte-code? How?
If it is not an option:
Q 2: Are there any other possibilities other than disassembler the code?
PS I have Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
.
Regarding byte code: there is no inlining on the byte code level. Thus nothing that could be observed by de-assembling that byte code.
Regarding the JIT part: see here for example (or theree for IBM java). But you have to understand that such things depend on the version of your JVM; as far as I know, there are no means that you could use to understand for all kinds of JVMs (Oracle, IBM, Azuul, ...) what exactly each implementation is doing under the covers.
And beyond that: keep in mind that the JIT is highly dynamic. It might not inline methods immediately, but maybe at a later point in time. The idea is that the JIT decides based on runtime data what kind of optimizations it is going to apply. The JIT might even come back and re-compile a method when it later finds that there could be a better sequence of machine instructions ...