Skip to content

feature(Bytecode DSL): share one constant-pool slot for null constant operands - #14538

Open
The-Alchemist wants to merge 1 commit into
oracle:masterfrom
The-Alchemist:truffle/constants-buffer-shared-null
Open

The-Alchemist wants to merge 1 commit into
oracle:masterfrom
The-Alchemist:truffle/constants-buffer-shared-null

Conversation

@The-Alchemist

@The-Alchemist The-Alchemist commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A language sometimes needs a reference constant operand whose value is null, for example an optional type or a missing default. ConstantsBuffer.add(null) threw NullPointerException because it started with Objects.requireNonNull. Serialization already records null with CODE_$CREATE_NULL, but the builder rejected the value before it reached the pool.

addNull() is not a substitute. Its reserved slots are meant to be patched after materialization, and each call allocates a new slot. Using it for a real null constant grows the pool and can later alias a patched value. We've worked around the rejection in our Cloffle project with a sentinel value instead of passing null.

Summary

  • Reference constant operands may be null. ConstantsBuffer.add(null) stores that null in one shared constant-pool slot.
  • addNull() still reserves a distinct empty slot on each call so the slot can be patched after materialization.
  • LoadConstant still rejects null; use LoadNull for a null dynamic value. Local accessors still reject null.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 26, 2026
@The-Alchemist
The-Alchemist force-pushed the truffle/constants-buffer-shared-null branch from 8425478 to 67f3bbf Compare September 26, 2026 23:14
@The-Alchemist The-Alchemist changed the title Bytecode DSL: share one constant-pool slot for null constant operands feature(Bytecode DSL): share one constant-pool slot for null constant operands Sep 26, 2026
@The-Alchemist
The-Alchemist marked this pull request as ready for review September 27, 2026 11:53
Reference constants can be null without reserving a fresh patchable slot on every call.

Signed-off-by: The-Alchemist <kap4020@gmail.com>
@The-Alchemist
The-Alchemist force-pushed the truffle/constants-buffer-shared-null branch from 67f3bbf to 1e978a8 Compare October 28, 2026 23:51

This branch has not been deployed

No deployments
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.

1 participant