OSDN Git Service

Add GC support in V8 and calling GC in WebCoreFrameBridge::clearCache.
authorFeng Qian <fqian@google.com>
Fri, 14 Aug 2009 04:54:48 +0000 (21:54 -0700)
committerFeng Qian <fqian@google.com>
Fri, 14 Aug 2009 04:54:48 +0000 (21:54 -0700)
This is experimental, we'd like to see the impact on page cycler intl1 and intl2.

V8Binding/v8/include/v8.h
V8Binding/v8/src/api.cc
WebCore/bindings/v8/ScriptController.cpp
WebKit/android/jni/WebCoreFrameBridge.cpp

index 83d5bed..6815ec9 100644 (file)
@@ -2184,6 +2184,14 @@ class V8EXPORT V8 {
    */
   static int GetLogLines(int from_pos, char* dest_buf, int max_size);
 
+#if defined(ANDROID)
+  /**
+   * Android system sends the browser low memory signal, and it is good to
+   * collect JS heap, which can free some DOM nodes.
+   * This function should ONLY be used by the browser in low memory condition.
+   */
+  static void CollectAllGarbage();
+#endif
 
   /**
    * Releases any resources used by v8 and stops any utility threads
index 4222353..3eb6d60 100644 (file)
@@ -3298,6 +3298,12 @@ int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
   return 0;
 }
 
+
+void V8::CollectAllGarbage() {
+  i::Heap::CollectAllGarbage();
+}
+
+
 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) {
   EnsureInitialized("v8::String::Utf8Value::Utf8Value()");
   if (obj.IsEmpty()) {
index eecff45..674de43 100644 (file)
@@ -251,8 +251,11 @@ void ScriptController::collectGarbage()
         return;
 
     v8::Context::Scope scope(context);
-
+#if PLATFORM(ANDROID)
+    v8::V8::CollectAllGarbage();
+#else
     m_proxy->evaluate(ScriptSourceCode("if (window.gc) void(gc());"), 0);
+#endif
 }
 
 bool ScriptController::haveInterpreter() const
index f47603b..4672427 100644 (file)
@@ -1136,6 +1136,9 @@ static void ClearCache(JNIEnv *env, jobject obj)
 #if USE(JSC)    
     // force JavaScript to GC when clear cache
     WebCore::gcController().garbageCollectSoon();
+#elif USE(V8)
+    WebCore::Frame* pFrame = GET_NATIVE_FRAME(env, obj);
+    pFrame->script()->collectGarbage(); 
 #endif  // USE(JSC)
 }