2011-02-03 Geoffrey Garen <ggaren@apple.com>
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 07:41:33 +0000 (07:41 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 07:41:33 +0000 (07:41 +0000)
        Reviewed by Cameron Zwarich.

        Changed MarkedSpace to delegate grow/shrink decisions to Heap
        https://bugs.webkit.org/show_bug.cgi?id=53759

        SunSpider reports no change.

        * runtime/Heap.cpp:
        (JSC::Heap::Heap):
        (JSC::Heap::reset):
        * runtime/Heap.h: Reorganized a few data members for better cache locality.
        Added a grow policy.

        * runtime/MarkedSpace.cpp:
        (JSC::MarkedSpace::allocate):
        (JSC::MarkedSpace::sweep):
        (JSC::MarkedSpace::reset): Don't shrink automatically. Instead, wait for
        the heap to make an explicit sweep call.

        * runtime/MarkedSpace.h:
        (JSC::MarkedSpace::highWaterMark):
        (JSC::MarkedSpace::setHighWaterMark): Use a watermark to determine how
        many bytes to allocate before failing and giving the heap an opportunity
        to collect garbage. This also means that we allocate blocks on demand,
        instead of ahead of time.

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/Heap.cpp
Source/JavaScriptCore/runtime/Heap.h
Source/JavaScriptCore/runtime/MarkedSpace.cpp
Source/JavaScriptCore/runtime/MarkedSpace.h

index 1923c260fe1e90a4417688c2c4ef95cc026b4d69..db1cf207c174f775c63416be01aa485d0e2ef835 100644 (file)
@@ -1,3 +1,31 @@
+2011-02-03  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Cameron Zwarich.
+
+        Changed MarkedSpace to delegate grow/shrink decisions to Heap
+        https://bugs.webkit.org/show_bug.cgi?id=53759
+        
+        SunSpider reports no change.
+        
+        * runtime/Heap.cpp:
+        (JSC::Heap::Heap):
+        (JSC::Heap::reset):
+        * runtime/Heap.h: Reorganized a few data members for better cache locality.
+        Added a grow policy.
+        
+        * runtime/MarkedSpace.cpp:
+        (JSC::MarkedSpace::allocate):
+        (JSC::MarkedSpace::sweep):
+        (JSC::MarkedSpace::reset): Don't shrink automatically. Instead, wait for
+        the heap to make an explicit sweep call.
+
+        * runtime/MarkedSpace.h:
+        (JSC::MarkedSpace::highWaterMark):
+        (JSC::MarkedSpace::setHighWaterMark): Use a watermark to determine how
+        many bytes to allocate before failing and giving the heap an opportunity
+        to collect garbage. This also means that we allocate blocks on demand,
+        instead of ahead of time.
+
 2011-02-03  James Kozianski  <koz@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 89cc6f82e149e9892c3b49c4367f81367ed6e9ba..20fae80de10f66207b453df7cf0a30d06fa6325f 100644 (file)
 #include "JSLock.h"
 #include "JSONObject.h"
 #include "Tracing.h"
+#include <algorithm>
 
 #define COLLECT_ON_EVERY_ALLOCATION 0
 
+using namespace std;
+
 namespace JSC {
 
+const size_t minBytesPerCycle = 512 * 1024;
+
 Heap::Heap(JSGlobalData* globalData)
-    : m_markedSpace(globalData)
-    , m_operationInProgress(NoOperation)
+    : m_operationInProgress(NoOperation)
+    , m_markedSpace(globalData)
     , m_markListSet(0)
     , m_activityCallback(DefaultGCActivityCallback::create(this))
     , m_globalData(globalData)
@@ -381,6 +386,10 @@ void Heap::reset(SweepToggle sweepToggle)
     if (sweepToggle == DoSweep)
         m_markedSpace.sweep();
 
+    size_t usedCellCount = m_markedSpace.markedCells();
+    size_t proportionalBytes = usedCellCount * 1.5 * HeapConstants::cellSize;
+    m_markedSpace.setHighWaterMark(max(proportionalBytes, minBytesPerCycle));
+
     JAVASCRIPTCORE_GC_END();
 
     (*m_activityCallback)();
index a896819e8b72a071967fdd0b70cbc62dd0ece9ba..1e2f5856ffbb29e7097caf02fdaeed2f733bdd3c 100644 (file)
@@ -122,8 +122,8 @@ namespace JSC {
 
         RegisterFile& registerFile();
 
-        MarkedSpace m_markedSpace;
         OperationInProgress m_operationInProgress;
+        MarkedSpace m_markedSpace;
 
         ProtectCountSet m_protectedValues;
         Vector<PageAllocationAligned> m_weakGCHandlePools;
index 027a9731a9885d8f4da271230d869c3486668226..869a03feda2b402974c0c796a2857e13a912f196 100644 (file)
@@ -138,8 +138,12 @@ void* MarkedSpace::allocate(size_t s)
             m_heap.nextCell = block->marked.nextPossiblyUnset(m_heap.nextCell);
         } while (m_heap.nextCell != HeapConstants::cellsPerBlock);
         m_heap.nextCell = 0;
+        m_heap.waterMark += BLOCK_SIZE;
     } while (++m_heap.nextBlock != m_heap.usedBlocks);
-    
+
+    if (m_heap.waterMark < m_heap.highWaterMark)
+        return &allocateBlock()->cells[m_heap.nextCell++];
+
     return 0;
 }
 
@@ -270,6 +274,8 @@ void MarkedSpace::sweep()
         new (cell) JSCell(dummyMarkableCellStructure);
 #endif
     }
+    
+    shrinkBlocks(0);
 }
 
 size_t MarkedSpace::objectCount() const
@@ -294,10 +300,10 @@ void MarkedSpace::reset()
 {
     m_heap.nextCell = 0;
     m_heap.nextBlock = 0;
+    m_heap.waterMark = 0;
 #if ENABLE(JSC_ZOMBIES)
     sweep();
 #endif
-    resizeBlocks();
 }
 
 LiveObjectIterator MarkedSpace::primaryHeapBegin()
index a2bdb31e84329ec6d7b4874efbc2690681a89c26..ab656191ce9d0b70275c8316e1c5cde07069685f 100644 (file)
@@ -47,6 +47,9 @@ namespace JSC {
         
         size_t numBlocks;
         size_t usedBlocks;
+        
+        size_t waterMark;
+        size_t highWaterMark;
 
         MarkedBlock* collectorBlock(size_t index) const
         {
@@ -68,12 +71,16 @@ namespace JSC {
 
         JSGlobalData* globalData() { return m_globalData; }
 
+        size_t highWaterMark() { return m_heap.highWaterMark; }
+        void setHighWaterMark(size_t highWaterMark) { m_heap.highWaterMark = highWaterMark; }
+
         void* allocate(size_t);
 
         void clearMarkBits();
         void markRoots();
         void reset();
         void sweep();
+        size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const;
 
         size_t size() const;
         size_t capacity() const;
@@ -94,7 +101,6 @@ namespace JSC {
         void shrinkBlocks(size_t neededBlocks);
 
         void clearMarkBits(MarkedBlock*);
-        size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const;
 
         CollectorHeap m_heap;
         JSGlobalData* m_globalData;