2009-11-10 Anton Muhin <antonm@chromium.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2009 20:00:33 +0000 (20:00 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2009 20:00:33 +0000 (20:00 +0000)
        Reviewed by Adam Barth.

        Reapply 50562 reverted by 50588 due to issues with sandboxing (should be fine now).
        https://bugs.webkit.org/show_bug.cgi?id=31051

        * bindings/v8/V8GCController.cpp:
        (WebCore::V8GCController::gcEpilogue):
        (WebCore::V8GCController::checkMemoryUsage):
        * bindings/v8/V8GCController.h:
        * bindings/v8/V8Proxy.cpp:
        (WebCore::V8Proxy::evaluate):
        (WebCore::V8Proxy::runScript):
        (WebCore::V8Proxy::callFunction):

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

WebCore/ChangeLog
WebCore/bindings/v8/V8GCController.cpp
WebCore/bindings/v8/V8GCController.h
WebCore/bindings/v8/V8Proxy.cpp

index 4afbc601989037400a89f97b7fbf4b8286ce9706..f46b9a41b7a7569f116694a462a2eb707410e2eb 100644 (file)
@@ -1,3 +1,19 @@
+2009-11-10  Anton Muhin  <antonm@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Reapply 50562 reverted by 50588 due to issues with sandboxing (should be fine now).
+        https://bugs.webkit.org/show_bug.cgi?id=31051
+
+        * bindings/v8/V8GCController.cpp:
+        (WebCore::V8GCController::gcEpilogue):
+        (WebCore::V8GCController::checkMemoryUsage):
+        * bindings/v8/V8GCController.h:
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::V8Proxy::evaluate):
+        (WebCore::V8Proxy::runScript):
+        (WebCore::V8Proxy::callFunction):
+
 2009-11-10  Zoltan Horvath  <zoltan@webkit.org>
 
         Reviewed by Darin Adler.
index a1dc819f892dccc0e0d8b241d20e952feafa06de..bd545bbf7638861e17cceabf6c6efdf9356abbb8 100644 (file)
@@ -416,6 +416,17 @@ ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE)
     }
 };
 
+int V8GCController::workingSetEstimateMB = 0;
+
+namespace {
+
+int getMemoryUsageInMB()
+{
+    return ChromiumBridge::memoryUsageMB();
+}
+
+}  // anonymous namespace
+
 void V8GCController::gcEpilogue()
 {
     v8::HandleScope scope;
@@ -425,6 +436,8 @@ void V8GCController::gcEpilogue()
     GCEpilogueVisitor epilogueVisitor;
     visitActiveDOMObjectsInCurrentThread(&epilogueVisitor);
 
+    workingSetEstimateMB = getMemoryUsageInMB();
+
 #ifndef NDEBUG
     // Check all survivals are weak.
     DOMObjectVisitor domObjectVisitor;
@@ -438,4 +451,16 @@ void V8GCController::gcEpilogue()
 #endif
 }
 
+void V8GCController::checkMemoryUsage()
+{
+    const int lowUsageMB = 256;  // If memory usage is below this threshold, do not bother forcing GC.
+    const int highUsageMB = 1024;  // If memory usage is above this threshold, force GC more aggresively.
+    const int highUsageDeltaMB = 128;  // Delta of memory usage growth (vs. last workingSetEstimateMB) to force GC when memory usage is high.
+
+    int memoryUsageMB = getMemoryUsageInMB();
+    if ((memoryUsageMB > lowUsageMB && memoryUsageMB > 2 * workingSetEstimateMB) || (memoryUsageMB > highUsageMB && memoryUsageMB > workingSetEstimateMB + highUsageDeltaMB))
+        v8::V8::LowMemoryNotification();
+}
+
+
 }  // namespace WebCore
index 7441bf0043fe1b8460122a6b77f0c5a8d54c81dd..484be240543c8addf42c63f5a846fabfabddf8bc 100644 (file)
@@ -78,6 +78,12 @@ namespace WebCore {
 
         static void gcPrologue();
         static void gcEpilogue();
+
+        static void checkMemoryUsage();
+
+    private:
+        // Estimate of current working set.
+        static int workingSetEstimateMB;
     };
 
 }
index defdb270a37d0a59560cab116ec7ffd68fd12a97..161d630465745ecabd8e007741ab7e42b3f0cc5b 100644 (file)
@@ -374,6 +374,8 @@ v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* nod
 {
     ASSERT(v8::Context::InContext());
 
+    V8GCController::checkMemoryUsage();
+
 #if ENABLE(INSPECTOR)
     if (InspectorTimelineAgent* timelineAgent = m_frame->page() ? m_frame->page()->inspectorTimelineAgent() : 0)
         timelineAgent->willEvaluateScript(source.url().isNull() ? String() : source.url().string(), source.startLine());
@@ -418,6 +420,7 @@ v8::Local<v8::Value> V8Proxy::runScript(v8::Handle<v8::Script> script, bool isIn
     if (script.IsEmpty())
         return notHandledByInterceptor();
 
+    V8GCController::checkMemoryUsage();
     // Compute the source string and prevent against infinite recursion.
     if (m_recursion >= kMaxRecursionDepth) {
         v8::Local<v8::String> code = v8ExternalString("throw RangeError('Recursion too deep')");
@@ -472,6 +475,7 @@ v8::Local<v8::Value> V8Proxy::runScript(v8::Handle<v8::Script> script, bool isIn
 
 v8::Local<v8::Value> V8Proxy::callFunction(v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[])
 {
+    V8GCController::checkMemoryUsage();
     v8::Local<v8::Value> result;
     {
         V8ConsoleMessage::Scope scope;