JIT: Properly unify JIT behaviour on OSX so both x86_64 and arm64 uses dynamic allocation for JIT (#2783)

* JIT: Re-enable ENABLE_JIT for x86_64 OS X

* JIT: Force *ALL* OS X arch's to use dynamic JIT code paths

* JIT: let arm64 OS X use dynamic memory alloc

* JIT: revert "let arm64 OS X use dynamic memory alloc" & change the check to also check for arm64
This commit is contained in:
Izzy Meyer authored and GitHub committed 2026-10-21 23:16:04 +02:00
1 parent 906e9ebb27
commit 7d8dea42e2
2 files changed
+7 -11

No files matched your search

+1 -1
View File
@@ -63,7 +63,7 @@ detect_architecture("__arm__" ARM)
detect_architecture("__aarch64__" ARM64)
cmake_dependent_option(ENABLE_JIT "Enable JIT recompiler" ON
"ARCHITECTURE STREQUAL x86_64 OR ARCHITECTURE STREQUAL ARM64;NOT ARCHITECTURE STREQUAL x86_64 OR NOT APPLE" OFF)
"ARCHITECTURE STREQUAL x86_64 OR ARCHITECTURE STREQUAL ARM64" OFF)
cmake_dependent_option(ENABLE_JIT_PROFILING "Enable JIT profiling with VTune" OFF "ENABLE_JIT" OFF)
option(ENABLE_OGLRENDERER "Enable OpenGL renderer" ON)
+6 -10
View File
@@ -21,11 +21,7 @@ namespace ARMJIT_Global
std::mutex globalMutex;
#if defined(__APPLE__) && defined(__aarch64__)
#define APPLE_AARCH64
#endif
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__) && !defined(__OpenBSD__)
#if !defined(__APPLE__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
static constexpr size_t NumCodeMemSlices = 4;
static constexpr size_t CodeMemoryAlignedSize = NumCodeMemSlices * CodeMemorySliceSize;
@@ -46,7 +42,7 @@ void* AllocateCodeMem()
{
std::lock_guard guard(globalMutex);
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__) && !defined(__OpenBSD__)
#if !defined(__APPLE__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
if (AvailableCodeMemSlices)
{
int slice = __builtin_ctz(AvailableCodeMemSlices);
@@ -59,7 +55,7 @@ void* AllocateCodeMem()
// allocate
#ifdef _WIN32
return VirtualAlloc(nullptr, CodeMemorySliceSize, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#elif defined(APPLE_AARCH64)
#elif defined(__APPLE__) && defined(__aarch64__)
return mmap(NULL, CodeMemorySliceSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT,-1, 0);
#elif defined(__NetBSD__)
return mmap(nullptr, CodeMemorySliceSize, PROT_MPROTECT(PROT_READ | PROT_WRITE | PROT_EXEC), MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
@@ -73,7 +69,7 @@ void FreeCodeMem(void* codeMem)
{
std::lock_guard guard(globalMutex);
#if !defined(APPLE_AARCH64) && !defined(__NetBSD__) && !defined(__OpenBSD__)
#if !defined(__APPLE__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
for (int i = 0; i < NumCodeMemSlices; i++)
{
if (codeMem == &GetAlignedCodeMemoryStart()[CodeMemorySliceSize * i])
@@ -102,8 +98,8 @@ void Init()
#ifdef _WIN32
DWORD dummy;
VirtualProtect(GetAlignedCodeMemoryStart(), CodeMemoryAlignedSize, PAGE_EXECUTE_READWRITE, &dummy);
#elif defined(APPLE_AARCH64) || defined(__NetBSD__) || defined(__OpenBSD__)
// Apple aarch64 always uses dynamic allocation
#elif defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__)
// these platforms always use dynamic allocation
#else
mprotect(GetAlignedCodeMemoryStart(), CodeMemoryAlignedSize, PROT_EXEC | PROT_READ | PROT_WRITE);
#endif