Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 82 inside the jvm System out println sum The HotSpot JVM is able to eliminate the inner nested lock so the code will efectively become this for int i 0 i 1_ 000_ 000 i synchronized lock sum random nextInt sum random nextInt The nested lock optimization is enabled by default but can be disabled using the VM switch XX EliminateNestedLocks Arrays and Escape Analysis Escape analysis like other optimizations is subject to trade ofs because every allocation not made on the heap must happen somewhere on the stack or in CPU registers both of which are relatively scarce resources One limitation in the HotSpot JVM is that by default arrays of more than 64 elements will not benefit from escape analysis This size is controlled by the VM switch XX EliminateAllocationArraySizeLimit n where n is the number of elements Consider a hot code path that contains a temporary array allocation to read from a buffer If the array does not escape the method scope escape analysis should prevent the heap allocation However if the array length is more than 64 elements even if they are not all used it must be stored on the heap This restores the heap allocation and defeats escape analysis for the array
You must have JavaScript enabled to view digital editions.