Using Array.newInstance still generates checkcast instructions

Vitaly Davidovich vitalyd at
Tue Oct 27 17:23:48 UTC 2015


I (intuitively) thought that using Array.newInstance() and specifying a
final class (e.g. String) would remove checkcasts in the caller.  However,
it appears that the check is still generated (at least on 8u51).  Why would
this be? It seems the JIT should know the true runtime type of the array,
and if accesses to it are inlined, the checkcast could be removed.  Am I
missing something?


public final class ArrayList<T> {
    private final T[] _items;

    public ArrayList(Class<T> klass, int size) {
         _items = (T[])Array.newInstance(klass, size);

    // rest omitted for brevity

    public T get(int index) { return _items[index]; }


ArrayList<String> strings = new ArrayList<>(String.class, 10);
String s = strings.get(0); // why is this checkcast not eliminated?

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

More information about the hotspot-compiler-dev mailing list