From f1f0c47f160c94be92963023bb0035651faa7f26 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Wed, 24 Jan 2024 00:48:55 +0000 Subject: [PATCH 1/3] AllocatorHooks: Allow using jemalloc on win32 --- .../include/FEXCore/Utils/AllocatorHooks.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/FEXCore/include/FEXCore/Utils/AllocatorHooks.h b/FEXCore/include/FEXCore/Utils/AllocatorHooks.h index 0d0c246317..8650a2de4c 100644 --- a/FEXCore/include/FEXCore/Utils/AllocatorHooks.h +++ b/FEXCore/include/FEXCore/Utils/AllocatorHooks.h @@ -90,7 +90,18 @@ namespace FEXCore::Allocator { #endif // Memory allocation routines aliased to jemalloc functions. -#ifdef _WIN32 +#ifdef ENABLE_JEMALLOC + inline void *malloc(size_t size) { return ::je_malloc(size); } + inline void *calloc(size_t n, size_t size) { return ::je_calloc(n, size); } + inline void *memalign(size_t align, size_t s) { return ::je_memalign(align, s); } + inline void *valloc(size_t size) { return ::je_valloc(size); } + inline int posix_memalign(void** r, size_t a, size_t s) { return ::je_posix_memalign(r, a, s); } + inline void *realloc(void* ptr, size_t size) { return ::je_realloc(ptr, size); } + inline void free(void* ptr) { return ::je_free(ptr); } + inline size_t malloc_usable_size(void *ptr) { return ::je_malloc_usable_size(ptr); } + inline void *aligned_alloc(size_t a, size_t s) { return ::je_aligned_alloc(a, s); } + inline void aligned_free(void* ptr) { return ::je_free(ptr); } +#elif defined(_WIN32) inline void *malloc(size_t size) { return ::malloc(size); } inline void *calloc(size_t n, size_t size) { return ::calloc(n, size); } inline void *memalign(size_t align, size_t s) { return ::_aligned_malloc(s, align); } @@ -110,17 +121,6 @@ namespace FEXCore::Allocator { inline size_t malloc_usable_size(void *ptr) { return ::_msize(ptr); } inline void *aligned_alloc(size_t a, size_t s) { return ::_aligned_malloc(s, a); } inline void aligned_free(void* ptr) { return ::_aligned_free(ptr); } -#elif defined(ENABLE_JEMALLOC) - inline void *malloc(size_t size) { return ::je_malloc(size); } - inline void *calloc(size_t n, size_t size) { return ::je_calloc(n, size); } - inline void *memalign(size_t align, size_t s) { return ::je_memalign(align, s); } - inline void *valloc(size_t size) { return ::je_valloc(size); } - inline int posix_memalign(void** r, size_t a, size_t s) { return ::je_posix_memalign(r, a, s); } - inline void *realloc(void* ptr, size_t size) { return ::je_realloc(ptr, size); } - inline void free(void* ptr) { return ::je_free(ptr); } - inline size_t malloc_usable_size(void *ptr) { return ::je_malloc_usable_size(ptr); } - inline void *aligned_alloc(size_t a, size_t s) { return ::je_aligned_alloc(a, s); } - inline void aligned_free(void* ptr) { return ::je_free(ptr); } #else inline void *malloc(size_t size) { return ::malloc(size); } inline void *calloc(size_t n, size_t size) { return ::calloc(n, size); } From 5ed593b59f80fd6b9d9c9d7f51419a0cea344e80 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Wed, 21 Feb 2024 11:19:30 +0000 Subject: [PATCH 2/3] CMake: Force enable jemalloc when targetting ARM64EC --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b53c80fde3..329c58abc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,9 @@ endif() if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm64ec") set(_M_ARM_64EC 1) add_definitions(-D_M_ARM_64EC=1) + + # Required as FEX is not allowed to lock the CRT heap lock during compilation or callbacks + set(ENABLE_JEMALLOC TRUE) endif() if (ENABLE_CCACHE) From 7ff4cd9108615a89ae41f3be4e2d025615990e4d Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Tue, 9 Apr 2024 23:43:49 +0000 Subject: [PATCH 3/3] Update jemalloc submodule --- External/jemalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/jemalloc b/External/jemalloc index 16f8061955..5695452413 160000 --- a/External/jemalloc +++ b/External/jemalloc @@ -1 +1 @@ -Subproject commit 16f80619558c44c917695228e00c1a7ec1b2b752 +Subproject commit 569545241370457e2d14b0458b0ae9261491ea83