Use FastMalloc (bmalloc) instead of BlockAllocator for GC pages
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Feb 2015 22:27:18 +0000 (22:27 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Feb 2015 22:27:18 +0000 (22:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140900

Reviewed by Mark Hahnenberg.

Re-landing just the HandleBlock piece of this patch.

Source/JavaScriptCore:

* heap/HandleBlock.h:
* heap/HandleBlockInlines.h:
(JSC::HandleBlock::create):
(JSC::HandleBlock::destroy):
(JSC::HandleBlock::HandleBlock):
(JSC::HandleBlock::payloadEnd):
* heap/HandleSet.cpp:
(JSC::HandleSet::~HandleSet):
(JSC::HandleSet::grow):

Source/WebCore:

* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::install):

Source/WTF:

* wtf/FastMalloc.cpp:
(WTF::fastAlignedMalloc):
(WTF::fastAlignedFree):
(WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
* wtf/FastMalloc.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179500 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/HandleBlock.h
Source/JavaScriptCore/heap/HandleBlockInlines.h
Source/JavaScriptCore/heap/HandleSet.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/FastMalloc.cpp
Source/WTF/wtf/FastMalloc.h
Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm

index 0282942..07c9830 100644 (file)
@@ -1,3 +1,22 @@
+2015-02-02  Geoffrey Garen  <ggaren@apple.com>
+
+        Use FastMalloc (bmalloc) instead of BlockAllocator for GC pages
+        https://bugs.webkit.org/show_bug.cgi?id=140900
+
+        Reviewed by Mark Hahnenberg.
+
+        Re-landing just the HandleBlock piece of this patch.
+
+        * heap/HandleBlock.h:
+        * heap/HandleBlockInlines.h:
+        (JSC::HandleBlock::create):
+        (JSC::HandleBlock::destroy):
+        (JSC::HandleBlock::HandleBlock):
+        (JSC::HandleBlock::payloadEnd):
+        * heap/HandleSet.cpp:
+        (JSC::HandleSet::~HandleSet):
+        (JSC::HandleSet::grow):
+
 2015-02-02  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Support console.table
index 962d37c..6f31322 100644 (file)
@@ -34,9 +34,11 @@ class DeadBlock;
 class HandleSet;
 class HandleNode;
 
-class HandleBlock : public HeapBlock<HandleBlock> {
+class HandleBlock : public DoublyLinkedListNode<HandleBlock> {
+    friend class WTF::DoublyLinkedListNode<HandleBlock>;
 public:
-    static HandleBlock* create(DeadBlock*, HandleSet*);
+    static HandleBlock* create(HandleSet*);
+    static void destroy(HandleBlock*);
     static HandleBlock* blockFor(HandleNode*);
 
     static const size_t blockSize = 4 * KB;
@@ -48,13 +50,15 @@ public:
     unsigned nodeCapacity();
 
 private:
-    HandleBlock(Region*, HandleSet*);
+    HandleBlock(HandleSet*);
 
     char* payload();
     char* payloadEnd();
 
     static const size_t s_blockMask = ~(blockSize - 1);
 
+    HandleBlock* m_prev;
+    HandleBlock* m_next;
     HandleSet* m_handleSet;
 };
 
index 7c77193..370e683 100644 (file)
 
 #include "BlockAllocator.h"
 #include "HandleBlock.h"
+#include <wtf/FastMalloc.h>
 
 namespace JSC {
 
-inline HandleBlock* HandleBlock::create(DeadBlock* block, HandleSet* handleSet)
+inline HandleBlock* HandleBlock::create(HandleSet* handleSet)
 {
-    Region* region = block->region();
-    return new (NotNull, block) HandleBlock(region, handleSet);
+    return new (NotNull, fastAlignedMalloc(blockSize, blockSize)) HandleBlock(handleSet);
 }
 
-inline HandleBlock::HandleBlock(Region* region, HandleSet* handleSet)
-    : HeapBlock<HandleBlock>(region)
+inline void HandleBlock::destroy(HandleBlock* block)
+{
+    block->~HandleBlock();
+    fastAlignedFree(block);
+}
+
+inline HandleBlock::HandleBlock(HandleSet* handleSet)
+    : DoublyLinkedListNode<HandleBlock>()
     , m_handleSet(handleSet)
 {
 }
 
 inline char* HandleBlock::payloadEnd()
 {
-    return reinterpret_cast<char*>(this) + region()->blockSize();
+    return reinterpret_cast<char*>(this) + blockSize;
 }
 
 inline char* HandleBlock::payload()
index be667e8..dec8370 100644 (file)
@@ -44,12 +44,12 @@ HandleSet::HandleSet(VM* vm)
 HandleSet::~HandleSet()
 {
     while (!m_blockList.isEmpty())
-        m_vm->heap.blockAllocator().deallocate(HandleBlock::destroy(m_blockList.removeHead()));
+        HandleBlock::destroy(m_blockList.removeHead());
 }
 
 void HandleSet::grow()
 {
-    HandleBlock* newBlock = HandleBlock::create(m_vm->heap.blockAllocator().allocate<HandleBlock>(), this);
+    HandleBlock* newBlock = HandleBlock::create(this);
     m_blockList.append(newBlock);
 
     for (int i = newBlock->nodeCapacity() - 1; i >= 0; --i) {
index 3588cfb..0f43c1f 100644 (file)
@@ -1,3 +1,18 @@
+2015-02-02  Geoffrey Garen  <ggaren@apple.com>
+
+        Use FastMalloc (bmalloc) instead of BlockAllocator for GC pages
+        https://bugs.webkit.org/show_bug.cgi?id=140900
+
+        Reviewed by Mark Hahnenberg.
+
+        Re-landing just the HandleBlock piece of this patch.
+
+        * wtf/FastMalloc.cpp:
+        (WTF::fastAlignedMalloc):
+        (WTF::fastAlignedFree):
+        (WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
+        * wtf/FastMalloc.h:
+
 2015-02-02  Daniel Bates  <dabates@apple.com>
 
         [iOS] ASSERTION FAILED: m_scriptExecutionContext->isContextThread() in ContextDestructionObserver::observeContext
index d7757b2..c5320d2 100644 (file)
@@ -162,6 +162,34 @@ size_t fastMallocGoodSize(size_t bytes)
 #endif
 }
 
+#if OS(WINDOWS)
+
+void* fastAlignedMalloc(size_t alignment, size_t size) 
+{
+    return _aligned_malloc(alignment, size);
+}
+
+void fastAlignedFree(void* p) 
+{
+    _aligned_free(p);
+}
+
+#else
+
+void* fastAlignedMalloc(size_t alignment, size_t size) 
+{
+    void* p = nullptr;
+    posix_memalign(&p, alignment, size);
+    return p;
+}
+
+void fastAlignedFree(void* p) 
+{
+    free(p);
+}
+
+#endif // OS(WINDOWS)
+
 TryMallocReturnValue tryFastMalloc(size_t n) 
 {
     return malloc(n);
@@ -273,6 +301,16 @@ size_t fastMallocGoodSize(size_t size)
     return size;
 }
     
+void* fastAlignedMalloc(size_t alignment, size_t size) 
+{
+    return bmalloc::api::memalign(alignment, size);
+}
+
+void fastAlignedFree(void* p) 
+{
+    bmalloc::api::free(p);
+}
+
 TryMallocReturnValue tryFastMalloc(size_t size)
 {
     return fastMalloc(size);
@@ -4024,7 +4062,6 @@ static ALWAYS_INLINE void do_free(void* ptr) {
   }
 }
 
-#ifndef WTF_CHANGES
 // For use by exported routines below that want specific alignments
 //
 // Note: this code can be slow, and can significantly fragment memory.
@@ -4095,7 +4132,6 @@ static void* do_memalign(size_t align, size_t size) {
   }
   return SpanToMallocResult(span);
 }
-#endif
 
 // Helpers for use by exported routines below:
 
@@ -4152,6 +4188,16 @@ extern "C"
 template <bool crashOnFailure>
 ALWAYS_INLINE void* malloc(size_t);
 
+void* fastAlignedMalloc(size_t alignment, size_t size) 
+{
+    return do_memalign(alignment, size);
+}
+
+void fastAlignedFree(void* p) 
+{
+    do_free(p);
+}
+
 void* fastMalloc(size_t size)
 {
     void* result = malloc<true>(size);
index 5c0f821..f7612e0 100644 (file)
@@ -37,6 +37,10 @@ namespace WTF {
     WTF_EXPORT_PRIVATE size_t fastMallocSize(const void*);
     WTF_EXPORT_PRIVATE size_t fastMallocGoodSize(size_t);
 
+    // Allocations from fastAlignedMalloc() must be freed using fastAlignedFree().
+    WTF_EXPORT_PRIVATE void* fastAlignedMalloc(size_t alignment, size_t);
+    WTF_EXPORT_PRIVATE void fastAlignedFree(void*);
+
     struct TryMallocReturnValue {
         TryMallocReturnValue(void* data)
             : m_data(data)
@@ -104,6 +108,8 @@ using WTF::tryFastCalloc;
 using WTF::tryFastMalloc;
 using WTF::tryFastRealloc;
 using WTF::tryFastZeroedMalloc;
+using WTF::fastAlignedMalloc;
+using WTF::fastAlignedFree;
 
 #if COMPILER(GCC) && OS(DARWIN)
 #define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline))
index d71d45f..052ca56 100644 (file)
@@ -1,3 +1,15 @@
+2015-02-02  Geoffrey Garen  <ggaren@apple.com>
+
+        Use FastMalloc (bmalloc) instead of BlockAllocator for GC pages
+        https://bugs.webkit.org/show_bug.cgi?id=140900
+
+        Reviewed by Mark Hahnenberg.
+
+        Re-landing just the HandleBlock piece of this patch.
+
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::install):
+
 2015-02-02  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] 64-bit build fix after r179492.
index f584ce2..577220b 100644 (file)
@@ -124,6 +124,8 @@ void MemoryPressureHandler::install()
         // Release any freed up blocks from the JS heap back to the system.
         JSDOMWindowBase::commonVM().heap.blockAllocator().releaseFreeRegions();
 
+        WTF::releaseFastMallocFreeMemory();
+
         malloc_zone_pressure_relief(nullptr, 0);
     });