Commit 7c32e07d authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap] Marking cleanup

BUG=

Review-Url: https://codereview.chromium.org/2640783007
Cr-Commit-Position: refs/heads/master@{#42906}
parent 1cca9423
...@@ -623,7 +623,7 @@ void IncrementalMarking::ProcessWeakCells() { ...@@ -623,7 +623,7 @@ void IncrementalMarking::ProcessWeakCells() {
HeapObject* value = HeapObject::cast(weak_cell->value()); HeapObject* value = HeapObject::cast(weak_cell->value());
// Remove weak cells with live objects from the list, they do not need // Remove weak cells with live objects from the list, they do not need
// clearing. // clearing.
if (MarkCompactCollector::IsMarked(value)) { if (ObjectMarking::IsBlackOrGrey(value)) {
// Record slot, if value is pointing to an evacuation candidate. // Record slot, if value is pointing to an evacuation candidate.
Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset); Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
heap_->mark_compact_collector()->RecordSlot(weak_cell, slot, *slot); heap_->mark_compact_collector()->RecordSlot(weak_cell, slot, *slot);
......
...@@ -36,25 +36,13 @@ void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) { ...@@ -36,25 +36,13 @@ void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) {
} }
} }
void MarkCompactCollector::SetMark(HeapObject* obj) {
DCHECK(ObjectMarking::IsWhite(obj));
ObjectMarking::WhiteToBlack(obj);
}
bool MarkCompactCollector::IsMarked(Object* obj) {
DCHECK(obj->IsHeapObject());
return ObjectMarking::IsBlackOrGrey(HeapObject::cast(obj));
}
void MarkCompactCollector::RecordSlot(HeapObject* object, Object** slot, void MarkCompactCollector::RecordSlot(HeapObject* object, Object** slot,
Object* target) { Object* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target)); Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
Page* source_page = Page::FromAddress(reinterpret_cast<Address>(object)); Page* source_page = Page::FromAddress(reinterpret_cast<Address>(object));
if (target_page->IsEvacuationCandidate() && if (target_page->IsEvacuationCandidate() &&
!ShouldSkipEvacuationSlotRecording(object)) { !ShouldSkipEvacuationSlotRecording(object)) {
DCHECK(IsMarked(object)); DCHECK(ObjectMarking::IsBlackOrGrey(object));
RememberedSet<OLD_TO_OLD>::Insert(source_page, RememberedSet<OLD_TO_OLD>::Insert(source_page,
reinterpret_cast<Address>(slot)); reinterpret_cast<Address>(slot));
} }
......
...@@ -66,13 +66,11 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap) ...@@ -66,13 +66,11 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap)
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
class VerifyMarkingVisitor : public ObjectVisitor { class VerifyMarkingVisitor : public ObjectVisitor {
public: public:
explicit VerifyMarkingVisitor(Heap* heap) : heap_(heap) {}
void VisitPointers(Object** start, Object** end) override { void VisitPointers(Object** start, Object** end) override {
for (Object** current = start; current < end; current++) { for (Object** current = start; current < end; current++) {
if ((*current)->IsHeapObject()) { if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current); HeapObject* object = HeapObject::cast(*current);
CHECK(heap_->mark_compact_collector()->IsMarked(object)); CHECK(ObjectMarking::IsBlackOrGrey(object));
} }
} }
} }
...@@ -92,20 +90,17 @@ class VerifyMarkingVisitor : public ObjectVisitor { ...@@ -92,20 +90,17 @@ class VerifyMarkingVisitor : public ObjectVisitor {
ObjectVisitor::VisitCell(rinfo); ObjectVisitor::VisitCell(rinfo);
} }
} }
private:
Heap* heap_;
}; };
static void VerifyMarking(Heap* heap, Address bottom, Address top) { static void VerifyMarking(Heap* heap, Address bottom, Address top) {
VerifyMarkingVisitor visitor(heap); VerifyMarkingVisitor visitor;
HeapObject* object; HeapObject* object;
Address next_object_must_be_here_or_later = bottom; Address next_object_must_be_here_or_later = bottom;
for (Address current = bottom; current < top;) { for (Address current = bottom; current < top;) {
object = HeapObject::FromAddress(current); object = HeapObject::FromAddress(current);
// One word fillers at the end of a black area can be grey. // One word fillers at the end of a black area can be grey.
if (MarkCompactCollector::IsMarked(object) && if (ObjectMarking::IsBlackOrGrey(object) &&
object->map() != heap->one_pointer_filler_map()) { object->map() != heap->one_pointer_filler_map()) {
CHECK(ObjectMarking::IsBlack(object)); CHECK(ObjectMarking::IsBlack(object));
CHECK(current >= next_object_must_be_here_or_later); CHECK(current >= next_object_must_be_here_or_later);
...@@ -157,11 +152,11 @@ static void VerifyMarking(Heap* heap) { ...@@ -157,11 +152,11 @@ static void VerifyMarking(Heap* heap) {
VerifyMarking(heap->map_space()); VerifyMarking(heap->map_space());
VerifyMarking(heap->new_space()); VerifyMarking(heap->new_space());
VerifyMarkingVisitor visitor(heap); VerifyMarkingVisitor visitor;
LargeObjectIterator it(heap->lo_space()); LargeObjectIterator it(heap->lo_space());
for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
if (MarkCompactCollector::IsMarked(obj)) { if (ObjectMarking::IsBlackOrGrey(obj)) {
obj->Iterate(&visitor); obj->Iterate(&visitor);
} }
} }
...@@ -1101,7 +1096,7 @@ class StaticYoungGenerationMarkingVisitor ...@@ -1101,7 +1096,7 @@ class StaticYoungGenerationMarkingVisitor
if (check.HasOverflowed()) return false; if (check.HasOverflowed()) return false;
if (ObjectMarking::IsBlackOrGrey(object)) return true; if (ObjectMarking::IsBlackOrGrey(object)) return true;
heap->mark_compact_collector()->SetMark(object); ObjectMarking::WhiteToBlack(object);
IterateBody(object->map(), object); IterateBody(object->map(), object);
return true; return true;
} }
...@@ -1140,7 +1135,7 @@ class MarkCompactMarkingVisitor ...@@ -1140,7 +1135,7 @@ class MarkCompactMarkingVisitor
// Returns true if object needed marking and false otherwise. // Returns true if object needed marking and false otherwise.
INLINE(static bool MarkObjectWithoutPush(Heap* heap, HeapObject* object)) { INLINE(static bool MarkObjectWithoutPush(Heap* heap, HeapObject* object)) {
if (ObjectMarking::IsWhite(object)) { if (ObjectMarking::IsWhite(object)) {
heap->mark_compact_collector()->SetMark(object); ObjectMarking::WhiteToBlack(object);
return true; return true;
} }
return false; return false;
...@@ -1162,11 +1157,11 @@ class MarkCompactMarkingVisitor ...@@ -1162,11 +1157,11 @@ class MarkCompactMarkingVisitor
HeapObject* obj)) { HeapObject* obj)) {
#ifdef DEBUG #ifdef DEBUG
DCHECK(collector->heap()->Contains(obj)); DCHECK(collector->heap()->Contains(obj));
DCHECK(!collector->heap()->mark_compact_collector()->IsMarked(obj)); DCHECK(ObjectMarking::IsWhite(obj));
#endif #endif
Map* map = obj->map(); Map* map = obj->map();
Heap* heap = obj->GetHeap(); Heap* heap = obj->GetHeap();
heap->mark_compact_collector()->SetMark(obj); ObjectMarking::WhiteToBlack(obj);
// Mark the map pointer and the body. // Mark the map pointer and the body.
MarkBit map_mark = ObjectMarking::MarkBitFrom(map); MarkBit map_mark = ObjectMarking::MarkBitFrom(map);
heap->mark_compact_collector()->MarkObject(map, map_mark); heap->mark_compact_collector()->MarkObject(map, map_mark);
...@@ -1391,7 +1386,7 @@ class RootMarkingVisitor : public ObjectVisitor { ...@@ -1391,7 +1386,7 @@ class RootMarkingVisitor : public ObjectVisitor {
Map* map = object->map(); Map* map = object->map();
// Mark the object. // Mark the object.
collector_->SetMark(object); ObjectMarking::WhiteToBlack(object);
switch (mode) { switch (mode) {
case MarkCompactMode::FULL: { case MarkCompactMode::FULL: {
...@@ -1479,7 +1474,7 @@ class MarkCompactWeakObjectRetainer : public WeakObjectRetainer { ...@@ -1479,7 +1474,7 @@ class MarkCompactWeakObjectRetainer : public WeakObjectRetainer {
// space. These sites get a one-time reprieve. // space. These sites get a one-time reprieve.
AllocationSite* site = AllocationSite::cast(object); AllocationSite* site = AllocationSite::cast(object);
site->MarkZombie(); site->MarkZombie();
site->GetHeap()->mark_compact_collector()->MarkAllocationSite(site); ObjectMarking::WhiteToBlack(site);
return object; return object;
} else { } else {
return NULL; return NULL;
...@@ -1980,18 +1975,13 @@ void MarkCompactCollector::MarkStringTable( ...@@ -1980,18 +1975,13 @@ void MarkCompactCollector::MarkStringTable(
// Mark the string table itself. // Mark the string table itself.
if (ObjectMarking::IsWhite(string_table)) { if (ObjectMarking::IsWhite(string_table)) {
// String table could have already been marked by visiting the handles list. // String table could have already been marked by visiting the handles list.
SetMark(string_table); ObjectMarking::WhiteToBlack(string_table);
} }
// Explicitly mark the prefix. // Explicitly mark the prefix.
string_table->IteratePrefix(visitor); string_table->IteratePrefix(visitor);
ProcessMarkingDeque<MarkCompactMode::FULL>(); ProcessMarkingDeque<MarkCompactMode::FULL>();
} }
void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) {
SetMark(site);
}
void MarkCompactCollector::MarkRoots( void MarkCompactCollector::MarkRoots(
RootMarkingVisitor<MarkCompactMode::FULL>* visitor) { RootMarkingVisitor<MarkCompactMode::FULL>* visitor) {
// Mark the heap roots including global variables, stack variables, // Mark the heap roots including global variables, stack variables,
...@@ -2019,7 +2009,7 @@ void MarkCompactCollector::MarkImplicitRefGroups( ...@@ -2019,7 +2009,7 @@ void MarkCompactCollector::MarkImplicitRefGroups(
ImplicitRefGroup* entry = ref_groups->at(i); ImplicitRefGroup* entry = ref_groups->at(i);
DCHECK(entry != NULL); DCHECK(entry != NULL);
if (!IsMarked(*entry->parent)) { if (ObjectMarking::IsWhite(*entry->parent)) {
(*ref_groups)[last++] = entry; (*ref_groups)[last++] = entry;
continue; continue;
} }
...@@ -2325,7 +2315,7 @@ SlotCallbackResult MarkCompactCollector::CheckAndMarkObject( ...@@ -2325,7 +2315,7 @@ SlotCallbackResult MarkCompactCollector::CheckAndMarkObject(
if (ObjectMarking::IsBlackOrGrey(heap_object)) { if (ObjectMarking::IsBlackOrGrey(heap_object)) {
return KEEP_SLOT; return KEEP_SLOT;
} }
heap->mark_compact_collector()->SetMark(heap_object); ObjectMarking::WhiteToBlack(heap_object);
StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(), StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(),
heap_object); heap_object);
return KEEP_SLOT; return KEEP_SLOT;
...@@ -2777,11 +2767,11 @@ void MarkCompactCollector::ProcessWeakCollections() { ...@@ -2777,11 +2767,11 @@ void MarkCompactCollector::ProcessWeakCollections() {
while (weak_collection_obj != Smi::kZero) { while (weak_collection_obj != Smi::kZero) {
JSWeakCollection* weak_collection = JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj); reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
DCHECK(MarkCompactCollector::IsMarked(weak_collection)); DCHECK(ObjectMarking::IsBlackOrGrey(weak_collection));
if (weak_collection->table()->IsHashTable()) { if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table()); ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) { for (int i = 0; i < table->Capacity(); i++) {
if (MarkCompactCollector::IsMarked(HeapObject::cast(table->KeyAt(i)))) { if (ObjectMarking::IsBlackOrGrey(HeapObject::cast(table->KeyAt(i)))) {
Object** key_slot = Object** key_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i)); table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i));
RecordSlot(table, key_slot, *key_slot); RecordSlot(table, key_slot, *key_slot);
...@@ -2803,12 +2793,12 @@ void MarkCompactCollector::ClearWeakCollections() { ...@@ -2803,12 +2793,12 @@ void MarkCompactCollector::ClearWeakCollections() {
while (weak_collection_obj != Smi::kZero) { while (weak_collection_obj != Smi::kZero) {
JSWeakCollection* weak_collection = JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj); reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
DCHECK(MarkCompactCollector::IsMarked(weak_collection)); DCHECK(ObjectMarking::IsBlackOrGrey(weak_collection));
if (weak_collection->table()->IsHashTable()) { if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table()); ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) { for (int i = 0; i < table->Capacity(); i++) {
HeapObject* key = HeapObject::cast(table->KeyAt(i)); HeapObject* key = HeapObject::cast(table->KeyAt(i));
if (!MarkCompactCollector::IsMarked(key)) { if (!ObjectMarking::IsBlackOrGrey(key)) {
table->RemoveEntry(i); table->RemoveEntry(i);
} }
} }
...@@ -2849,7 +2839,7 @@ void MarkCompactCollector::ClearWeakCells(Object** non_live_map_list, ...@@ -2849,7 +2839,7 @@ void MarkCompactCollector::ClearWeakCells(Object** non_live_map_list,
// We do not insert cleared weak cells into the list, so the value // We do not insert cleared weak cells into the list, so the value
// cannot be a Smi here. // cannot be a Smi here.
HeapObject* value = HeapObject::cast(weak_cell->value()); HeapObject* value = HeapObject::cast(weak_cell->value());
if (!MarkCompactCollector::IsMarked(value)) { if (!ObjectMarking::IsBlackOrGrey(value)) {
// Cells for new-space objects embedded in optimized code are wrapped in // Cells for new-space objects embedded in optimized code are wrapped in
// WeakCell and put into Heap::weak_object_to_code_table. // WeakCell and put into Heap::weak_object_to_code_table.
// Such cells do not have any strong references but we want to keep them // Such cells do not have any strong references but we want to keep them
...@@ -2858,9 +2848,9 @@ void MarkCompactCollector::ClearWeakCells(Object** non_live_map_list, ...@@ -2858,9 +2848,9 @@ void MarkCompactCollector::ClearWeakCells(Object** non_live_map_list,
if (value->IsCell()) { if (value->IsCell()) {
Object* cell_value = Cell::cast(value)->value(); Object* cell_value = Cell::cast(value)->value();
if (cell_value->IsHeapObject() && if (cell_value->IsHeapObject() &&
MarkCompactCollector::IsMarked(HeapObject::cast(cell_value))) { ObjectMarking::IsBlackOrGrey(HeapObject::cast(cell_value))) {
// Resurrect the cell. // Resurrect the cell.
SetMark(value); ObjectMarking::WhiteToBlack(value);
Object** slot = HeapObject::RawField(value, Cell::kValueOffset); Object** slot = HeapObject::RawField(value, Cell::kValueOffset);
RecordSlot(value, slot, *slot); RecordSlot(value, slot, *slot);
slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset); slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
......
...@@ -516,7 +516,6 @@ class MarkCompactCollector { ...@@ -516,7 +516,6 @@ class MarkCompactCollector {
static const uint32_t kSingleFreeEncoding = 0; static const uint32_t kSingleFreeEncoding = 0;
static const uint32_t kMultiFreeEncoding = 1; static const uint32_t kMultiFreeEncoding = 1;
static inline bool IsMarked(Object* obj);
static bool IsUnmarkedHeapObjectWithHeap(Heap* heap, Object** p); static bool IsUnmarkedHeapObjectWithHeap(Heap* heap, Object** p);
inline Heap* heap() const { return heap_; } inline Heap* heap() const { return heap_; }
...@@ -569,10 +568,6 @@ class MarkCompactCollector { ...@@ -569,10 +568,6 @@ class MarkCompactCollector {
bool evacuation() const { return evacuation_; } bool evacuation() const { return evacuation_; }
// Special case for processing weak references in a full collection. We need
// to artificially keep AllocationSites alive for a time.
void MarkAllocationSite(AllocationSite* site);
// Mark objects in implicit references groups if their parent object // Mark objects in implicit references groups if their parent object
// is marked. // is marked.
void MarkImplicitRefGroups(MarkObjectFunction mark_object); void MarkImplicitRefGroups(MarkObjectFunction mark_object);
...@@ -663,10 +658,6 @@ class MarkCompactCollector { ...@@ -663,10 +658,6 @@ class MarkCompactCollector {
// This is for non-incremental marking only. // This is for non-incremental marking only.
INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit)); INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit));
// Marks the object black assuming that it is not yet marked.
// This is for non-incremental marking only.
INLINE(void SetMark(HeapObject* obj));
// Mark the heap roots and all objects reachable from them. // Mark the heap roots and all objects reachable from them.
void MarkRoots(RootMarkingVisitor<MarkCompactMode::FULL>* visitor); void MarkRoots(RootMarkingVisitor<MarkCompactMode::FULL>* visitor);
......
...@@ -342,7 +342,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCell(Map* map, ...@@ -342,7 +342,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCell(Map* map,
// contain smi zero. // contain smi zero.
if (weak_cell->next_cleared() && !weak_cell->cleared()) { if (weak_cell->next_cleared() && !weak_cell->cleared()) {
HeapObject* value = HeapObject::cast(weak_cell->value()); HeapObject* value = HeapObject::cast(weak_cell->value());
if (MarkCompactCollector::IsMarked(value)) { if (ObjectMarking::IsBlackOrGrey(value)) {
// Weak cells with live values are directly processed here to reduce // Weak cells with live values are directly processed here to reduce
// the processing time of weak cells during the main GC pause. // the processing time of weak cells during the main GC pause.
Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset); Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment