X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/jit/ExecutableAllocator.cpp diff --git a/jit/ExecutableAllocator.cpp b/jit/ExecutableAllocator.cpp index 7939919..bb49e73 100644 --- a/jit/ExecutableAllocator.cpp +++ b/jit/ExecutableAllocator.cpp @@ -24,17 +24,16 @@ */ #include "config.h" - #include "ExecutableAllocator.h" +#include "JSCInlines.h" + #if ENABLE(EXECUTABLE_ALLOCATOR_DEMAND) #include "CodeProfiling.h" #include #include +#include #include -#if ENABLE(ASSEMBLER_WX_EXCLUSIVE) -#include -#endif #include #include #endif @@ -55,9 +54,9 @@ namespace JSC { class DemandExecutableAllocator : public MetaAllocator { public: DemandExecutableAllocator() - : MetaAllocator(32) // round up all allocations to 32 bytes + : MetaAllocator(jitAllocationGranule) { - MutexLocker lock(allocatorsMutex()); + std::lock_guard lock(allocatorsMutex()); allocators().add(this); // Don't preallocate any memory here. } @@ -65,7 +64,7 @@ public: virtual ~DemandExecutableAllocator() { { - MutexLocker lock(allocatorsMutex()); + std::lock_guard lock(allocatorsMutex()); allocators().remove(this); } for (unsigned i = 0; i < reservations.size(); ++i) @@ -75,7 +74,7 @@ public: static size_t bytesAllocatedByAllAllocators() { size_t total = 0; - MutexLocker lock(allocatorsMutex()); + std::lock_guard lock(allocatorsMutex()); for (HashSet::const_iterator allocator = allocators().begin(); allocator != allocators().end(); ++allocator) total += (*allocator)->bytesAllocated(); return total; @@ -84,7 +83,7 @@ public: static size_t bytesCommittedByAllocactors() { size_t total = 0; - MutexLocker lock(allocatorsMutex()); + std::lock_guard lock(allocatorsMutex()); for (HashSet::const_iterator allocator = allocators().begin(); allocator != allocators().end(); ++allocator) total += (*allocator)->bytesCommitted(); return total; @@ -93,7 +92,7 @@ public: #if ENABLE(META_ALLOCATOR_PROFILE) static void dumpProfileFromAllAllocators() { - MutexLocker lock(allocatorsMutex()); + std::lock_guard lock(allocatorsMutex()); for (HashSet::const_iterator allocator = allocators().begin(); allocator != allocators().end(); ++allocator) (*allocator)->dumpProfile(); } @@ -114,8 +113,7 @@ protected: #endif PageReservation reservation = PageReservation::reserve(numPages * pageSize(), OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true); - if (!reservation) - CRASH(); + RELEASE_ASSERT(reservation); reservations.append(reservation); @@ -136,12 +134,14 @@ private: Vector reservations; static HashSet& allocators() { - DEFINE_STATIC_LOCAL(HashSet, sAllocators, ()); + DEPRECATED_DEFINE_STATIC_LOCAL(HashSet, sAllocators, ()); return sAllocators; } - static Mutex& allocatorsMutex() + + static std::mutex& allocatorsMutex() { - DEFINE_STATIC_LOCAL(Mutex, mutex, ()); + static NeverDestroyed mutex; + return mutex; } }; @@ -168,9 +168,9 @@ void ExecutableAllocator::initializeAllocator() } #endif -ExecutableAllocator::ExecutableAllocator(JSGlobalData&) +ExecutableAllocator::ExecutableAllocator(VM&) #if ENABLE(ASSEMBLER_WX_EXCLUSIVE) - : m_allocator(adoptPtr(new DemandExecutableAllocator())) + : m_allocator(std::make_unique()) #endif { ASSERT(allocator()); @@ -213,12 +213,11 @@ double ExecutableAllocator::memoryPressureMultiplier(size_t addedMemoryUsage) } -PassRefPtr ExecutableAllocator::allocate(JSGlobalData&, size_t sizeInBytes, void* ownerUID, JITCompilationEffort effort) +RefPtr ExecutableAllocator::allocate(VM&, size_t sizeInBytes, void* ownerUID, JITCompilationEffort effort) { RefPtr result = allocator()->allocate(sizeInBytes, ownerUID); - if (!result && effort == JITCompilationMustSucceed) - CRASH(); - return result.release(); + RELEASE_ASSERT(result || effort != JITCompilationMustSucceed); + return result; } size_t ExecutableAllocator::committedByteCount()