Skip to content

Enable arrayset for Unsafe.setMemory0#8291

Open
Deigue wants to merge 2 commits into
eclipse-omr:masterfrom
Deigue:1003-unsafesetmemory
Open

Enable arrayset for Unsafe.setMemory0#8291
Deigue wants to merge 2 commits into
eclipse-omr:masterfrom
Deigue:1003-unsafesetmemory

Conversation

@Deigue

@Deigue Deigue commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Associated with: https://github.com/eclipse-openj9/openj9/pull/23854/changes

Adds JIT TR option to enable arrayset for Unsafe.setMemory0
and adds missing Int8/byte case to pick the correct STC instruction for OpMemToMem (used by the arraysetEvaluator)

@Deigue Deigue marked this pull request as ready for review June 15, 2026 15:26
@dchopra001

Copy link
Copy Markdown
Contributor

@Deigue Do you plan to keep the commit history? Or will you squash these into a single commit? Looking at your commits and the code change itself, I would recommend squashing into a single commit.

@Deigue

Deigue commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Definitely planning to squash into one, was just seeing if there is more feedback/changes to add. Otherwise I will squash now itself.

@dchopra001

Copy link
Copy Markdown
Contributor

Let's squash and write a clean commit message, and then we can start reviewing the changes in their final state.


switch (_destType) {
case TR::Int8:
cursor = generateRXInstruction(_cg, TR::InstOpCode::STC, _dstNode, _initReg, newMR);

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.

If you wanted to separate this part of the change into a separate commit, I would be okay with that since it's logically different than the rest of the changes (which are moreso about enabling the transformation). The PR title and first message in the PR should also probably mention that we are also adding support for bytes.

@Deigue Deigue force-pushed the 1003-unsafesetmemory branch from 184ec12 to 145f6c9 Compare June 17, 2026 19:26
TR_S390ScratchRegisterManager *generateScratchRegisterManager(int32_t capacity = 8);

bool canTransformUnsafeCopyToArrayCopy();
bool canTransformUnsafeSetMemory();

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.

Can we add doxygen comments for this new API? See lines 238-257 for examples.


switch (_destType) {
case TR::Int8:
cursor = generateRXInstruction(_cg, TR::InstOpCode::STC, _dstNode, _initReg, newMR);

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 new addition looks reasonable to me. It would be good to test this OMR change in a personal build by itself (without your own openj9 changes) just to make sure the commit is clean.

@Deigue Deigue force-pushed the 1003-unsafesetmemory branch from 145f6c9 to 40d8e72 Compare June 18, 2026 15:58
Deigue added 2 commits June 22, 2026 10:51
Store instruction handling bytes is missing and would fallback to STG.
This adds the appropriate case to pick the appropriate instruction.

Signed-off-by: Gaurav Chaudhari <Gaurav.Chaudhari@ibm.com>
Signed-off-by: Gaurav Chaudhari <Gaurav.Chaudhari@ibm.com>
@Deigue Deigue force-pushed the 1003-unsafesetmemory branch from 40d8e72 to c2ae9e0 Compare June 22, 2026 14:51
@dchopra001

Copy link
Copy Markdown
Contributor

@r30shah Can I request a review from you as well for this PR?

@r30shah r30shah 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.

OpMemToMem.cpp changes looks good to me. I do not think other changes should in the OMR (It should be moved to OpenJ9).

{ "enableTraps", "C\tenable trap instructions", RESET_OPTION_BIT(TR_DisableTraps), "F" },
{ "enableTreePatternMatching", "O\tEnable opts that use the TR_Pattern framework",
RESET_OPTION_BIT(TR_DisableTreePatternMatching), "F" },
{ "enableUnsafeSetMemoryArrayset", "O\tenable arrayset for Unsafe.setMemory0",

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.

Can we rename this option to something more relatable ? The option should give an indication that it is enabling accelerating Unsafe.setMemory0 - not necessarily tied to the node it is lowered to.

Also - There is no notion of unsafe in OMR - either move this option to OpenJ9 or guard it with J9 project specific macro.

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.

Keep in mind - if the intention to have this option so that it can be applied per method, it needs to be in OMR.

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.

So the equivalent would be like the ones in J9Options.cpp/hpp instead? I guess it is contingent on the other comment, whether I can keep it in OMRCodeGenerator to match the POWER equivalent behavior, or change things and move it to J9. Because then, I would need the TR option accessible in OMR . if I am keeping the canTransform... bool here.

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.

on that note, would enableAccelerateUnsafeSetMemory be acceptable?
Or accelerateUnsafeSetMemory if the prefix is not a must?

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.

I was thinking to control enablement through environment flag. This is the kind of acceleration that we want to happen by default so rather than using entry in the Options, I would use feGetEnv in the code where you are transforming to enable. We do not need to use entry in options for this one.

return (!disableTran && !comp()->getCurrentMethod()->isJNINative() && !comp()->getOption(TR_DisableArrayCopyOpts));
}

bool OMR::Z::CodeGenerator::canTransformUnsafeSetMemory()

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.

Similar to previous comment - This should be in the J9CodeGenerator as it is accelerating Unsafe API in Java. We should not have this in OMR.

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.

We have this in the power equivalent already in OMR:

bool canTransformUnsafeSetMemory();

Inheriting from:

bool canTransformUnsafeSetMemory();
anyway.
I just re-defined on the Z level

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.

I understand, but I do not see any reason that even on P - it should be in OMR. Even the user of the flag is in OpenJ9. I would simply propose to move this to J9 and clean-up OMR.

@Deigue Deigue Jun 24, 2026

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.

Add OpenJ9 equivalents: eclipse-openj9/openj9#24229
Remove OMR bools: #8301

@r30shah r30shah 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.

Changes - Needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants