Skip to content

Commit ee49289

Browse files
committed
Fix crash in code coverage generation.
Separate the higher- and lower-level cleanup steps during isolate shutdown. The former (currently only code coverage and timeline) may need to allocate, but the latter should not. Add assertions. (cc:zra, who's working on clean shutdown) BUG=23848 R=rmacnak@google.com Review URL: https://codereview.chromium.org//1236913006 .
1 parent d37ac8d commit ee49289

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

runtime/vm/isolate.cc

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,24 +1433,42 @@ void Isolate::Shutdown() {
14331433
}
14341434
#endif // DEBUG
14351435

1436+
// First, perform higher-level cleanup that may need to allocate.
1437+
{
1438+
// Ensure we have a zone and handle scope so that we can call VM functions.
1439+
StackZone stack_zone(this);
1440+
HandleScope handle_scope(this);
1441+
1442+
// Write out the coverage data if collection has been enabled.
1443+
CodeCoverage::Write(this);
1444+
1445+
if ((timeline_event_recorder_ != NULL) &&
1446+
(FLAG_timeline_trace_dir != NULL)) {
1447+
timeline_event_recorder_->WriteTo(FLAG_timeline_trace_dir);
1448+
}
1449+
}
1450+
14361451
// Remove this isolate from the list *before* we start tearing it down, to
14371452
// avoid exposing it in a state of decay.
14381453
RemoveIsolateFromList(this);
14391454

14401455
if (heap_ != NULL) {
14411456
// Wait for any concurrent GC tasks to finish before shutting down.
1457+
// TODO(koda): Support faster sweeper shutdown (e.g., after current page).
14421458
PageSpace* old_space = heap_->old_space();
14431459
MonitorLocker ml(old_space->tasks_lock());
14441460
while (old_space->tasks() > 0) {
14451461
ml.Wait();
14461462
}
14471463
}
14481464

1449-
// Create an area where we do have a zone and a handle scope so that we can
1450-
// call VM functions while tearing this isolate down.
1465+
// Then, proceed with low-level teardown.
14511466
{
1467+
// Ensure we have a zone and handle scope so that we can call VM functions,
1468+
// but we no longer allocate new heap objects.
14521469
StackZone stack_zone(this);
14531470
HandleScope handle_scope(this);
1471+
NoSafepointScope no_safepoint_scope;
14541472

14551473
if (compiler_stats_ != NULL) {
14561474
compiler_stats()->Print();
@@ -1474,9 +1492,6 @@ void Isolate::Shutdown() {
14741492
// Dump all accumulated timer data for the isolate.
14751493
timer_list_.ReportTimers();
14761494

1477-
// Write out the coverage data if collection has been enabled.
1478-
CodeCoverage::Write(this);
1479-
14801495
// Finalize any weak persistent handles with a non-null referent.
14811496
FinalizeWeakPersistentHandlesVisitor visitor;
14821497
api_state()->weak_persistent_handles().VisitHandles(&visitor);
@@ -1489,12 +1504,16 @@ void Isolate::Shutdown() {
14891504
OS::Print("[-] Stopping isolate:\n"
14901505
"\tisolate: %s\n", name());
14911506
}
1507+
}
14921508

1493-
if ((timeline_event_recorder_ != NULL) &&
1494-
(FLAG_timeline_trace_dir != NULL)) {
1495-
timeline_event_recorder_->WriteTo(FLAG_timeline_trace_dir);
1496-
}
1509+
#if defined(DEBUG)
1510+
// No concurrent sweeper tasks should be running at this point.
1511+
if (heap_ != NULL) {
1512+
PageSpace* old_space = heap_->old_space();
1513+
MonitorLocker ml(old_space->tasks_lock());
1514+
ASSERT(old_space->tasks() == 0);
14971515
}
1516+
#endif
14981517

14991518
// TODO(5411455): For now just make sure there are no current isolates
15001519
// as we are shutting down the isolate.

0 commit comments

Comments
 (0)