Using Array.newInstance still generates checkcast instructions

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


On Oct 28, 2015, at 12:54 PM, Vitaly Davidovich <vitalyd at gmail.com> 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.

YMMV

— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20151028/84b21e50/attachment-0001.html>


More information about the hotspot-compiler-dev mailing list