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)

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

Commit messages:
 - 8306697: Add method to obtain String for CONSTANT_Class_info in ClassDesc

Changes: https://git.openjdk.org/jdk/pull/13598/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13598&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8306697
  Stats: 46 lines in 4 files changed: 39 ins; 5 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/13598.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/13598/head:pull/13598

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

Reply via email to