[lworld] RFR: 8280382: [lworld] JCWithField AST node support should evolve to work with value classes

Srikanth Adayapalam sadayapalam at openjdk.java.net
Fri Jan 28 11:54:26 UTC 2022


On Fri, 28 Jan 2022 10:19:52 GMT, Aggelos Biboudis <duke at openjdk.java.net> wrote:

>>> You are right. The idea behind it was that I was getting a null reference exception on the subtype check. `t.referenceProjection()` was returning `null` and it was blowing up on the `t.equalsIgnoreMetadata(s)`. The triggering code was something like the following (so the reference projection of `o` was `null`).
>>> 
>>> ```
>>> value static final class V {}
>>> 
>>> Object o = V.default;
>>> ```
>>> 
>>> What do you think?
>> 
>> If this probem is still persisting, I suggest we raise a separate ticket for it. I don't know what is going on there, but can take a look and share observations on a separate task basis.
>
> It was only introduced only after changing the lines 608 and 609 above, so it feels related to this change:
> 
>> https://github.com/openjdk/valhalla/pull/621/files/e0f302f20eacdbb796d03240b5b727ce053ed451#diff-244efd7111106b403c989b25a6d0c719dcb15d44892320cfdc6056a418defb21L608-L609

But those lines need not change at all. The original code in com.sun.tools.javac.code.Types#isConvertible(com.sun.tools.javac.code.Type, com.sun.tools.javac.code.Type, com.sun.tools.javac.util.Warner) viz:

boolean tValue = t.isPrimitiveClass();
        boolean sValue = s.isPrimitiveClass();
        if (tValue != sValue) {
            return tValue ?
                    isSubtype(t.referenceProjection(), s) :
                    !t.hasTag(BOT) && isSubtype(t, s.referenceProjection());
        }

is necessitated by the fact that in the language model a primitive class is an island. Even though Point may be declared to be:

primitive class Point extends Object {}

asSuper(Point, Object) would return null meaning Point is not a subclass of Object. We bend over backwards maintaining this isolated world view of primitive classes to make it analogous to how int is not a subtype of Object, but is convertible to Integer which is a subtype of Object. Likewise Point is not a subtype of Object, but is convertible to Point.ref and Point.ref is a subtype of Object.

So is Point convertible to Object ? Yes, not because it is a subtype of Object, but because it can be converted to Point.ref and Point.ref is a subtype of Object.

This is the dance that is being done in the code above. This code should not and need not change at all for the present topic at hand.

-------------

PR: https://git.openjdk.java.net/valhalla/pull/621



More information about the valhalla-dev mailing list