Reland of "[heap] Better integrate handling of aborted compaction pages"

- Get rid of fixing up pointers on the main thread
- Get rid of sweeping on the main thread

Instead:
- Record (and process afterwards) slots in parallel
- Add the pages to the concurrent sweeper as pointers have already been fixed

This reverts commit 6df04b296b.

BUG=chromium:581412
LOG=N
TEST=cctest/test-compaction/*

Review URL: https://codereview.chromium.org/1891683002

Cr-Commit-Position: refs/heads/master@{#35485}
This commit is contained in:
mlippautz 2016-04-14 04:06:22 -07:00 committed by Commit bot
parent f541033b5f
commit 3ace01d1b3
7 changed files with 59 additions and 78 deletions

View File

@ -555,7 +555,6 @@ void GCTracer::PrintNVP() const {
"evacuate.clean_up=%.1f "
"evacuate.copy=%.1f "
"evacuate.update_pointers=%.1f "
"evacuate.update_pointers.between_evacuated=%.1f "
"evacuate.update_pointers.to_evacuated=%.1f "
"evacuate.update_pointers.to_new=%.1f "
"evacuate.update_pointers.weak=%.1f "
@ -628,7 +627,6 @@ void GCTracer::PrintNVP() const {
current_.scopes[Scope::MC_EVACUATE_CLEAN_UP],
current_.scopes[Scope::MC_EVACUATE_COPY],
current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS],
current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_BETWEEN_EVACUATED],
current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_TO_EVACUATED],
current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_TO_NEW],
current_.scopes[Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK],

View File

@ -77,7 +77,6 @@ enum ScavengeSpeedMode { kForAllObjects, kForSurvivedObjects };
F(MC_EVACUATE_CLEAN_UP) \
F(MC_EVACUATE_COPY) \
F(MC_EVACUATE_UPDATE_POINTERS) \
F(MC_EVACUATE_UPDATE_POINTERS_BETWEEN_EVACUATED) \
F(MC_EVACUATE_UPDATE_POINTERS_TO_EVACUATED) \
F(MC_EVACUATE_UPDATE_POINTERS_TO_NEW) \
F(MC_EVACUATE_UPDATE_POINTERS_WEAK) \

View File

@ -1818,6 +1818,28 @@ class MarkCompactCollector::EvacuateOldSpaceVisitor final
}
};
class MarkCompactCollector::EvacuateRecordOnlyVisitor final
: public MarkCompactCollector::HeapObjectVisitor {
public:
explicit EvacuateRecordOnlyVisitor(AllocationSpace space) : space_(space) {}
inline bool Visit(HeapObject* object) {
if (space_ == OLD_SPACE) {
RecordMigratedSlotVisitor visitor;
object->IterateBody(&visitor);
} else {
DCHECK_EQ(space_, CODE_SPACE);
// Add a typed slot for the whole code object.
RememberedSet<OLD_TO_OLD>::InsertTyped(
Page::FromAddress(object->address()), RELOCATED_CODE_OBJECT,
object->address());
}
return true;
}
private:
AllocationSpace space_;
};
void MarkCompactCollector::DiscoverGreyObjectsInSpace(PagedSpace* space) {
PageIterator it(space);
@ -3092,6 +3114,17 @@ bool MarkCompactCollector::Evacuator::EvacuatePage(MemoryChunk* chunk) {
DCHECK(chunk->IsEvacuationCandidate());
DCHECK_EQ(chunk->concurrent_sweeping_state().Value(), Page::kSweepingDone);
success = EvacuateSinglePage<kClearMarkbits>(chunk, &old_space_visitor_);
if (!success) {
// Aborted compaction page. We can record slots here to have them
// processed in parallel later on.
EvacuateRecordOnlyVisitor record_visitor(chunk->owner()->identity());
success = EvacuateSinglePage<kKeepMarking>(chunk, &record_visitor);
DCHECK(success);
USE(success);
// We need to return failure here to indicate that we want this page added
// to the sweeper.
return false;
}
}
return success;
}
@ -3152,8 +3185,8 @@ class EvacuationJobTraits {
return evacuator->EvacuatePage(chunk);
}
static void FinalizePageSequentially(Heap*, MemoryChunk* chunk, bool success,
PerPageData data) {
static void FinalizePageSequentially(Heap* heap, MemoryChunk* chunk,
bool success, PerPageData data) {
if (chunk->InNewSpace()) {
DCHECK(success);
} else {
@ -3165,17 +3198,10 @@ class EvacuationJobTraits {
} else {
// We have partially compacted the page, i.e., some objects may have
// moved, others are still in place.
// We need to:
// - Leave the evacuation candidate flag for later processing of slots
// buffer entries.
// - Leave the slots buffer there for processing of entries added by
// the write barrier.
// - Rescan the page as slot recording in the migration buffer only
// happens upon moving (which we potentially didn't do).
// - Leave the page in the list of pages of a space since we could not
// fully evacuate it.
DCHECK(p->IsEvacuationCandidate());
p->SetFlag(Page::COMPACTION_WAS_ABORTED);
p->ClearEvacuationCandidate();
// Slots have already been recorded so we just need to add it to the
// sweeper.
*data += 1;
}
}
@ -3419,42 +3445,6 @@ void MarkCompactCollector::Sweeper::AddSweptPageSafe(PagedSpace* space,
swept_list_[space->identity()].Add(page);
}
void MarkCompactCollector::SweepAbortedPages() {
// Second pass on aborted pages.
for (Page* p : evacuation_candidates_) {
if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) {
p->ClearFlag(MemoryChunk::COMPACTION_WAS_ABORTED);
p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress);
PagedSpace* space = static_cast<PagedSpace*>(p->owner());
switch (space->identity()) {
case OLD_SPACE:
Sweeper::RawSweep<Sweeper::SWEEP_ONLY, Sweeper::SWEEP_ON_MAIN_THREAD,
Sweeper::IGNORE_SKIP_LIST,
Sweeper::IGNORE_FREE_SPACE>(space, p, nullptr);
break;
case CODE_SPACE:
if (FLAG_zap_code_space) {
Sweeper::RawSweep<
Sweeper::SWEEP_ONLY, Sweeper::SWEEP_ON_MAIN_THREAD,
Sweeper::REBUILD_SKIP_LIST, Sweeper::ZAP_FREE_SPACE>(space, p,
nullptr);
} else {
Sweeper::RawSweep<
Sweeper::SWEEP_ONLY, Sweeper::SWEEP_ON_MAIN_THREAD,
Sweeper::REBUILD_SKIP_LIST, Sweeper::IGNORE_FREE_SPACE>(
space, p, nullptr);
}
break;
default:
UNREACHABLE();
break;
}
sweeper().AddSweptPageSafe(space, p);
}
}
}
void MarkCompactCollector::EvacuateNewSpaceAndCandidates() {
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_EVACUATE);
Heap::RelocationLock relocation_lock(heap());
@ -3479,9 +3469,18 @@ void MarkCompactCollector::EvacuateNewSpaceAndCandidates() {
{
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_EVACUATE_CLEAN_UP);
// After updating all pointers, we can finally sweep the aborted pages,
// effectively overriding any forward pointers.
SweepAbortedPages();
for (Page* p : evacuation_candidates_) {
// Important: skip list should be cleared only after roots were updated
// because root iteration traverses the stack and might have to find
// code objects from non-updated pc pointing into evacuation candidate.
SkipList* list = p->skip_list();
if (list != NULL) list->Clear();
if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) {
sweeper().AddLatePage(p->owner()->identity(), p);
p->ClearFlag(Page::COMPACTION_WAS_ABORTED);
}
}
// EvacuateNewSpaceAndCandidates iterates over new space objects and for
// ArrayBuffers either re-registers them as live or promotes them. This is
@ -3635,25 +3634,6 @@ void MarkCompactCollector::UpdatePointersAfterEvacuation() {
UpdatePointersInParallel<OLD_TO_OLD>(heap_);
}
{
TRACE_GC(heap()->tracer(),
GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_BETWEEN_EVACUATED);
for (Page* p : evacuation_candidates_) {
DCHECK(p->IsEvacuationCandidate());
// Important: skip list should be cleared only after roots were updated
// because root iteration traverses the stack and might have to find
// code objects from non-updated pc pointing into evacuation candidate.
SkipList* list = p->skip_list();
if (list != NULL) list->Clear();
// First pass on aborted pages, fixing up all live objects.
if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) {
p->ClearEvacuationCandidate();
VisitLiveObjectsBody(p, &updating_visitor);
}
}
}
{
TRACE_GC(heap()->tracer(),
GCTracer::Scope::MC_EVACUATE_UPDATE_POINTERS_WEAK);

View File

@ -630,6 +630,7 @@ class MarkCompactCollector {
private:
class EvacuateNewSpaceVisitor;
class EvacuateOldSpaceVisitor;
class EvacuateRecordOnlyVisitor;
class EvacuateVisitorBase;
class HeapObjectVisitor;
@ -834,8 +835,6 @@ class MarkCompactCollector {
void RecomputeLiveBytes(MemoryChunk* page);
void SweepAbortedPages();
void ReleaseEvacuationCandidates();
// Starts sweeping of a space by contributing on the main thread and setting

View File

@ -382,8 +382,10 @@ void Page::MarkEvacuationCandidate() {
}
void Page::ClearEvacuationCandidate() {
DCHECK_NULL(old_to_old_slots_);
DCHECK_NULL(typed_old_to_old_slots_);
if (!IsFlagSet(COMPACTION_WAS_ABORTED)) {
DCHECK_NULL(old_to_old_slots_);
DCHECK_NULL(typed_old_to_old_slots_);
}
ClearFlag(EVACUATION_CANDIDATE);
InitializeFreeListCategories();
}

View File

@ -50,6 +50,7 @@ HEAP_TEST(CompactionFullAbortedPage) {
heap->set_force_oom(true);
heap->CollectAllGarbage();
heap->mark_compact_collector()->EnsureSweepingCompleted();
// Check that all handles still point to the same page, i.e., compaction
// has been aborted on the page.
@ -108,6 +109,7 @@ HEAP_TEST(CompactionPartiallyAbortedPage) {
heap->set_force_oom(true);
heap->CollectAllGarbage();
heap->mark_compact_collector()->EnsureSweepingCompleted();
bool migration_aborted = false;
for (Handle<FixedArray> object : compaction_page_handles) {
@ -190,6 +192,7 @@ HEAP_TEST(CompactionPartiallyAbortedPageIntraAbortedPointers) {
heap->set_force_oom(true);
heap->CollectAllGarbage();
heap->mark_compact_collector()->EnsureSweepingCompleted();
// The following check makes sure that we compacted "some" objects, while
// leaving others in place.
@ -283,6 +286,7 @@ HEAP_TEST(CompactionPartiallyAbortedPageWithStoreBufferEntries) {
heap->set_force_oom(true);
heap->CollectAllGarbage();
heap->mark_compact_collector()->EnsureSweepingCompleted();
// The following check makes sure that we compacted "some" objects, while
// leaving others in place.

View File

@ -104,7 +104,6 @@ INTERESTING_OLD_GEN_KEYS="\
evacuate.clean_up \
evacuate.copy \
evacuate.update_pointers \
evacuate.update_pointers.between_evacuated \
evacuate.update_pointers.to_evacuated \
evacuate.update_pointers.to_new \
evacuate.update_pointers.weak \