WebKit Bugzilla
Attachment 362481 Details for
Bug 194836
: [bmalloc] bmalloc::Heap is allocated even though we use system malloc mode
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-194836-20190219212209.patch (text/plain), 23.04 KB, created by
Yusuke Suzuki
on 2019-02-19 21:22:10 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2019-02-19 21:22:10 PST
Size:
23.04 KB
patch
obsolete
>Subversion Revision: 241789 >diff --git a/Source/bmalloc/ChangeLog b/Source/bmalloc/ChangeLog >index ff9a88a69ec5cdcbb051425bb4081414e525f699..cacd0255d51908854f478abf3bafac811922eecb 100644 >--- a/Source/bmalloc/ChangeLog >+++ b/Source/bmalloc/ChangeLog >@@ -1,3 +1,71 @@ >+2019-02-19 Yusuke Suzuki <ysuzuki@apple.com> >+ >+ [bmalloc] bmalloc::Heap is allocated even though we use system malloc mode >+ https://bugs.webkit.org/show_bug.cgi?id=194836 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Previously, bmalloc::Heap holds DebugHeap, and delegates allocation and deallocation to debug heap. >+ However, bmalloc::Heap is large. We would like to avoid initialization of bmalloc::Heap under the >+ system malloc mode. >+ >+ This patch extracts out DebugHeap from bmalloc::Heap, and logically puts this in a boundary of >+ bmalloc::api. bmalloc::api delegates allocation and deallocation to DebugHeap if DebugHeap is enabled. >+ Otherwise, using bmalloc's usual mechanism. The challenge is that we would like to keep bmalloc fast >+ path fast. >+ >+ 1. For IsoHeaps, we use the similar techniques done in Cache. If the debug mode is enabled, we always go >+ to the slow path of the IsoHeap allocation, and keep IsoTLS::get() returning nullptr. In the slow path, >+ we just fallback to the usual bmalloc::api::tryMalloc implementation. This is efficient because bmalloc >+ continues using the fast path. >+ >+ 2. For the other APIs, like freeLargeVirtual, we just put DebugHeap check because this API itself takes fair >+ amount of time. Then debug heap check does not matter. >+ >+ * bmalloc/Allocator.cpp: >+ (bmalloc::Allocator::reallocateImpl): >+ * bmalloc/Cache.cpp: >+ (bmalloc::Cache::tryAllocateSlowCaseNullCache): >+ (bmalloc::Cache::allocateSlowCaseNullCache): >+ (bmalloc::Cache::deallocateSlowCaseNullCache): >+ (bmalloc::Cache::tryReallocateSlowCaseNullCache): >+ (bmalloc::Cache::reallocateSlowCaseNullCache): >+ (): Deleted. >+ (bmalloc::debugHeap): Deleted. >+ * bmalloc/DebugHeap.cpp: >+ * bmalloc/DebugHeap.h: >+ (bmalloc::DebugHeap::tryGet): >+ * bmalloc/Heap.cpp: >+ (bmalloc::Heap::Heap): >+ (bmalloc::Heap::footprint): >+ (bmalloc::Heap::tryAllocateLarge): >+ (bmalloc::Heap::deallocateLarge): >+ * bmalloc/Heap.h: >+ (bmalloc::Heap::debugHeap): Deleted. >+ * bmalloc/IsoTLS.cpp: >+ (bmalloc::IsoTLS::IsoTLS): >+ (bmalloc::IsoTLS::isUsingDebugHeap): Deleted. >+ (bmalloc::IsoTLS::debugMalloc): Deleted. >+ (bmalloc::IsoTLS::debugFree): Deleted. >+ * bmalloc/IsoTLS.h: >+ * bmalloc/IsoTLSInlines.h: >+ (bmalloc::IsoTLS::allocateSlow): >+ (bmalloc::IsoTLS::deallocateSlow): >+ * bmalloc/ObjectType.cpp: >+ (bmalloc::objectType): >+ * bmalloc/ObjectType.h: >+ * bmalloc/Scavenger.cpp: >+ (bmalloc::Scavenger::Scavenger): >+ * bmalloc/bmalloc.cpp: >+ (bmalloc::api::tryLargeZeroedMemalignVirtual): >+ (bmalloc::api::freeLargeVirtual): >+ (bmalloc::api::scavenge): >+ (bmalloc::api::isEnabled): >+ (bmalloc::api::setScavengerThreadQOSClass): >+ (bmalloc::api::commitAlignedPhysical): >+ (bmalloc::api::decommitAlignedPhysical): >+ (bmalloc::api::enableMiniMode): >+ > 2019-02-19 Yusuke Suzuki <ysuzuki@apple.com> > > [bmalloc] bmalloc::Cache should not be instantiated if we are using system malloc >diff --git a/Source/bmalloc/bmalloc/Allocator.cpp b/Source/bmalloc/bmalloc/Allocator.cpp >index cfd01fe3ed6fda8f443172394f448195f23169ba..409140eb0e7846629542a2c59129d1a974073be3 100644 >--- a/Source/bmalloc/bmalloc/Allocator.cpp >+++ b/Source/bmalloc/bmalloc/Allocator.cpp >@@ -102,9 +102,9 @@ void* Allocator::tryReallocate(void* object, size_t newSize) > void* Allocator::reallocateImpl(void* object, size_t newSize, bool crashOnFailure) > { > size_t oldSize = 0; >- switch (objectType(m_heap.kind(), object)) { >+ switch (objectType(m_heap, object)) { > case ObjectType::Small: { >- BASSERT(objectType(m_heap.kind(), nullptr) == ObjectType::Small); >+ BASSERT(objectType(m_heap, nullptr) == ObjectType::Small); > if (!object) > break; > >diff --git a/Source/bmalloc/bmalloc/Cache.cpp b/Source/bmalloc/bmalloc/Cache.cpp >index 29ad1309866f12d809f6f121d9f6511ed735362a..70d4882e5c06639c77de4958e998ccc08afb8649 100644 >--- a/Source/bmalloc/bmalloc/Cache.cpp >+++ b/Source/bmalloc/bmalloc/Cache.cpp >@@ -32,8 +32,6 @@ > > namespace bmalloc { > >-static DebugHeap* debugHeapCache { nullptr }; >- > void Cache::scavenge(HeapKind heapKind) > { > PerHeapKind<Cache>* caches = PerThread<PerHeapKind<Cache>>::getFastCase(); >@@ -46,17 +44,6 @@ void Cache::scavenge(HeapKind heapKind) > caches->at(heapKind).deallocator().scavenge(); > } > >-static BINLINE DebugHeap* debugHeap() >-{ >- if (debugHeapCache) >- return debugHeapCache; >- if (PerProcess<Environment>::get()->isDebugHeapEnabled()) { >- debugHeapCache = PerProcess<DebugHeap>::get(); >- return debugHeapCache; >- } >- return nullptr; >-} >- > Cache::Cache(HeapKind heapKind) > : m_deallocator(PerProcess<PerHeapKind<Heap>>::get()->at(heapKind)) > , m_allocator(PerProcess<PerHeapKind<Heap>>::get()->at(heapKind), m_deallocator) >@@ -68,40 +55,40 @@ BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t s > { > // FIXME: DebugHeap does not have tryAllocate feature. > // https://bugs.webkit.org/show_bug.cgi?id=194837 >- if (auto* heap = debugHeap()) >- return heap->malloc(size); >+ if (auto* debugHeap = DebugHeap::tryGet()) >+ return debugHeap->malloc(size); > return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(size); > } > > BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t size) > { >- if (auto* heap = debugHeap()) >- return heap->malloc(size); >+ if (auto* debugHeap = DebugHeap::tryGet()) >+ return debugHeap->malloc(size); > return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(size); > } > > BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t alignment, size_t size) > { >- if (auto* heap = debugHeap()) { >+ if (auto* debugHeap = DebugHeap::tryGet()) { > constexpr bool crashOnFailure = false; >- return heap->memalign(alignment, size, crashOnFailure); >+ return debugHeap->memalign(alignment, size, crashOnFailure); > } > return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(alignment, size); > } > > BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t alignment, size_t size) > { >- if (auto* heap = debugHeap()) { >+ if (auto* debugHeap = DebugHeap::tryGet()) { > constexpr bool crashOnFailure = true; >- return heap->memalign(alignment, size, crashOnFailure); >+ return debugHeap->memalign(alignment, size, crashOnFailure); > } > return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(alignment, size); > } > > BNO_INLINE void Cache::deallocateSlowCaseNullCache(HeapKind heapKind, void* object) > { >- if (auto* heap = debugHeap()) { >- heap->free(object); >+ if (auto* debugHeap = DebugHeap::tryGet()) { >+ debugHeap->free(object); > return; > } > PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).deallocator().deallocate(object); >@@ -109,18 +96,18 @@ BNO_INLINE void Cache::deallocateSlowCaseNullCache(HeapKind heapKind, void* obje > > BNO_INLINE void* Cache::tryReallocateSlowCaseNullCache(HeapKind heapKind, void* object, size_t newSize) > { >- if (auto* heap = debugHeap()) { >+ if (auto* debugHeap = DebugHeap::tryGet()) { > constexpr bool crashOnFailure = false; >- return heap->realloc(object, newSize, crashOnFailure); >+ return debugHeap->realloc(object, newSize, crashOnFailure); > } > return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryReallocate(object, newSize); > } > > BNO_INLINE void* Cache::reallocateSlowCaseNullCache(HeapKind heapKind, void* object, size_t newSize) > { >- if (auto* heap = debugHeap()) { >+ if (auto* debugHeap = DebugHeap::tryGet()) { > constexpr bool crashOnFailure = true; >- return heap->realloc(object, newSize, crashOnFailure); >+ return debugHeap->realloc(object, newSize, crashOnFailure); > } > return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().reallocate(object, newSize); > } >diff --git a/Source/bmalloc/bmalloc/DebugHeap.cpp b/Source/bmalloc/bmalloc/DebugHeap.cpp >index f21f5a52f5c2a65eea0efbe8c6191751b5904990..4d9292c7d82fbce1f720937fa8a0baa5103fc7a6 100644 >--- a/Source/bmalloc/bmalloc/DebugHeap.cpp >+++ b/Source/bmalloc/bmalloc/DebugHeap.cpp >@@ -33,6 +33,8 @@ > #include <thread> > > namespace bmalloc { >+ >+DebugHeap* debugHeapCache { nullptr }; > > #if BOS(DARWIN) > >diff --git a/Source/bmalloc/bmalloc/DebugHeap.h b/Source/bmalloc/bmalloc/DebugHeap.h >index 219f8374e579f19c45d8645f0f4e890ddd82b98d..d1e0e9bf569ba54abd6e61be8366c67bacbd500d 100644 >--- a/Source/bmalloc/bmalloc/DebugHeap.h >+++ b/Source/bmalloc/bmalloc/DebugHeap.h >@@ -25,7 +25,9 @@ > > #pragma once > >+#include "Environment.h" > #include "Mutex.h" >+#include "PerProcess.h" > #include <mutex> > #include <unordered_map> > >@@ -47,6 +49,8 @@ class DebugHeap { > void* memalignLarge(size_t alignment, size_t); > void freeLarge(void* base); > >+ static DebugHeap* tryGet(); >+ > private: > #if BOS(DARWIN) > malloc_zone_t* m_zone; >@@ -58,4 +62,16 @@ class DebugHeap { > std::unordered_map<void*, size_t> m_sizeMap; > }; > >+extern BEXPORT DebugHeap* debugHeapCache; >+BINLINE DebugHeap* DebugHeap::tryGet() >+{ >+ if (debugHeapCache) >+ return debugHeapCache; >+ if (PerProcess<Environment>::get()->isDebugHeapEnabled()) { >+ debugHeapCache = PerProcess<DebugHeap>::get(); >+ return debugHeapCache; >+ } >+ return nullptr; >+} >+ > } // namespace bmalloc >diff --git a/Source/bmalloc/bmalloc/Heap.cpp b/Source/bmalloc/bmalloc/Heap.cpp >index 528cfebf973d23d8c3453e279396b22da726cc0c..25a29ab44b7a63acebc48e4cde21dbe597a96b7d 100644 >--- a/Source/bmalloc/bmalloc/Heap.cpp >+++ b/Source/bmalloc/bmalloc/Heap.cpp >@@ -47,7 +47,6 @@ namespace bmalloc { > Heap::Heap(HeapKind kind, std::lock_guard<Mutex>&) > : m_kind(kind) > , m_vmPageSizePhysical(vmPageSizePhysical()) >- , m_debugHeap(nullptr) > { > RELEASE_BASSERT(vmPageSizePhysical() >= smallPageSize); > RELEASE_BASSERT(vmPageSize() >= vmPageSizePhysical()); >@@ -55,22 +54,20 @@ Heap::Heap(HeapKind kind, std::lock_guard<Mutex>&) > initializeLineMetadata(); > initializePageMetadata(); > >- if (PerProcess<Environment>::get()->isDebugHeapEnabled()) >- m_debugHeap = PerProcess<DebugHeap>::get(); >- else { >- Gigacage::ensureGigacage(); >+ BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); >+ >+ Gigacage::ensureGigacage(); > #if GIGACAGE_ENABLED >- if (usingGigacage()) { >- RELEASE_BASSERT(gigacageBasePtr()); >- uint64_t random[2]; >- cryptoRandom(reinterpret_cast<unsigned char*>(random), sizeof(random)); >- size_t size = roundDownToMultipleOf(vmPageSize(), gigacageSize() - (random[0] % Gigacage::maximumCageSizeReductionForSlide)); >- ptrdiff_t offset = roundDownToMultipleOf(vmPageSize(), random[1] % (gigacageSize() - size)); >- void* base = reinterpret_cast<unsigned char*>(gigacageBasePtr()) + offset; >- m_largeFree.add(LargeRange(base, size, 0, 0)); >- } >-#endif >+ if (usingGigacage()) { >+ RELEASE_BASSERT(gigacageBasePtr()); >+ uint64_t random[2]; >+ cryptoRandom(reinterpret_cast<unsigned char*>(random), sizeof(random)); >+ size_t size = roundDownToMultipleOf(vmPageSize(), gigacageSize() - (random[0] % Gigacage::maximumCageSizeReductionForSlide)); >+ ptrdiff_t offset = roundDownToMultipleOf(vmPageSize(), random[1] % (gigacageSize() - size)); >+ void* base = reinterpret_cast<unsigned char*>(gigacageBasePtr()) + offset; >+ m_largeFree.add(LargeRange(base, size, 0, 0)); > } >+#endif > > m_scavenger = PerProcess<Scavenger>::get(); > } >@@ -153,7 +150,6 @@ size_t Heap::freeableMemory(std::lock_guard<Mutex>&) > > size_t Heap::footprint() > { >- BASSERT(!m_debugHeap); > return m_footprint; > } > >@@ -555,9 +551,6 @@ void* Heap::tryAllocateLarge(std::unique_lock<Mutex>& lock, size_t alignment, si > > BASSERT(isPowerOfTwo(alignment)); > >- if (m_debugHeap) >- return m_debugHeap->memalignLarge(alignment, size); >- > m_scavenger->didStartGrowing(); > > size_t roundedSize = size ? roundUpToMultipleOf(largeAlignment, size) : largeAlignment; >@@ -626,9 +619,6 @@ void Heap::shrinkLarge(std::unique_lock<Mutex>& lock, const Range& object, size_ > > void Heap::deallocateLarge(std::unique_lock<Mutex>&, void* object) > { >- if (m_debugHeap) >- return m_debugHeap->freeLarge(object); >- > size_t size = m_largeAllocated.remove(object); > m_largeFree.add(LargeRange(object, size, size, size)); > m_freeableMemory += size; >diff --git a/Source/bmalloc/bmalloc/Heap.h b/Source/bmalloc/bmalloc/Heap.h >index 7146dd7b1d7a5788b89e7d124fb1b473e14f189f..38ae724896f4d8cf0a9d5805a0212a946ff06f5d 100644 >--- a/Source/bmalloc/bmalloc/Heap.h >+++ b/Source/bmalloc/bmalloc/Heap.h >@@ -63,8 +63,6 @@ class Heap { > > HeapKind kind() const { return m_kind; } > >- DebugHeap* debugHeap() { return m_debugHeap; } >- > void allocateSmallBumpRanges(std::unique_lock<Mutex>&, size_t sizeClass, > BumpAllocator&, BumpRangeCache&, LineCache&); > void derefSmallLine(std::unique_lock<Mutex>&, Object, LineCache&); >@@ -145,7 +143,6 @@ class Heap { > Map<Chunk*, ObjectType, ChunkHash> m_objectTypes; > > Scavenger* m_scavenger { nullptr }; >- DebugHeap* m_debugHeap { nullptr }; > > size_t m_footprint { 0 }; > size_t m_freeableMemory { 0 }; >diff --git a/Source/bmalloc/bmalloc/IsoTLS.cpp b/Source/bmalloc/bmalloc/IsoTLS.cpp >index c96f22277767e57bd0dff2ffd854f66f9d6fe265..28e005a31b70452eb67a4d19c49b298f91efd402 100644 >--- a/Source/bmalloc/bmalloc/IsoTLS.cpp >+++ b/Source/bmalloc/bmalloc/IsoTLS.cpp >@@ -25,7 +25,6 @@ > > #include "IsoTLS.h" > >-#include "DebugHeap.h" > #include "Environment.h" > #include "Gigacage.h" > #include "IsoTLSEntryInlines.h" >@@ -55,6 +54,7 @@ void IsoTLS::scavenge() > > IsoTLS::IsoTLS() > { >+ BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); > } > > IsoTLS* IsoTLS::ensureEntries(unsigned offset) >@@ -174,28 +174,6 @@ void IsoTLS::forEachEntry(const Func& func) > }); > } > >-bool IsoTLS::isUsingDebugHeap() >-{ >- return PerProcess<Environment>::get()->isDebugHeapEnabled(); >-} >- >-auto IsoTLS::debugMalloc(size_t size) -> DebugMallocResult >-{ >- DebugMallocResult result; >- if ((result.usingDebugHeap = isUsingDebugHeap())) >- result.ptr = PerProcess<DebugHeap>::get()->malloc(size); >- return result; >-} >- >-bool IsoTLS::debugFree(void* p) >-{ >- if (isUsingDebugHeap()) { >- PerProcess<DebugHeap>::get()->free(p); >- return true; >- } >- return false; >-} >- > void IsoTLS::determineMallocFallbackState() > { > static std::once_flag onceFlag; >diff --git a/Source/bmalloc/bmalloc/IsoTLS.h b/Source/bmalloc/bmalloc/IsoTLS.h >index 1b38cce42380d3524422bc786dbf03bbd8e56361..27effc2bd360789f69325a5da5d1cb3a76a2a714 100644 >--- a/Source/bmalloc/bmalloc/IsoTLS.h >+++ b/Source/bmalloc/bmalloc/IsoTLS.h >@@ -103,16 +103,6 @@ class IsoTLS { > > BEXPORT static void determineMallocFallbackState(); > >- static bool isUsingDebugHeap(); >- >- struct DebugMallocResult { >- void* ptr { nullptr }; >- bool usingDebugHeap { false }; >- }; >- >- BEXPORT static DebugMallocResult debugMalloc(size_t); >- BEXPORT static bool debugFree(void*); >- > IsoTLSEntry* m_lastEntry { nullptr }; > unsigned m_extent { 0 }; > unsigned m_capacity { 0 }; >diff --git a/Source/bmalloc/bmalloc/IsoTLSInlines.h b/Source/bmalloc/bmalloc/IsoTLSInlines.h >index 20f6afeacd9d9ae97af0bf0c6dc518551c7eea09..a120c6f74505b4109212c84dbbb883bd247c6e69 100644 >--- a/Source/bmalloc/bmalloc/IsoTLSInlines.h >+++ b/Source/bmalloc/bmalloc/IsoTLSInlines.h >@@ -94,9 +94,8 @@ BNO_INLINE void* IsoTLS::allocateSlow(api::IsoHeap<Type>& handle, bool abortOnFa > break; > } > >- auto debugMallocResult = debugMalloc(Config::objectSize); >- if (debugMallocResult.usingDebugHeap) >- return debugMallocResult.ptr; >+ // If debug heap is enabled, s_mallocFallbackState becomes MallocFallbackState::FallBackToMalloc. >+ BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); > > IsoTLS* tls = ensureHeapAndEntries(handle); > >@@ -138,8 +137,8 @@ BNO_INLINE void IsoTLS::deallocateSlow(api::IsoHeap<Type>& handle, void* p) > break; > } > >- if (debugFree(p)) >- return; >+ // If debug heap is enabled, s_mallocFallbackState becomes MallocFallbackState::FallBackToMalloc. >+ BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); > > RELEASE_BASSERT(handle.isInitialized()); > >diff --git a/Source/bmalloc/bmalloc/ObjectType.cpp b/Source/bmalloc/bmalloc/ObjectType.cpp >index c06e5785ce82e75b1c4ea4f37e850a8b2a327b7f..168761980fa07d19e9c197c5e71c37295f928bd9 100644 >--- a/Source/bmalloc/bmalloc/ObjectType.cpp >+++ b/Source/bmalloc/bmalloc/ObjectType.cpp >@@ -32,14 +32,14 @@ > > namespace bmalloc { > >-ObjectType objectType(HeapKind kind, void* object) >+ObjectType objectType(Heap& heap, void* object) > { > if (mightBeLarge(object)) { > if (!object) > return ObjectType::Small; > > std::unique_lock<Mutex> lock(Heap::mutex()); >- if (PerProcess<PerHeapKind<Heap>>::getFastCase()->at(kind).isLarge(lock, object)) >+ if (heap.isLarge(lock, object)) > return ObjectType::Large; > } > >diff --git a/Source/bmalloc/bmalloc/ObjectType.h b/Source/bmalloc/bmalloc/ObjectType.h >index 097f9872e54f2b409a19fc3f6ca03f7aee929846..74c13465eba78f7f8a78499676e6c84c9ad9148b 100644 >--- a/Source/bmalloc/bmalloc/ObjectType.h >+++ b/Source/bmalloc/bmalloc/ObjectType.h >@@ -32,9 +32,11 @@ > > namespace bmalloc { > >+class Heap; >+ > enum class ObjectType : unsigned char { Small, Large }; > >-ObjectType objectType(HeapKind, void*); >+ObjectType objectType(Heap&, void*); > > inline bool mightBeLarge(void* object) > { >diff --git a/Source/bmalloc/bmalloc/Scavenger.cpp b/Source/bmalloc/bmalloc/Scavenger.cpp >index ca3362657bfa01f1090f91ac81eae14a13fabce1..f9ee8c0d9d5cd54a48654ccba4eb0434dd815401 100644 >--- a/Source/bmalloc/bmalloc/Scavenger.cpp >+++ b/Source/bmalloc/bmalloc/Scavenger.cpp >@@ -67,8 +67,7 @@ struct PrintTime { > > Scavenger::Scavenger(std::lock_guard<Mutex>&) > { >- if (PerProcess<Environment>::get()->isDebugHeapEnabled()) >- return; >+ BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); > > #if BOS(DARWIN) > auto queue = dispatch_queue_create("WebKit Malloc Memory Pressure Handler", DISPATCH_QUEUE_SERIAL); >diff --git a/Source/bmalloc/bmalloc/bmalloc.cpp b/Source/bmalloc/bmalloc/bmalloc.cpp >index 620dbfc446cd220559d10f68cfe5e0e5c56639c5..ca8242c217be0aeead24fe28516fe01381d67726 100644 >--- a/Source/bmalloc/bmalloc/bmalloc.cpp >+++ b/Source/bmalloc/bmalloc/bmalloc.cpp >@@ -25,6 +25,8 @@ > > #include "bmalloc.h" > >+#include "DebugHeap.h" >+#include "Environment.h" > #include "PerProcess.h" > > namespace bmalloc { namespace api { >@@ -49,19 +51,23 @@ void* tryLargeZeroedMemalignVirtual(size_t requiredAlignment, size_t requestedSi > RELEASE_BASSERT(alignment >= requiredAlignment); > RELEASE_BASSERT(size >= requestedSize); > >- kind = mapToActiveHeapKind(kind); >- Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind); >- > void* result; >- { >- std::unique_lock<Mutex> lock(Heap::mutex()); >- result = heap.tryAllocateLarge(lock, alignment, size); >- if (result) { >- // Don't track this as dirty memory that dictates how we drive the scavenger. >- // FIXME: We should make it so that users of this API inform bmalloc which >- // pages they dirty: >- // https://bugs.webkit.org/show_bug.cgi?id=184207 >- heap.externalDecommit(lock, result, size); >+ if (auto* debugHeap = DebugHeap::tryGet()) >+ result = debugHeap->memalignLarge(alignment, size); >+ else { >+ kind = mapToActiveHeapKind(kind); >+ Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind); >+ >+ { >+ std::unique_lock<Mutex> lock(Heap::mutex()); >+ result = heap.tryAllocateLarge(lock, alignment, size); >+ if (result) { >+ // Don't track this as dirty memory that dictates how we drive the scavenger. >+ // FIXME: We should make it so that users of this API inform bmalloc which >+ // pages they dirty: >+ // https://bugs.webkit.org/show_bug.cgi?id=184207 >+ heap.externalDecommit(lock, result, size); >+ } > } > } > >@@ -72,6 +78,10 @@ void* tryLargeZeroedMemalignVirtual(size_t requiredAlignment, size_t requestedSi > > void freeLargeVirtual(void* object, size_t size, HeapKind kind) > { >+ if (auto* debugHeap = DebugHeap::tryGet()) { >+ debugHeap->freeLarge(object); >+ return; >+ } > kind = mapToActiveHeapKind(kind); > Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind); > std::unique_lock<Mutex> lock(Heap::mutex()); >@@ -84,19 +94,22 @@ void scavenge() > { > scavengeThisThread(); > >- PerProcess<Scavenger>::get()->scavenge(); >+ if (!DebugHeap::tryGet()) >+ PerProcess<Scavenger>::get()->scavenge(); > } > > bool isEnabled(HeapKind kind) > { > kind = mapToActiveHeapKind(kind); > std::unique_lock<Mutex> lock(Heap::mutex()); >- return !PerProcess<PerHeapKind<Heap>>::getFastCase()->at(kind).debugHeap(); >+ return !PerProcess<Environment>::get()->isDebugHeapEnabled(); > } > > #if BOS(DARWIN) > void setScavengerThreadQOSClass(qos_class_t overrideClass) > { >+ if (DebugHeap::tryGet()) >+ return; > std::unique_lock<Mutex> lock(Heap::mutex()); > PerProcess<Scavenger>::get()->setScavengerThreadQOSClass(overrideClass); > } >@@ -106,21 +119,22 @@ void commitAlignedPhysical(void* object, size_t size, HeapKind kind) > { > vmValidatePhysical(object, size); > vmAllocatePhysicalPages(object, size); >- Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind); >- heap.externalCommit(object, size); >+ if (!DebugHeap::tryGet()) >+ PerProcess<PerHeapKind<Heap>>::get()->at(kind).externalCommit(object, size); > } > > void decommitAlignedPhysical(void* object, size_t size, HeapKind kind) > { > vmValidatePhysical(object, size); > vmDeallocatePhysicalPages(object, size); >- Heap& heap = PerProcess<PerHeapKind<Heap>>::get()->at(kind); >- heap.externalDecommit(object, size); >+ if (!DebugHeap::tryGet()) >+ PerProcess<PerHeapKind<Heap>>::get()->at(kind).externalDecommit(object, size); > } > > void enableMiniMode() > { >- PerProcess<Scavenger>::get()->enableMiniMode(); >+ if (!DebugHeap::tryGet()) >+ PerProcess<Scavenger>::get()->enableMiniMode(); > } > > } } // namespace bmalloc::api
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194836
:
362481
|
362482