[code-reflection] RFR: BytecodeGenerator cleanup and switch support [v10]
Adam Sotona
asotona at openjdk.org
Wed Dec 3 07:03:24 UTC 2025
On Wed, 3 Dec 2025 00:22:17 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.
>>
>> Lowering of `BreakOp`, `SwitchFallthroughOp` and nested switches will be implemented in a follow-up 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:
>
> - Generalize the lower transform
> - Keep switch cases in the same order as in source code
src/jdk.incubator.code/share/classes/jdk/incubator/code/bytecode/impl/LoweringTransform.java line 101:
> 99: yield b;
> 100: }
> 101: case Lowerable lop -> lop.lower(b, null);
Nested bodies should be lowered using this lowering transformation.
src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java line 2148:
> 2146: }
> 2147:
> 2148: public record BranchTarget(Block.Builder breakBlock, Block.Builder continueBlock) {
This forms a new public API.
Implementation code worth to internally share across the module and tests must be moved to a non-public package. The other option is to copy/paste.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/706#discussion_r2583883219
PR Review Comment: https://git.openjdk.org/babylon/pull/706#discussion_r2583879326
More information about the babylon-dev
mailing list