Using Array.newInstance still generates checkcast instructions

John Rose john.r.rose at
Wed Oct 28 20:51:25 UTC 2015

On Oct 28, 2015, at 12:54 PM, Vitaly Davidovich <vitalyd at> wrote:
> what should my example ArrayList look like

Try changing your ArrayList class constructor:

  -   ArrayList(final Class<T> klass, final int size) {
  -      _items = (T[]) Array.newInstance(klass, size);
  +   ArrayList(final Class<T[]> arrayKlass, final int size) {
  +      _items = (T[]) Array.newInstance(arrayKlass.getComponentType(), size);

That will make the source code shape more like Arrays.copyOfRange, and what the optimizer expects.


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

More information about the hotspot-compiler-dev mailing list