-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8306697: Add method to obtain String for CONSTANT_Class_info in ClassDesc #13598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/csr needed |
|
👋 Welcome back liach! A progress list of the required criteria for merging this PR into |
|
@liach has indicated that a compatibility and specification (CSR) request is needed for this pull request. @liach please create a CSR request for issue JDK-8306697 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Webrevs
|
|
After taking a look at https://bugs.openjdk.org/browse/JDK-8278863 #9201, I think we should take a bold step and make
The decision for |
…info, remove misleading JVMS 4.4.1 links
| * @see ClassDesc#ofDescriptor(String) | ||
| * @see ClassDesc#internalName() | ||
| * @see <a href="#constant-class-info">The {@code CONSTANT_Class_info} Structure</a> | ||
| * @since 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have @revised, as array descriptors are not allowed as input to this method in JDK 20.
| * @since 20 | |
| * @since 20 | |
| * @revised 21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no guideline on using revised. Also, I don't think we will declare it revised if it starts accepting Valhalla Q-types.
|
@mlchung Sorry to bother, but since you are frequently working on the Constant API and the caching allowed by this patch allows the Classfile API to speed up significantly, can you review this patch and its associated CSR? In particular, I wish that you can review in these perspectives:
|
|
You don't have to use |
|
I'm not working on the Constant API area while I'm happy to help. FYI I'll be on vacation for 3 weeks from May 1. |
|
An array does not have an internal name. Changing Have you considered |
Users would have to check the obtained string from a
That might be feasible. I initially fear that this may hurt performance-sensitive operations, but now I think as long as we can make public Optional<String> internalName() {
if (!isClassOrInterface()) // assuming constant-foldable
return Optional.of(descriptorString);
var internalName = this.internalName; // caching
if (internalName != null)
return Optional.of(internalName);
return Optional.of(this.internalName = descriptorString.substring(1, descriptorString.length() - 1));
} |
|
Only the class name of a class or interface is encoded in the internal form. I expect the What you are thinking is a method to return some string for any ClassDesc. If that's desirable, that should be a different method name. |
|
I am aiming for an API to interact with the string in Should I use the |
|
I want to see what @asotona thinks. I also want to see some examples how ClassFile API implementation uses this new API. |
|
I support this addition. Classfile API contains utility method obtaining internal name from |
|
|
||
| @Override | ||
| public String internalName() { | ||
| return isArray() ? descriptorString() : descriptorString().substring(1, descriptorString().length() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to cache the internal name to avoid repeated substring-ing with each call.
ClassDesc instances are frequently used as static constants serving for generations or transformations of many classes, methods, instructions.
It is highly expected that if this method is invoked at least once on the particular instance, it will be invoked many times on the same instance.
|
One comment to the topic of if internal name should include array descriptors. It should not include array descriptors if it is called internal name, however even with excluded arrays the method will help a lot by caching the internal names and avoiding repeated substringing. Or it can include also array descriptors if it is named differently ;) Classfile API will benefit from both ways. |
|
For API design, I have 3 choices for the accessor method:
Which route should I take? I personally reject 1 as internal names are meaningless if they are used alone without being part of CONSTANT_Class_info. For 2 and 3, the main problem is the overhead of Optional vs whether there are better ways to detect if a class cannot be encoded in CONSTANT_Class_info (for now it's only primitives, but valhalla might change that if non-null types are loadable but cannot be in CONSTANT_Class_info) On second thought, I think I will go option 2; it will be in line with |
|
|
With option 4, vs option 2: |
I think I will still resort to an Pros of Optional:
Cons of Optional:
So, I most likely will add With this new model, we will have: default ClassEntry classEntry(ClassDesc classDesc) {
return classEntry(utf8Entry(classDesc.classDescString().orElseThrow(() -> new IllegalArgumentException(classDesc + " cannot be encoded as ClassEntry"))));
}which will take care of non-primitive cases from valhalla. |
|
|
It is always treated as an internal name when it is without a |
|
I consulted with @briangoetz. The internal name should probably be cached in the ClassFile API implementation. |
|
With the upcoming refactor to make parse/build instance methods, there
is a logical place and lifetime for caches.
…On 4/27/2023 2:37 PM, Mandy Chung wrote:
I consulted with @briangoetz <https://github.com/briangoetz>. The
internal name should probably be cached in the ClassFile API
implementation.
—
Reply to this email directly, view it on GitHub
<#13598 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABJ4RD2Q5PVEPGAYIHRKZLXDK4GRANCNFSM6AAAAAAXH4TPLU>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Sounds good. I will close the pull request and the JBS issue. |
@briangoetz Most of the class generation code starts with static ClassDesc constants (or references to ConstantDescs). |
|
I benchmarked merged this PR with #13671 and benefits of internal names caching in ClassDesc are insignificant (~2% performance boost). |
Add a method
internalNametoClassDesc, and unifies handling of string representation of a class constant in CONSTANT_Class_info viaofInternalNameandinternalNameAPIs, documented inClassDescitself. In particular,ofInternalNamenow accepts arrays.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 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
Progress
Issues
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13598/head:pull/13598$ git checkout pull/13598Update a local copy of the PR:
$ git checkout pull/13598$ git pull https://git.openjdk.org/jdk.git pull/13598/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 13598View PR using the GUI difftool:
$ git pr show -t 13598Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13598.diff
Webrev
Link to Webrev Comment