Skip to content

Add value type hash logic under Valhalla flag - #24224

Merged
hangshao0 merged 1 commit into
eclipse-openj9:masterfrom
AditiS11:hashcode_perf
Jul 9, 2026
Merged

Add value type hash logic under Valhalla flag#24224
hangshao0 merged 1 commit into
eclipse-openj9:masterfrom
AditiS11:hashcode_perf

Conversation

@AditiS11

Copy link
Copy Markdown
  • Guard zero hashcode check with Valhalla flags.

@theresa-m theresa-m added comp:vm project:valhalla Used to track Project Valhalla related work labels Jun 24, 2026

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

GC part of the change is good. And most likely there is the reason for regression. Need to inline or call function might change registers layout potentially.

Comment thread jcl/src/java.base/share/classes/java/lang/J9VMInternals.java Outdated
/* If the hash is 0, it may be a value object and the hash should be calculated. */
if (0 != hashValue) {
return hashValue;
if (0 == hashValue) {

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.

Why not also adding a check if the object is VT before calling identityHashCode() ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I felt that if the hash is zero, it's clear that the object is a value type, so I didn't add an additional check.

If we do add one, it introduces another if condition that would be executed. Could that cause a performance regression in Valhalla builds?

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 felt that if the hash is zero, it's clear that the object is a value type, so I didn't add an additional check.

What this PR does is to move the zero hashcode case into the Valhalla flag, and it fixed a performance regression in non-Valhalla build, where there is no value types. So it means there are non-value types that have zero hashcode and they have a measurable performance impact if the code directly calls into identityHashCode(). Do I miss anything ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The zero hashcode check was added by me while implementing hash calculation for value types.
So I think non-value types will not have a zero hash.

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.

So I think non-value types will not have a zero hash.

Do we have code that prevent non-value type having zero hash ?

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.

My point is that the regression (this PR is trying to fix) is caused by non-value type objects that have zero hash code and we repeated calls into identityHashCode() for sub objects. So we do have non-value type objects with zero hash.

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.

My point is that the regression (this PR is trying to fix) is caused by non-value type objects that have zero hash code and we repeated calls into identityHashCode() for sub objects. So we do have non-value type objects with zero hash.

Do we have confirmation of this theory, do we really see valid 0 hash codes in mass for non-vt builds?
My theory most likely the reason of regression is adding handling of hash code equal 0 (calling function in this case) has introduced new registers/memory usage layout, for example move some values from registers to c-stack. This known xLC for Z compiler behaviour. As a result hot code in GC executes slowly.

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 value classes can be detected less expensively than an unnecessary call to identityHashCode(), then perhaps we should do that:

				/* If the hash is 0, and it is a value object, the hash should be calculated. */
				if ((0 == hashValue) && anObject.getClass().isValue()) {
					return identityHashCode(anObject);
				}

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.

Do we have confirmation of this theory, do we really see valid 0 hash codes in mass for non-vt builds?

We all agree that the handling of zero hash should be moved inside the valhalla flags.

It is just whether to add anObject.getClass().isValue() check. @AditiS11 You can provide 2 builds with and without this check to the perf team to do a comparison.

@dmitripivkine dmitripivkine Jun 26, 2026

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.

As a test we can add print or even assertion if non-vt build discovers zero hash code. I have a suspicion we will never observe it.

Comment thread runtime/gc_glue_java/ObjectModel.hpp
@AditiS11
AditiS11 force-pushed the hashcode_perf branch 2 times, most recently from 5096e99 to af0d3d3 Compare June 29, 2026 05:40
@AditiS11

AditiS11 commented Jun 29, 2026

Copy link
Copy Markdown
Author

I have added the isValue() check.
The check is within the Valhalla flag, hence I don't think it will create any difference in performance for the normal build.
Should I check the performance results a the Valhalla build?

@hangshao0

Copy link
Copy Markdown
Contributor

I have added the isValue() check.
The check is within the Valhalla flag, hence I don't think it will create any difference in performance for the normal build.
Should I check the performance results a the Valhalla build?

@dmitripivkine suggested the following:

As a test we can add print or even assertion if non-vt build discovers zero hash code. I have a suspicion we will never observe it.

You can build a non-vt JDK with the suggested change and let the perf team run that to see if we really hit the non-VT zero hashcode case.

Comment thread jcl/src/java.base/share/classes/java/lang/J9VMInternals.java
Comment thread runtime/gc_glue_java/ObjectModel.hpp
@AditiS11

Copy link
Copy Markdown
Author

I have made the changes and shared the build with the perf team.

@hangshao0

Copy link
Copy Markdown
Contributor

I have made the changes and shared the build with the perf team.

Thanks. Please update here once you get the result from the perf team.

@AditiS11

AditiS11 commented Jul 1, 2026

Copy link
Copy Markdown
Author

Went through the benchmark console logs, the print statement was not hit.

@hangshao0

hangshao0 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Went through the benchmark console logs, the print statement was not hit.

OK, so we didn't not hit the zero hashcode case. I'll leave it to you and other reviewers whether to add/keep the anObject.getClass().isValue() check.

@AditiS11

AditiS11 commented Jul 6, 2026

Copy link
Copy Markdown
Author

I have removed the anObject.getClass().isValue() check as I feel it would add a performance overhead for the valhalla builds.

@AditiS11
AditiS11 requested a review from keithc-ca July 8, 2026 12:15
@hangshao0

Copy link
Copy Markdown
Contributor

@keithc-ca This is waiting for your approval.

@keithc-ca

Copy link
Copy Markdown
Contributor

I'll make time to have another look tomorrow.

Comment thread jcl/src/java.base/share/classes/java/lang/J9VMInternals.java Outdated
- Guard zero hashcode check with Valhalla flags.

Signed-off-by: Aditi Srinivas M <Aditi.Srini@ibm.com>
@keithc-ca

Copy link
Copy Markdown
Contributor

@hangshao0 Please initiate testing you think appropriate.

@hangshao0

Copy link
Copy Markdown
Contributor

Jenkins test sanity.functional,extended alinuxval jdknext

@hangshao0

Copy link
Copy Markdown
Contributor

Jenkins compile amac jdk21

@hangshao0
hangshao0 merged commit d17cae1 into eclipse-openj9:master Jul 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:gc comp:vm project:valhalla Used to track Project Valhalla related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants