Skip to content

Implement constant references in compiler IL (initially disabled) - #8121

Merged
0xdaryl merged 2 commits into
eclipse-omr:masterfrom
nbhuiyan:const-refs-jit-impl
Feb 19, 2026
Merged

Implement constant references in compiler IL (initially disabled)#8121
0xdaryl merged 2 commits into
eclipse-omr:masterfrom
nbhuiyan:const-refs-jit-impl

Conversation

@nbhuiyan

@nbhuiyan nbhuiyan commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

This PR contributes @jdmpapin's const refs implementation in the compiler. Please refer to the commit message for an overview of the changes.

Issue: eclipse-openj9/openj9#16616

@nbhuiyan

nbhuiyan commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

@0xdaryl @vijaysun-omr @hzongaro FYI

Comment thread compiler/codegen/OMRCodeGenerator.cpp
Comment thread compiler/codegen/OMRCodeGenerator.cpp
Comment thread compiler/codegen/OMRCodeGenerator.hpp Outdated

@0xdaryl 0xdaryl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks fine to me, modulo a small documentation request.

Kudos for preparing a readable, well thought-out PR @jdmpapin !


void setLmmdFailed() { _lmmdFailed = true; }

TR::LabelSymbol *assignConstRefLabel(TR::Node *node);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these functions get some Doxygen comments? In particular, the ones (like this one) that may return NULL instead of a label and the semantics of that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the doxygen comments in the newly pushed commit. I will squash the last 2 commits after review is complete.

@0xdaryl

0xdaryl commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Jenkins build all

I'm just launching a build just to see if it shakes anything out.

@0xdaryl

0xdaryl commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Jenkins build all

@nbhuiyan

Copy link
Copy Markdown
Contributor Author

Two of the test jobs ended up in failure:

  1. ppc64le linux gcc:
08:03:26  97% tests passed, 1 tests failed out of 30
08:03:26  
08:03:26  Total Test time (real) = 486.06 sec
08:03:26  
08:03:26  The following tests FAILED:
08:03:26  	 30 - compunittest (Child aborted)
08:03:26  Errors while running CTest

This failure has been present for sometime now, and not introduced by the changes in the PR.

  1. riscv:
07:47:18  Still waiting to schedule task
07:47:18  ‘[riscv-build2](https://ci.eclipse.org/omr/computer/riscv%2Dbuild2/)’ is offline

I will now proceed with updating the branch to resolve merge conflicts and to squash the last 2 commits.

@nbhuiyan
nbhuiyan force-pushed the const-refs-jit-impl branch 3 times, most recently from 4308b4b to 9bfce1e Compare February 17, 2026 18:05
This commit introduces a representation for non-null reference constants
in the IL. For each known object, there is now a lazily created symbol
reference representing the constant that always refers to that object.
The symref has a known object index in the same way that existing
"improved" symrefs do. It's static, and the IL should load it directly,
i.e. using aload. A constant represented as such a load looks as follows
in tracing:

    aload  <constant object ref>[eclipse-omr#429  final Static] (obj3)

This new representation is meant to completely supplant the existing
ways of attaching known object information to nodes in the IL, namely
the per-node known object index and the aforementioned "improved"
symrefs. There are two reasons for this change:

1. These reference constants are inherently guaranteed to evaluate to
   references to the expected objects, unlike nodes where we've used the
   prior techniques, since those left the original operations in place.
   This guarantee makes it less error prone to constant-fold loads, and
   it makes it possible to do so in more circumstances.

2. These reference constants make the resulting references available
   more or less directly. It generally takes only a single load to get
   the reference. This improves performance in cases where the reference
   was originally coming from a chain of two or more dependent loads
   (and where it doesn't become unused before code generation).

The new preprocessor symbol TR_ALLOW_NON_CONST_KNOWN_OBJECTS gates old
functionality that should no longer be used once const refs are enabled.
In particular, if that symbol is not defined, then attempts to get or
set the per-node known object index, and attempts to create an
"improved" version of an existing symref, will cause a build error. This
is useful for making sure that every use of those APIs has alternative
logic implemented to use const refs instead (when enabled). It should
also eventually be useful for eliminating those old APIs. However, it's
expected that there will be builds that need to disable const refs for
some time yet. Indeed, this commit does not even enable const refs by
default.

This commit also implements a cross-platform code generation strategy
for const refs, along with minimal architecture-specific instruction
selection changes. During evaluation, each known object used as a const
ref will be assigned a label, and the generated instructions will use
the label to identify the address from which to load. Later, the
reference slots will be allocated amongst the snippets in the binary
code, in particular between the regular snippets and the data snippets.
Before allocating the slots though, the downstream project needs to add
labels for any necessary keepalives (see RetainedMethodSet), and then it
has an opportunity to specify any arbitrary order for the references to
appear in, as convenient for the downstream implementation. Finally, at
the end of the compilation, the downstream project must arrange for the
slots to be scanned by GC as appropriate, and it must initialize them to
point to their respective objects.
@nbhuiyan
nbhuiyan force-pushed the const-refs-jit-impl branch from 9bfce1e to 2583522 Compare February 17, 2026 19:37

@hzongaro hzongaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few very minor comments. I think the changes look, but I did not review the code generation changes.

Comment thread compiler/codegen/OMRCodeGenerator.hpp Outdated
Comment thread compiler/codegen/OMRCodeGenerator.hpp Outdated
Comment thread compiler/codegen/OMRCodeGenerator.hpp
Comment thread compiler/optimizer/CopyPropagation.cpp Outdated
@nbhuiyan
nbhuiyan force-pushed the const-refs-jit-impl branch from 2583522 to 87122fd Compare February 19, 2026 17:30
The ifdef guards were specific to a downstream project, and were
intended to return NULL in cases where that macro was not defined,
as that would imply that const refs support was disabled.
However, assignConstRefLabel() would have already returned NULL
without the ifdef guards due to the existing useConstRefs() check.
In addition, a fatal assert has been added in
assignConstRefLabelImpl() to verify that it is not being used
with const refs disabled.

Also added Doxygen comments for these new functions.

Signed-off-by: Nazim Bhuiyan <nubhuiyan@ibm.com>
@nbhuiyan
nbhuiyan force-pushed the const-refs-jit-impl branch from 87122fd to f302433 Compare February 19, 2026 18:03
@0xdaryl

0xdaryl commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Jenkins build all

@hzongaro hzongaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. Thanks!

@0xdaryl
0xdaryl merged commit 3d99b93 into eclipse-omr:master Feb 19, 2026
10 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants