-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8359707: Add classfile modification code to RedefineClassHelper #25857
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 coleenp! A progress list of the required criteria for merging this PR into |
@coleenp 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 70 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. ➡️ To integrate this PR with the above commit message to the |
/label add hotspot-runtime |
@coleenp |
Webrevs
|
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 looks reasonable. I've posted one nit suggestion.
test/lib/RedefineClassHelper.java
Outdated
* @param newString new class name to replace with old class name. | ||
*/ | ||
|
||
public static byte[] replaceAllStrings(ClassLoader loader, String oldString, String newString) throws Exception { |
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.
Nit: I'd suggest to rename parameters:
oldString
=> oldClassName
newString
=> newClassName
Alternatively, it is possible to pass bytecodes buffer instead of class loader and keep oldString
and newString
as before.
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 wanted this code to also read bytecodes off the disk and not the caller do that either. The code for getBytecodes or very similar is duplicated all over the tests also.
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 can add a byte buffer version though.
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 the update! Looks good.
@@ -61,6 +64,64 @@ public static void redefineClass(Class<?> clazz, byte[] bytecode) throws Excepti | |||
instrumentation.redefineClasses(new ClassDefinition(clazz, bytecode)); | |||
} | |||
|
|||
private static byte[] getBytecodes(ClassLoader loader, String name) throws Exception { | |||
InputStream is = loader.getResourceAsStream(name + ".class"); |
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 think this should be
try(InputStream is = loader.getResourceAsStream(name + ".class");) {
...
I copied this code for another test in the Valhalla repo and thought it would be a good utility function. It might be better written using the Classfile API.
Tested with test.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25857/head:pull/25857
$ git checkout pull/25857
Update a local copy of the PR:
$ git checkout pull/25857
$ git pull https://git.openjdk.org/jdk.git pull/25857/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25857
View PR using the GUI difftool:
$ git pr show -t 25857
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25857.diff
Using Webrev
Link to Webrev Comment