Java Magazine, Mar/Apr 2018
ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 78 inside the jvm method JITWatch provides a useful graphical representation of which methods will be inlined illustrated in Figure 1 which due to its size is available only online Remember that the order in which the Java HotSpot VM applies its JIT compiler optimizations is important Method inlining is one of the first optimizations and is known as a gateway optimization because it opens the door to other techniques by first bringing related code closer together Now that the call to sameArea and the calls to area have been inlined the method scopes no longer exist and the variables are present only in the scope of main This means that EA will no longer treat either r1 or r2 as an ArgEscape both are now classified as a NoEscape after the methods have been fully inlined This might seem like a counterintuitive result but you need to bear in mind that the original source code is not what the JIT compiler will use as a starting point Without this knowledge its easy to draw the wrong conclusion about what is eligible for EA In the previous example both of these object allocations can avoid using the heap and instead their fields will be treated as individual values The register allocator will normally place the broken up object fields directly into registers but if not enough free registers are available the remaining fields will be placed on the stack This situation is known as a stack spill To illustrate the power of eliminating heap allocations inside tight loops of code run this program with and without EA enabled and inspect the activity of the garbage collector Because EA is enabled by default in modern JVMs to do this you need to disable EA by using the JVM switch XX DoEscapeAnalysis Here is the garbage collection log with EA enabled with some extraneous detail removed java XX PrintGCDetails Rect Same area 18073993 Heap PSYoungGen total 95744K used 13462K eden space 82432K 16 used from space 13312K 0 used
You must have JavaScript enabled to view digital editions.