RFR: 8359707: Add classfile modification code to RedefineClassHelper [v6]
Coleen Phillimore
coleenp at openjdk.org
Thu Jun 26 11:58:11 UTC 2025
On Thu, 26 Jun 2025 07:30:13 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Made it even shorter.
>
> test/lib/RedefineClassHelper.java line 29:
>
>> 27: import java.lang.classfile.ClassFile;
>> 28: import java.lang.classfile.ClassModel;
>> 29: import java.util.Map;
>
> Nit: import out of order
I like the imports when they're grouped by things they support. Map isn't being used in the final version though.
> test/lib/RedefineClassHelper.java line 92:
>
>> 90: byte[] buf = getBytecodes(loader, oldClassName);
>> 91: ClassModel classModel = ClassFile.of().parse(buf);
>> 92: return ClassFile.of().build(ClassDesc.of(newClassName), classModel::forEach);
>
> That's cool! I have no idea how to read it to understand what it does, but it is cool it can be done in one line. :)
>
> Seriously though, which part of that is doing the actual replace??
Java's gone overly terse, but if you look at the n-1 commit, the classModel::forEach copies everything in the class to the new class. At least that's what Chen told me and it seems to do. Isn't this cool?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25857#discussion_r2168886521
PR Review Comment: https://git.openjdk.org/jdk/pull/25857#discussion_r2168884543
More information about the serviceability-dev
mailing list