Title: [157537] trunk/Source/_javascript_Core
Revision
157537
Author
dba...@webkit.org
Date
2013-10-16 16:36:25 -0700 (Wed, 16 Oct 2013)

Log Message

Add SPI to disable the garbage collector timer
https://bugs.webkit.org/show_bug.cgi?id=122921

Reviewed by Geoffrey Garen.

Based on a patch by Mark Hahnenberg.

* API/JSBase.cpp:
(JSDisableGCTimer): Added; SPI function.
* API/JSBasePrivate.h:
* heap/BlockAllocator.cpp:
(JSC::createBlockFreeingThread): Added.
(JSC::BlockAllocator::BlockAllocator): Modified to use JSC::createBlockFreeingThread()
to conditionally create the "block freeing" thread depending on the value of
GCActivityCallback::s_shouldCreateGCTimer.
(JSC::BlockAllocator::~BlockAllocator):
* heap/BlockAllocator.h:
(JSC::BlockAllocator::deallocate):
* heap/Heap.cpp:
(JSC::Heap::didAbandon):
(JSC::Heap::collect):
(JSC::Heap::didAllocate):
* heap/HeapTimer.cpp:
(JSC::HeapTimer::timerDidFire):
* runtime/GCActivityCallback.cpp:
* runtime/GCActivityCallback.h:
(JSC::DefaultGCActivityCallback::create): Only instantiate a DefaultGCActivityCallback object
when GCActivityCallback::s_shouldCreateGCTimer is true so as to prevent allocating a HeapTimer
object (since DefaultGCActivityCallback ultimately extends HeapTimer).

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSBase.cpp (157536 => 157537)


--- trunk/Source/_javascript_Core/API/JSBase.cpp	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/API/JSBase.cpp	2013-10-16 23:36:25 UTC (rev 157537)
@@ -134,3 +134,8 @@
     APIEntryShim entryShim(exec);
     exec->vm().heap.collectAllGarbage();
 }
+
+void JSDisableGCTimer(void)
+{
+    GCActivityCallback::s_shouldCreateGCTimer = false;
+}

Modified: trunk/Source/_javascript_Core/API/JSBasePrivate.h (157536 => 157537)


--- trunk/Source/_javascript_Core/API/JSBasePrivate.h	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/API/JSBasePrivate.h	2013-10-16 23:36:25 UTC (rev 157537)
@@ -45,6 +45,8 @@
 */
 JS_EXPORT void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) AVAILABLE_IN_WEBKIT_VERSION_4_0;
 
+JS_EXPORT void JSDisableGCTimer(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Source/_javascript_Core/ChangeLog (157536 => 157537)


--- trunk/Source/_javascript_Core/ChangeLog	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-10-16 23:36:25 UTC (rev 157537)
@@ -1,3 +1,35 @@
+2013-10-16  Daniel Bates  <daba...@apple.com>
+
+        Add SPI to disable the garbage collector timer
+        https://bugs.webkit.org/show_bug.cgi?id=122921
+
+        Reviewed by Geoffrey Garen.
+
+        Based on a patch by Mark Hahnenberg.
+
+        * API/JSBase.cpp:
+        (JSDisableGCTimer): Added; SPI function.
+        * API/JSBasePrivate.h:
+        * heap/BlockAllocator.cpp:
+        (JSC::createBlockFreeingThread): Added.
+        (JSC::BlockAllocator::BlockAllocator): Modified to use JSC::createBlockFreeingThread()
+        to conditionally create the "block freeing" thread depending on the value of
+        GCActivityCallback::s_shouldCreateGCTimer.
+        (JSC::BlockAllocator::~BlockAllocator):
+        * heap/BlockAllocator.h:
+        (JSC::BlockAllocator::deallocate):
+        * heap/Heap.cpp:
+        (JSC::Heap::didAbandon):
+        (JSC::Heap::collect):
+        (JSC::Heap::didAllocate):
+        * heap/HeapTimer.cpp:
+        (JSC::HeapTimer::timerDidFire):
+        * runtime/GCActivityCallback.cpp:
+        * runtime/GCActivityCallback.h:
+        (JSC::DefaultGCActivityCallback::create): Only instantiate a DefaultGCActivityCallback object
+        when GCActivityCallback::s_shouldCreateGCTimer is true so as to prevent allocating a HeapTimer
+        object (since DefaultGCActivityCallback ultimately extends HeapTimer).
+
 2013-10-16  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r157529.

Modified: trunk/Source/_javascript_Core/heap/BlockAllocator.cpp (157536 => 157537)


--- trunk/Source/_javascript_Core/heap/BlockAllocator.cpp	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/heap/BlockAllocator.cpp	2013-10-16 23:36:25 UTC (rev 157537)
@@ -34,6 +34,15 @@
 
 namespace JSC {
 
+inline ThreadIdentifier createBlockFreeingThread(BlockAllocator* allocator)
+{
+    if (!GCActivityCallback::s_shouldCreateGCTimer)
+        return 0; // No block freeing thread.
+    ThreadIdentifier identifier = createThread(allocator->blockFreeingThreadStartFunc, allocator, "_javascript_Core::BlockFree");
+    RELEASE_ASSERT(identifier);
+    return identifier;
+}
+
 BlockAllocator::BlockAllocator()
     : m_superRegion()
     , m_copiedRegionSet(CopiedBlock::blockSize)
@@ -43,9 +52,8 @@
     , m_numberOfEmptyRegions(0)
     , m_isCurrentlyAllocating(false)
     , m_blockFreeingThreadShouldQuit(false)
-    , m_blockFreeingThread(createThread(blockFreeingThreadStartFunc, this, "_javascript_Core::BlockFree"))
+    , m_blockFreeingThread(createBlockFreeingThread(this))
 {
-    RELEASE_ASSERT(m_blockFreeingThread);
     m_regionLock.Init();
 }
 
@@ -57,7 +65,8 @@
         m_blockFreeingThreadShouldQuit = true;
         m_emptyRegionCondition.broadcast();
     }
-    waitForThreadCompletion(m_blockFreeingThread);
+    if (m_blockFreeingThread)
+        waitForThreadCompletion(m_blockFreeingThread);
     ASSERT(allRegionSetsAreEmpty());
     ASSERT(m_emptyRegions.isEmpty());
 }

Modified: trunk/Source/_javascript_Core/heap/BlockAllocator.h (157536 => 157537)


--- trunk/Source/_javascript_Core/heap/BlockAllocator.h	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/heap/BlockAllocator.h	2013-10-16 23:36:25 UTC (rev 157537)
@@ -26,6 +26,7 @@
 #ifndef BlockAllocator_h
 #define BlockAllocator_h
 
+#include "GCActivityCallback.h"
 #include "HeapBlock.h"
 #include "Region.h"
 #include <wtf/DoublyLinkedList.h>
@@ -62,6 +63,7 @@
     void waitForRelativeTimeWhileHoldingLock(double relative);
     void waitForRelativeTime(double relative);
 
+    friend ThreadIdentifier createBlockFreeingThread(BlockAllocator*);
     void blockFreeingThreadMain();
     static void blockFreeingThreadStartFunc(void* heap);
 
@@ -200,6 +202,9 @@
         MutexLocker mutexLocker(m_emptyRegionConditionLock);
         m_emptyRegionCondition.signal();
     }
+
+    if (!m_blockFreeingThread)
+        releaseFreeRegions();
 }
 
 template<typename T>

Modified: trunk/Source/_javascript_Core/heap/Heap.cpp (157536 => 157537)


--- trunk/Source/_javascript_Core/heap/Heap.cpp	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/heap/Heap.cpp	2013-10-16 23:36:25 UTC (rev 157537)
@@ -333,7 +333,8 @@
 
 void Heap::didAbandon(size_t bytes)
 {
-    m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);
+    if (m_activityCallback)
+        m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);
     m_bytesAbandoned += bytes;
 }
 
@@ -762,7 +763,8 @@
     m_operationInProgress = Collection;
     m_extraMemoryUsage = 0;
 
-    m_activityCallback->willCollect();
+    if (m_activityCallback)
+        m_activityCallback->willCollect();
 
     double lastGCStartTime = WTF::monotonicallyIncreasingTime();
     if (lastGCStartTime - m_lastCodeDiscardTime > minute) {
@@ -909,7 +911,8 @@
 
 void Heap::didAllocate(size_t bytes)
 {
-    m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);
+    if (m_activityCallback)
+        m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);
     m_bytesAllocated += bytes;
 }
 

Modified: trunk/Source/_javascript_Core/heap/HeapTimer.cpp (157536 => 157537)


--- trunk/Source/_javascript_Core/heap/HeapTimer.cpp	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/heap/HeapTimer.cpp	2013-10-16 23:36:25 UTC (rev 157537)
@@ -85,7 +85,7 @@
     }
 
     HeapTimer* heapTimer = 0;
-    if (vm->heap.activityCallback()->m_timer.get() == timer)
+    if (vm->heap.activityCallback() && vm->heap.activityCallback()->m_timer.get() == timer)
         heapTimer = vm->heap.activityCallback();
     else if (vm->heap.sweeper()->m_timer.get() == timer)
         heapTimer = vm->heap.sweeper();

Modified: trunk/Source/_javascript_Core/runtime/GCActivityCallback.cpp (157536 => 157537)


--- trunk/Source/_javascript_Core/runtime/GCActivityCallback.cpp	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/runtime/GCActivityCallback.cpp	2013-10-16 23:36:25 UTC (rev 157537)
@@ -44,6 +44,8 @@
 
 namespace JSC {
 
+bool GCActivityCallback::s_shouldCreateGCTimer = true;
+
 #if USE(CF) || PLATFORM(EFL)
 
 const double gcTimeSlicePerMB = 0.01; // Percentage of CPU time we will spend to reclaim 1 MB

Modified: trunk/Source/_javascript_Core/runtime/GCActivityCallback.h (157536 => 157537)


--- trunk/Source/_javascript_Core/runtime/GCActivityCallback.h	2013-10-16 22:33:05 UTC (rev 157536)
+++ trunk/Source/_javascript_Core/runtime/GCActivityCallback.h	2013-10-16 23:36:25 UTC (rev 157537)
@@ -50,6 +50,8 @@
     bool isEnabled() const { return m_enabled; }
     void setEnabled(bool enabled) { m_enabled = enabled; }
 
+    static bool s_shouldCreateGCTimer;
+
 protected:
 #if USE(CF)
     GCActivityCallback(VM* vm, CFRunLoopRef runLoop)
@@ -102,7 +104,7 @@
 
 inline PassOwnPtr<DefaultGCActivityCallback> DefaultGCActivityCallback::create(Heap* heap)
 {
-    return adoptPtr(new DefaultGCActivityCallback(heap));
+    return GCActivityCallback::s_shouldCreateGCTimer ? adoptPtr(new DefaultGCActivityCallback(heap)) : nullptr;
 }
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to