Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Issue 2283053002: Fix BaseAudioContext::hasPendingActivity() to make it GCed correctly (Closed)

Created:
4 years, 3 months ago by hongchan
Modified:
3 years, 9 months ago
CC:
blink-reviews, chromium-reviews
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

[This CL is Work-In-Progress.] Fix BaseAudioContext::hasPendingActivity() to make it GCed correctly The realtime AudioContext is not GCed properly even after the tear-down. It is because the context mark itself as 'has pending activity' no matter what the actual status is. This CL changes heuristic of hasPendingActivity method to signal V8 that this context is ready for GC; rtoy@ and I discussed that the best logic is when the destination handler does not have incoming connection any more. BUG=503845 TEST=LayoutTests/webaudio/audiocontext-leak.html

Patch Set 1 #

Total comments: 2

Patch Set 2 : [DO NOT SUBMIT] Adding printf for verification #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+55 lines, -0 lines) Patch
A third_party/WebKit/LayoutTests/webaudio/audiocontext-leak.html View 1 chunk +37 lines, -0 lines 0 comments Download
M third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js View 1 chunk +14 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp View 1 3 chunks +4 lines, -0 lines 1 comment Download

Messages

Total messages: 27 (6 generated)
hongchan
PTAL.
4 years, 3 months ago (2016-08-26 19:06:52 UTC) #2
Raymond Toy
https://codereview.chromium.org/2283053002/diff/1/third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp File third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp (right): https://codereview.chromium.org/2283053002/diff/1/third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp#newcode137 third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp:137: } Since AudioDestinationNode is an AudioNode with a single ...
4 years, 3 months ago (2016-08-26 20:12:15 UTC) #3
haraken
> This CL changes heuristic of hasPendingActivity method to signal Oilpan that this context is ...
4 years, 3 months ago (2016-08-27 02:10:03 UTC) #4
hongchan
On 2016/08/27 02:10:03, haraken wrote: > > This CL changes heuristic of hasPendingActivity method to ...
4 years, 3 months ago (2016-08-27 17:06:38 UTC) #6
hongchan
https://codereview.chromium.org/2283053002/diff/1/third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp File third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp (right): https://codereview.chromium.org/2283053002/diff/1/third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp#newcode137 third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp:137: } On 2016/08/26 20:12:15, Raymond Toy wrote: > Since ...
4 years, 3 months ago (2016-08-27 17:09:40 UTC) #9
hongchan
+dominicc@ Could you take a look at why stop() is not getting called at all ...
4 years, 3 months ago (2016-08-31 16:49:33 UTC) #11
dominicc (has gone to gerrit)
On 2016/08/31 at 16:49:33, hongchan wrote: > +dominicc@ > > Could you take a look ...
4 years, 3 months ago (2016-09-02 01:22:11 UTC) #12
haraken
On 2016/09/02 01:22:11, dominicc (traveling) wrote: > On 2016/08/31 at 16:49:33, hongchan wrote: > > ...
4 years, 3 months ago (2016-09-02 03:15:47 UTC) #13
hongchan
On 2016/09/02 01:22:11, dominicc (traveling) wrote: > On 2016/08/31 at 16:49:33, hongchan wrote: > > ...
4 years, 3 months ago (2016-09-02 04:16:55 UTC) #14
hongchan
On 2016/09/02 03:15:47, haraken wrote: > On 2016/09/02 01:22:11, dominicc (traveling) wrote: > > On ...
4 years, 3 months ago (2016-09-02 04:35:41 UTC) #15
haraken
On 2016/09/02 04:35:41, hoch wrote: > On 2016/09/02 03:15:47, haraken wrote: > > On 2016/09/02 ...
4 years, 3 months ago (2016-09-02 09:58:32 UTC) #16
hongchan
> There is no way to detect when a JS object is derefed (by design). ...
4 years, 3 months ago (2016-09-02 17:04:25 UTC) #17
haraken
On 2016/09/02 17:04:25, hoch wrote: > > There is no way to detect when a ...
4 years, 3 months ago (2016-09-02 18:08:09 UTC) #18
Raymond Toy
https://codereview.chromium.org/2283053002/diff/20001/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp File third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp (right): https://codereview.chromium.org/2283053002/diff/20001/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp#newcode221 third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp:221: return !m_isCleared; This is different from PS1, where you ...
4 years, 3 months ago (2016-09-02 18:19:21 UTC) #19
hongchan
> No. hasPendingActivity() is called for all wrappers. If you return true, the > wrapper ...
4 years, 3 months ago (2016-09-02 18:40:19 UTC) #20
hongchan
On 2016/09/02 18:19:21, Raymond Toy wrote: > https://codereview.chromium.org/2283053002/diff/20001/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp > File third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp (right): > > https://codereview.chromium.org/2283053002/diff/20001/third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp#newcode221 ...
4 years, 3 months ago (2016-09-02 18:41:17 UTC) #21
haraken
On 2016/09/02 18:40:19, hoch wrote: > > No. hasPendingActivity() is called for all wrappers. If ...
4 years, 3 months ago (2016-09-02 19:11:46 UTC) #23
Raymond Toy
On 2016/09/02 at 19:11:46, haraken wrote: > On 2016/09/02 18:40:19, hoch wrote: > > > ...
4 years, 3 months ago (2016-09-02 20:37:58 UTC) #24
dominicc (has gone to gerrit)
On 2016/09/02 at 20:37:58, rtoy wrote: > On 2016/09/02 at 19:11:46, haraken wrote: > > ...
4 years, 3 months ago (2016-09-06 17:11:24 UTC) #25
dominicc (has gone to gerrit)
On 2016/09/06 at 17:11:24, dominicc wrote: > On 2016/09/02 at 20:37:58, rtoy wrote: > > ...
4 years, 2 months ago (2016-10-14 08:23:46 UTC) #26
hongchan
4 years, 2 months ago (2016-10-14 08:27:54 UTC) #27
On 2016/10/14 08:23:46, dominicc wrote:
> On 2016/09/06 at 17:11:24, dominicc wrote:
> > On 2016/09/02 at 20:37:58, rtoy wrote:
> > > On 2016/09/02 at 19:11:46, haraken wrote:
> > > > On 2016/09/02 18:40:19, hoch wrote:
> > > > > > No. hasPendingActivity() is called for all wrappers. If you return
> true, the
> > > > > > wrapper will be kept alive. If you return false and the wrapper is
> unreachable
> > > > > > on the V8 side, the wrapper will be collected.
> > > > > 
> > > > > Ack.
> > > > > 
> > > > > 
> > > > > > Again, there's no way to know the timing when a wrapper is GCed.
> > > > > > Why doesn't the approach I mentioned in #16 work?
> > > > > 
> > > > > And the suggestion from #16: "make hasPendingActivity return false it
> has zero
> > > > > connection or the document is detached."
> > > > > 
> > > > > First, we don't care about the case of document being detached,
because
> it
> > > > > already works correctly. stop() is explicitly called then we can do
> > > > > tearing-down. 
> > > > > So the concern here is the first condition - "zero connect". Let me
> simplify the
> > > > > question:
> > > > > 
> > > > > a) var ac = new AudioContext();
> > > > > 
> > > > > You don't do anything after that, the destination has zero connection.
> However,
> > > > > the object should not be GCed because the reference is still active.
> > > > > 
> > > > > b) var ac = new AudioContext(); ac = null;
> > > > > 
> > > > > In this case, the object must be GCed as soon as possible releasing
all
> the
> > > > > resources allocated.
> > > > > 
> > > > > However, the problem here is that we cannot differentiate these two
> cases from
> > > > > the AudioContext's perspective. So we basically leak the AudioContext
in
> b) - it
> > > > > does not have a JS reference, but we don't release the resources. If
any
> object
> > > > > can signal the AudioContext that 'hey you need to go away', this
problem
> can be
> > > > > fixed easily.
> > > > 
> > > > tkent@ was previously hitting the same problem for AudioNodes and wrote
a
> design doc here:
>
https://docs.google.com/document/d/1MrHQ5RNMTEqlWMR-_yuqmxIG1lxvhA3xF32r2SJ73...
> > > > 
> > > > Is it helpful?
> > > 
> > > hongchan@ and I were discussing a little earlier whether we could make the
> contexts
> > > look more like the AudioNode/AudioHandler classes.  Then JS could collect
> the context,
> > > while the context handler could stay alive for a bit longer, if needed. 
On
> the other
> > > hand, I'm fine if we kill the handler right away if the context were
> collected.  There's
> > > no expectation that audio should continue to play if you drop all
references
> to the
> > > context.
> > 
> > What does Chris Wilson or Eiji Kitamura think about the idea of stopping the
> audio if you drop a reference to the context? There was an old crbug which
> complained that the audio stopped when something got garbage collected too
soon;
> I think some users may expect the audio to continue to play?
> > 
> > I think there's a danger if you stop the audio when the context is dropped
> that authors will cargo-cult leaking the context by stuffing it on window as
> soon as they create one.
> > 
> > I think we should collect the context as soon as practical after it's not
> observable whether it stays alive. That is, when you don't hear any difference
> and there's no reference to it which would let you restart it. Everything else
> that is garbage collected works this way (or tries to.)
> 
> Should we close this issue for now and reopen it later? (Was there any
> resolution about the semantics?)

I should get back to this later, but currently held up by AudioWorklet spec work
and implementation.
There seem to be an implication of user-visible change when dropping the
context, so I think this needs a wider discussion.

Powered by Google App Engine
This is Rietveld 408576698