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

Deterministic System.identityHashCode for Trace Debugger. #444

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

ndkoval
Copy link
Collaborator

@ndkoval ndkoval commented Jan 17, 2025

This is an adapted version of #430.

@zhelenskiy zhelenskiy self-requested a review January 21, 2025 17:21
Copy link
Collaborator

@zhelenskiy zhelenskiy left a comment

Choose a reason for hiding this comment

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

Rebase on top of new develop, please.

@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch from 687083c to c9af12a Compare January 24, 2025 21:01
@zhelenskiy zhelenskiy requested review from zhelenskiy and eupp and removed request for zhelenskiy January 24, 2025 21:08
zhelenskiy
zhelenskiy previously approved these changes Jan 24, 2025
@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch 4 times, most recently from d0fe5f2 to f6f8002 Compare January 25, 2025 19:53
identityHashCode = System.identityHashCode(obj)
)
// ATTENTION: bizarre and crazy code below (might not work for all JVM implementations)
UnsafeHolder.UNSAFE.putInt(obj, IDENTITY_HASHCODE_OFFSET, initialIdentityHashCode)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need a CAS here, this put races with GC allocation/monitor inflation etc.

Also, you may want to triple-check it with liliput and header shenanigans: https://wiki.openjdk.org/display/lilliput/Compact+Identity+Hashcode

Copy link
Collaborator

@zhelenskiy zhelenskiy Jan 25, 2025

Choose a reason for hiding this comment

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

I call identityHashCode in line 51, so by line 54, the hash-code of the newly created object must be already calculated and stored inside. So, there would be no need for CAS.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As @zhelenskiy mentioned, the hash-code computation is enforced just before this line, so the hash code should already be stored.

Given that we currently run this tracker under ManagedStrategy, which controls thread scheduling, only single thread can have access to this object at the time, so no other thread may try to synchronize on this object and set its lock bits.

So it looks like the only possibility is if the concurrent GC will decide to change some marking bits concurrently.
I am not sure what exactly can happen in this case. Although the two concurrent writes (our hash code write and GC mark bits write) are to disjoint bits, they are still going to be rounded off to word-sized writes, and thus interfere with each other. Even worse, I am not sure would it be the case that int-sized write at offset of 1 byte can lead to word-tearing?

On the other hand, we don't observe the bugs on our CI right now.
And this is still an early prototype, and we might still decide to choose some alternative implementation strategy for deterministic hash-codes later.

So we left a comment and TODOs to investigate the problem further in the future.

@zhelenskiy zhelenskiy requested a review from qwwdfsad January 25, 2025 21:30
@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch from f6f8002 to 90aa51d Compare January 27, 2025 20:16
@zhelenskiy zhelenskiy self-assigned this Jan 27, 2025
@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch 3 times, most recently from bbcf605 to 2eda219 Compare February 3, 2025 18:33
@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch 7 times, most recently from 5f07261 to 29d50c3 Compare February 5, 2025 21:18
@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch 5 times, most recently from 7ab9d11 to 50c3f25 Compare February 6, 2025 03:02
@zhelenskiy zhelenskiy force-pushed the trace-debugger-identity-hash-code branch from 50c3f25 to 9fa9d1c Compare February 6, 2025 03:32
eupp and others added 6 commits February 6, 2025 20:00
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
@eupp
Copy link
Collaborator

eupp commented Feb 6, 2025

Merge is blocked without @qwwdfsad approval : )

@qwwdfsad should we wait for review or can we proceed?

@qwwdfsad qwwdfsad requested review from qwwdfsad and removed request for qwwdfsad February 7, 2025 12:50
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.

4 participants