From 100b9d836fa7df0c7010c78743a93e69342e6a17 Mon Sep 17 00:00:00 2001 From: "hpayer@chromium.org" Date: Mon, 23 Jun 2014 08:50:54 +0000 Subject: [PATCH] An object should only be promoted to the old generation if it survived a scavenge operation. BUG= R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/345523002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21915 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap-inl.h | 9 +++------ src/mark-compact.cc | 10 ++++++---- src/mark-compact.h | 2 +- test/cctest/test-api.cc | 1 + test/cctest/test-heap.cc | 1 + test/cctest/test-mark-compact.cc | 3 ++- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index 2de7616..22e4c97 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -388,15 +388,12 @@ bool Heap::OldGenerationAllocationLimitReached() { bool Heap::ShouldBePromoted(Address old_address, int object_size) { - // An object should be promoted if: - // - the object has survived a scavenge operation or - // - to space is already 25% full. + // An object should be promoted if the object has survived a + // scavenge operation. NewSpacePage* page = NewSpacePage::FromAddress(old_address); Address age_mark = new_space_.age_mark(); - bool below_mark = page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && + return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && (!page->ContainsLimit(age_mark) || old_address < age_mark); - return below_mark || (new_space_.Size() + object_size) >= - (new_space_.EffectiveCapacity() >> 2); } diff --git a/src/mark-compact.cc b/src/mark-compact.cc index 17b3c34..047e772 100644 --- a/src/mark-compact.cc +++ b/src/mark-compact.cc @@ -1975,7 +1975,7 @@ static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque, } -int MarkCompactCollector::DiscoverAndPromoteBlackObjectsOnPage( +int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage( NewSpace* new_space, NewSpacePage* p) { ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); @@ -2008,8 +2008,10 @@ int MarkCompactCollector::DiscoverAndPromoteBlackObjectsOnPage( offset++; current_cell >>= 1; - // Aggressively promote young survivors to the old space. - if (TryPromoteObject(object, size)) { + + // TODO(hpayer): Refactor EvacuateObject and call this function instead. + if (heap()->ShouldBePromoted(object->address(), size) && + TryPromoteObject(object, size)) { continue; } @@ -3049,7 +3051,7 @@ void MarkCompactCollector::EvacuateNewSpace() { NewSpacePageIterator it(from_bottom, from_top); while (it.has_next()) { NewSpacePage* p = it.next(); - survivors_size += DiscoverAndPromoteBlackObjectsOnPage(new_space, p); + survivors_size += DiscoverAndEvacuateBlackObjectsOnPage(new_space, p); } heap_->IncrementYoungSurvivorsCounter(survivors_size); diff --git a/src/mark-compact.h b/src/mark-compact.h index ae6767f..4e85978 100644 --- a/src/mark-compact.h +++ b/src/mark-compact.h @@ -870,7 +870,7 @@ class MarkCompactCollector { // regions to each space's free list. void SweepSpaces(); - int DiscoverAndPromoteBlackObjectsOnPage(NewSpace* new_space, + int DiscoverAndEvacuateBlackObjectsOnPage(NewSpace* new_space, NewSpacePage* p); void EvacuateNewSpace(); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 229950f..cd38f91 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -19879,6 +19879,7 @@ TEST(PersistentHandleInNewSpaceVisitor) { CHECK_EQ(42, object1.WrapperClassId()); CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); + CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); v8::Persistent object2(isolate, v8::Object::New(isolate)); CHECK_EQ(0, object2.WrapperClassId()); diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index bb54b0a..f0682b2 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -4315,6 +4315,7 @@ TEST(ArrayShiftSweeping) { "var tmp = new Array(100000);" "array[0] = 10;" "gc();" + "gc();" "array.shift();" "array;"); diff --git a/test/cctest/test-mark-compact.cc b/test/cctest/test-mark-compact.cc index b5fcdfa..1790a0d 100644 --- a/test/cctest/test-mark-compact.cc +++ b/test/cctest/test-mark-compact.cc @@ -92,7 +92,8 @@ TEST(Promotion) { CHECK(heap->InSpace(*array, NEW_SPACE)); // Call mark compact GC, so array becomes an old object. - heap->CollectGarbage(OLD_POINTER_SPACE); + heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); + heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); // Array now sits in the old space CHECK(heap->InSpace(*array, OLD_POINTER_SPACE)); -- 2.7.4