[lworld] RFR: 8282107: Valhalla: javac does not correctly recognize value class factory <init>
Srikanth Adayapalam
sadayapalam at openjdk.java.net
Wed Mar 2 10:00:35 UTC 2022
On Wed, 2 Mar 2022 09:47:52 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:
> Cope with the ill effects of javac downgrading the value class file at lower source levels leaving fuller treatment to JDK-8282525
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java line 1010:
> 1008: if (sym.kind == MTH && sym.type.getThrownTypes().isEmpty())
> 1009: sym.type.asMethodType().thrown = thrown;
> 1010: // Map value class factory methods back to constructors for the benefit of earlier pipeline stages
At source levels less than the one where the value class feature is supported, javac incorrectly downgrades a value class to an ordinary class. (See the method com.sun.tools.javac.jvm.ClassReader#adjustClassFlags which internalizes the flags from a class file's header). As a result isValueClass returns false and we don't restore the correct return type of the constructor. This leads to the present problem. The present fix works around by not relying on isValueClass - the only instance where a constructor may have a non-Void return is the case of value class factory, so the check is redundant.
https://bugs.openjdk.java.net/browse/JDK-8282525 has been raised for a fuller fix.
A nuance for the reviewers: Source level constructors are lowered into static factory methods late in the pipeline stage and are remapped into constructors when read from class files - this is so as to minimize the changes to the compiler. Rather than know and deal with an entity called static value factory methods, most of the compiler simply works with constructors.
-------------
PR: https://git.openjdk.java.net/valhalla/pull/661
More information about the valhalla-dev
mailing list