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

Issue 194923007: Explicit notification and removal of lifecycle observers. (Closed)

Created:
6 years, 9 months ago by sof
Modified:
6 years, 8 months ago
CC:
blink-reviews, eae+blinkwatch, falken, dglazkov+blink, adamk+blink_chromium.org, Inactive, horo+watch_chromium.org, kinuko+watch, rwlbuis, dcheng
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Visibility:
Public.

Description

Explicit notification and removal of lifecycle observers. To help make disposing of execution contexts cleaner in a setting where both a context and its lifetime observers are being finalized by a garbage collector, add support for explicitly clearing out all lifecycle observers: protected: void LifecycleNotifier<T>::removeAndNotifyAllObservers() Notifying them that the context has been destroyed while doing so. An operation that was previously (only) done by the LifecycleNotifier destructor. Also provide a convenience method over ExecutionContext for clearing out its observers: void ExecutionContext::removeAllLifecycleObservers() The operation is used here when shutting down and finalizing a worker thread and its global scope -- explicitly severing the connection of all observers to its execution context before performing the final garbage collection. Doing so ensures that all observer objects being finalized during that garbage collection will not have access to its execution context object. A heap object that may or may not have been finalized by the garbage collector already. R=haraken@chromium.org,ager@chromium.org,abarth@chromium.org BUG=340522 Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=169435

Patch Set 1 #

Patch Set 2 : Complete set of removeAndNotifyAllObservers() implementations #

Patch Set 3 : Delay notifying thread's worker proxy when dispose()ing #

Patch Set 4 : Make LifeCycleNotifier<T>::removeAndNotifyAllObservers() protect:ed #

Patch Set 5 : Delay proxy notification #

Total comments: 5

Patch Set 6 : Try to clarify shutdown step sequencing a bit. #

Total comments: 1

Patch Set 7 : Comment improvements #

Patch Set 8 : Perform ThreadState detachment last #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+52 lines, -19 lines) Patch
M Source/core/dom/ContextLifecycleNotifier.h View 1 2 3 4 1 chunk +2 lines, -0 lines 0 comments Download
M Source/core/dom/ContextLifecycleNotifier.cpp View 1 2 3 4 1 chunk +6 lines, -0 lines 0 comments Download
M Source/core/dom/ExecutionContext.h View 1 chunk +2 lines, -0 lines 0 comments Download
M Source/core/dom/ExecutionContext.cpp View 1 chunk +5 lines, -0 lines 0 comments Download
M Source/core/workers/WorkerGlobalScope.h View 1 2 3 4 1 chunk +2 lines, -0 lines 0 comments Download
M Source/core/workers/WorkerGlobalScope.cpp View 1 2 3 4 5 2 chunks +11 lines, -11 lines 0 comments Download
M Source/core/workers/WorkerThread.cpp View 1 2 3 4 5 6 7 1 chunk +15 lines, -7 lines 0 comments Download
M Source/platform/LifecycleNotifier.h View 1 2 3 3 chunks +9 lines, -1 line 2 comments Download

Messages

Total messages: 35 (0 generated)
sof
When you get the chance, please take a look. I think this is ready now. ...
6 years, 9 months ago (2014-03-12 11:03:35 UTC) #1
sof
On 2014/03/12 11:03:35, sof wrote: > When you get the chance, please take a look. ...
6 years, 9 months ago (2014-03-12 11:48:08 UTC) #2
sof
On 2014/03/12 11:48:08, sof wrote: > On 2014/03/12 11:03:35, sof wrote: ... > > Just ...
6 years, 9 months ago (2014-03-16 21:37:54 UTC) #3
haraken
LGTM. abarth: would you take another look? https://codereview.chromium.org/194923007/diff/80001/Source/core/workers/WorkerThread.cpp File Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/194923007/diff/80001/Source/core/workers/WorkerThread.cpp#newcode147 Source/core/workers/WorkerThread.cpp:147: ThreadState::detach(); Shall ...
6 years, 9 months ago (2014-03-17 01:22:56 UTC) #4
haraken
https://codereview.chromium.org/194923007/diff/80001/Source/core/workers/WorkerThread.cpp File Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/194923007/diff/80001/Source/core/workers/WorkerThread.cpp#newcode147 Source/core/workers/WorkerThread.cpp:147: ThreadState::detach(); On 2014/03/17 01:22:56, haraken wrote: > > Shall ...
6 years, 9 months ago (2014-03-17 01:25:44 UTC) #5
Mads Ager (chromium)
LGTM I agree with Haraken that it would be nice to have ThreadState::detach() as the ...
6 years, 9 months ago (2014-03-17 06:46:14 UTC) #6
Mads Ager (chromium)
PS: The description of the issue is a little misleading. "Doing so ensures that all ...
6 years, 9 months ago (2014-03-17 07:00:57 UTC) #7
sof
On 2014/03/17 07:00:57, Mads Ager (chromium) wrote: > PS: The description of the issue is ...
6 years, 9 months ago (2014-03-17 07:14:27 UTC) #8
sof
On 2014/03/17 06:46:14, Mads Ager (chromium) wrote: > LGTM > > I agree with Haraken ...
6 years, 9 months ago (2014-03-17 07:38:10 UTC) #9
sof
https://codereview.chromium.org/194923007/diff/80001/Source/core/workers/WorkerGlobalScope.cpp File Source/core/workers/WorkerGlobalScope.cpp (right): https://codereview.chromium.org/194923007/diff/80001/Source/core/workers/WorkerGlobalScope.cpp#newcode200 Source/core/workers/WorkerGlobalScope.cpp:200: removeAllLifecycleObservers(); On 2014/03/17 06:46:14, Mads Ager (chromium) wrote: > ...
6 years, 9 months ago (2014-03-17 07:46:40 UTC) #10
haraken
> > > Shall we move ThreadState::detach() at the very end of this method? A ...
6 years, 9 months ago (2014-03-17 07:48:57 UTC) #11
Mads Ager (chromium)
On 2014/03/17 07:38:10, sof wrote: > On 2014/03/17 06:46:14, Mads Ager (chromium) wrote: > > ...
6 years, 9 months ago (2014-03-17 08:20:37 UTC) #12
Mads Ager (chromium)
Still LGTM! https://codereview.chromium.org/194923007/diff/100001/Source/core/workers/WorkerThread.cpp File Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/194923007/diff/100001/Source/core/workers/WorkerThread.cpp#newcode141 Source/core/workers/WorkerThread.cpp:141: // The below assignment will destroy the ...
6 years, 9 months ago (2014-03-17 08:20:51 UTC) #13
sof
On 2014/03/17 08:20:37, Mads Ager (chromium) wrote: .. > > The problem was the m_workerGlobalScope ...
6 years, 9 months ago (2014-03-17 14:01:37 UTC) #14
eseidel
6 years, 9 months ago (2014-03-17 22:25:18 UTC) #15
abarth-chromium
https://codereview.chromium.org/194923007/diff/140001/Source/platform/LifecycleNotifier.h File Source/platform/LifecycleNotifier.h (right): https://codereview.chromium.org/194923007/diff/140001/Source/platform/LifecycleNotifier.h#newcode51 Source/platform/LifecycleNotifier.h:51: virtual ~LifecycleNotifier(); Does this mean we can make the ...
6 years, 9 months ago (2014-03-17 22:48:05 UTC) #16
sof
https://codereview.chromium.org/194923007/diff/140001/Source/platform/LifecycleNotifier.h File Source/platform/LifecycleNotifier.h (right): https://codereview.chromium.org/194923007/diff/140001/Source/platform/LifecycleNotifier.h#newcode51 Source/platform/LifecycleNotifier.h:51: virtual ~LifecycleNotifier(); On 2014/03/17 22:48:05, abarth wrote: > Does ...
6 years, 9 months ago (2014-03-18 08:25:30 UTC) #17
sof
The CQ bit was checked by sigbjornf@opera.com
6 years, 9 months ago (2014-03-18 08:35:59 UTC) #18
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sigbjornf@opera.com/194923007/140001
6 years, 9 months ago (2014-03-18 08:36:08 UTC) #19
commit-bot: I haz the power
The CQ bit was unchecked by commit-bot@chromium.org
6 years, 9 months ago (2014-03-18 08:46:57 UTC) #20
commit-bot: I haz the power
Try jobs failed on following builders: tryserver.blink on blink_presubmit
6 years, 9 months ago (2014-03-18 08:46:58 UTC) #21
sof
On 2014/03/18 08:46:58, I haz the power (commit-bot) wrote: > Try jobs failed on following ...
6 years, 9 months ago (2014-03-18 08:50:33 UTC) #22
tkent
rslgtm
6 years, 9 months ago (2014-03-18 09:26:37 UTC) #23
sof
The CQ bit was checked by sigbjornf@opera.com
6 years, 9 months ago (2014-03-18 09:36:11 UTC) #24
sof
On 2014/03/18 09:26:37, tkent wrote: > rslgtm thanks!
6 years, 9 months ago (2014-03-18 09:36:18 UTC) #25
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sigbjornf@opera.com/194923007/140001
6 years, 9 months ago (2014-03-18 09:36:20 UTC) #26
commit-bot: I haz the power
Change committed as 169435
6 years, 9 months ago (2014-03-18 09:46:04 UTC) #27
sof
Some problems have surfaced as a result of this one, http://test-results.appspot.com/dashboards/flakiness_dashboard.html#group=%40ToT%20Blink&tests=fast/workers/storage/interrupt-database.html,http/tests/w3c/webperf/submission/Google/resource-timing/html/test_resource_dedicated_worker.html,http/tests/xmlhttprequest/workers/referer.html,http/tests/xmlhttprequest/workers/xmlhttprequest-response-type-blob.html Reverting to address.
6 years, 9 months ago (2014-03-18 11:53:16 UTC) #28
sof
A revert of this CL has been created in https://codereview.chromium.org/203393002/ by sigbjornf@opera.com. The reason for ...
6 years, 9 months ago (2014-03-18 11:54:11 UTC) #29
sof
The LifecycleNotifier changes here won't be needed, as we're unable to strictly finalize/dispose WorkerGlobalScopes in ...
6 years, 9 months ago (2014-03-18 14:45:21 UTC) #30
haraken
On 2014/03/18 14:45:21, sof wrote: > The LifecycleNotifier changes here won't be needed, as we're ...
6 years, 8 months ago (2014-04-16 13:01:28 UTC) #31
sof
On 2014/04/16 13:01:28, haraken wrote: > On 2014/03/18 14:45:21, sof wrote: > > The LifecycleNotifier ...
6 years, 8 months ago (2014-04-16 13:38:33 UTC) #32
haraken
On 2014/04/16 13:38:33, sof wrote: > On 2014/04/16 13:01:28, haraken wrote: > > On 2014/03/18 ...
6 years, 8 months ago (2014-04-16 14:13:35 UTC) #33
sof
On 2014/04/16 14:13:35, haraken wrote: > On 2014/04/16 13:38:33, sof wrote: > > On 2014/04/16 ...
6 years, 8 months ago (2014-04-16 14:17:19 UTC) #34
haraken
6 years, 8 months ago (2014-04-16 14:23:02 UTC) #35
Message was sent while issue was closed.
On 2014/04/16 14:17:19, sof wrote:
> On 2014/04/16 14:13:35, haraken wrote:
> > On 2014/04/16 13:38:33, sof wrote:
> > > On 2014/04/16 13:01:28, haraken wrote:
> > > > On 2014/03/18 14:45:21, sof wrote:
> > > > > The LifecycleNotifier changes here won't be needed, as we're unable to
> > > > strictly
> > > > > finalize/dispose WorkerGlobalScopes in the general case.
> > > > > 
> > > > > https://codereview.chromium.org/203233004/ makes the necessary
shutdown
> > > > changes.
> > > > 
> > > > I'm sorry for asking you the same question as before, but I'd be happy
if
> > you
> > > > could help me understand:
> > > > 
> > > > Why can't we call 'm_thread = 0' in WorkerGlobalScope::dispose()? Why
does
> > the
> > > > following logic not work?
> > > > 
> > > > void WorkerGlobalScope::dispose() {
> > > >   ...;
> > > >   willDestroyContext(); // This clears m_executionContext of
> > ActiveDOMObjects
> > > > associated with this WorkerGlobalScope.
> > > >   m_thread = 0;
> > > > }
> > > 
> > > That runs into problems with objects that need to keep the execution
context
> > > alive until they really are destructed -- the 2nd paragraph of ager's fine
> > > description in https://codereview.chromium.org/203233004/ explains in some
> > > detail. Overall, that description captures the offline discussion we had
> about
> > > why the current shutdown sequence is the one needed.
> > > 
> > > If you can make it simpler, that'd be (again) awesome, of course :-)
> > 
> > If an ActiveDOMObject is the only problematic case, I guess that it's not a
> > problem. ~ActiveDOMObject() has the following code:
> > 
> > ActiveDOMObject::~ActiveDOMObject() {
> >     // ActiveDOMObject may be inherited by a sub-class whose life-cycle
> >     // exceeds that of the associated ExecutionContext. In those cases,
> >     // m_executionContext would/should have been nullified by
> >     // ContextLifecycleObserver::contextDestroyed() (which we implement /
> >     // inherit). Hence, we should ensure that this is not 0 before use it
> >     // here.
> >     if (!executionContext())
> >         return;
> >     ASSERT(m_suspendIfNeededCalled);
> >     ASSERT(executionContext()->isContextThread());
> > }
> > 
> > If we clear LifecycleObserver::m_lifecycleContext in willDestroyContext(),
> > ~ActiveDOMObject() will hit the "if (!executionContext())" branch and return
> > immediately.
> 
> It's not the only issue (I thought it was when going ahead with this CL) -- cf
> SQLCallbackWrapper that that description mentions uses the execution context
to
> control where to shut down.

ah, this looks like a real issue. Thanks for the clarification!

Powered by Google App Engine
This is Rietveld 408576698