From a2e0d7c96a21cc48aa089938609669502cfdf407 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 14 Mar 2013 14:11:02 +0100 Subject: [Qt] Implement GCActivityCallback https://bugs.webkit.org/show_bug.cgi?id=103998 Reviewed by Simon Hausmann. Source/JavaScriptCore: Implements the activity triggered garbage collector. * runtime/GCActivityCallback.cpp: (JSC::DefaultGCActivityCallback::DefaultGCActivityCallback): (JSC::DefaultGCActivityCallback::scheduleTimer): (JSC::DefaultGCActivityCallback::cancelTimer): * runtime/GCActivityCallback.h: (GCActivityCallback): (DefaultGCActivityCallback): Source/WebCore: Implements the activity triggered garbage collector, and disables the timer based fallback. * bindings/js/GCController.cpp: (WebCore::GCController::GCController): (WebCore::GCController::garbageCollectSoon): * bindings/js/GCController.h: (GCController): Change-Id: Idd8f714e71871b3cc991f8d1866cdd271a47eff4 git-svn-id: http://svn.webkit.org/repository/webkit/trunk@141114 268f45cc-cd09-0410-ab3c-d52691b4dbfc Reviewed-by: Jocelyn Turcotte --- .../JavaScriptCore/runtime/GCActivityCallback.cpp | 29 ++++++++++++++++++++-- Source/JavaScriptCore/runtime/GCActivityCallback.h | 8 +++--- 2 files changed, 32 insertions(+), 5 deletions(-) (limited to 'Source/JavaScriptCore/runtime') diff --git a/Source/JavaScriptCore/runtime/GCActivityCallback.cpp b/Source/JavaScriptCore/runtime/GCActivityCallback.cpp index 74cbdbaef..0c07b5e02 100644 --- a/Source/JavaScriptCore/runtime/GCActivityCallback.cpp +++ b/Source/JavaScriptCore/runtime/GCActivityCallback.cpp @@ -40,14 +40,15 @@ namespace JSC { -#if USE(CF) +#if USE(CF) || PLATFORM(QT) const double gcTimeSlicePerMB = 0.01; // Percentage of CPU time we will spend to reclaim 1 MB const double maxGCTimeSlice = 0.05; // The maximum amount of CPU time we want to use for opportunistic timer-triggered collections. const double timerSlop = 2.0; // Fudge factor to avoid performance cost of resetting timer. const double pagingTimeOut = 0.1; // Time in seconds to allow opportunistic timer to iterate over all blocks to see if the Heap is paged out. -const CFTimeInterval hour = 60 * 60; +const double hour = 60 * 60; +#if USE(CF) DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap) : GCActivityCallback(heap->globalData(), CFRunLoopGetCurrent()) , m_delay(s_decade) @@ -59,6 +60,13 @@ DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap, CFRunLoopRef ru , m_delay(s_decade) { } +#elif PLATFORM(QT) +DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap) + : GCActivityCallback(heap->globalData()) + , m_delay(hour) +{ +} +#endif void DefaultGCActivityCallback::doWork() { @@ -78,6 +86,7 @@ void DefaultGCActivityCallback::doWork() heap->collect(Heap::DoNotSweep); } +#if USE(CF) void DefaultGCActivityCallback::scheduleTimer(double newDelay) { if (newDelay * timerSlop > m_delay) @@ -92,6 +101,22 @@ void DefaultGCActivityCallback::cancelTimer() m_delay = s_decade; CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade); } +#elif PLATFORM(QT) + +void DefaultGCActivityCallback::scheduleTimer(double newDelay) +{ + if (newDelay * timerSlop > m_delay) + return; + m_delay = newDelay; + m_timer.start(newDelay * 1000, this); +} + +void DefaultGCActivityCallback::cancelTimer() +{ + m_delay = hour; + m_timer.stop(); +} +#endif void DefaultGCActivityCallback::didAllocate(size_t bytes) { diff --git a/Source/JavaScriptCore/runtime/GCActivityCallback.h b/Source/JavaScriptCore/runtime/GCActivityCallback.h index c112a7120..3522e6c8e 100644 --- a/Source/JavaScriptCore/runtime/GCActivityCallback.h +++ b/Source/JavaScriptCore/runtime/GCActivityCallback.h @@ -57,7 +57,7 @@ protected: , m_enabled(true) { } -# else +#else GCActivityCallback(JSGlobalData* globalData) : HeapTimer(globalData) , m_enabled(true) @@ -83,10 +83,12 @@ public: #if USE(CF) protected: DefaultGCActivityCallback(Heap*, CFRunLoopRef); - +#endif +#if USE(CF) || PLATFORM(QT) +protected: void cancelTimer(); void scheduleTimer(double); - + private: double m_delay; #endif -- cgit v1.2.1