@@ -1433,24 +1433,42 @@ void Isolate::Shutdown() {
1433
1433
}
1434
1434
#endif // DEBUG
1435
1435
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
+
1436
1451
// Remove this isolate from the list *before* we start tearing it down, to
1437
1452
// avoid exposing it in a state of decay.
1438
1453
RemoveIsolateFromList (this );
1439
1454
1440
1455
if (heap_ != NULL ) {
1441
1456
// Wait for any concurrent GC tasks to finish before shutting down.
1457
+ // TODO(koda): Support faster sweeper shutdown (e.g., after current page).
1442
1458
PageSpace* old_space = heap_->old_space ();
1443
1459
MonitorLocker ml (old_space->tasks_lock ());
1444
1460
while (old_space->tasks () > 0 ) {
1445
1461
ml.Wait ();
1446
1462
}
1447
1463
}
1448
1464
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.
1451
1466
{
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.
1452
1469
StackZone stack_zone (this );
1453
1470
HandleScope handle_scope (this );
1471
+ NoSafepointScope no_safepoint_scope;
1454
1472
1455
1473
if (compiler_stats_ != NULL ) {
1456
1474
compiler_stats ()->Print ();
@@ -1474,9 +1492,6 @@ void Isolate::Shutdown() {
1474
1492
// Dump all accumulated timer data for the isolate.
1475
1493
timer_list_.ReportTimers ();
1476
1494
1477
- // Write out the coverage data if collection has been enabled.
1478
- CodeCoverage::Write (this );
1479
-
1480
1495
// Finalize any weak persistent handles with a non-null referent.
1481
1496
FinalizeWeakPersistentHandlesVisitor visitor;
1482
1497
api_state ()->weak_persistent_handles ().VisitHandles (&visitor);
@@ -1489,12 +1504,16 @@ void Isolate::Shutdown() {
1489
1504
OS::Print (" [-] Stopping isolate:\n "
1490
1505
" \t isolate: %s\n " , name ());
1491
1506
}
1507
+ }
1492
1508
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 );
1497
1515
}
1516
+ #endif
1498
1517
1499
1518
// TODO(5411455): For now just make sure there are no current isolates
1500
1519
// as we are shutting down the isolate.
0 commit comments