final methods are inlined?-Collection of common programming errors
As Jon said the inlining is done (when needed) by the JIT compiler not at bytecode generation level. Note also that sometimes inlining can result in a performance degradation because it could create a situation where the same code is present multiple times in the cpu l1 cache, removing space for other code. L1 cache misses can impact the performance more than a jump to a cached function.
Constants (aka final static var) are inlined instead.
See this to check
public class InlineTest {
final static int add(int x, int y) {
return x + y;
}
}
public class Main {
static final int DIVISOR = 7;
static void main(String[] args){
final int a = new Integer(args[0]);
final int b = new Integer(args[1]);
if (InlineTest.add(a, b) % DIVISOR == 0)
System.exit(InlineTest.add(a, b));
System.out.print("The sum is " + InlineTest.add(a, b));
}
}
This is translated in:
0 new #2
3 dup
4 aload_0
5 iconst_0
6 aaload
7 invokespecial #3
10 invokevirtual #4
13 istore_1
14 new #2
17 dup
18 aload_0
19 iconst_1
20 aaload
21 invokespecial #3
24 invokevirtual #4
27 istore_2
28 iload_1
29 iload_2
30 invokestatic #5
33 bipush 7
35 irem
36 ifne 47 (+11)
39 iload_1
40 iload_2
41 invokestatic #5
44 invokestatic #7
47 getstatic #8
50 new #9
53 dup
54 invokespecial #10
57 ldc #11
59 invokevirtual #12
62 iload_1
63 iload_2
64 invokestatic #5
67 invokevirtual #13
70 invokevirtual #14
73 invokevirtual #15
76 return
You can see that static function InlineTest.add has been called multiple times with invokestatic