RFR: 8306697: Add method to obtain String for CONSTANT_Class_info in ClassDesc
Chen Liang
liach at openjdk.org
Sat Apr 22 16:17:42 UTC 2023
On Sat, 22 Apr 2023 15:12:48 GMT, Chen Liang <liach at openjdk.org> wrote:
> Add a method `internalName` (name subject to discussion) to `ClassDesc`, which allows easily obtaining a String for representation of a class constant in CONSTANT_Class_info.
>
> The motivation of this API is that avoiding frequent String creations via caching (enabled by this new API, will be in a separate patch) would speed up Classfile API's [writing of simple class files](https://github.com/openjdk/jdk/blob/master/test/micro/org/openjdk/bench/jdk/classfile/Write.java) by 1/3. See https://mail.openjdk.org/pipermail/classfile-api-dev/2023-April/000296.html for more context.
>
> This API is futureproof: for Valhalla's Q-types, it will return their string representation in CONSTANT_Class_info, which is most likely their full descriptor string.
>
> Javadoc: https://cr.openjdk.org/~liach/8306697/java.base/java/lang/constant/ClassDesc.html#internalName()
>
> For the method name: `internalName` is intuitive as it is almost like an inverse operation of `ofInternalName`, but the concept of internal name only applies to classes and interfaces (as described in [JVMS 4.4.1](https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.4.1)) and doesn't apply to arrays. And internal names (binary name in internal form) is useless outside of CONSTANT_Class_info; other usages are already covered by `descriptorString`. If we stay on the naming of "internal name" (which I would prefer), we might expand it and potentially upgrade `ofInternalName` to take care of future CONSTANT_Class_info content (like Q-types)
After taking a look at https://bugs.openjdk.org/browse/JDK-8278863 #9201, I think we should take a bold step and make `ofInternalName` handle all possible `CONSTANT_Class_info` values:
1. Internal names for classes and interfaces have no merit on their own, and has no usages besides `CONSTANT_Class_info`
2. In the current form, shall future developments like Valhalla add a new form of value to `CONSTANT_Class_info`, users won't be able to reliably convert a `CONSTANT_Class_info` structure into a `ClassDesc`, adding more maintenance burdens.
The decision for `ofInternalName` to accept only class and interface internal names was an ad-hoc decision that was questioned by CSR lead in CSR review as well.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13598#issuecomment-1518695087
More information about the core-libs-dev
mailing list