Skip to content

[0.46.0] Change order of tests for inline Unsafe.{get|put}* calls #19660

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

Merged

Conversation

hzongaro
Copy link
Member

@hzongaro hzongaro commented Jun 9, 2024

If the J9Class for java/lang/Class is available to the compiler, the IL it generates inline for Unsafe.{get|put}{int|long|Object}* tests whether the Object being accessed is null (for native memory references), has the low-order bit set for the specified offset and whether its J9Class is that of java/lang/Class, in that order. Those tests are trying to distinguish whether a static field is being accessed, which requires different code to access the memory than all the other cases.

For both instance fields and static fields, the Object will be a non-null reference. However, the low-order bit of the offset will never be set for instance fields. Therefore, what is likely the most common usage would benefit from having the low-order offset bit tested first.

This commit changes the order of the tests accordingly for that case.

This opportunity was identified by @vijaysun-omr and @ymanton.

This is a port of pull request #19640 to the v0.46.0-release branch.

hzongaro added 2 commits June 9, 2024 09:09
If the J9Class for java/lang/Class is available to the compiler, the
IL it generates inline for Unsafe.{get|put}{int|long|Object}* tests
whether the Object being accessed is null (for native memory
references), has the low-order bit set for the specified offset
and whether its J9Class is that of java/lang/Class, in that order.
Those tests are trying to distinguish whether a static field is being
accessed, which requires different code to access the memory than
all the other cases.

For both instance fields and static fields, the Object will be a non-
null reference.  However, the low-order bit of the offset will never
be set for instance fields.  Therefore, what is likely the most common
usage would benefit from having the low-order offset bit tested first.

This commit changes the order of the tests accordingly for that case.

Signed-off-by:  Henry Zongaro <[email protected]>
Various places in the inliner refer to the target TR::Block,
TR::TreeTop or TR::Node of a branch in the IL as the "if" path and the
fall-through path as the "else" path.  Programmers might have different
intuitions about whether the fall-through path is the "if path" or the
"else" path.

To avoid confusion, this change updates variable names to make it clear
whether they represent things that will be executed if the branch is
taken or executed if the branch is not taken.

Signed-off-by:  Henry Zongaro <[email protected]>
@hzongaro
Copy link
Member Author

hzongaro commented Jun 9, 2024

@vijaysun-omr, may I ask you to consider this for the v0.46.0-release branch?

@vijaysun-omr
Copy link
Contributor

I have reviewed that the code changes are what was merged in the head stream a couple of days back. Henry has done extensive testing that is mentioned in the head stream PR.

@vijaysun-omr vijaysun-omr merged commit 3bbdb0e into eclipse-openj9:v0.46.0-release Jun 10, 2024
@hzongaro hzongaro deleted the unsafe-test-order-0.46.0 branch June 10, 2024 17:11
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