Skip to content

Commit

Permalink
Merge pull request #19967 from mpirvu/iprofiler_race
Browse files Browse the repository at this point in the history
Make IProfiler race conditon less likely
  • Loading branch information
dsouzai authored Aug 7, 2024
2 parents 27dac39 + a0b3479 commit 8d929fe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions runtime/compiler/runtime/IProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,17 @@ TR_IProfiler::findOrCreateEntry(int32_t bucket, uintptr_t pc, bool addIt)
if (!entry)
return NULL;

// While the entry is being allocated, another thread could have added an entry with the same PC.
// If that happened, it's likely that the duplicate entry is at the head of this list.
// Check to see if that's the case. This technique does not eliminate the race completely
// but catches most of duplicate situations.
TR_IPBytecodeHashTableEntry *headEntry = _bcHashTable[bucket];
if (headEntry && headEntry->getPC() == pc)
{
// Note: We never delete IP entries
return headEntry;
}

entry->setNext(_bcHashTable[bucket]);
FLUSH_MEMORY(TR::Compiler->target.isSMP());
_bcHashTable[bucket] = entry;
Expand Down

0 comments on commit 8d929fe

Please sign in to comment.