-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8350938: ResourceParsingClassHierarchyResolver inflates all Utf8 CP entries #28458
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back trevorkbond! A progress list of the required criteria for merging this PR into |
|
@trevorkbond This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 45 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@liach) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
@trevorkbond The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
|
I'm available as a sponsor when we get this reviewed |
|
It might be better to make the previous version lazy, as the new version requires pre‑parsing the whole input, whereas the old version would only read the classfile header. |
|
The new version would always read all classfile bytes, the old one in chunks of 8192 bytes, both stop parsing at this_class position (with or without inflating constant pool entries). |
|
Maybe |
liach
left a comment
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.
Looks good in principle. Even though people wonder about the buffering policy, I think it is negligible considering that we have caching mechanism. And the constant pool is flexible sized, so "only read the classfile header" might be an optimisitic assumption.
| int superIndex = in.readUnsignedShort(); | ||
| var superClass = superIndex > 0 ? ClassDesc.ofInternalName(cpStrings[cpClasses[superIndex]]) : null; | ||
| try (ci) { | ||
| ClassReader reader = new ClassReaderImpl(ci.readAllBytes(), (ClassFileImpl) ClassFile.of()); |
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.
| ClassReader reader = new ClassReaderImpl(ci.readAllBytes(), (ClassFileImpl) ClassFile.of()); | |
| var reader = new ClassReaderImpl(ci.readAllBytes(), ClassFileImpl.DEFAULT_CONTEXT); |
And you can remove the 3 imports you have added.
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.
Thank you for this. I adjusted that line and the imports accordingly. I still found a need to import java.lang.classfile.constantpool.ClassEntry for the line further down converting the ClassEntry to a ClassDesc. If that can also be avoided I'm happy to fix. I also removed a few imports previously needed but that can be removed with these changes.
|
Also, the key to this patch is not performance - it is about the maintainability from a consistent way to parse class files, so in the future, we don't need to update this site any more if we have new constant pool entry type or other format expansions. |
|
/integrate |
|
@trevorkbond |
|
Hello Trevor, please update the copyright year on |
Enhance
ResourceParsingClassHierarchyResolver.getClassInfoto useClassReaderImplto improve performance. Previously this method inflated and stored all UTF-8 entries in the constant pool and later accessed the array of strings to try finding the name of the superclass.ClassReaderImplinstead stores constant pool offsets and later lazily reads/inflates UTF8 entries as needed.I’ve ran all tier 1 tests and tests within
test/jdk/jdk/classfileon the latest version of this change, and they all pass.I ran some informal performance testing to see if these changes led to any improvement. I created a .class file with several thousand unique strings in a String array to deliberately enlarge the number of UTF-8 entries in the constant pool. I then benchmarked the performance of running a process nearly identical to
ClassHierarchyInfoTest.testClassLoaderParsingResolveron this custom class over 200 runs using JMH. The results are as follows.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28458/head:pull/28458$ git checkout pull/28458Update a local copy of the PR:
$ git checkout pull/28458$ git pull https://git.openjdk.org/jdk.git pull/28458/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28458View PR using the GUI difftool:
$ git pr show -t 28458Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28458.diff
Using Webrev
Link to Webrev Comment