Title: [92224] trunk/Source
Revision
92224
Author
fpi...@apple.com
Date
2011-08-02 13:40:17 -0700 (Tue, 02 Aug 2011)

Log Message

JSC GC is far too conservative about growing the heap size, particularly
on desktop platforms
https://bugs.webkit.org/show_bug.cgi?id=65438

Reviewed by Oliver Hunt.

Source/_javascript_Core:

The minimum heap size is now 16MB instead of 512KB, provided all of the
following are true:
a) ENABLE(LARGE_HEAP) is set, which currently only happens on
   x86 targets, but could reasonably happen on any platform that is
   known to have a decent amount of RAM.
b) JSGlobalData is initialized with HeapSize = LargeHeap, which
   currently only happens when it's the JSDOMWindowBase in WebCore or
   in the jsc command-line tool.

This is a 4.1% speed-up on SunSpider.

* _javascript_Core.exp:
* heap/Heap.cpp:
(JSC::Heap::Heap):
(JSC::Heap::collect):
* heap/Heap.h:
* jsc.cpp:
(main):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::createContextGroup):
(JSC::JSGlobalData::create):
(JSC::JSGlobalData::createLeaked):
(JSC::JSGlobalData::sharedInstance):
* runtime/JSGlobalData.h:
* wtf/Platform.h:

Source/WebCore:

No change in behavior, thus no new tests.

Pass the LargeHeap hint to JSGlobalData when creating the JSC runtime
instance corresponding to non-worker JS code.

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::commonJSGlobalData):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (92223 => 92224)


--- trunk/Source/_javascript_Core/ChangeLog	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-08-02 20:40:17 UTC (rev 92224)
@@ -1,5 +1,40 @@
 2011-08-02  Filip Pizlo  <fpi...@apple.com>
 
+        JSC GC is far too conservative about growing the heap size, particularly
+        on desktop platforms
+        https://bugs.webkit.org/show_bug.cgi?id=65438
+
+        Reviewed by Oliver Hunt.
+
+        The minimum heap size is now 16MB instead of 512KB, provided all of the
+        following are true:
+        a) ENABLE(LARGE_HEAP) is set, which currently only happens on
+           x86 targets, but could reasonably happen on any platform that is
+           known to have a decent amount of RAM.
+        b) JSGlobalData is initialized with HeapSize = LargeHeap, which
+           currently only happens when it's the JSDOMWindowBase in WebCore or
+           in the jsc command-line tool.
+           
+        This is a 4.1% speed-up on SunSpider.
+
+        * _javascript_Core.exp:
+        * heap/Heap.cpp:
+        (JSC::Heap::Heap):
+        (JSC::Heap::collect):
+        * heap/Heap.h:
+        * jsc.cpp:
+        (main):
+        * runtime/JSGlobalData.cpp:
+        (JSC::JSGlobalData::JSGlobalData):
+        (JSC::JSGlobalData::createContextGroup):
+        (JSC::JSGlobalData::create):
+        (JSC::JSGlobalData::createLeaked):
+        (JSC::JSGlobalData::sharedInstance):
+        * runtime/JSGlobalData.h:
+        * wtf/Platform.h:
+
+2011-08-02  Filip Pizlo  <fpi...@apple.com>
+
         JSC does a GC even when the heap still has free pages
         https://bugs.webkit.org/show_bug.cgi?id=65445
 

Modified: trunk/Source/_javascript_Core/_javascript_Core.exp (92223 => 92224)


--- trunk/Source/_javascript_Core/_javascript_Core.exp	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/_javascript_Core.exp	2011-08-02 20:40:17 UTC (rev 92224)
@@ -125,7 +125,7 @@
 __ZN3JSC12DateInstanceC1EPNS_9ExecStateEPNS_9StructureEd
 __ZN3JSC12JSGlobalData10ClientDataD2Ev
 __ZN3JSC12JSGlobalData11jsArrayVPtrE
-__ZN3JSC12JSGlobalData12createLeakedENS_15ThreadStackTypeE
+__ZN3JSC12JSGlobalData12createLeakedENS_15ThreadStackTypeENS_8HeapSizeE
 __ZN3JSC12JSGlobalData12jsStringVPtrE
 __ZN3JSC12JSGlobalData12stopSamplingEv
 __ZN3JSC12JSGlobalData13startSamplingEv
@@ -137,7 +137,7 @@
 #ifndef NDEBUG
 __ZN3JSC12JSGlobalData23releaseExecutableMemoryEv
 #endif
-__ZN3JSC12JSGlobalData6createENS_15ThreadStackTypeE
+__ZN3JSC12JSGlobalData6createENS_15ThreadStackTypeENS_8HeapSizeE
 __ZN3JSC12JSGlobalDataD1Ev
 __ZN3JSC12RegExpObject6s_infoE
 __ZN3JSC12RegExpObjectC1EPNS_14JSGlobalObjectEPNS_9StructureEPNS_6RegExpE

Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (92223 => 92224)


--- trunk/Source/_javascript_Core/heap/Heap.cpp	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp	2011-08-02 20:40:17 UTC (rev 92224)
@@ -42,7 +42,15 @@
 
 namespace { 
 
-const size_t minBytesPerCycle = 512 * 1024;
+static size_t heapSizeForHint(HeapSize heapSize)
+{
+#if ENABLE(LARGE_HEAP)
+    if (heapSize == LargeHeap)
+        return 16 * 1024 * 1024;
+    ASSERT(heapSize == SmallHeap);
+#endif
+    return 512 * 1024;
+}
 
 static inline bool isValidSharedInstanceThreadState()
 {
@@ -230,8 +238,10 @@
 
 } // anonymous namespace
 
-Heap::Heap(JSGlobalData* globalData)
-    : m_operationInProgress(NoOperation)
+Heap::Heap(JSGlobalData* globalData, HeapSize heapSize)
+    : m_heapSize(heapSize)
+    , m_minBytesPerCycle(heapSizeForHint(heapSize))
+    , m_operationInProgress(NoOperation)
     , m_newSpace(this)
     , m_extraCost(0)
     , m_markListSet(0)
@@ -242,7 +252,7 @@
     , m_isSafeToCollect(false)
     , m_globalData(globalData)
 {
-    m_newSpace.setHighWaterMark(minBytesPerCycle);
+    m_newSpace.setHighWaterMark(m_minBytesPerCycle);
     (*m_activityCallback)();
 #if ENABLE(LAZY_BLOCK_FREEING)
     m_numberOfFreeBlocks = 0;
@@ -660,7 +670,7 @@
     // proportion is a bit arbitrary. A 2X multiplier gives a 1:1 (heap size :
     // new bytes allocated) proportion, and seems to work well in benchmarks.
     size_t proportionalBytes = 2 * size();
-    m_newSpace.setHighWaterMark(max(proportionalBytes, minBytesPerCycle));
+    m_newSpace.setHighWaterMark(max(proportionalBytes, m_minBytesPerCycle));
 
     _javascript_CORE_GC_END();
 

Modified: trunk/Source/_javascript_Core/heap/Heap.h (92223 => 92224)


--- trunk/Source/_javascript_Core/heap/Heap.h	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/heap/Heap.h	2011-08-02 20:40:17 UTC (rev 92224)
@@ -53,6 +53,9 @@
 
     enum OperationInProgress { NoOperation, Allocation, Collection };
     
+    // Heap size hint.
+    enum HeapSize { SmallHeap, LargeHeap };
+    
     class Heap {
         WTF_MAKE_NONCOPYABLE(Heap);
     public:
@@ -67,7 +70,7 @@
         static void writeBarrier(const JSCell*, JSValue);
         static void writeBarrier(const JSCell*, JSCell*);
 
-        Heap(JSGlobalData*);
+        Heap(JSGlobalData*, HeapSize);
         ~Heap();
         void destroy(); // JSGlobalData must call destroy() before ~Heap().
 
@@ -160,6 +163,9 @@
         static void* blockFreeingThreadStartFunc(void* heap);
 #endif
 
+        const HeapSize m_heapSize;
+        const size_t m_minBytesPerCycle;
+        
         OperationInProgress m_operationInProgress;
         NewSpace m_newSpace;
         MarkedBlockSet m_blocks;

Modified: trunk/Source/_javascript_Core/jsc.cpp (92223 => 92224)


--- trunk/Source/_javascript_Core/jsc.cpp	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/jsc.cpp	2011-08-02 20:40:17 UTC (rev 92224)
@@ -382,7 +382,7 @@
     // We can't use destructors in the following code because it uses Windows
     // Structured Exception Handling
     int res = 0;
-    JSGlobalData* globalData = JSGlobalData::create(ThreadStackTypeLarge).leakRef();
+    JSGlobalData* globalData = JSGlobalData::create(ThreadStackTypeLarge, LargeHeap).leakRef();
     TRY
         res = jscmain(argc, argv, globalData);
     EXCEPT(res = 3)

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp (92223 => 92224)


--- trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp	2011-08-02 20:40:17 UTC (rev 92224)
@@ -159,7 +159,7 @@
     JSGlobalData::jsFunctionVPtr = jsFunction->vptr();
 }
 
-JSGlobalData::JSGlobalData(GlobalDataType globalDataType, ThreadStackType threadStackType)
+JSGlobalData::JSGlobalData(GlobalDataType globalDataType, ThreadStackType threadStackType, HeapSize heapSize)
     : globalDataType(globalDataType)
     , clientData(0)
     , arrayConstructorTable(fastNew<HashTable>(JSC::arrayConstructorTable))
@@ -190,7 +190,7 @@
     , lexer(new Lexer(this))
     , parser(new Parser)
     , interpreter(0)
-    , heap(this)
+    , heap(this, heapSize)
     , dynamicGlobalObject(0)
     , cachedUTCOffset(std::numeric_limits<double>::quiet_NaN())
     , maxReentryDepth(threadStackType == ThreadStackTypeSmall ? MaxSmallThreadReentryDepth : MaxLargeThreadReentryDepth)
@@ -357,19 +357,19 @@
 #endif
 }
 
-PassRefPtr<JSGlobalData> JSGlobalData::createContextGroup(ThreadStackType type)
+PassRefPtr<JSGlobalData> JSGlobalData::createContextGroup(ThreadStackType type, HeapSize heapSize)
 {
-    return adoptRef(new JSGlobalData(APIContextGroup, type));
+    return adoptRef(new JSGlobalData(APIContextGroup, type, heapSize));
 }
 
-PassRefPtr<JSGlobalData> JSGlobalData::create(ThreadStackType type)
+PassRefPtr<JSGlobalData> JSGlobalData::create(ThreadStackType type, HeapSize heapSize)
 {
-    return adoptRef(new JSGlobalData(Default, type));
+    return adoptRef(new JSGlobalData(Default, type, heapSize));
 }
 
-PassRefPtr<JSGlobalData> JSGlobalData::createLeaked(ThreadStackType type)
+PassRefPtr<JSGlobalData> JSGlobalData::createLeaked(ThreadStackType type, HeapSize heapSize)
 {
-    return create(type);
+    return create(type, heapSize);
 }
 
 bool JSGlobalData::sharedInstanceExists()
@@ -381,7 +381,7 @@
 {
     JSGlobalData*& instance = sharedInstanceInternal();
     if (!instance) {
-        instance = adoptRef(new JSGlobalData(APIShared, ThreadStackTypeSmall)).leakRef();
+        instance = adoptRef(new JSGlobalData(APIShared, ThreadStackTypeSmall, SmallHeap)).leakRef();
 #if ENABLE(JSC_MULTIPLE_THREADS)
         instance->makeUsableFromMultipleThreads();
 #endif

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalData.h (92223 => 92224)


--- trunk/Source/_javascript_Core/runtime/JSGlobalData.h	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalData.h	2011-08-02 20:40:17 UTC (rev 92224)
@@ -113,7 +113,7 @@
         // than the old singleton APIShared JSGlobalData created for use by
         // the original API.
         enum GlobalDataType { Default, APIContextGroup, APIShared };
-
+        
         struct ClientData {
             virtual ~ClientData() = 0;
         };
@@ -123,9 +123,9 @@
         static bool sharedInstanceExists();
         static JSGlobalData& sharedInstance();
 
-        static PassRefPtr<JSGlobalData> create(ThreadStackType);
-        static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType);
-        static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType);
+        static PassRefPtr<JSGlobalData> create(ThreadStackType, HeapSize = SmallHeap);
+        static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType, HeapSize = SmallHeap);
+        static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType, HeapSize = SmallHeap);
         ~JSGlobalData();
 
 #if ENABLE(JSC_MULTIPLE_THREADS)
@@ -281,7 +281,7 @@
         void releaseExecutableMemory();
 
     private:
-        JSGlobalData(GlobalDataType, ThreadStackType);
+        JSGlobalData(GlobalDataType, ThreadStackType, HeapSize);
         static JSGlobalData*& sharedInstanceInternal();
         void createNativeThunk();
 #if ENABLE(JIT) && ENABLE(INTERPRETER)

Modified: trunk/Source/_javascript_Core/wtf/Platform.h (92223 => 92224)


--- trunk/Source/_javascript_Core/wtf/Platform.h	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/_javascript_Core/wtf/Platform.h	2011-08-02 20:40:17 UTC (rev 92224)
@@ -1112,6 +1112,14 @@
 #define ENABLE_LAZY_BLOCK_FREEING 1
 #endif
 
+#ifndef ENABLE_LARGE_HEAP
+#if CPU(X86) || CPU(X86_64)
+#define ENABLE_LARGE_HEAP 1
+#else
+#define ENABLE_LARGE_HEAP 0
+#endif
+#endif
+
 #if !defined(ENABLE_PAN_SCROLLING) && OS(WINDOWS)
 #define ENABLE_PAN_SCROLLING 1
 #endif

Modified: trunk/Source/WebCore/ChangeLog (92223 => 92224)


--- trunk/Source/WebCore/ChangeLog	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/WebCore/ChangeLog	2011-08-02 20:40:17 UTC (rev 92224)
@@ -1,3 +1,19 @@
+2011-08-02  Filip Pizlo  <fpi...@apple.com>
+
+        JSC GC is far too conservative about growing the heap size, particularly
+        on desktop platforms
+        https://bugs.webkit.org/show_bug.cgi?id=65438
+
+        Reviewed by Oliver Hunt.
+
+        No change in behavior, thus no new tests.
+        
+        Pass the LargeHeap hint to JSGlobalData when creating the JSC runtime
+        instance corresponding to non-worker JS code.
+
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::commonJSGlobalData):
+
 2011-08-02  Van Lam  <van...@google.com>
 
         --webkit-visual-word: ctrl-arrow is not able to reach the boundary of line

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (92223 => 92224)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp	2011-08-02 20:38:04 UTC (rev 92223)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp	2011-08-02 20:40:17 UTC (rev 92224)
@@ -172,7 +172,7 @@
 
     static JSGlobalData* globalData = 0;
     if (!globalData) {
-        globalData = JSGlobalData::createLeaked(ThreadStackTypeLarge).releaseRef();
+        globalData = JSGlobalData::createLeaked(ThreadStackTypeLarge, LargeHeap).releaseRef();
         globalData->timeoutChecker.setTimeoutInterval(10000); // 10 seconds
 #ifndef NDEBUG
         globalData->exclusiveThread = currentThread();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to