escape analysis issue with nested objects
Hontvári Attila
attila at hontvari.net
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.
[1]
http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-January/010933.html
[2] https://gist.github.com/anonymous/bd46075ef1ebd858dae49fe6cfe39da8
More information about the hotspot-compiler-dev
mailing list