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() {
HeapObject* value = HeapObject::cast(weak_cell->value());
// Remove weak cells with live objects from the list, they do not need
// clearing.
if (MarkCompactCollector::IsMarked(value)) {
if (ObjectMarking::IsBlackOrGrey(value)) {
// Record slot, if value is pointing to an evacuation candidate.
Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
heap_->mark_compact_collector()->RecordSlot(weak_cell, slot, *slot);
......
......@@ -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,
Object* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
Page* source_page = Page::FromAddress(reinterpret_cast<Address>(object));
if (target_page->IsEvacuationCandidate() &&
!ShouldSkipEvacuationSlotRecording(object)) {
DCHECK(IsMarked(object));
DCHECK(ObjectMarking::IsBlackOrGrey(object));
RememberedSet<OLD_TO_OLD>::Insert(source_page,
reinterpret_cast<Address>(slot));
}
......
......@@ -66,13 +66,11 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap)
#ifdef VERIFY_HEAP
class VerifyMarkingVisitor : public ObjectVisitor {
public:
explicit VerifyMarkingVisitor(Heap* heap) : heap_(heap) {}
void VisitPointers(Object** start, Object** end) override {
for (Object** current = start; current < end; current++) {
if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current);
CHECK(heap_->mark_compact_collector()->IsMarked(object));
CHECK(ObjectMarking::IsBlackOrGrey(object));
}
}
}
......@@ -92,20 +90,17 @@ class VerifyMarkingVisitor : public ObjectVisitor {
ObjectVisitor::VisitCell(rinfo);
}
}
private:
Heap* heap_;
};
static void VerifyMarking(Heap* heap, Address bottom, Address top) {
VerifyMarkingVisitor visitor(heap);
VerifyMarkingVisitor visitor;
HeapObject* object;
Address next_object_must_be_here_or_later = bottom;
for (Address current = bottom; current < top;) {
object = HeapObject::FromAddress(current);
// 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()) {
CHECK(ObjectMarking::IsBlack(object));
CHECK(current >= next_object_must_be_here_or_later);
......@@ -157,11 +152,11 @@ static void VerifyMarking(Heap* heap) {
VerifyMarking(heap->map_space());
VerifyMarking(heap->new_space());
VerifyMarkingVisitor visitor(heap);
VerifyMarkingVisitor visitor;
LargeObjectIterator it(heap->lo_space());
for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
if (MarkCompactCollector::IsMarked(obj)) {
if (ObjectMarking::IsBlackOrGrey(obj)) {
obj->Iterate(&visitor);
}
}
......@@ -1101,7 +1096,7 @@ class StaticYoungGenerationMarkingVisitor
if (check.HasOverflowed()) return false;
if (ObjectMarking::IsBlackOrGrey(object)) return true;
heap->mark_compact_collector()->SetMark(object);
ObjectMarking::WhiteToBlack(object);
IterateBody(object->map(), object);
return true;
}
......@@ -1140,7 +1135,7 @@ class MarkCompactMarkingVisitor
// Returns true if object needed marking and false otherwise.
INLINE(static bool MarkObjectWithoutPush(Heap* heap, HeapObject* object)) {
if (ObjectMarking::IsWhite(object)) {
heap->mark_compact_collector()->SetMark(object);
ObjectMarking::WhiteToBlack(object);
return true;
}
return false;
......@@ -1162,11 +1157,11 @@ class MarkCompactMarkingVisitor
HeapObject* obj)) {
#ifdef DEBUG
DCHECK(collector->heap()->Contains(obj));
DCHECK(!collector->heap()->mark_compact_collector()->IsMarked(obj));
DCHECK(ObjectMarking::IsWhite(obj));
#endif
Map* map = obj->map();
Heap* heap = obj->GetHeap();
heap->mark_compact_collector()->SetMark(obj);
ObjectMarking::WhiteToBlack(obj);
// Mark the map pointer and the body.
MarkBit map_mark = ObjectMarking::MarkBitFrom(map);
heap->mark_compact_collector()->MarkObject(map, map_mark);
......@@ -1391,7 +1386,7 @@ class RootMarkingVisitor : public ObjectVisitor {
Map* map = object->map();
// Mark the object.
collector_->SetMark(object);
ObjectMarking::WhiteToBlack(object);
switch (mode) {
case MarkCompactMode::FULL: {
......@@ -1479,7 +1474,7 @@ class MarkCompactWeakObjectRetainer : public WeakObjectRetainer {
// space. These sites get a one-time reprieve.
AllocationSite* site = AllocationSite::cast(object);
site->MarkZombie();
site->GetHeap()->mark_compact_collector()->MarkAllocationSite(site);
ObjectMarking::WhiteToBlack(site);
return object;
} else {
return NULL;
......@@ -1980,18 +1975,13 @@ void MarkCompactCollector::MarkStringTable(
// Mark the string table itself.
if (ObjectMarking::IsWhite(string_table)) {
// String table could have already been marked by visiting the handles list.
SetMark(string_table);
ObjectMarking::WhiteToBlack(string_table);
}
// Explicitly mark the prefix.
string_table->IteratePrefix(visitor);
ProcessMarkingDeque<MarkCompactMode::FULL>();
}
void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) {
SetMark(site);
}
void MarkCompactCollector::MarkRoots(
RootMarkingVisitor<MarkCompactMode::FULL>* visitor) {
// Mark the heap roots including global variables, stack variables,
......@@ -2019,7 +2009,7 @@ void MarkCompactCollector::MarkImplicitRefGroups(
ImplicitRefGroup* entry = ref_groups->at(i);
DCHECK(entry != NULL);
if (!IsMarked(*entry->parent)) {
if (ObjectMarking::IsWhite(*entry->parent)) {
(*ref_groups)[last++] = entry;
continue;
}
......@@ -2325,7 +2315,7 @@ SlotCallbackResult MarkCompactCollector::CheckAndMarkObject(
if (ObjectMarking::IsBlackOrGrey(heap_object)) {
return KEEP_SLOT;
}
heap->mark_compact_collector()->SetMark(heap_object);
ObjectMarking::WhiteToBlack(heap_object);
StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(),
heap_object);
return KEEP_SLOT;
......@@ -2777,11 +2767,11 @@ void MarkCompactCollector::ProcessWeakCollections() {
while (weak_collection_obj != Smi::kZero) {
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
DCHECK(MarkCompactCollector::IsMarked(weak_collection));
DCHECK(ObjectMarking::IsBlackOrGrey(weak_collection));
if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
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 =
table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i));
RecordSlot(table, key_slot, *key_slot);
......@@ -2803,12 +2793,12 @@ void MarkCompactCollector::ClearWeakCollections() {
while (weak_collection_obj != Smi::kZero) {
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
DCHECK(MarkCompactCollector::IsMarked(weak_collection));
DCHECK(ObjectMarking::IsBlackOrGrey(weak_collection));
if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) {
HeapObject* key = HeapObject::cast(table->KeyAt(i));
if (!MarkCompactCollector::IsMarked(key)) {
if (!ObjectMarking::IsBlackOrGrey(key)) {
table->RemoveEntry(i);
}
}
......@@ -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
// cannot be a Smi here.
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
// WeakCell and put into Heap::weak_object_to_code_table.
// 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,
if (value->IsCell()) {
Object* cell_value = Cell::cast(value)->value();
if (cell_value->IsHeapObject() &&
MarkCompactCollector::IsMarked(HeapObject::cast(cell_value))) {
ObjectMarking::IsBlackOrGrey(HeapObject::cast(cell_value))) {
// Resurrect the cell.
SetMark(value);
ObjectMarking::WhiteToBlack(value);
Object** slot = HeapObject::RawField(value, Cell::kValueOffset);
RecordSlot(value, slot, *slot);
slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
......
......@@ -516,7 +516,6 @@ class MarkCompactCollector {
static const uint32_t kSingleFreeEncoding = 0;
static const uint32_t kMultiFreeEncoding = 1;
static inline bool IsMarked(Object* obj);
static bool IsUnmarkedHeapObjectWithHeap(Heap* heap, Object** p);
inline Heap* heap() const { return heap_; }
......@@ -569,10 +568,6 @@ class MarkCompactCollector {
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
// is marked.
void MarkImplicitRefGroups(MarkObjectFunction mark_object);
......@@ -663,10 +658,6 @@ class MarkCompactCollector {
// This is for non-incremental marking only.
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.
void MarkRoots(RootMarkingVisitor<MarkCompactMode::FULL>* visitor);
......
......@@ -342,7 +342,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCell(Map* map,
// contain smi zero.
if (weak_cell->next_cleared() && !weak_cell->cleared()) {
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
// the processing time of weak cells during the main GC pause.
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