diff --git a/compiler/runtime/OMRCodeCacheMemorySegment.cpp b/compiler/runtime/OMRCodeCacheMemorySegment.cpp index be34848fa1e..3bd3b4003ff 100644 --- a/compiler/runtime/OMRCodeCacheMemorySegment.cpp +++ b/compiler/runtime/OMRCodeCacheMemorySegment.cpp @@ -21,6 +21,7 @@ #include "runtime/CodeCacheMemorySegment.hpp" #include "runtime/CodeCacheManager.hpp" +#include "thread_api.h" TR::CodeCacheMemorySegment* OMR::CodeCacheMemorySegment::self() @@ -42,3 +43,37 @@ OMR::CodeCacheMemorySegment::free(TR::CodeCacheManager *manager) manager->freeMemory(_base); new (static_cast(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(); + } diff --git a/compiler/runtime/OMRCodeCacheMemorySegment.hpp b/compiler/runtime/OMRCodeCacheMemorySegment.hpp index fe6abffe47d..25d9e2a99b1 100644 --- a/compiler/runtime/OMRCodeCacheMemorySegment.hpp +++ b/compiler/runtime/OMRCodeCacheMemorySegment.hpp @@ -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); diff --git a/jitbuilder/runtime/JBCodeCacheManager.cpp b/jitbuilder/runtime/JBCodeCacheManager.cpp index ecacdc428c2..5d30a055113 100644 --- a/jitbuilder/runtime/JBCodeCacheManager.cpp +++ b/jitbuilder/runtime/JBCodeCacheManager.cpp @@ -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(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(memSegment)); -#endif + omrthread_jit_write_protect_enable(); return memSegment; } @@ -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