[code-reflection] RFR: BytecodeGenerator cleanup and switch support [v10]
Adam Sotona
asotona at openjdk.org
Wed Dec 3 00:22:17 UTC 2025
> 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
-------------
Changes:
- all: https://git.openjdk.org/babylon/pull/706/files
- new: https://git.openjdk.org/babylon/pull/706/files/2994865c..12c3eb91
Webrevs:
- full: https://webrevs.openjdk.org/?repo=babylon&pr=706&range=09
- incr: https://webrevs.openjdk.org/?repo=babylon&pr=706&range=08-09
Stats: 225 lines in 6 files changed: 164 ins; 45 del; 16 mod
Patch: https://git.openjdk.org/babylon/pull/706.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/706/head:pull/706
PR: https://git.openjdk.org/babylon/pull/706
More information about the babylon-dev
mailing list