Skip to content

Make IProfiler race conditon less likely #19967

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
merged 1 commit into from
Aug 7, 2024

Conversation

mpirvu
Copy link
Contributor

@mpirvu mpirvu commented Aug 3, 2024

Interpreter profiling is uses lockless mechanisms that allow for some races to occur. The outcome of these races is some small memory leak.
When adding new profiling info to the IProfiler hashtable, we first determine if an entry with the same pc exists (pc is the key) and if not, we allocate memory for a new entry and then add the entry to the head of the linked list of the corresponding bucket of the IP hashtable. It turns out that allocating memory for a new entry is relatively expensive, and in this window of time another thread could perform the same check, deciding to add a new entry with the same pc.
This commit performs another check just before adding to the linked list of the bucket. This reduces the likelihood of two threads adding entries with the same pc.

@mpirvu mpirvu requested a review from dsouzai as a code owner August 3, 2024 21:41
@mpirvu
Copy link
Contributor Author

mpirvu commented Aug 3, 2024

jenkins test sanity all jdk21

Interpreter profiling is uses lockless mechanisms that
allow for some races to occur. The outcome of these races
is some small memory leak.
When adding new profiling info to the IProfiler hashtable, we
first determine if an entry with the same pc exists (pc is the key)
and if not, we allocate memory for a new entry and then add the
entry to the head of the linked list of the corresponding bucket
of the IP hashtable. It turns out that allocating memory for a
new entry is relatively expensive, and in this window of time
another thread could perform the same check, deciding to add
a new entry with the same pc.
This commit performs another check just before adding to the
linked list of the bucket. This reduces the likelihood of
two threads adding entries with the same pc.

Signed-off-by: Marius Pirvu <[email protected]>
@mpirvu
Copy link
Contributor Author

mpirvu commented Aug 4, 2024

jenkins test sanity xlinux jdk21

@mpirvu
Copy link
Contributor Author

mpirvu commented Aug 5, 2024

jenkins test sanity all jdk17

if (headEntry && headEntry->getPC() == pc)
{
// Note: We never delete IP entries
return headEntry;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we detect this, shouldn't we delete entry so that we don't leak here?

Copy link
Contributor Author

@mpirvu mpirvu Aug 7, 2024

Choose a reason for hiding this comment

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

The allocator does some alignment which means that the pointer we get back may not be the real start of the allocated block. The assumption was all along that we never delete IP entries. The delete operator is actually empty.

@dsouzai dsouzai merged commit 8d929fe into eclipse-openj9:master Aug 7, 2024
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants