[code-reflection] Integrated: BytecodeGenerator cleanup and switch support

Adam Sotona asotona at openjdk.org
Thu Dec 4 15:12:46 UTC 2025


On Tue, 25 Nov 2025 14:23:19 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 has been implemented in this PR.
> 
> The PR also fixes standard lowering of `SwitchStatementOp` with default case fall-through.
> 
> This PR also makes minor refinements to the BytecodeGenerator post-processing transformations.

This pull request has now been integrated.

Changeset: 832efca9
Author:    Adam Sotona <asotona at openjdk.org>
URL:       https://git.openjdk.org/babylon/commit/832efca9d9e2769118226c532af5e2fc17eb8ba5
Stats:     1428 lines in 24 files changed: 1170 ins; 176 del; 82 mod

BytecodeGenerator cleanup and switch support

Co-authored-by: Mourad Abbay <mabbay at openjdk.org>

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

PR: https://git.openjdk.org/babylon/pull/706


More information about the babylon-dev mailing list