Skip to content

Commit 8d929fe

Browse files
authored
Merge pull request #19967 from mpirvu/iprofiler_race
Make IProfiler race conditon less likely
2 parents 27dac39 + a0b3479 commit 8d929fe

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

runtime/compiler/runtime/IProfiler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,17 @@ TR_IProfiler::findOrCreateEntry(int32_t bucket, uintptr_t pc, bool addIt)
11211121
if (!entry)
11221122
return NULL;
11231123

1124+
// While the entry is being allocated, another thread could have added an entry with the same PC.
1125+
// If that happened, it's likely that the duplicate entry is at the head of this list.
1126+
// Check to see if that's the case. This technique does not eliminate the race completely
1127+
// but catches most of duplicate situations.
1128+
TR_IPBytecodeHashTableEntry *headEntry = _bcHashTable[bucket];
1129+
if (headEntry && headEntry->getPC() == pc)
1130+
{
1131+
// Note: We never delete IP entries
1132+
return headEntry;
1133+
}
1134+
11241135
entry->setNext(_bcHashTable[bucket]);
11251136
FLUSH_MEMORY(TR::Compiler->target.isSMP());
11261137
_bcHashTable[bucket] = entry;

0 commit comments

Comments
 (0)