escape analysis issue with nested objects

Hontvári Attila attila at
Thu May 25 16:16:57 UTC 2017

When creating a non-escaping array and putting a newly created, 
non-escaping object in it, the EA works, there are no heap allocations.

     private static void single() {
         Object x = new Object();
         Object[] array = new Object[]{x};
         Object a = array[0];

But if we do the same with two or more objects, the array will be 
allocated on the heap, and not eliminated.

     private static void multi() {
         Object x = new Object();
         Object y = new Object();
         Object[] array = new Object[]{x, y};
         Object a = array[0];
         Object b = array[1];

Is there a reason why it is only working in the first case?

This would be useful for example, MethodHandle::invokeWithArguments, 
when the primitive types are boxed, and put into a varargs array, see my 
older email [1].

A complete test source code is in [2], if we run it with -verbose:gc, we 
can see there are many GCs in the second case, but there are no GCs in 
the first case.



More information about the hotspot-compiler-dev mailing list