Closed
Bug 1479035
Opened 6 years ago
Closed 6 years ago
Cleanup lifetime handling of thread-local nsThread wrappers
Categories
(Core :: XPCOM, enhancement)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla64
Tracking | Status | |
---|---|---|
firefox64 | --- | fixed |
People
(Reporter: kmag, Assigned: kmag)
References
Details
Attachments
(3 files)
The lifetime handling of nsThread wrappers is pretty hairy, and got hairier with bug 1476405.
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment 3•6 years ago
|
||
mozreview-review |
Comment on attachment 8995742 [details] Bug 1479035: Part 1 - Don't create event queues for stub nsThread wrappers. https://reviewboard.mozilla.org/r/260106/#review267142 Code analysis found 1 defect in this patch: - 1 defect found by clang-tidy You can run this analysis locally with: - `./mach static-analysis check path/to/file.cpp` (C/C++) If you see a problem in this automated review, please report it here: http://bit.ly/2y9N9Vx ::: dom/storage/StorageDBThread.cpp:497 (Diff revision 1) > void > StorageDBThread::ThreadFunc(void* aArg) > { > + { > + auto queue = MakeRefPtr<ThreadEventQueue<EventQueue>>(MakeUnique<EventQueue>()); > + nsCOMPtr<nsIThread> thread = Error: Unused "kungFuDeathGrip" 'nsCOMPtr<nsIThread>' objects constructed from temporary values are prohibited [clang-tidy: mozilla-kungfu-death-grip] nsCOMPtr<nsIThread> thread = ^
Comment 4•6 years ago
|
||
mozreview-review |
Comment on attachment 8995742 [details] Bug 1479035: Part 1 - Don't create event queues for stub nsThread wrappers. https://reviewboard.mozilla.org/r/260106/#review267308 This seems good. ::: xpcom/threads/nsThread.h:63 (Diff revision 1) > > nsThread(NotNull<mozilla::SynchronizedEventQueue*> aQueue, > MainThreadFlag aMainThread, > uint32_t aStackSize); > > + nsThread(); I suppose the other constructor is already public, but it would be nice if this and the existing constructor were private. =/ A follow-up, perhaps? ::: xpcom/threads/nsThread.h:187 (Diff revision 1) > RefPtr<mozilla::SynchronizedEventQueue> mEvents; > RefPtr<mozilla::ThreadEventTarget> mEventTarget; These could probably use some comments to describe their new discriminatory role in the implementation? ::: xpcom/threads/nsThread.cpp:690 (Diff revision 1) > +nsThread::nsThread() > + : mEvents(nullptr) > + , mEventTarget(nullptr) > + , mShutdownContext(nullptr) > + , mScriptObserver(nullptr) > + , mThread(nullptr) > + , mStackSize(0) > + , mNestedEventLoopDepth(0) > + , mCurrentEventLoopDepth(-1) > + , mShutdownRequired(false) > + , mPriority(PRIORITY_NORMAL) > + , mIsMainThread(NOT_MAIN_THREAD) > + , mCanInvokeJS(false) > + , mCurrentEvent(nullptr) > + , mCurrentEventStart(TimeStamp::Now()) > + , mCurrentPerformanceCounter(nullptr) Can we convert some of these member variables to member initializers in a follow-up? Or figure out a nice way to use delegating constructors to minimize the duplication between the two constructors? ::: xpcom/threads/nsThreadManager.cpp:471 (Diff revision 1) > // OK, that's fine. We'll dynamically create one :-) > - RefPtr<ThreadEventQueue<EventQueue>> queue = > + RefPtr<nsThread> thread = new nsThread(); Should we expand the comment to explicitly note that we assume anybody implicitly creating a thread through this method doesn't actually want an event queue for the thread?
Attachment #8995742 -
Flags: review?(nfroyd) → review+
Comment 5•6 years ago
|
||
Comment on attachment 8995743 [details] Bug 1479035: Part 2 - Get rid of PRThread to nsThread map. Eric, are you able to review this? I haven't had the mental space to, but I can review it early next week if you don't have time.
Attachment #8995743 -
Flags: review?(nfroyd) → review?(erahm)
Comment 6•6 years ago
|
||
Comment on attachment 8995743 [details] Bug 1479035: Part 2 - Get rid of PRThread to nsThread map. Sorry I don't have time to get to this before PTO.
Attachment #8995743 -
Flags: review?(erahm)
Comment 7•6 years ago
|
||
Hi guys, can you please review the patch or point to someone who can? This bug has other dependencies, i'm referring here to Bug 1479273 that has a very high frequency rate. Thank you.
Flags: needinfo?(nfroyd)
Flags: needinfo?(erahm)
Comment 8•6 years ago
|
||
I'm back, I can review. Kris can you rebase and attach as a splinter review?
Flags: needinfo?(erahm) → needinfo?(kmaglione+bmo)
Updated•6 years ago
|
Flags: needinfo?(nfroyd)
Assignee | ||
Comment 9•6 years ago
|
||
These maps hold strong references which complicate nsThread lifetime handling considerably, and only have a couple of fringe uses. We have a linked list of active threads that the thread manager can use for its internal enumeration purposes, and the external uses are easily done away with, so there doesn't seem to be much reason to keep the map around. MozReview-Commit-ID: x7dsj6C4x8
Attachment #9007105 -
Flags: review?(erahm)
Comment 10•6 years ago
|
||
Comment on attachment 9007105 [details] [diff] [review] Part 2 - Get rid of PRThread to nsThread map Review of attachment 9007105 [details] [diff] [review]: ----------------------------------------------------------------- Thanks, this is a nice cleanup. r=me with minor tweaks. ::: dom/workers/WorkerPrivate.cpp @@ +5350,5 @@ > WorkerPrivate::IsOnWorkerThread() const > { > // This is much more complicated than it needs to be but we can't use mThread > // because it must be protected by mMutex and sometimes this method is called > // when mMutex is already locked. This method should always work. I guess we can get rid of the wording about this being complicated :) ::: xpcom/threads/nsThread.cpp @@ +422,5 @@ > + return sMaxActiveThreads; > +} > + > +uint32_t nsThread::sActiveThreads; > +uint32_t nsThread::sMaxActiveThreads; Please move these towards the beginning of the file with the other nsThread static. ::: xpcom/threads/nsThreadManager.cpp @@ +319,5 @@ > > { > // We gather the threads from the hashtable into a list, so that we avoid > + // holding the enumerator lock while calling nsIThread::Shutdown. > + nsTArray<RefPtr<nsThread>> threads; Can you change the name of this to something like `threadsToShutdown` as it's no longer a full list of the threads. ::: xpcom/threads/nsThreadManager.h @@ +83,5 @@ > bool aCheckingShutdown); > > static void ReleaseThread(void* aData); > > nsRefPtrHashtable<nsPtrHashKey<PRThread>, nsThread> mThreadsByPRThread; We should remove this, right? Also we can get rid of the nsRefPtrHashtable.h include as well.
Attachment #9007105 -
Flags: review?(erahm) → review+
Comment 11•6 years ago
|
||
Kris, mind finishing the patches so we can get them landed? It would stop all the failures as dependent on bug 1479273. Thanks
Comment 12•6 years ago
|
||
This seems to be missing checkin-needed, can i land it?
Flags: needinfo?(erahm)
Comment 13•6 years ago
|
||
(In reply to Andreea Pavel [:apavel] from comment #12) > This seems to be missing checkin-needed, can i land it? There are a few minor review comments to address before landing.
Flags: needinfo?(erahm)
Comment 14•6 years ago
|
||
Thanks Eric :)
Assignee | ||
Comment 15•6 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/a03a61d6d724503c3b7c5e31fe32ced1f5d1c219 Bug 1479035: Part 1 - Don't create event queues for stub nsThread wrappers. r=froydnj https://hg.mozilla.org/integration/mozilla-inbound/rev/5f870621361012ba459943212d8c68a9ff81cb16 Bug 1479035: Part 2 - Get rid of PRThread to nsThread map. r=erahm
Comment 16•6 years ago
|
||
Backed out 2 changesets (Bug 1479035) for build bustages bustages netwerk/cache2/target on CLOSED TREE Push with failures: https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&resultStatus=testfailed,busted,exception&classifiedState=unclassified&selectedJob=201621130&revision=5f870621361012ba459943212d8c68a9ff81cb16 Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=201621130&repo=mozilla-inbound&lineNumber=14453 Backout: https://hg.mozilla.org/integration/mozilla-inbound/rev/0f22d244af4dea74766377b7fc3e3bcd292f9057
Assignee | ||
Comment 17•6 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/5152af6ab3e399216ef6db8f060c257b2ffbd330 Bug 1479035: Part 1 - Don't create event queues for stub nsThread wrappers. r=froydnj https://hg.mozilla.org/integration/mozilla-inbound/rev/89a0c0874d400dd324df6fc3627c0c47d130df19 Bug 1479035: Part 2 - Get rid of PRThread to nsThread map. r=erahm
Comment 18•6 years ago
|
||
Backed out for assertion failures: mEvents on nsThread.cpp Push link: https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&resultStatus=testfailed,busted,exception,runnable&classifiedState=unclassified&selectedJob=201765631&revision=89a0c0874d400dd324df6fc3627c0c47d130df19 Backout link: https://hg.mozilla.org/integration/mozilla-inbound/rev/981bcfe73738b56bfb63ce5971cd7ec667b0bba8 Log link: https://hg.mozilla.org/integration/mozilla-inbound/rev/981bcfe73738b56bfb63ce5971cd7ec667b0bba8
Comment 19•6 years ago
|
||
The IPC thread is setting an observer [1] and then asserting because there's no event queue. This is fallout from part 1 of the patch. I think we need some way for the ipc thread to opt in to having an event queue. [1] https://searchfox.org/mozilla-central/rev/ce57be88b8aa2ad03ace1b9684cd6c361be5109f/ipc/glue/MessagePump.cpp#392
Assignee | ||
Comment 20•6 years ago
|
||
(In reply to Eric Rahm [:erahm] from comment #19) > The IPC thread is setting an observer [1] and then asserting because there's > no event queue. This is fallout from part 1 of the patch. I think we need > some way for the ipc thread to opt in to having an event queue. There already is a way. I special-cased one of the event loop types, but there's another that's apparently used on Windows.
Flags: needinfo?(kmaglione+bmo)
Assignee | ||
Comment 21•6 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/cf6b1314df05066e33bcdf980bb976af35a7d3f7 Bug 1479035: Part 1 - Don't create event queues for stub nsThread wrappers. r=froydnj https://hg.mozilla.org/integration/mozilla-inbound/rev/6164a5ced4f748962157a1f0884056a569588cf9 Bug 1479035: Part 2 - Get rid of PRThread to nsThread map. r=erahm
Comment 22•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/cf6b1314df05 https://hg.mozilla.org/mozilla-central/rev/6164a5ced4f7
Status: NEW → RESOLVED
Closed: 6 years ago
status-firefox64:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Assignee | ||
Comment 23•6 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/12f5280f25c862decd0917eebbcf685853575678 Bug 1479035: Follow-up: Fix invarient which is no longer true. r=me
Comment 24•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/12f5280f25c8
You need to log in
before you can comment on or make changes to this bug.
Description
•