2011-01-28 Geoffrey Garen <ggaren@apple.com>
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 30 Jan 2011 03:32:52 +0000 (03:32 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 30 Jan 2011 03:32:52 +0000 (03:32 +0000)
        Reviewed by Maciej Stachowiak.

        Some more Heap cleanup.
        https://bugs.webkit.org/show_bug.cgi?id=53357

        * JavaScriptCore.exp:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Updated exported symbols.

        * runtime/Heap.cpp:
        (JSC::Heap::reportExtraMemoryCostSlowCase): Renamed recordExtraCost to
        reportExtraMemoryCostSlowCase to match our naming conventions.

        (JSC::Heap::capacity): Renamed size to capacity because this function
        returns the capacity of the heap, including unused portions.

        * runtime/Heap.h:
        (JSC::Heap::globalData):
        (JSC::Heap::markedSpace):
        (JSC::Heap::machineStackMarker):
        (JSC::Heap::reportExtraMemoryCost): Moved statics to the top of the file.
        Moved ctor and dtor to the beginning of the class definition. Grouped
        functions by purpose.

        * runtime/MarkedSpace.cpp:
        (JSC::MarkedSpace::capacity): Renamed size to capacity because this
        function returns the capacity of the heap, including unused portions.

        * runtime/MarkedSpace.h: Removed statistics and the Statistics class because
        the same information can be gotten just by calling size() and capacity().

        * runtime/MemoryStatistics.cpp:
        * runtime/MemoryStatistics.h: Ditto.
2011-01-28  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Maciej Stachowiak.

        Some more Heap cleanup.
        https://bugs.webkit.org/show_bug.cgi?id=53357

        Updated for JavaScriptCore changes.

        * Misc/WebCoreStatistics.mm:
        (+[WebCoreStatistics memoryStatistics]):
2011-01-28  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Maciej Stachowiak.

        Some more Heap cleanup.
        https://bugs.webkit.org/show_bug.cgi?id=53357

        Updated for JavaScriptCore changes.

        * bindings/js/ScriptGCEvent.cpp:
        (WebCore::ScriptGCEvent::getHeapSize):

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

14 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.exp
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
Source/JavaScriptCore/runtime/Heap.cpp
Source/JavaScriptCore/runtime/Heap.h
Source/JavaScriptCore/runtime/MarkedSpace.cpp
Source/JavaScriptCore/runtime/MarkedSpace.h
Source/JavaScriptCore/runtime/MemoryStatistics.cpp
Source/JavaScriptCore/runtime/MemoryStatistics.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptGCEvent.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebCoreStatistics.mm
Source/WebKit2/Shared/mac/WebMemorySampler.mac.mm

index 159ba4b9a19b939b0916f245a3a6912305b04fa2..16bd377752c3e6393c4c820f5115bc4a51e1b080 100644 (file)
@@ -1,3 +1,38 @@
+2011-01-28  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Some more Heap cleanup.
+        https://bugs.webkit.org/show_bug.cgi?id=53357
+        
+        * JavaScriptCore.exp:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Updated exported symbols.
+
+        * runtime/Heap.cpp:
+        (JSC::Heap::reportExtraMemoryCostSlowCase): Renamed recordExtraCost to 
+        reportExtraMemoryCostSlowCase to match our naming conventions.
+
+        (JSC::Heap::capacity): Renamed size to capacity because this function
+        returns the capacity of the heap, including unused portions.
+
+        * runtime/Heap.h:
+        (JSC::Heap::globalData):
+        (JSC::Heap::markedSpace):
+        (JSC::Heap::machineStackMarker):
+        (JSC::Heap::reportExtraMemoryCost): Moved statics to the top of the file.
+        Moved ctor and dtor to the beginning of the class definition. Grouped
+        functions by purpose.
+
+        * runtime/MarkedSpace.cpp:
+        (JSC::MarkedSpace::capacity): Renamed size to capacity because this
+        function returns the capacity of the heap, including unused portions.
+
+        * runtime/MarkedSpace.h: Removed statistics and the Statistics class because
+        the same information can be gotten just by calling size() and capacity().
+
+        * runtime/MemoryStatistics.cpp:
+        * runtime/MemoryStatistics.h: Ditto.
+
 2011-01-29  Daniel Bates  <dbates@rim.com>
 
         Reviewed by Eric Seidel.
index 199c37f0c2b642bf1c6994439d399aa9cf4b5d44..95474437e100bac9ea5803001b3ab7ddf8dd249a 100644 (file)
@@ -166,7 +166,6 @@ __ZN3JSC14SamplingThread4stopEv
 __ZN3JSC14SamplingThread5startEj
 __ZN3JSC14TimeoutChecker10didTimeOutEPNS_9ExecStateE
 __ZN3JSC14TimeoutChecker5resetEv
-__ZN3JSC14heapStatisticsEPNS_12JSGlobalDataE
 __ZN3JSC14throwTypeErrorEPNS_9ExecStateE
 __ZN3JSC15JSWrapperObject12markChildrenERNS_9MarkStackE
 __ZN3JSC15createTypeErrorEPNS_9ExecStateERKNS_7UStringE
@@ -210,7 +209,6 @@ __ZN3JSC35createInterruptedExecutionExceptionEPNS_12JSGlobalDataE
 __ZN3JSC3NaNE
 __ZN3JSC4Heap14primaryHeapEndEv
 __ZN3JSC4Heap15addWeakGCHandleEPNS_6JSCellE
-__ZN3JSC4Heap15recordExtraCostEm
 __ZN3JSC4Heap16objectTypeCountsEv
 __ZN3JSC4Heap16primaryHeapBeginEv
 __ZN3JSC4Heap17collectAllGarbageEv
@@ -219,6 +217,7 @@ __ZN3JSC4Heap19setActivityCallbackEN3WTF10PassOwnPtrINS_18GCActivityCallbackEEE
 __ZN3JSC4Heap20protectedObjectCountEv
 __ZN3JSC4Heap25protectedObjectTypeCountsEv
 __ZN3JSC4Heap26protectedGlobalObjectCountEv
+__ZN3JSC4Heap29reportExtraMemoryCostSlowCaseEm
 __ZN3JSC4Heap6isBusyEv
 __ZN3JSC4Heap7destroyEv
 __ZN3JSC4Heap7protectENS_7JSValueE
@@ -519,9 +518,9 @@ __ZNK3JSC18PropertyDescriptor6setterEv
 __ZNK3JSC18PropertyDescriptor8writableEv
 __ZNK3JSC19SourceProviderCache8byteSizeEv
 __ZNK3JSC24JSObjectWithGlobalObject12globalObjectEv
-__ZNK3JSC4Heap10statisticsEv
 __ZNK3JSC4Heap11objectCountEv
 __ZNK3JSC4Heap4sizeEv
+__ZNK3JSC4Heap8capacityEv
 __ZNK3JSC6JSCell11toPrimitiveEPNS_9ExecStateENS_22PreferredPrimitiveTypeE
 __ZNK3JSC6JSCell12toThisObjectEPNS_9ExecStateE
 __ZNK3JSC6JSCell14isGetterSetterEv
index f8786b52f2a180d7a45aa4e0cf4d121ebd81630f..0d7e514d37dd218562bbe74aa827bfa5d89db761 100644 (file)
@@ -70,6 +70,7 @@ EXPORTS
     ?callOnMainThread@WTF@@YAXP6AXPAX@Z0@Z
     ?callOnMainThreadAndWait@WTF@@YAXP6AXPAX@Z0@Z
     ?cancelCallOnMainThread@WTF@@YAXP6AXPAX@Z0@Z
+    ?capacity@Heap@JSC@@QBEIXZ
     ?changePrototypeTransition@Structure@JSC@@SA?AV?$PassRefPtr@VStructure@JSC@@@WTF@@PAV12@VJSValue@2@@Z
     ?checkCurrentIdentifierTable@Identifier@JSC@@CAXPAVExecState@2@@Z
     ?checkCurrentIdentifierTable@Identifier@JSC@@CAXPAVJSGlobalData@2@@Z
@@ -267,10 +268,10 @@ EXPORTS
     ?putWithAttributes@JSObject@JSC@@UAEXPAVJSGlobalData@2@IVJSValue@2@I@Z
     ?randomNumber@WTF@@YANXZ
     ?recompileAllJSFunctions@Debugger@JSC@@QAEXPAVJSGlobalData@2@@Z
-    ?recordExtraCost@Heap@JSC@@AAEXI@Z
     ?reifyString@StringBuilder@WTF@@AAEXXZ
     ?releaseDecommitted@OSAllocator@WTF@@SAXPAXI@Z
     ?releaseStack@MarkStack@JSC@@CAXPAXI@Z
+    ?reportExtraMemoryCostSlowCase@Heap@JSC@@AAEXI@Z
     ?reserveAndCommit@OSAllocator@WTF@@SAPAXIW4Usage@12@_N1@Z
     ?reset@ParserArena@JSC@@QAEXXZ
     ?reset@TimeoutChecker@JSC@@QAEXXZ
index 9ec3799b04cb0a5dabc4f594a07d303814f9e956..7af0d3de08d4fdecbc4591a07460c5060d15ea52 100644 (file)
@@ -79,7 +79,7 @@ void Heap::destroy()
     m_globalData = 0;
 }
 
-void Heap::recordExtraCost(size_t cost)
+void Heap::reportExtraMemoryCostSlowCase(size_t cost)
 {
     // Our frequency of garbage collection tries to balance memory use against speed
     // by collecting based on the number of newly created values. However, for values
@@ -92,7 +92,7 @@ void Heap::recordExtraCost(size_t cost)
     // if a large value survives one garbage collection, there is not much point to
     // collecting more frequently as long as it stays alive.
 
-    if (m_extraCost > maxExtraCost && m_extraCost > m_markedSpace.size() / 2) {
+    if (m_extraCost > maxExtraCost && m_extraCost > m_markedSpace.capacity() / 2) {
         JAVASCRIPTCORE_GC_BEGIN();
 
         markRoots();
@@ -302,14 +302,14 @@ size_t Heap::objectCount() const
     return m_markedSpace.objectCount();
 }
 
-MarkedSpace::Statistics Heap::statistics() const
+size_t Heap::size() const
 {
-    return m_markedSpace.statistics();
+    return m_markedSpace.size();
 }
 
-size_t Heap::size() const
+size_t Heap::capacity() const
 {
-    return m_markedSpace.size();
+    return m_markedSpace.capacity();
 }
 
 size_t Heap::globalObjectCount()
index db05d81782d8e2fbc5244e6199c8a75c84a1c3db..bf8c31741e9c1d49794105865dfad07ef20fba26 100644 (file)
@@ -50,45 +50,44 @@ namespace JSC {
     class Heap {
         WTF_MAKE_NONCOPYABLE(Heap);
     public:
-        void destroy();
+        static Heap* heap(JSValue); // 0 for immediate values
+        static Heap* heap(JSCell*);
 
-        void* allocate(size_t);
+        static bool isCellMarked(const JSCell*);
+        static bool checkMarkCell(const JSCell*);
+        static void markCell(JSCell*);
+        
+        Heap(JSGlobalData*);
+        ~Heap();
+        void destroy(); // JSGlobalData must call destroy() before ~Heap().
 
-        bool isBusy(); // true if an allocation or collection is in progress
-        void collectAllGarbage();
+        JSGlobalData* globalData() const { return m_globalData; }
+        MarkedSpace& markedSpace() { return m_markedSpace; }
+        MachineStackMarker& machineStackMarker() { return m_machineStackMarker; }
 
         GCActivityCallback* activityCallback();
         void setActivityCallback(PassOwnPtr<GCActivityCallback>);
 
-        static const size_t minExtraCost = 256;
-        static const size_t maxExtraCost = 1024 * 1024;
+        bool isBusy(); // true if an allocation or collection is in progress
+        void* allocate(size_t);
+        void collectAllGarbage();
 
         void reportExtraMemoryCost(size_t cost);
 
-        size_t objectCount() const;
-        MarkedSpace::Statistics statistics() const;
-        size_t size() const;
-
         void protect(JSValue);
-        // Returns true if the value is no longer protected by any protect pointers
-        // (though it may still be alive due to heap/stack references).
-        bool unprotect(JSValue);
+        bool unprotect(JSValue); // True when the protect count drops to 0.
 
-        static Heap* heap(JSValue); // 0 for immediate values
-        static Heap* heap(JSCell*);
+        bool contains(void*);
 
+        size_t size() const;
+        size_t capacity() const;
+        size_t objectCount() const;
         size_t globalObjectCount();
         size_t protectedObjectCount();
         size_t protectedGlobalObjectCount();
         HashCountedSet<const char*>* protectedObjectTypeCounts();
         HashCountedSet<const char*>* objectTypeCounts();
 
-        static bool isCellMarked(const JSCell*);
-        static bool checkMarkCell(const JSCell*);
-        static void markCell(JSCell*);
-        
-        bool contains(void*);
-
         WeakGCHandle* addWeakGCHandle(JSCell*);
 
         void pushTempSortVector(WTF::Vector<ValueStringPair>*);
@@ -96,21 +95,16 @@ namespace JSC {
 
         HashSet<MarkedArgumentBuffer*>& markListSet() { if (!m_markListSet) m_markListSet = new HashSet<MarkedArgumentBuffer*>; return *m_markListSet; }
 
-        JSGlobalData* globalData() const { return m_globalData; }
-        
         LiveObjectIterator primaryHeapBegin();
         LiveObjectIterator primaryHeapEnd();
         
-        MachineStackMarker& machineStackMarker() { return m_machineStackMarker; }
-
-        MarkedSpace& markedSpace() { return m_markedSpace; }
-
     private:
         friend class JSGlobalData;
-        Heap(JSGlobalData*);
-        ~Heap();
 
-        void recordExtraCost(size_t);
+        static const size_t minExtraCost = 256;
+        static const size_t maxExtraCost = 1024 * 1024;
+
+        void reportExtraMemoryCostSlowCase(size_t);
 
         void markRoots();
         void markProtectedObjects(MarkStack&);
@@ -163,7 +157,7 @@ namespace JSC {
     inline void Heap::reportExtraMemoryCost(size_t cost)
     {
         if (cost > minExtraCost) 
-            recordExtraCost(cost);
+            reportExtraMemoryCostSlowCase(cost);
     }
     
     inline WeakGCHandlePool* Heap::weakGCHandlePool(size_t index)
index c020617a896085261e1ac71b102f6db049796d29..aeb520f6a236b725638fba48c4635df6894b569d 100644 (file)
@@ -295,20 +295,12 @@ size_t MarkedSpace::objectCount() const
            - m_heap.usedBlocks; // 1 cell per block is a dummy sentinel
 }
 
-void MarkedSpace::addToStatistics(Statistics& statistics) const
-{
-    statistics.size += m_heap.usedBlocks * BLOCK_SIZE;
-    statistics.free += m_heap.usedBlocks * BLOCK_SIZE - (objectCount() * HeapConstants::cellSize);
-}
-
-MarkedSpace::Statistics MarkedSpace::statistics() const
+size_t MarkedSpace::size() const
 {
-    Statistics statistics = { 0, 0 };
-    addToStatistics(statistics);
-    return statistics;
+    return objectCount() * HeapConstants::cellSize;
 }
 
-size_t MarkedSpace::size() const
+size_t MarkedSpace::capacity() const
 {
     return m_heap.usedBlocks * BLOCK_SIZE;
 }
index 566ac5f8c123ce95eceea0407bf3ad298a335a59..3b23d8c1c0ed2ef3b6fe8f229060606779a7a326 100644 (file)
@@ -64,11 +64,6 @@ namespace JSC {
     class MarkedSpace {
         WTF_MAKE_NONCOPYABLE(MarkedSpace);
     public:
-        struct Statistics {
-            size_t size;
-            size_t free;
-        };
-
         static Heap* heap(JSCell*);
 
         static bool isCellMarked(const JSCell*);
@@ -88,8 +83,8 @@ namespace JSC {
         void sweep();
 
         size_t size() const;
+        size_t capacity() const;
         size_t objectCount() const;
-        Statistics statistics() const;
 
         bool contains(void*);
 
@@ -113,8 +108,6 @@ namespace JSC {
         void clearMarkBits(CollectorBlock*);
         size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const;
 
-        void addToStatistics(Statistics&) const;
-
         CollectorHeap m_heap;
         JSGlobalData* m_globalData;
     };
index 06a319b01d5ff051cb6e59431fb3021e2a1363a3..86101f559f1e8fba5321802980c24615928be63b 100644 (file)
 
 namespace JSC {
 
-MarkedSpace::Statistics heapStatistics(JSGlobalData* commonGlobalData)
-{
-    return commonGlobalData->heap.statistics();
-}        
-
 GlobalMemoryStatistics globalMemoryStatistics() 
 {
     GlobalMemoryStatistics stats;
index 265970214fbd6cf6c15ab679261864c826727d44..d4b8b6fc1018ac06a84572e629cefceb3a60c4eb 100644 (file)
@@ -37,7 +37,6 @@ struct GlobalMemoryStatistics {
     size_t JITBytes;
 };
 
-MarkedSpace::Statistics heapStatistics(JSGlobalData* commonGlobalData);
 GlobalMemoryStatistics globalMemoryStatistics();
 
 }
index e7c015b7a14d64e7be5c9cffe51972acd232a3c9..413707d058a89a1e964775de79286095fbff2e1e 100644 (file)
@@ -1,3 +1,15 @@
+2011-01-28  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Some more Heap cleanup.
+        https://bugs.webkit.org/show_bug.cgi?id=53357
+        
+        Updated for JavaScriptCore changes.
+
+        * bindings/js/ScriptGCEvent.cpp:
+        (WebCore::ScriptGCEvent::getHeapSize):
+
 2011-01-29  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Daniel Bates.
index b7fc7b3e710ae553dc46b342b854e98d1fb2a1c0..21c21bd00e870bc123455f5888da1257f6698464 100644 (file)
@@ -45,9 +45,10 @@ using namespace JSC;
 void ScriptGCEvent::getHeapSize(size_t& usedHeapSize, size_t& totalHeapSize)
 {
     JSGlobalData* globalData = JSDOMWindow::commonJSGlobalData();
-    totalHeapSize = globalData->heap.size();
+    totalHeapSize = globalData->heap.capacity();
     usedHeapSize = totalHeapSize;
 }
+
 } // namespace WebCore
 
 #endif // !ENABLE(INSPECTOR)
index 821a8fd3d206245f076552b27ac40904f314b8d1..f7e310e52b67d7703a6e4c8bc4bdabc4c6997082 100644 (file)
@@ -1,3 +1,15 @@
+2011-01-28  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Some more Heap cleanup.
+        https://bugs.webkit.org/show_bug.cgi?id=53357
+
+        Updated for JavaScriptCore changes.
+
+        * Misc/WebCoreStatistics.mm:
+        (+[WebCoreStatistics memoryStatistics]):
+
 2011-01-28  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r77006 and r77020.
index 5d96c95cebaa0a004dbb14a04acef071ec894abd..a1589dbf778a570e43c16c968bd9e67b018bbab4 100644 (file)
@@ -197,15 +197,16 @@ using namespace WebCore;
     WTF::FastMallocStatistics fastMallocStatistics = WTF::fastMallocStatistics();
     
     JSLock lock(SilenceAssertionsOnly);
-    MarkedSpace::Statistics heapMemoryStats = heapStatistics(JSDOMWindow::commonJSGlobalData());
+    size_t heapSize = JSDOMWindow::commonJSGlobalData()->heap.size();
+    size_t heapFree = JSDOMWindow::commonJSGlobalData()->heap.capacity() - heapSize;
     GlobalMemoryStatistics globalMemoryStats = globalMemoryStatistics();
     
     return [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSNumber numberWithInt:fastMallocStatistics.reservedVMBytes], @"FastMallocReservedVMBytes",
                 [NSNumber numberWithInt:fastMallocStatistics.committedVMBytes], @"FastMallocCommittedVMBytes",
                 [NSNumber numberWithInt:fastMallocStatistics.freeListBytes], @"FastMallocFreeListBytes",
-                [NSNumber numberWithInt:heapMemoryStats.size], @"JavaScriptHeapSize",
-                [NSNumber numberWithInt:heapMemoryStats.free], @"JavaScriptFreeSize",
+                [NSNumber numberWithInt:heapSize], @"JavaScriptHeapSize",
+                [NSNumber numberWithInt:heapFree], @"JavaScriptFreeSize",
                 [NSNumber numberWithUnsignedInt:(unsigned int)globalMemoryStats.stackBytes], @"JavaScriptStackSize",
                 [NSNumber numberWithUnsignedInt:(unsigned int)globalMemoryStats.JITBytes], @"JavaScriptJITSize",
             nil];
index ba8410ed1312d95eae654edb1b0b7c7c0f0d8c77..ed12cc43bc4395543345c829ffa025b74ecbef3f 100644 (file)
@@ -116,9 +116,8 @@ WebMemoryStatistics WebMemorySampler::sampleWebKit() const
     totalBytesCommitted += fastMallocBytesCommitted;
     
     JSLock lock(SilenceAssertionsOnly);
-    MarkedSpace::Statistics heapMemoryStats = heapStatistics(JSDOMWindow::commonJSGlobalData());
-    size_t jscHeapBytesInUse = heapMemoryStats.size - heapMemoryStats.free;
-    size_t jscHeapBytesCommitted = heapMemoryStats.size;
+    size_t jscHeapBytesInUse = JSDOMWindow::commonJSGlobalData()->heap.size();
+    size_t jscHeapBytesCommitted = JSDOMWindow::commonJSGlobalData()->heap.capacity();
     totalBytesInUse += jscHeapBytesInUse;
     totalBytesCommitted += jscHeapBytesCommitted;