Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent commoning of l2a operations in localCSE #7217

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

hzongaro
Copy link
Contributor

@hzongaro hzongaro commented Jan 6, 2024

An l2a operation might be used to convert the result of a compressed reference sequence to an address, but it is also used in other circumstances - for instance, if an Int64 value holds the address of a j9class or a j9method. The l2aEvaluators[1,2,3,4] assume that l2a is used for compressed references or accessing arraylets. If the node is not accessing an arraylet and compressed references are enabled, the evaluator will mark the source register as containing a collected reference under the assumption that it's working with a compressed reference. However, if the l2a is being used for a j9class, j9method, etc., the register that holds it should not be marked as a collected reference.

As an interim fix, this change will prevent commoning of l2a operations. The various OMR::<CPU>::MemoryReference::populateMemoryReference code generation methods[5,6,7,8] will usually skip evaluation of an l2a that has a reference count of one, so that prevents the register containing the operand of the l2a from being marked as a collected reference.

In the longer term, OMR issue #6508 proposes introducing a new opcode - l2gcref - that would be used to mark explicitly the result of a conversion from long to an address as holding a collected reference. Once implemented, the change implemented by this commit can be reverted.

This will work around the problem reported in OpenJ9 issue eclipse-openj9/openj9#18098 as affecting SharedClasses.SCM01.MultiThread_1. Other test failures could have other causes that will need further investigation.

[1] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/aarch64/codegen/UnaryEvaluator.cpp#L640-L641
[2] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/p/codegen/UnaryEvaluator.cpp#L573-L574
[3] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/x/codegen/UnaryEvaluator.cpp#L381-L382
[4] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/z/codegen/UnaryEvaluator.cpp#L251-L252
[5] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/aarch64/codegen/OMRMemoryReference.cpp#L587-L612
[6] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/p/codegen/OMRMemoryReference.cpp#L587-L597
[7] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/x/codegen/OMRMemoryReference.cpp#L521-L533
[8] https://github.com/eclipse/omr/blob/3a4787401fffbdbb8088021d3553915ea3ff8edf/compiler/z/codegen/OMRMemoryReference.cpp#L1801-L1809

An l2a operation might be used to convert the result of a compressed
reference sequence to an address, but it is also used in other
circumstances - for instance, if an Int64 value holds the address of a
j9class or a j9method.  The l2aEvaluators assume that l2a is used for
compressed references or accessing arraylets.  If the node is not
accessing an arraylet and compressed references are enabled, the
evaluator will mark the source register as containing a collected
reference under the assumption that it's working with a compressed
reference.  However, if the l2a is being used for a j9class, j9method,
etc., the register that holds it should not be marked as a collected
reference.

As an interim fix, this change will prevent commoning of l2a operations.
The various OMR::<CPU>::MemoryReference::populateMemoryReference
code generation methods will skip evaluation of an l2a that has a
reference count of one, so that prevents the register containing the
operand of the l2a from being marked as a collected reference.

In the longer term, OMR issue 6508 proposes introducing a new opcode -
l2gcref - that would be used to mark explicitly the result of a
conversion from long to an address as holding a collected reference.
Once implemented, the change implemented by this commit can be reverted.
@hzongaro
Copy link
Contributor Author

hzongaro commented Jan 6, 2024

@vijaysun-omr, may I ask you to review this change?

@@ -1186,6 +1186,9 @@ bool OMR::LocalCSE::canBeAvailable(TR::Node *parent, TR::Node *node, TR_BitVecto
if (node->getOpCodeValue() == TR::allocationFence)
return false;

if (node->getOpCodeValue() == TR::l2a)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should TR::i2a also be treated the same way (could be used on 32-bit maybe ?) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you have time to handle TR::i2a in the next day or so, please do so. Otherwise I won't hold up this fix (assuming all tests pass) past tomorrow, since it is addressing a real failure, and you can add the TR::i2a in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't touched the other operations that convert to address, as their evaluators don't seem to mark their registers as collected references. To be safe, I'll capture all of the *2a operators in a follow-on pull request that checks the following in OMR::LocalCSE::canBeAvailable instead:

if (node->getOpCode().isConversion() && node->getOpCode().isRef())
   return false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened pull request #7218 to address this comment.

@vijaysun-omr
Copy link
Contributor

jenkins build all

@vijaysun-omr
Copy link
Contributor

Tests have passed (except for macOS where the build was cancelled). Merging.

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.

2 participants