Skip to content

Commit

Permalink
Merge pull request #7129 from mpirvu/codecacheracefix
Browse files Browse the repository at this point in the history
Fix code cache segment race condition
  • Loading branch information
dsouzai authored Oct 4, 2023
2 parents 366c6e8 + 24685fe commit 83cb598
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions compiler/runtime/OMRCodeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "AtomicSupport.hpp"
#include "env/FrontEnd.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
Expand Down Expand Up @@ -309,9 +310,6 @@ OMR::CodeCache::initialize(TR::CodeCacheManager *manager,
_sizeOfLargestFreeWarmBlock = 0;
_lastAllocatedBlock = NULL; // MP

omrthread_jit_write_protect_disable();
*((TR::CodeCache **)(_segment->segmentBase())) = self(); // Write a pointer to this cache at the beginning of the segment
omrthread_jit_write_protect_enable();
_warmCodeAlloc = _segment->segmentBase() + sizeof(this);

_warmCodeAlloc = (uint8_t *)align((size_t)_warmCodeAlloc, config.codeCacheAlignment());
Expand Down Expand Up @@ -417,6 +415,13 @@ OMR::CodeCache::initialize(TR::CodeCacheManager *manager,
size_t spaceLost = (_warmCodeAlloc - _segment->segmentBase()) + (_segment->segmentTop() - _trampolineBase);
_manager->increaseCurrTotalUsedInBytes(spaceLost);

// Now that we have initialized the code cache, (including _warmCodeAlloc and _coldCodeAlloc)
// write a pointer to this cache at the beginning of the segment
VM_AtomicSupport::writeBarrier();
omrthread_jit_write_protect_disable();
*((TR::CodeCache **)(_segment->segmentBase())) = self();
omrthread_jit_write_protect_enable();

return true;
}

Expand Down

0 comments on commit 83cb598

Please sign in to comment.