Changeset 123556 in webkit


Ignore:
Timestamp:
Jul 24, 2012 5:37:11 PM (12 years ago)
Author:
kbr@google.com
Message:

[chromium] Hint garbage collector to run if page uses Canvas contexts
https://bugs.webkit.org/show_bug.cgi?id=76225

Reviewed by Kentaro Hara.

Source/WebCore:

Upon creating a canvas context, set a hint in the current isolate
indicating that a full GC should be done upon the next page
navigation.

This improves Chrome's robustness on some WebGL stress tests which
simulate real-world behavior by repeatedly navigating among
several samples. More general measures are being investigated, but
this change makes V8 behave the same as JSC on these stress tests.
JSC doesn't currently use generational garbage collection, so it
has more opportunities to discover unreferenced canvas contexts.

Test: fast/canvas/webgl/context-creation-and-destruction.html

  • bindings/v8/V8Binding.cpp:

(WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):

Initialize per-isolate low memory hint.

  • bindings/v8/V8Binding.h:

(V8BindingPerIsolateData):
(WebCore::V8BindingPerIsolateData::setLowMemoryNotificationHint):

Set a per-isolate hint to signal a low memory condition upon the next page navigation.

(WebCore::V8BindingPerIsolateData::clearLowMemoryNotificationHint):

Clear the previously set hint.

(WebCore::V8BindingPerIsolateData::isLowMemoryNotificationHint):

Get the previously set hint.

  • bindings/v8/V8Proxy.cpp:

(WebCore::V8Proxy::hintForGCIfNecessary):

If necessary, send V8 a hint that it should GC.

(WebCore):
(WebCore::V8Proxy::clearForClose):
(WebCore::V8Proxy::clearForNavigation):

Call hintForGCIfNecessary.

  • bindings/v8/V8Proxy.h:

(V8Proxy):

  • bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:

(WebCore::V8HTMLCanvasElement::getContextCallback):

Set a hint that we should GC upon the next page navigation.

LayoutTests:

This test doesn't directly exercise this code path yet, but it
needs to work regardless and also needs to be expanded.

  • fast/canvas/webgl/context-creation-and-destruction-expected.txt: Added.
  • fast/canvas/webgl/context-creation-and-destruction.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r123555 r123556  
     12012-07-24  Kenneth Russell  <kbr@google.com>
     2
     3        [chromium] Hint garbage collector to run if page uses Canvas contexts
     4        https://bugs.webkit.org/show_bug.cgi?id=76225
     5
     6        Reviewed by Kentaro Hara.
     7
     8        This test doesn't directly exercise this code path yet, but it
     9        needs to work regardless and also needs to be expanded.
     10
     11        * fast/canvas/webgl/context-creation-and-destruction-expected.txt: Added.
     12        * fast/canvas/webgl/context-creation-and-destruction.html: Added.
     13
    1142012-07-24  Alexis Menard  <alexis.menard@openbossa.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r123553 r123556  
     12012-07-24  Kenneth Russell  <kbr@google.com>
     2
     3        [chromium] Hint garbage collector to run if page uses Canvas contexts
     4        https://bugs.webkit.org/show_bug.cgi?id=76225
     5
     6        Reviewed by Kentaro Hara.
     7
     8        Upon creating a canvas context, set a hint in the current isolate
     9        indicating that a full GC should be done upon the next page
     10        navigation.
     11
     12        This improves Chrome's robustness on some WebGL stress tests which
     13        simulate real-world behavior by repeatedly navigating among
     14        several samples. More general measures are being investigated, but
     15        this change makes V8 behave the same as JSC on these stress tests.
     16        JSC doesn't currently use generational garbage collection, so it
     17        has more opportunities to discover unreferenced canvas contexts.
     18
     19        Test: fast/canvas/webgl/context-creation-and-destruction.html
     20
     21        * bindings/v8/V8Binding.cpp:
     22        (WebCore::V8BindingPerIsolateData::V8BindingPerIsolateData):
     23            Initialize per-isolate low memory hint.
     24        * bindings/v8/V8Binding.h:
     25        (V8BindingPerIsolateData):
     26        (WebCore::V8BindingPerIsolateData::setLowMemoryNotificationHint):
     27            Set a per-isolate hint to signal a low memory condition upon the next page navigation.
     28        (WebCore::V8BindingPerIsolateData::clearLowMemoryNotificationHint):
     29            Clear the previously set hint.
     30        (WebCore::V8BindingPerIsolateData::isLowMemoryNotificationHint):
     31            Get the previously set hint.
     32        * bindings/v8/V8Proxy.cpp:
     33        (WebCore::V8Proxy::hintForGCIfNecessary):
     34            If necessary, send V8 a hint that it should GC.
     35        (WebCore):
     36        (WebCore::V8Proxy::clearForClose):
     37        (WebCore::V8Proxy::clearForNavigation):
     38            Call hintForGCIfNecessary.
     39        * bindings/v8/V8Proxy.h:
     40        (V8Proxy):
     41        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
     42        (WebCore::V8HTMLCanvasElement::getContextCallback):
     43            Set a hint that we should GC upon the next page navigation.
     44
    1452012-07-24  Dave Tu  <dtu@chromium.org>
    246
  • trunk/Source/WebCore/bindings/v8/V8Binding.cpp

    r123500 r123556  
    6161    , m_internalScriptRecursionLevel(0)
    6262#endif
     63    , m_lowMemoryNotificationHint(false)
    6364{
    6465}
  • trunk/Source/WebCore/bindings/v8/V8Binding.h

    r122555 r123556  
    221221        void reportMemoryUsage(MemoryObjectInfo*) const;
    222222
     223        // Gives the system a hint that we should send a low memory
     224        // notification upon the next close or navigation event,
     225        // because some expensive objects have been allocated that we
     226        // want to take every opportunity to collect.
     227        void setLowMemoryNotificationHint() { m_lowMemoryNotificationHint = true; }
     228        void clearLowMemoryNotificationHint() { m_lowMemoryNotificationHint = false; }
     229        bool isLowMemoryNotificationHint() const { return m_lowMemoryNotificationHint; }
     230
    223231    private:
    224232        explicit V8BindingPerIsolateData(v8::Isolate*);
     
    249257#endif
    250258        GCEventData m_gcEventData;
     259
     260        bool m_lowMemoryNotificationHint;
    251261    };
    252262
  • trunk/Source/WebCore/bindings/v8/V8Proxy.cpp

    r123112 r123556  
    560560}
    561561
     562void V8Proxy::hintForGCIfNecessary()
     563{
     564    V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
     565    if (data->isLowMemoryNotificationHint()) {
     566        data->clearLowMemoryNotificationHint();
     567        v8::V8::LowMemoryNotification();
     568    }
     569}
     570
    562571void V8Proxy::clearForClose()
    563572{
    564573    resetIsolatedWorlds();
     574    hintForGCIfNecessary();
    565575    windowShell()->clearForClose();
    566576}
     
    569579{
    570580    resetIsolatedWorlds();
     581    hintForGCIfNecessary();
    571582    windowShell()->clearForNavigation();
    572583}
  • trunk/Source/WebCore/bindings/v8/V8Proxy.h

    r120229 r123556  
    272272        void resetIsolatedWorlds();
    273273
     274        void hintForGCIfNecessary();
     275
    274276        PassOwnPtr<v8::ScriptData> precompileScript(v8::Handle<v8::String>, CachedScript*);
    275277
  • trunk/Source/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

    r119572 r123556  
    8787    if (!result)
    8888        return v8::Null(args.GetIsolate());
     89
     90    // Both 2D and 3D canvas contexts can hold on to lots of GPU resources, and we
     91    // want to take an opportunity to get rid of them as soon as possible when we
     92    // navigate away from pages using them.
     93    V8BindingPerIsolateData* perIsolateData = V8BindingPerIsolateData::current(args.GetIsolate());
     94    perIsolateData->setLowMemoryNotificationHint();
     95
    8996    if (result->is2d())
    9097        return toV8(static_cast<CanvasRenderingContext2D*>(result), args.GetIsolate());
Note: See TracChangeset for help on using the changeset viewer.