[code-reflection] RFR: BytecodeGenerator cleanup and switch support [v2]

Adam Sotona asotona at openjdk.org
Mon Dec 1 16:00:29 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, `BytecodeGenerator.ConstantLabelSwitchOp`, has been introduced. This acts as an intermediate representation for lowered `SwitchExpressionOp` and `SwitchStatementOp` instances with constant labels. Logic for detecting constant labels and transforming them into `BytecodeGenerator.ConstantLabelSwitchOp` will be introduced in a follow-up pull request.
> 
> 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:

 - added test
   
 - ConstantLabelSwitchOp refactored out to jdk.incubator.code.bytecode.impl package

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

Changes:
  - all: https://git.openjdk.org/babylon/pull/706/files
  - new: https://git.openjdk.org/babylon/pull/706/files/d5c550cb..abff6609

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=babylon&pr=706&range=01
 - incr: https://webrevs.openjdk.org/?repo=babylon&pr=706&range=00-01

  Stats: 250 lines in 3 files changed: 211 ins; 33 del; 6 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