diff --git a/src/heap/heap.cc b/src/heap/heap.cc index af20470ba8..cb0426dc56 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -2220,7 +2220,11 @@ class ScavengingVisitor : public StaticVisitorBase { object_size)) { return; } - V8::FatalProcessOutOfMemory("Scavenge promotion failed"); + + // If promotion failed, we try to copy the object to the other semi-space + if (SemiSpaceCopyObject(map, slot, object, object_size)) return; + + UNREACHABLE(); } diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index e8b1c70ac3..aacefd818a 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -1935,27 +1935,26 @@ int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage( current_cell >>= 1; // TODO(hpayer): Refactor EvacuateObject and call this function instead. - if (heap()->ShouldBePromoted(object->address(), size)) { - if (!TryPromoteObject(object, size)) { - V8::FatalProcessOutOfMemory("Full GC promotion failed"); - } - } else { - AllocationResult allocation = new_space->AllocateRaw(size); - if (allocation.IsRetry()) { - if (!new_space->AddFreshPage()) { - // Shouldn't happen. We are sweeping linearly, and to-space - // has the same number of pages as from-space, so there is - // always room. - UNREACHABLE(); - } - allocation = new_space->AllocateRaw(size); - DCHECK(!allocation.IsRetry()); - } - Object* target = allocation.ToObjectChecked(); - - MigrateObject(HeapObject::cast(target), object, size, NEW_SPACE); - heap()->IncrementSemiSpaceCopiedObjectSize(size); + if (heap()->ShouldBePromoted(object->address(), size) && + TryPromoteObject(object, size)) { + continue; } + + AllocationResult allocation = new_space->AllocateRaw(size); + if (allocation.IsRetry()) { + if (!new_space->AddFreshPage()) { + // Shouldn't happen. We are sweeping linearly, and to-space + // has the same number of pages as from-space, so there is + // always room. + UNREACHABLE(); + } + allocation = new_space->AllocateRaw(size); + DCHECK(!allocation.IsRetry()); + } + Object* target = allocation.ToObjectChecked(); + + MigrateObject(HeapObject::cast(target), object, size, NEW_SPACE); + heap()->IncrementSemiSpaceCopiedObjectSize(size); } *cells = 0; }