Using Array.newInstance still generates checkcast instructions

John Rose john.r.rose at
Wed Oct 28 19:40:27 UTC 2015

On Oct 27, 2015, at 11:14 AM, Vitaly Davidovich <vitalyd at> wrote:
> Here's the basic example I used earlier, a bit more spelled out + assembly:

(This is going back several years.)  Look at the code in Arrays.copyOfRange.
Note how the call to Array.newInstance is passed newType.getComponentType.
That part is important.  The C2 intrinsic only optimizes the case where the ARRAY
Class is available, not the ELEMENT Class.  Try re-doing your experiment by
reifying the T[] type, not the T (element) type.  Make sure your use of
Array.newInstance takes its metadata from a call to getComponentType.

Perhaps this could be upgraded; maybe it is time to.  The old code shape
is designed for the case where constant folding is infrequent, and the
dynamic (non-constant) version works best when you start with the T[] type.

— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the hotspot-compiler-dev mailing list