[lworld] RFR: JDK-8251986: [lworld] implement Class::valueType and Class::referenceType in Java

Roger Riggs rriggs at openjdk.java.net
Wed Aug 19 19:53:09 UTC 2020


On Tue, 18 Aug 2020 19:47:36 GMT, Mandy Chung <mchung at openjdk.org> wrote:

> Now that javac generates the reference projection class as a sealed type,
> this patch reimplements  `Class::valueType` and `Class::referenceType` in Java.
> VM no longer has any knowledge of the value projection type and reference projection type.
> 
> This patch includes a temporary workaround to disable the preview feature check
> for sealed types because inline types are not (yet) a preview feature in valhalla repo.
> This workaround should be removed when it's time to make inline class a preview feature.

src/java.base/share/classes/java/lang/Class.java line 605:

> 604:         ensureProjectionTypesInited();
> 605:         System.out.println(getName() + " " + Arrays.toString(projectionTypes));
> 606:         return projectionTypes.length == 2 ? Optional.of(projectionTypes[1]) : Optional.empty();

Remove the println.

src/java.base/share/classes/java/lang/Class.java line 584:

> 583:         ensureProjectionTypesInited();
> 584:         System.out.println(getName() + " " + Arrays.toString(projectionTypes));
> 585:         return projectionTypes.length > 0 ? Optional.of(projectionTypes[0]) : Optional.empty();

println?

src/java.base/share/classes/java/lang/Class.java line 659:

> 658:         String[] subclassNames = getPermittedSubclasses0();
> 659:         System.out.println(getName() + " permits " + Arrays.toString(subclassNames));
> 660:         if (subclassNames.length == 1) {

Debug println().

src/java.base/share/classes/java/lang/Class.java line 661:

> 660:         if (subclassNames.length == 1) {
> 661:             String cn = subclassNames[0].replace('/', '.');
> 662:             int index = cn.lastIndexOf('.');

String.regionMatches() could be used to compare the substrings without making copies and it should be ok to compare the
package names without translating '/' to '.'.

src/java.base/share/classes/java/lang/Class.java line 650:

> 649:
> 650:         return valueProjectionType() != null;
> 651:     }

This path computed the valueProjecttionType and then discards it to be computed again on line 631.

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

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


More information about the valhalla-dev mailing list