[code-reflection] RFR: BytecodeGenerator cleanup and switch support [v7]
Adam Sotona
asotona at openjdk.org
Tue Dec 2 13:06:33 UTC 2025
On Tue, 2 Dec 2025 10:25:34 GMT, Adam Sotona <asotona at openjdk.org> wrote:
>> The current `BytecodeGenerator` implementation assumes that code models have already been lowered before generation. Both `SwitchExpressionOp` and `SwitchStatementOp` with all-constant labels are examples of operations that can be lowered an alternative way, allowing `BytecodeGenerator` to produce more efficient bytecode using `tableswitch` and `lookupswitch` instructions.
>>
>> The proposed change shifts the responsibility for lowering these operations into the `BytecodeGenerator` itself, enabling selective lowering during bytecode generation. Consequently, `OpBuilder` and `BytecodeGenerator` tests have been updated to avoid invoking the lower transformation step before the `BytecodeGenerator` is called.
>>
>> A new internal operation, `ConstantLabelSwitchOp`, has been introduced. This acts as an intermediate representation for lowered `SwitchExpressionOp` and `SwitchStatementOp` instances with constant labels.
>>
>> Lowering of `SwitchExpressionOp` and `SwitchStatementOp` into `ConstantLabelSwitchOp` is also a part of this PR.
>>
>> This PR also makes minor refinements to the BytecodeGenerator post-processing transformations.
>
> Adam Sotona has updated the pull request incrementally with two additional commits since the last revision:
>
> - removed obsolete block
>
> - LoweringTransform refactored out to jdk.incubator.code.bytecode.impl package
@mabbay nice job!
Synthetic type factory now looks like this:
public static jdk.incubator.code.extern.ExternalizedTypeElement $exterType(int);
descriptor: (I)Ljdk/incubator/code/extern/ExternalizedTypeElement;
flags: (0x0009) ACC_PUBLIC, ACC_STATIC
Code:
stack=5, locals=9, args_size=1
0: iload_0
1: tableswitch { // 0 to 146
...
-------------
PR Review: https://git.openjdk.org/babylon/pull/706#pullrequestreview-3529999325
More information about the babylon-dev
mailing list