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

Issue 1881933005: Oilpan: Add ThreadState cleanup callbacks for static thread-specific persistent. (Closed)

Created:
4 years, 8 months ago by jbroman
Modified:
4 years, 8 months ago
Reviewers:
haraken, xlai (Olivia), sof
CC:
Mads Ager (chromium), blink-reviews, chromium-reviews, kinuko+watch, kouhei+heap_chromium.org, oilpan-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Oilpan: Add ThreadState cleanup callbacks for static thread-specific persistent. This allows clients to register a cleanup hook in ThreadState before the final collection occurs, so that, for example, static thread-specific persistent handles can be cleared. Also provided is a helper function, with an example, which uses this facility to provide for a static local thread-specific persistent handle. Committed: https://crrev.com/8a89723f74422ac8bd015f5e36aca06b296bed4e Cr-Commit-Position: refs/heads/master@{#387519}

Patch Set 1 #

Total comments: 5

Patch Set 2 : change to a method on Persistent<T>, per haraken #

Patch Set 3 : unit test #

Total comments: 2

Patch Set 4 : rename per haraken #

Unified diffs Side-by-side diffs Delta from patch set Stats (+95 lines, -0 lines) Patch
M third_party/WebKit/Source/platform/heap/Handle.h View 1 2 3 1 chunk +27 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/platform/heap/HeapTest.cpp View 1 2 3 2 chunks +45 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/platform/heap/ThreadState.h View 1 2 3 3 chunks +10 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/platform/heap/ThreadState.cpp View 1 2 3 2 chunks +13 lines, -0 lines 0 comments Download

Messages

Total messages: 25 (8 generated)
jbroman
PTAL. Ideally I'd like to have unit tests for this, but it seems fairly straightforward ...
4 years, 8 months ago (2016-04-13 21:53:58 UTC) #3
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1881933005/1 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1881933005/1
4 years, 8 months ago (2016-04-13 22:09:36 UTC) #5
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
4 years, 8 months ago (2016-04-14 01:55:55 UTC) #7
haraken
https://codereview.chromium.org/1881933005/diff/1/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h File third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h (right): https://codereview.chromium.org/1881933005/diff/1/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h#newcode16 third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h:16: // It's important that the Persistent<T> exist until then, ...
4 years, 8 months ago (2016-04-14 02:36:24 UTC) #8
haraken
Thanks for working on this btw!
4 years, 8 months ago (2016-04-14 02:36:40 UTC) #9
xlai (Olivia)
https://codereview.chromium.org/1881933005/diff/1/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h File third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h (right): https://codereview.chromium.org/1881933005/diff/1/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h#newcode16 third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h:16: // It's important that the Persistent<T> exist until then, ...
4 years, 8 months ago (2016-04-14 16:04:46 UTC) #10
jbroman
https://codereview.chromium.org/1881933005/diff/1/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h File third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h (right): https://codereview.chromium.org/1881933005/diff/1/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h#newcode16 third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h:16: // It's important that the Persistent<T> exist until then, ...
4 years, 8 months ago (2016-04-14 19:15:28 UTC) #11
jbroman
...and I have now also added a unit test.
4 years, 8 months ago (2016-04-14 21:06:26 UTC) #12
haraken
LGTM > I did consider this (and actually tried it, now that you've mentioned it). ...
4 years, 8 months ago (2016-04-14 23:46:15 UTC) #13
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1881933005/60001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1881933005/60001
4 years, 8 months ago (2016-04-15 00:48:36 UTC) #16
commit-bot: I haz the power
Committed patchset #4 (id:60001)
4 years, 8 months ago (2016-04-15 02:06:26 UTC) #17
commit-bot: I haz the power
Patchset 4 (id:??) landed as https://crrev.com/8a89723f74422ac8bd015f5e36aca06b296bed4e Cr-Commit-Position: refs/heads/master@{#387519}
4 years, 8 months ago (2016-04-15 02:08:52 UTC) #19
sof
It looks like registerStaticPersistentNode() could handle this use case?
4 years, 8 months ago (2016-04-16 05:34:39 UTC) #21
jbroman
On 2016/04/16 at 05:34:39, sigbjornf wrote: > It looks like registerStaticPersistentNode() could handle this use ...
4 years, 8 months ago (2016-04-16 13:58:28 UTC) #22
sof
On 2016/04/16 13:58:28, jbroman wrote: > On 2016/04/16 at 05:34:39, sigbjornf wrote: > > It ...
4 years, 8 months ago (2016-04-16 14:12:16 UTC) #23
jbroman
On 2016/04/16 at 14:12:16, sigbjornf wrote: > On 2016/04/16 13:58:28, jbroman wrote: > > On ...
4 years, 8 months ago (2016-04-16 22:40:20 UTC) #24
haraken
4 years, 8 months ago (2016-04-18 00:40:10 UTC) #25
Message was sent while issue was closed.
On 2016/04/16 22:40:20, jbroman wrote:
> On 2016/04/16 at 14:12:16, sigbjornf wrote:
> > On 2016/04/16 13:58:28, jbroman wrote:
> > > On 2016/04/16 at 05:34:39, sigbjornf wrote:
> > > > It looks like registerStaticPersistentNode() could handle this use case?
> > > 
> > > Olivia and I looked at that code when trying to solve this, but it's not
> quite
> > > the same thing.
> > > 
> > > registerStaticPersistentNode (which, incidentally, is only enabled only
for
> leak
> > > sanitizer builds) deals with static references that truly never go away
(and
> so
> > > it's an error to have a static persistent pointing into a heap whose
thread
> is
> > > terminating). This handles something importantly different: these
> persistents
> > > are head in thread-local storage (and only the key is held in a static).
> > > 
> > 
> > It's the same facility, just that we don't currently have thread-specific
> singletons (we used to, for cssTextCache) created via DEFINE_STATIC_LOCAL(),
so
> there's no need for ThreadState to support this outside of the main thread. No
> reason why that mechanism couldn't be exposed outside of LSan, but only have
> DEFINE_STATIC_LOCAL() use it with LSan enabled.
> 
> I wasn't aware of cssTextCache having been similar in the past. It's not clear
> to me why in that case, you only needed to deal with this issue in the
> ENABLE(OILPAN) && defined(LEAK_SANITIZER) case, as the assertions that no
> persistent handles remain fires even if !defined(LEAK_SANITIZER). I suspect
> evolution of surrounding code.
> 
> > > While static persistents shouldn't exist when a thread is terminated
> (because,
> > > being static, the handle will outlive the thread), thread-specific
> persistents
> > > do, because the handle will be torn down by pthreads (or equivalent on
other
> > > platforms) when the OS thread exits.
> > 
> > I don't see the difference in behaviour, some persistents needing to remain
> alive until the ThreadState is detached. But have to be cleared out then.
> 
> When I checked, it seemed the existing code did not deal correctly with the
> handles being destroyed after that, in the TLS destruction callbacks. (I think
> it double-frees the PersistentNode; am I missing something that deals with
> that?) Dealing with that seemed like it would take extra plumbing, much as
> haraken's other suggestion would.
> 
> It's possible it's not as dissimilar as it seemed to me. I don't object to
some
> other factoring of this if you or the rest of the Oilpan team prefer; this CL
> seemed the most straightforward and unobtrusive way to solve the immediate
> problem.

I think Sigbjorn's point makes sense, if I'm not missing something.

I guess we can just replace registerStaticPersistentNode with
Persistent::clearOnThreadShutdown() (probably regardless of whether LSAN is
enabled or disabled, for simplicity).

What matters for the leak detector is that the underlying PersistentNodes (and
objects that are reachable from the Persistent Nodes) are released, rather than
that the Persistent handles are released (if this becomes problematic, we can
just mark all Persistent handles as leaky objects so that LSAN can understand
it).

Powered by Google App Engine
This is Rietveld 408576698