diff --git a/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp b/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp index 6c1e1ae21..7fa145000 100644 --- a/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp +++ b/External/FEXCore/Source/Interface/IR/Passes/RegisterAllocationPass.cpp @@ -90,7 +90,7 @@ namespace { IR::OrderedNode *SpilledNode; }; - struct RegisterGraph { + struct RegisterGraph : public FEXCore::Allocator::FEXAllocOperators { IR::RegisterAllocationData::UniquePtr AllocData; RegisterSet Set; fextl::vector Nodes{}; @@ -98,15 +98,6 @@ namespace { fextl::vector SpillStack; fextl::unordered_map> BlockPredecessors; fextl::unordered_map> VisitedNodePredecessors; - - // Required due to raw new usage. - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } }; void ResetRegisterGraph(RegisterGraph *Graph, uint64_t NodeCount); diff --git a/External/FEXCore/include/FEXCore/Debug/InternalThreadState.h b/External/FEXCore/include/FEXCore/Debug/InternalThreadState.h index 47395bd7c..c5b2fdbe9 100644 --- a/External/FEXCore/include/FEXCore/Debug/InternalThreadState.h +++ b/External/FEXCore/include/FEXCore/Debug/InternalThreadState.h @@ -58,20 +58,11 @@ namespace FEXCore::Core { * * Needs to remain around for as long as the code could be executed at least */ - struct DebugData { + struct DebugData : public FEXCore::Allocator::FEXAllocOperators { uint64_t HostCodeSize; ///< The size of the code generated in the host JIT fextl::vector Subblocks; fextl::vector GuestOpcodes; fextl::vector *Relocations; - - // Required due to raw new usage. - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } }; enum class SignalEvent { @@ -90,7 +81,7 @@ namespace FEXCore::Core { fextl::unique_ptr DebugData; }; - struct InternalThreadState { + struct InternalThreadState : public FEXCore::Allocator::FEXAllocOperators { FEXCore::Core::CpuStateFrame* const CurrentFrame = &BaseFrameState; struct { @@ -128,15 +119,6 @@ namespace FEXCore::Core { std::shared_mutex ObjectCacheRefCounter{}; bool DestroyedByParent{false}; // Should the parent destroy this thread, or it destory itself - // Required due to raw new usage. - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } - alignas(16) FEXCore::Core::CpuStateFrame BaseFrameState{}; }; diff --git a/External/FEXCore/include/FEXCore/IR/IntrusiveIRList.h b/External/FEXCore/include/FEXCore/IR/IntrusiveIRList.h index f9cc621a6..e2c46f299 100644 --- a/External/FEXCore/include/FEXCore/IR/IntrusiveIRList.h +++ b/External/FEXCore/include/FEXCore/IR/IntrusiveIRList.h @@ -120,7 +120,7 @@ class DualIntrusiveAllocatorThreadPool final : public DualIntrusiveAllocator { Utils::FixedSizePooledAllocation PoolObject; }; -class IRListView final { +class IRListView final : public FEXCore::Allocator::FEXAllocOperators { enum Flags { FLAG_IsCopy = 1, FLAG_Shared = 2, @@ -170,15 +170,6 @@ public: } } - // Required due to raw new usage. - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } - void Serialize(std::ostream& stream) const { void *nul = nullptr; //void *IRDataInternal; diff --git a/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h b/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h index 57a2baeff..d8ef2974f 100644 --- a/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h +++ b/External/FEXCore/include/FEXCore/Utils/AllocatorHooks.h @@ -30,4 +30,16 @@ namespace FEXCore::Allocator { FEX_DEFAULT_VISIBILITY extern FREE_Hook free; FEX_DEFAULT_VISIBILITY extern MALLOC_USABLE_SIZE_Hook malloc_usable_size; FEX_DEFAULT_VISIBILITY extern ALIGNED_ALLOC_Hook aligned_alloc; + + struct FEXAllocOperators { + FEXAllocOperators() = default; + + void *operator new(size_t size) { + return FEXCore::Allocator::malloc(size); + } + + void operator delete(void *ptr) { + return FEXCore::Allocator::free(ptr); + } + }; } diff --git a/External/FEXCore/include/FEXCore/Utils/ThreadPoolAllocator.h b/External/FEXCore/include/FEXCore/Utils/ThreadPoolAllocator.h index 9e8f6c8d7..da9666b69 100644 --- a/External/FEXCore/include/FEXCore/Utils/ThreadPoolAllocator.h +++ b/External/FEXCore/include/FEXCore/Utils/ThreadPoolAllocator.h @@ -63,19 +63,16 @@ namespace FEXCore::Utils { using BufferOwnedFlag = std::atomic; - struct MemoryBuffer { + struct MemoryBuffer : public FEXCore::Allocator::FEXAllocOperators { + MemoryBuffer(void* Ptr, size_t Size, std::chrono::time_point LastUsed) + : Ptr {Ptr} + , Size {Size} + , LastUsed {LastUsed} {} + void* Ptr; size_t Size; std::atomic> LastUsed; BufferOwnedFlag *CurrentClientOwnedFlag{}; - - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } }; // Ensure that the atomic objects of MemoryBuffer are lock free static_assert(decltype(MemoryBuffer::LastUsed){}.is_always_lock_free, "Oops, needs to be lock free"); diff --git a/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h b/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h index e22bc6b18..d249f0415 100644 --- a/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h +++ b/FEXHeaderUtils/FEXHeaderUtils/Filesystem.h @@ -222,8 +222,6 @@ namespace FHU::Filesystem { fextl::pmr::fixed_size_monotonic_buffer_resource mbr(Data, DataSize); std::pmr::polymorphic_allocator pa {&mbr}; std::pmr::list Parts{pa}; - // Calculate the expected string size while parsing to reduce allocations. - size_t ExpectedStringSize{}; size_t CurrentOffset{}; do { @@ -235,7 +233,6 @@ namespace FHU::Filesystem { const auto Begin = Path.begin() + CurrentOffset; const auto End = Path.begin() + FoundSeperator; const auto Size = End - Begin; - ExpectedStringSize += Size; // Only insert parts that contain data. if (Size != 0) { @@ -258,7 +255,6 @@ namespace FHU::Filesystem { if (CurrentIterDistance > 0 || IsAbsolutePath) { // Erasing this iterator, don't increase iter distances iter = Parts.erase(iter); - --ExpectedStringSize; continue; } } @@ -275,14 +271,12 @@ namespace FHU::Filesystem { if (*PreviousIter == ".") { // Erasing the previous iterator, iterator distance has subtracted by one --CurrentIterDistance; - ExpectedStringSize -= PreviousIter->size(); Parts.erase(PreviousIter); } else if (*PreviousIter != "..") { // Erasing the previous iterator, iterator distance has subtracted by one // Also erasing current iterator, which means iterator distance also doesn't increase by one. --CurrentIterDistance; - ExpectedStringSize -= PreviousIter->size() + 2; Parts.erase(PreviousIter); iter = Parts.erase(iter); continue; @@ -290,7 +284,6 @@ namespace FHU::Filesystem { } else if (IsAbsolutePath) { // `..` at the base. Just remove this - ExpectedStringSize -= 2; iter = Parts.erase(iter); continue; } diff --git a/Source/Tests/LinuxSyscalls/SignalDelegator.h b/Source/Tests/LinuxSyscalls/SignalDelegator.h index 8c20b2dcc..eca37be08 100644 --- a/Source/Tests/LinuxSyscalls/SignalDelegator.h +++ b/Source/Tests/LinuxSyscalls/SignalDelegator.h @@ -23,16 +23,8 @@ namespace Core { } namespace FEX::HLE { - class SignalDelegator final : public FEXCore::SignalDelegator { + class SignalDelegator final : public FEXCore::SignalDelegator, public FEXCore::Allocator::FEXAllocOperators { public: - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } - // Returns true if the host handled the signal // Arguments are the same as sigaction handler SignalDelegator(); diff --git a/Source/Tests/LinuxSyscalls/Syscalls.h b/Source/Tests/LinuxSyscalls/Syscalls.h index 3b2181891..c09d6bbf1 100644 --- a/Source/Tests/LinuxSyscalls/Syscalls.h +++ b/Source/Tests/LinuxSyscalls/Syscalls.h @@ -93,16 +93,8 @@ struct ExecveAtArgs { uint64_t ExecveHandler(const char *pathname, char* const* argv, char* const* envp, ExecveAtArgs Args); -class SyscallHandler : public FEXCore::HLE::SyscallHandler, FEXCore::HLE::SourcecodeResolver { +class SyscallHandler : public FEXCore::HLE::SyscallHandler, FEXCore::HLE::SourcecodeResolver, public FEXCore::Allocator::FEXAllocOperators { public: - void *operator new(size_t size) { - return FEXCore::Allocator::malloc(size); - } - - void operator delete(void *ptr) { - return FEXCore::Allocator::free(ptr); - } - virtual ~SyscallHandler(); // In the case that the syscall doesn't hit the optimized path then we still need to go here