RFR: 8278863: Add method ClassDesc::ofInternalName [v2]

Adam Sotona asotona at openjdk.org
Fri Jun 17 17:23:59 UTC 2022


On Fri, 17 Jun 2022 17:03:52 GMT, Adam Sotona <asotona at openjdk.org> wrote:

>> The symbolic constants API (`java.lang.constant`) was designed, in part, to provide bytecode parsing and generation APIs with a validated, common, symbolic form for constants in Java class files. 
>> 
>> There is an easy way to create a `ClassDesc` from a binary name (`ClassDesc::of`) or a field descriptor (`ClassDesc::ofDescriptor`) but not from an internal name. But, the internal name is common in low-level bytecode-manipulation code. 
>> 
>> This patch adds `ClassDesc::ofInternalName` static factory method that creates a `ClassDesc` from class internal name.
>> Class internal name validation and extended ClassDescTest are also parts of this patch.
>> 
>> CSR is linked with the issue.
>> 
>> Please review.
>> 
>> Thank you,
>> Adam
>
> Adam Sotona has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update test/jdk/java/lang/constant/ClassDescTest.java
>   
>   Co-authored-by: Jorn Vernee <JornVernee at users.noreply.github.com>

My initial thoughts were the same. Passing internal class name through the ClassDesc in and out is very frequent when using ASM library or similar.
However the problem here is that not all ClassDesc have internal class name, it can be applied only to non-primitive and non-array descriptors.
Proposed approach to work with class names in various forms (which can be even more tricky with upcoming Valhalla) is to use ClassDesc as the primary class-describing entity (instead of any form of String).
 
While constructing ClassDesc from various other forms (internal names, binary names, derivation from other ClassDesc, getting it from Class, etc...) is mostly user responsibility. 
Different ways of ClassDesc serialization in various contexts (method descriptor, class reference, annotation, etc...) should be always responsibility of the processing library.

For ASM case I would rather recommend a util class directly converting ClassDesc to ASM Type, while passing ClassDesc through String internal name is risky and not covering all cases.

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

PR: https://git.openjdk.org/jdk/pull/9201


More information about the core-libs-dev mailing list