⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 283402 in webkit


Ignore:
Timestamp:
Oct 1, 2021, 2:24:36 PM (5 years ago)
Author:
Chris Dumez
Message:

GC may not know about memory used by AudioBufferSourceNode's buffer
https://bugs.webkit.org/show_bug.cgi?id=230966

Reviewed by Darin Adler.

Source/WebCore:

AudioBufferSourceNode has a 'buffer' attribute settable by JavaScript of type AudioBuffer.
An AudioBuffer may use a significant amount of memory and AudioBuffer.idl contains [ReportExtraMemoryCost]
extended attribute to report this memory to the GC. However, there is an issue if JS constructs a large
AudioBuffer, then sets it on an AudioBufferSourceNode and then the JSAudioBuffer wrapper gets garbage
collected. At this point, GC thinks it recovered the extra memory reported by the JSAudioBuffer but this
is not true since that AudioBuffer (and its internal memory) are still kept alive by AudioBufferSourceNode /
JSAudioBufferSourceNode. To address this issue, the proposal in this patch is to have JSAudioBufferSourceNode
mark its buffer when visiting childen during GC. As a result, the JSAudioBuffer wrapper will stay alive (and
report extra memory use) as long as its associated JSAudioBufferSourceNode wrapper is still alive.

Test: webaudio/AudioBufferSource/audiobuffersource-buffer-gc.html

  • Modules/webaudio/AudioBuffer.idl:
  • Modules/webaudio/AudioBufferSourceNode.h:
  • Modules/webaudio/AudioBufferSourceNode.idl:
  • Sources.txt:
  • bindings/js/JSAudioBufferSourceNodeCustom.cpp: Added.

(WebCore::JSAudioBufferSourceNode::visitAdditionalChildren):

LayoutTests:

Add layout test coverage.

  • webaudio/AudioBufferSource/audiobuffersource-buffer-gc-expected.txt: Added.
  • webaudio/AudioBufferSource/audiobuffersource-buffer-gc.html: Added.
Location:
trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r283401 r283402  
     12021-10-01  Chris Dumez  <cdumez@apple.com>
     2
     3        GC may not know about memory used by AudioBufferSourceNode's buffer
     4        https://bugs.webkit.org/show_bug.cgi?id=230966
     5
     6        Reviewed by Darin Adler.
     7
     8        Add layout test coverage.
     9
     10        * webaudio/AudioBufferSource/audiobuffersource-buffer-gc-expected.txt: Added.
     11        * webaudio/AudioBufferSource/audiobuffersource-buffer-gc.html: Added.
     12
    1132021-10-01  Ayumi Kojima  <ayumi_kojima@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r283398 r283402  
     12021-10-01  Chris Dumez  <cdumez@apple.com>
     2
     3        GC may not know about memory used by AudioBufferSourceNode's buffer
     4        https://bugs.webkit.org/show_bug.cgi?id=230966
     5
     6        Reviewed by Darin Adler.
     7
     8        AudioBufferSourceNode has a 'buffer' attribute settable by JavaScript of type AudioBuffer.
     9        An AudioBuffer may use a significant amount of memory and AudioBuffer.idl contains [ReportExtraMemoryCost]
     10        extended attribute to report this memory to the GC. However, there is an issue if JS constructs a large
     11        AudioBuffer, then sets it on an AudioBufferSourceNode and then the JSAudioBuffer wrapper gets garbage
     12        collected. At this point, GC thinks it recovered the extra memory reported by the JSAudioBuffer but this
     13        is not true since that AudioBuffer (and its internal memory) are still kept alive by AudioBufferSourceNode /
     14        JSAudioBufferSourceNode. To address this issue, the proposal in this patch is to have JSAudioBufferSourceNode
     15        mark its buffer when visiting childen during GC. As a result, the JSAudioBuffer wrapper will stay alive (and
     16        report extra memory use) as long as its associated JSAudioBufferSourceNode wrapper is still alive.
     17
     18        Test: webaudio/AudioBufferSource/audiobuffersource-buffer-gc.html
     19
     20        * Modules/webaudio/AudioBuffer.idl:
     21        * Modules/webaudio/AudioBufferSourceNode.h:
     22        * Modules/webaudio/AudioBufferSourceNode.idl:
     23        * Sources.txt:
     24        * bindings/js/JSAudioBufferSourceNodeCustom.cpp: Added.
     25        (WebCore::JSAudioBufferSourceNode::visitAdditionalChildren):
     26
    1272021-10-01  Myles C. Maxfield  <mmaxfield@apple.com>
    228
  • trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl

    r276715 r283402  
    2929[
    3030    Conditional=WEB_AUDIO,
     31    GenerateIsReachable=Impl,
    3132    ImplementationLacksVTable,
    3233    JSCustomMarkFunction,
  • trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.h

    r278287 r283402  
    5252    // setBufferForBindings() is called on the main thread. This is the buffer we use for playback.
    5353    ExceptionOr<void> setBufferForBindings(RefPtr<AudioBuffer>&&);
     54
     55    AudioBuffer* buffer() WTF_REQUIRES_LOCK(m_processLock) { return m_buffer.get(); }
     56    Lock& processLock() WTF_RETURNS_LOCK(m_processLock) { return m_processLock; }
    5457
    5558    // This function does not lock before accessing the buffer and should therefore only be called on the main thread.
  • trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.idl

    r278287 r283402  
    2727[
    2828    Conditional=WEB_AUDIO,
     29    JSCustomMarkFunction,
    2930    JSGenerateToJSObject,
    3031    Exposed=Window
  • trunk/Source/WebCore/Sources.txt

    r283377 r283402  
    443443bindings/js/JSAttrCustom.cpp
    444444bindings/js/JSAudioBufferCustom.cpp
     445bindings/js/JSAudioBufferSourceNodeCustom.cpp
    445446bindings/js/JSAudioNodeCustom.cpp
    446447bindings/js/JSAudioWorkletProcessorCustom.cpp
Note: See TracChangeset for help on using the changeset viewer.