java.lang.constant.ClassDesc and TypeDescriptor for hidden class??
Mandy Chung
mandy.chung at oracle.com
Thu Apr 2 00:09:00 UTC 2020
Hi Brian, et al,
Class is a Constable. So a Class object for a hidden class can be asked
to yield a ConstantDesc for the hidden class via
Class::describeConstable. It can also be asked to get the type
descriptor string for the hidden class via Class:descriptorString.
A hidden class has no binary name. It cannot be referenced by other
classes nominally. So hidden classes are not the kind of run-time
entities of interest to the bytecode readers and writers. I propose no
ClassDesc for hidden classes.
The relevant APIs need update for hidden classes are:
1. ClassDesc::ofDescriptor
The current spec already specifies to throw IAE if the given name is not
a binary name.
2. Class::describeConstable
There should be no ClassDesc for hidden classes.ClassDesc::ofDescriptor
returns an empty Optional if it's a hidden class.
3. Class::descriptorString (inherited method fromTypeDescriptor)
Three options:
a) throws an exception
b) returns null
c) returns `La/b/C.0x1234;`
`Lookup:defineHiddenClass` specifies the name derived from the `class`
file in the form of:
`N` + "." + <suffix>
where N is the binary name indicated by the `class` file and <suffix> is
an unqualified name that is guaranteed to be unique during this
execution of the JVM.
But this is not a valid binary name; so not a field descriptor. This has
a bigger impact to java.lang.constant.
None of the options is ideal. I lean toward (b). It's rare that a
compiler or other tools using java.lang.constant API will use it on a
hidden class.
Please advise.
Thanks
Mandy
[1]
http://cr.openjdk.java.net/~mchung/valhalla/webrevs/hidden-classes/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClass(byte[],boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)
More information about the valhalla-dev
mailing list