RFR: 8359707: Add classfile modification code to RedefineClassHelper [v6]

Chen Liang liach at openjdk.org
Thu Jun 26 16:36:37 UTC 2025


On Thu, 26 Jun 2025 11:52:36 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> 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?

> Seriously though, which part of that is doing the actual replace??

`ClassDesc.of(newClassName)` defines a new class with the new name, and the lambda just copies everything over as-is.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25857#discussion_r2169460161


More information about the serviceability-dev mailing list