Status of array covariance in lworld branch
Harold David Seigel
harold.seigel at oracle.com
Wed Dec 12 13:56:37 UTC 2018
Hi Ioi,
Fwiw, the verifier does not complain about, for example, this line:
"Object oa2[] = va;" because it just checks that the aload loads a
non-primitive and the following astore stores a non-primitive.
If your example tried to pass "V va[]" to a function expecting "Object
oa[]", then a VerifyError exception will get thrown because a verifier
assignability check is done in that case.
Harold
On 12/11/2018 7:02 PM, 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