[BlackBerry] Implement GCActivityCallback with platform timer
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2012 20:12:36 +0000 (20:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2012 20:12:36 +0000 (20:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90175

Patch by Yong Li <yoli@rim.com> on 2012-07-13
Reviewed by Rob Buis.

Implement GCActivityCallback and HeapTimer for BlackBerry port.

* heap/HeapTimer.cpp:
(JSC):
(JSC::HeapTimer::HeapTimer):
(JSC::HeapTimer::~HeapTimer):
(JSC::HeapTimer::timerDidFire):
(JSC::HeapTimer::synchronize):
(JSC::HeapTimer::invalidate):
(JSC::HeapTimer::didStartVMShutdown):
* heap/HeapTimer.h:
(HeapTimer):
* runtime/GCActivityCallbackBlackBerry.cpp:
(JSC):
(JSC::DefaultGCActivityCallback::doWork):
(JSC::DefaultGCActivityCallback::didAllocate):
(JSC::DefaultGCActivityCallback::willCollect):
(JSC::DefaultGCActivityCallback::cancel):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/HeapTimer.cpp
Source/JavaScriptCore/heap/HeapTimer.h
Source/JavaScriptCore/runtime/GCActivityCallbackBlackBerry.cpp

index 8718b0e..7465099 100644 (file)
@@ -1,3 +1,29 @@
+2012-07-13  Yong Li  <yoli@rim.com>
+
+        [BlackBerry] Implement GCActivityCallback with platform timer
+        https://bugs.webkit.org/show_bug.cgi?id=90175
+
+        Reviewed by Rob Buis.
+
+        Implement GCActivityCallback and HeapTimer for BlackBerry port.
+
+        * heap/HeapTimer.cpp:
+        (JSC):
+        (JSC::HeapTimer::HeapTimer):
+        (JSC::HeapTimer::~HeapTimer):
+        (JSC::HeapTimer::timerDidFire):
+        (JSC::HeapTimer::synchronize):
+        (JSC::HeapTimer::invalidate):
+        (JSC::HeapTimer::didStartVMShutdown):
+        * heap/HeapTimer.h:
+        (HeapTimer):
+        * runtime/GCActivityCallbackBlackBerry.cpp:
+        (JSC):
+        (JSC::DefaultGCActivityCallback::doWork):
+        (JSC::DefaultGCActivityCallback::didAllocate):
+        (JSC::DefaultGCActivityCallback::willCollect):
+        (JSC::DefaultGCActivityCallback::cancel):
+
 2012-07-13  Patrick Gansterer  <paroga@webkit.org>
 
         [WIN] Fix compilation of DFGRepatch.cpp
index ae66f9e..fa97978 100644 (file)
@@ -98,8 +98,38 @@ void HeapTimer::timerDidFire(CFRunLoopTimerRef, void* info)
     agent->m_shutdownMutex.unlock();
 }
 
+#elif PLATFORM(BLACKBERRY)
+
+HeapTimer::HeapTimer(JSGlobalData* globalData)
+    : m_globalData(globalData)
+    , m_timer(this, &HeapTimer::timerDidFire)
+{
+}
+
+HeapTimer::~HeapTimer()
+{
+}
+
+void HeapTimer::timerDidFire()
+{
+    doWork();
+}
+
+void HeapTimer::synchronize()
+{
+}
+
+void HeapTimer::invalidate()
+{
+}
+
+void HeapTimer::didStartVMShutdown()
+{
+    delete this;
+}
+
 #else
-    
+
 HeapTimer::HeapTimer(JSGlobalData* globalData)
     : m_globalData(globalData)
 {
index 9255e06..8871509 100644 (file)
@@ -31,6 +31,8 @@
 
 #if USE(CF)
 #include <CoreFoundation/CoreFoundation.h>
+#elif PLATFORM(BLACKBERRY)
+#include <BlackBerryPlatformTimer.h>
 #endif
 
 namespace JSC {
@@ -63,6 +65,10 @@ protected:
     CFRunLoopTimerContext m_context;
 
     Mutex m_shutdownMutex;
+#elif PLATFORM(BLACKBERRY)
+    void timerDidFire();
+
+    BlackBerry::Platform::Timer<HeapTimer> m_timer;
 #endif
     
 private:
index 3b0b5a7..d9f96fa 100644 (file)
 #include "GCActivityCallback.h"
 
 #include "Heap.h"
+#include "JSGlobalData.h"
 #include <BlackBerryPlatformMemory.h>
 
 namespace JSC {
 
+static const size_t bytesWorthGC = 4 * 1024 * 1024;
+
 DefaultGCActivityCallback::DefaultGCActivityCallback(Heap* heap)
     : GCActivityCallback(heap->globalData())
 {
 }
 
-DefaultGCActivityCallback::doWork()
+void DefaultGCActivityCallback::doWork()
 {
+    m_globalData->heap.collect(Heap::DoNotSweep);
 }
 
 void DefaultGCActivityCallback::didAllocate(size_t bytesAllocated)
 {
-    if (!BlackBerry::Platform::isMemoryLow())
-        return;
-
-    if (bytesAllocated < 1 * 1024 * 1024)
+    if (bytesAllocated < bytesWorthGC || m_timer.started())
         return;
 
-    if (m_globalData->heap.isBusy() || !m_globalData->heap.isSafeToCollect())
-        return;
-
-    m_globalData->heap.collect(Heap::DoNotSweep);
+    // Try using ~5% CPU time.
+    m_timer.start(m_globalData->heap.lastGCLength() * 20);
 }
 
 void DefaultGCActivityCallback::willCollect()
 {
+    cancel();
 }
 
 void DefaultGCActivityCallback::cancel()
 {
+    m_timer.stop();
 }
 
 }