RFR: 8307818: Convert Indify tool to Classfile API [v10]

Adam Sotona asotona at openjdk.org
Mon Jun 17 08:36:22 UTC 2024


On Fri, 24 May 2024 17:12:34 GMT, Oussama Louati <duke at openjdk.org> wrote:

>> test/jdk/java/lang/invoke/indify/Indify.java line 503:
>> 
>>> 501: 
>>> 502:                 Iterator<Instruction> instructionIterator =getInstructions(m).iterator();
>>> 503:                 final Stack<Boolean> shouldProceedAfterIndyAdded = new Stack<>();
>> 
>> What this stack of booleans suppose to do?
>
> We need a boolean value to determine if we should proceed after replacing the appropriate "pop" instruction with an "invokedynamic" instruction. However, instead of using just a boolean field, we use a stack. The reason for this is that within the lambda expression, we can only use final variables. By using a stack, we can update its value as needed, which is why this approach is chosen.

I see here an iteration over instructions of a method, where the whole class is retransformed in certain situations and some status is passed back in a stack of booleans.
The whole conversion should be implemented in a single transformation.
Original code repeatedly replaced instructions inline (that is BTW reason why added nops below), however architecture of ClassFile API is different, you are transforming one class into completely new class (free to remove and add as many elements as you need). You can compose transformations into complex trees and you can also collect information before the transformation, however the class transformation should be executed only once.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18841#discussion_r1642418788


More information about the core-libs-dev mailing list