@@ -439,6 +439,13 @@ void Heap::NotifyLowMemory() {
439
439
440
440
void Heap::EvacuateNewSpace (Thread* thread, GCReason reason) {
441
441
ASSERT ((reason != kOldSpace ) && (reason != kPromotion ));
442
+ if (thread->isolate () == Dart::vm_isolate ()) {
443
+ // The vm isolate cannot safely collect garbage due to unvisited read-only
444
+ // handles and slots bootstrapped with RAW_NULL. Ignore GC requests to
445
+ // trigger a nice out-of-memory message instead of a crash in the middle of
446
+ // visiting pointers.
447
+ return ;
448
+ }
442
449
if (BeginNewSpaceGC (thread)) {
443
450
RecordBeforeGC (kScavenge , reason);
444
451
VMTagScope tagScope (thread, reason == kIdle ? VMTag::kGCIdleTagId
@@ -454,6 +461,13 @@ void Heap::EvacuateNewSpace(Thread* thread, GCReason reason) {
454
461
455
462
void Heap::CollectNewSpaceGarbage (Thread* thread, GCReason reason) {
456
463
ASSERT ((reason != kOldSpace ) && (reason != kPromotion ));
464
+ if (thread->isolate () == Dart::vm_isolate ()) {
465
+ // The vm isolate cannot safely collect garbage due to unvisited read-only
466
+ // handles and slots bootstrapped with RAW_NULL. Ignore GC requests to
467
+ // trigger a nice out-of-memory message instead of a crash in the middle of
468
+ // visiting pointers.
469
+ return ;
470
+ }
457
471
if (BeginNewSpaceGC (thread)) {
458
472
RecordBeforeGC (kScavenge , reason);
459
473
{
@@ -484,6 +498,13 @@ void Heap::CollectOldSpaceGarbage(Thread* thread,
484
498
if (FLAG_use_compactor) {
485
499
type = kMarkCompact ;
486
500
}
501
+ if (thread->isolate () == Dart::vm_isolate ()) {
502
+ // The vm isolate cannot safely collect garbage due to unvisited read-only
503
+ // handles and slots bootstrapped with RAW_NULL. Ignore GC requests to
504
+ // trigger a nice out-of-memory message instead of a crash in the middle of
505
+ // visiting pointers.
506
+ return ;
507
+ }
487
508
if (BeginOldSpaceGC (thread)) {
488
509
RecordBeforeGC (type, reason);
489
510
VMTagScope tagScope (thread, reason == kIdle ? VMTag::kGCIdleTagId
0 commit comments