Skip to content

[GR-73325] Template and Top of Stack optimization - #13108

Open
graalvmbot wants to merge 49 commits into
masterfrom
yz/GR-73325
Open

[GR-73325] Template and Top of Stack optimization#13108
graalvmbot wants to merge 49 commits into
masterfrom
yz/GR-73325

Conversation

@graalvmbot

Copy link
Copy Markdown
Collaborator

This PR introduces support for template-based specialization and top-of-stack (TOS) optimization in the Graal/Truffle interpreter's "one compilation per bytecode handler" infrastructure. It enables generating multiple handler stub variants (templates), each specialized for different TOS state, by marking an expanded @Argument field as the template variable. The PR also adds framework integration for managing handler tables keyed by template index, ensuring correct handler selection in interpreter threading.

Key Changes:

  • Expanded the @HostCompilerDirectives.BytecodeInterpreterHandlerConfig.Argument.Field annotation with a templateVariable property to designate an int field as the template selector for handler specialization.
  • Added a new templates parameter to @HostCompilerDirectives.BytecodeInterpreterHandlerConfig to specify the number of template variants.
  • Modified TruffleBytecodeHandlerCallsite, handler stub generation, and stub lowering to inject a compile-time constant template variable, enabling specialization based on TOS or similar state.
  • Refactored handler dispatch and handler table construction to use both opcode and template index, ensuring correct selection of specialized handler stubs.
  • Updated relevant host and substrate modules for the new template-aware handler stubs

See detail documentation at OneCompilationPerBytecodeHandler.md

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 9, 2026
@graalvmbot
graalvmbot force-pushed the yz/GR-73325 branch 2 times, most recently from bb97516 to 288c667 Compare March 9, 2026 15:31
@graalvmbot
graalvmbot force-pushed the yz/GR-73325 branch 2 times, most recently from 039e47f to 66f8407 Compare June 3, 2026 09:20
@graalvmbot
graalvmbot force-pushed the yz/GR-73325 branch 2 times, most recently from fd78350 to 19ec24d Compare July 14, 2026 16:09
@graalvmbot
graalvmbot force-pushed the yz/GR-73325 branch 4 times, most recently from 0544c18 to e6f2870 Compare August 12, 2026 21:26
Insert PreserveFrameStateNode immediately before generated handler safepoints instead of preserving state in CHECKCAST source code. Anchor the WIDE handler BCI computation after opcode execution to avoid extending nextBCI across the dispatch switch and introducing a fast-path spill.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants