Status of array covariance in lworld branch

David Simms david.simms at oracle.com
Wed Dec 12 07:39:08 UTC 2018


LW2 plan was indeed, LFoo[] <: Object[], but not for QFoo[], but 
arraycopy works...

This results in a fairly horrid user model (IMO), prim example being 
j.u.Arrays and need to arraycopy to use it.

Counter proposals to enable better use, i.e. Array interface seems a 
little too far (i.e. Arrays 2.0 alpha)...Brian hinted at the last 
meeting that full covariance between ltype[] and qtype[] is not ruled out...

So it's totally fine for example if C2 keeps it's rather complex code 
for supporting full covariance support, we may through a switch around 
it...same goes for any other previous code investments.

/D

On 12/12/2018 1:02 AM, Ioi Lam wrote:
> As far as I understand, the plan is to not support covariance between 
> Object and value arrays. So I wrote a test case to see what's the 
> current behavior. Can anyone tell me if my understanding is correct?
>
>
> import java.util.Arrays;
>
> public class Test {
>     static final value class V {
>         public final int v1;
>         private V () {v1 = 0;}
>     }
>
>     public static void main(String args[]) {
>         Object oa[] = new Object[1];
>         oa[0] = V.default;
>         V va[] = new V[1];
>         va[0] = V.default;
>
>         System.out.println("Object[].class.isInstance(va) = " +
>                             Object[].class.isInstance(va));
>
>         Object oa2[] = va;    // <-- javac should reject, but doesn't
>         va = (V[])oa2;        // <-- javac should reject(?), but doesn't
>
>         V[] va2 = Arrays.copyOf(oa, oa.length, V[].class);
>         System.out.println("va  = " + va);
>         System.out.println("va2 = " + va2);
>     }
> }
>
>
> $ java -cp . -XX:+EnableValhalla Test
> Object[].class.isInstance(va) = true  // should be false
> va  = [QTest$V;@372f7a8d
> va2 = [QTest$V;@2f92e0f4        // should be [LObject;
>
>
> Thanks
> - Ioi


More information about the valhalla-dev mailing list