[chromium] Improve garbage collector hint if page uses Canvas contexts
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2012 09:26:37 +0000 (09:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2012 09:26:37 +0000 (09:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=92856

Patch by ulan@chromium.org <ulan@chromium.org> on 2012-08-02
Reviewed by Kentaro Hara.

Request GC by sending context disposed and idle notification to V8 instead
of sending low memory notification. It is faster as it causes one GC
instead of seven GCs caused by low memory notification.

* bindings/v8/V8Binding.cpp:
(WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
* bindings/v8/V8Binding.h:
(V8BindingPerIsolateData):
(WebCore::V8BindingPerIsolateData::setShouldCollectGarbageSoon):
(WebCore::V8BindingPerIsolateData::clearShouldCollectGarbageSoon):
(WebCore::V8BindingPerIsolateData::shouldCollectGarbageSoon):
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::hintForGCIfNecessary):
* bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
(WebCore::V8HTMLCanvasElement::getContextCallback):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/V8Binding.cpp
Source/WebCore/bindings/v8/V8Binding.h
Source/WebCore/bindings/v8/V8Proxy.cpp
Source/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

index 5653648..dc387da 100644 (file)
@@ -1,3 +1,26 @@
+2012-08-02  ulan@chromium.org  <ulan@chromium.org>
+
+        [chromium] Improve garbage collector hint if page uses Canvas contexts
+        https://bugs.webkit.org/show_bug.cgi?id=92856
+
+        Reviewed by Kentaro Hara.
+
+        Request GC by sending context disposed and idle notification to V8 instead
+        of sending low memory notification. It is faster as it causes one GC
+        instead of seven GCs caused by low memory notification.
+
+        * bindings/v8/V8Binding.cpp:
+        (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
+        * bindings/v8/V8Binding.h:
+        (V8BindingPerIsolateData):
+        (WebCore::V8BindingPerIsolateData::setShouldCollectGarbageSoon):
+        (WebCore::V8BindingPerIsolateData::clearShouldCollectGarbageSoon):
+        (WebCore::V8BindingPerIsolateData::shouldCollectGarbageSoon):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::V8Proxy::hintForGCIfNecessary):
+        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
+        (WebCore::V8HTMLCanvasElement::getContextCallback):
+
 2012-08-02  Mihnea Ovidenie  <mihnea@adobe.com>
 
         CSSRegions: Crash when reattaching a region to a named flow.
index b114227..cc609ad 100644 (file)
@@ -60,7 +60,7 @@ V8BindingPerIsolateData::V8BindingPerIsolateData(v8::Isolate* isolate)
 #ifndef NDEBUG
     , m_internalScriptRecursionLevel(0)
 #endif
-    , m_lowMemoryNotificationHint(false)
+    , m_shouldCollectGarbageSoon(false)
 {
 }
 
index 25f5a54..4336f3f 100644 (file)
@@ -220,13 +220,13 @@ namespace WebCore {
 
         void reportMemoryUsage(MemoryObjectInfo*) const;
 
-        // Gives the system a hint that we should send a low memory
-        // notification upon the next close or navigation event,
-        // because some expensive objects have been allocated that we
-        // want to take every opportunity to collect.
-        void setLowMemoryNotificationHint() { m_lowMemoryNotificationHint = true; }
-        void clearLowMemoryNotificationHint() { m_lowMemoryNotificationHint = false; }
-        bool isLowMemoryNotificationHint() const { return m_lowMemoryNotificationHint; }
+        // Gives the system a hint that we should request garbage collection
+        // upon the next close or navigation event, because some expensive
+        // objects have been allocated that we want to take every opportunity
+        // to collect.
+        void setShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = true; }
+        void clearShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = false; }
+        bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
 
     private:
         explicit V8BindingPerIsolateData(v8::Isolate*);
@@ -257,7 +257,7 @@ namespace WebCore {
 #endif
         GCEventData m_gcEventData;
 
-        bool m_lowMemoryNotificationHint;
+        bool m_shouldCollectGarbageSoon;
     };
 
     class ConstructorMode {
index 081f75f..58846ea 100644 (file)
@@ -562,9 +562,11 @@ void V8Proxy::resetIsolatedWorlds()
 void V8Proxy::hintForGCIfNecessary()
 {
     V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
-    if (data->isLowMemoryNotificationHint()) {
-        data->clearLowMemoryNotificationHint();
-        v8::V8::LowMemoryNotification();
+    if (data->shouldCollectGarbageSoon()) {
+        const int longIdlePauseInMs = 1000;
+        data->clearShouldCollectGarbageSoon();
+        v8::V8::ContextDisposedNotification();
+        v8::V8::IdleNotification(longIdlePauseInMs);
     }
 }
 
index 110ae9b..f9e8aa6 100644 (file)
@@ -91,7 +91,7 @@ v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Argument
     // want to take an opportunity to get rid of them as soon as possible when we
     // navigate away from pages using them.
     V8BindingPerIsolateData* perIsolateData = V8BindingPerIsolateData::current(args.GetIsolate());
-    perIsolateData->setLowMemoryNotificationHint();
+    perIsolateData->setShouldCollectGarbageSoon();
 
     if (result->is2d())
         return toV8(static_cast<CanvasRenderingContext2D*>(result), args.GetIsolate());