Repository navigation
Commit eaf0efa
committed
[JSC] Stop a heap's local Collector threads when the heap shuts down
https://bugs.webkit.org/show_bug.cgi?id=328418
rdar://190202961
Reviewed by Marcus Plutowski.
Heap::shutDown() waits for the Heap's Leave request to be processed by the Collector.
However, this can happen before the collector thread has returned from
m_stopIfNecessaryTimer->scheduleSoon():
1. The collector thread is conducting a collection and calls Heap::stopTheMutator().
The mutator holds heap access, so instead of stopping it, the collector thread hands
it the conn by setting mutatorHasConnBit.
2. The mutator thread, inside waitForCollector(), sees it has the conn, finishes the
collection and processes its own Leave request.
3. The collector thread hasn't yet returned from m_stopIfNecessaryTimer->scheduleSoon(),
which uses Heap state.
4. The mutator thread continues through ~VM, which unregisters the VM from
JSRunLoopTimer::Manager. ~Heap then destroys m_stopIfNecessaryTimer before
m_localCollector, so ~Collector joins the collector thread too late.
5. The collector thread accesses the freed m_stopIfNecessaryTimer, or hits the
RELEASE_ASSERT in JSRunLoopTimer::Manager::scheduleTimer() since the VM has unregistered.
Before 323479@main, Heap::shutDown() joined the collector thread before tearing
anything down. Restore that: Collector::shutDown() stops the collect-continuously
thread and the collector thread, and Heap::shutDown() calls it for a local
Collector right after leaving. ~Collector now asserts that the threads are already
stopped instead of stopping them itself.
This will need to be fixed for the --useGlobalGC=true case too, but that depends on
how stopping the mutators of several heaps will work, so it will come later. For now,
this fixes the default --useGlobalGC=false case.
Test: JSTests/stress/many-agents-teardown.js
* JSTests/stress/many-agents-teardown.js: Added.
(i.setTimeout):
* Source/JavaScriptCore/heap/Collector.cpp:
(JSC::Collector::~Collector):
(JSC::Collector::shutDown):
(JSC::Collector::stopCollectingContinuously):
* Source/JavaScriptCore/heap/Collector.h:
* Source/JavaScriptCore/heap/Heap.cpp:
(JSC::Heap::shutDown):
Canonical link: https://commits.webkit.org/324477@main1 parent 67cd519 commit eaf0efa
4 files changed
Lines changed: 44 additions & 2 deletions
File tree
- JSTests/stress
- Source/JavaScriptCore/heap
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
164 | 174 | | |
165 | 175 | | |
166 | | - | |
167 | 176 | | |
168 | 177 | | |
169 | 178 | | |
| |||
1112 | 1121 | | |
1113 | 1122 | | |
1114 | 1123 | | |
| 1124 | + | |
1115 | 1125 | | |
1116 | 1126 | | |
1117 | 1127 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
466 | 466 | | |
467 | 467 | | |
468 | 468 | | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
469 | 474 | | |
470 | 475 | | |
471 | 476 | | |
| |||
0 commit comments