Skip to content

Commit

Permalink
Merge pull request eclipse-omr#7151 from Akira1Saitoh/AMacJitBuilderVMem
Browse files Browse the repository at this point in the history
Update JBCodeCacheManager to allocate segment objects on mmaped memory
  • Loading branch information
knn-k authored Oct 25, 2023
2 parents 9bec530 + 6e63f2e commit 071c0c2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
35 changes: 35 additions & 0 deletions compiler/runtime/OMRCodeCacheMemorySegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "runtime/CodeCacheMemorySegment.hpp"
#include "runtime/CodeCacheManager.hpp"
#include "thread_api.h"

TR::CodeCacheMemorySegment*
OMR::CodeCacheMemorySegment::self()
Expand All @@ -42,3 +43,37 @@ OMR::CodeCacheMemorySegment::free(TR::CodeCacheManager *manager)
manager->freeMemory(_base);
new (static_cast<TR::CodeCacheMemorySegment *>(this)) TR::CodeCacheMemorySegment();
}

void
OMR::CodeCacheMemorySegment::setSegmentBase(uint8_t *newBase)
{
/*
* Assuming the code cache memory segment is allocated on the code cache memory,
* we need to modify the memory's permission before and after updating members.
*/
omrthread_jit_write_protect_disable();
_base = newBase;
omrthread_jit_write_protect_enable();
}

void OMR::CodeCacheMemorySegment::setSegmentAlloc(uint8_t *newAlloc)
{
/*
* Assuming the code cache memory segment is allocated on the code cache memory,
* we need to modify the memory's permission before and after updating members.
*/
omrthread_jit_write_protect_disable();
_alloc = newAlloc;
omrthread_jit_write_protect_enable();
}

void OMR::CodeCacheMemorySegment::setSegmentTop(uint8_t *newTop)
{
/*
* Assuming the code cache memory segment is allocated on the code cache memory,
* we need to modify the memory's permission before and after updating members.
*/
omrthread_jit_write_protect_disable();
_top = newTop;
omrthread_jit_write_protect_enable();
}
6 changes: 3 additions & 3 deletions compiler/runtime/OMRCodeCacheMemorySegment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class OMR_EXTENSIBLE CodeCacheMemorySegment

void adjustAlloc(int64_t adjust);

void setSegmentBase(uint8_t *newBase) { _base = newBase; }
void setSegmentAlloc(uint8_t *newAlloc) { _alloc = newAlloc; }
void setSegmentTop(uint8_t *newTop) { _top = newTop; }
void setSegmentBase(uint8_t *newBase);
void setSegmentAlloc(uint8_t *newAlloc);
void setSegmentTop(uint8_t *newTop);

// memory is backed by something else
void free(TR::CodeCacheManager *manager);
Expand Down
10 changes: 2 additions & 8 deletions jitbuilder/runtime/JBCodeCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,10 @@ JitBuilder::CodeCacheManager::allocateCodeCacheSegment(size_t segmentSize,
#undef NO_MAP_ANONYMOUS
#endif
#endif /* OMR_OS_WINDOWS */
#if defined(OMR_ARCH_AARCH64) && defined(OSX)
TR::CodeCacheMemorySegment *memSegment = (TR::CodeCacheMemorySegment *) malloc(sizeof(TR::CodeCacheMemorySegment));
new (memSegment) TR::CodeCacheMemorySegment(memorySlab, reinterpret_cast<uint8_t *>(memorySlab) + codeCacheSizeToAllocate);
#else /* OMR_ARCH_AARCH64 && OSX */
omrthread_jit_write_protect_disable();
TR::CodeCacheMemorySegment *memSegment = (TR::CodeCacheMemorySegment *) ((size_t)memorySlab + codeCacheSizeToAllocate - sizeof(TR::CodeCacheMemorySegment));
new (memSegment) TR::CodeCacheMemorySegment(memorySlab, reinterpret_cast<uint8_t *>(memSegment));
#endif
omrthread_jit_write_protect_enable();
return memSegment;
}

Expand All @@ -128,9 +125,6 @@ JitBuilder::CodeCacheManager::freeCodeCacheSegment(TR::CodeCacheMemorySegment *
VirtualFree(memSegment->_base, 0, MEM_RELEASE); // second arg must be zero when calling with MEM_RELEASE
#elif defined(J9ZOS390)
free(memSegment->_base);
#elif defined(OMR_ARCH_AARCH64) && defined(OSX)
munmap(memSegment->_base, memSegment->_top - memSegment->_base);
free(memSegment);
#else
munmap(memSegment->_base, memSegment->_top - memSegment->_base + sizeof(TR::CodeCacheMemorySegment));
#endif
Expand Down

0 comments on commit 071c0c2

Please sign in to comment.