Java Magazine, Mar/Apr 2018
ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 77 inside the jvm If this were the whole story it would seem that the feature of allocation elimination is extremely limited Fortunately the Java HotSpot VM can do better than this Lets look at the detail of the bytecode and see what can be observed The method sameArea is both small 17 bytes of bytecode and frequently called in the example thereby making it an ideal candidate to be inlined public boolean sameArea Rect Code 0 aload_ 0 1 invokevirtual 4 Method area I 4 aload_ 1 5 invokevirtual 4 Method area I 8 if_ icmpne 15 11 iconst_ 1 12 goto 16 15 iconst_ 0 16 ireturn The method makes two further calls to another easily inlineable method area public int area Code 0 aload_ 0 1 getfield 2 Field w I 4 aload_ 0 5 getfield 3 Field h I 8 imul 9 ireturn Using JITWatch or PrintCompilation you can see that the calls to area are indeed inlined into their caller sameArea and that method is inlined into its callsite in the loop body of the main
You must have JavaScript enabled to view digital editions.