Skip to content

Commit

Permalink
Merge pull request #18212 from mpirvu/codecacheracefix
Browse files Browse the repository at this point in the history
Fix code cache segment race condition
  • Loading branch information
gacholio committed Oct 4, 2023
2 parents 333d6c2 + 16b1a33 commit c9b2519
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions runtime/vm/segment.c
Expand Up @@ -32,6 +32,7 @@
#include "vm_internal.h"
#include "segment.h"
#include "j9modron.h"
#include "omrutilbase.h"

#define ROUND_TO(granularity, number) (((number) + (granularity) - 1) & ~((UDATA)(granularity) - 1))

Expand Down Expand Up @@ -404,6 +405,13 @@ static J9MemorySegment * allocateVirtualMemorySegmentInListInternal(J9JavaVM *ja
freeMemorySegmentListEntry(segmentList, segment);
segment = NULL;
} else {
if (J9_ARE_ALL_BITS_SET(type, MEMORY_TYPE_CODE)) {
/* For CodeCache segments the JIT will later write a TR::CodeCache structure pointer at the begining of the segment.
* Until then, make sure that a potential reader sees a NULL pointer.
*/
*((UDATA**)allocatedBase) = NULL;
issueWriteBarrier();
}
segment->baseAddress = allocatedBase;
segment->heapBase = allocatedBase;
segment->heapTop = (U_8 *)&(segment->heapBase)[size];
Expand Down

0 comments on commit c9b2519

Please sign in to comment.