Commit ba70a7a3 authored by hpayer's avatar hpayer Committed by Commit bot

MarkBit cleanup: They have to be accessed through Marking accessors. Avoid...

MarkBit cleanup: They have to be accessed through Marking accessors. Avoid arbitrary abuse of mark bits and make marking explicit.

Added DCHECKs to mark bit transitions to check source state.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#27689}
parent fd8d0d14
......@@ -5771,7 +5771,7 @@ class UnreachableObjectsFilter : public HeapObjectsFilter {
bool SkipObject(HeapObject* object) {
MarkBit mark_bit = Marking::MarkBitFrom(object);
return !mark_bit.Get();
return Marking::IsWhite(mark_bit);
}
private:
......@@ -5784,8 +5784,8 @@ class UnreachableObjectsFilter : public HeapObjectsFilter {
if (!(*p)->IsHeapObject()) continue;
HeapObject* obj = HeapObject::cast(*p);
MarkBit mark_bit = Marking::MarkBitFrom(obj);
if (!mark_bit.Get()) {
mark_bit.Set();
if (Marking::IsWhite(mark_bit)) {
Marking::WhiteToBlack(mark_bit);
marking_stack_.Add(obj);
}
}
......
......@@ -141,7 +141,6 @@ static inline void MarkBlackOrKeepBlack(HeapObject* heap_object,
if (Marking::IsBlack(mark_bit)) return;
Marking::MarkBlack(mark_bit);
MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), size);
DCHECK(Marking::IsBlack(mark_bit));
}
......@@ -251,7 +250,7 @@ class IncrementalMarkingMarkingVisitor
HeapObject* heap_object = HeapObject::cast(obj);
MarkBit mark_bit = Marking::MarkBitFrom(heap_object);
if (Marking::IsWhite(mark_bit)) {
mark_bit.Set();
Marking::MarkBlack(mark_bit);
MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(),
heap_object->Size());
return true;
......
......@@ -28,10 +28,9 @@ void MarkCompactCollector::SetFlags(int flags) {
void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) {
DCHECK(Marking::MarkBitFrom(obj) == mark_bit);
if (!mark_bit.Get()) {
mark_bit.Set();
if (Marking::IsWhite(mark_bit)) {
Marking::WhiteToBlack(mark_bit);
MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size());
DCHECK(IsMarked(obj));
DCHECK(obj->GetIsolate()->heap()->Contains(obj));
marking_deque_.PushBlack(obj);
}
......@@ -39,9 +38,9 @@ void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) {
void MarkCompactCollector::SetMark(HeapObject* obj, MarkBit mark_bit) {
DCHECK(!mark_bit.Get());
DCHECK(Marking::IsWhite(mark_bit));
DCHECK(Marking::MarkBitFrom(obj) == mark_bit);
mark_bit.Set();
Marking::WhiteToBlack(mark_bit);
MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size());
}
......@@ -49,7 +48,7 @@ void MarkCompactCollector::SetMark(HeapObject* obj, MarkBit mark_bit) {
bool MarkCompactCollector::IsMarked(Object* obj) {
DCHECK(obj->IsHeapObject());
HeapObject* heap_object = HeapObject::cast(obj);
return Marking::MarkBitFrom(heap_object).Get();
return Marking::IsBlackOrGrey(Marking::MarkBitFrom(heap_object));
}
......
This diff is collapsed.
......@@ -50,7 +50,10 @@ class Marking {
// White markbits: 00 - this is required by the mark bit clearer.
static const char* kWhiteBitPattern;
INLINE(static bool IsWhite(MarkBit mark_bit)) { return !mark_bit.Get(); }
INLINE(static bool IsWhite(MarkBit mark_bit)) {
DCHECK(!IsImpossible(mark_bit));
return !mark_bit.Get();
}
// Grey markbits: 11
static const char* kGreyBitPattern;
......@@ -58,19 +61,51 @@ class Marking {
return mark_bit.Get() && mark_bit.Next().Get();
}
// IsBlackOrGrey assumes that the first bit is set for black or grey
// objects.
INLINE(static bool IsBlackOrGrey(MarkBit mark_bit)) { return mark_bit.Get(); }
INLINE(static void MarkBlack(MarkBit mark_bit)) {
mark_bit.Set();
mark_bit.Next().Clear();
}
INLINE(static void BlackToGrey(MarkBit markbit)) { markbit.Next().Set(); }
INLINE(static void MarkWhite(MarkBit mark_bit)) {
mark_bit.Clear();
mark_bit.Next().Clear();
}
INLINE(static void BlackToWhite(MarkBit markbit)) {
DCHECK(IsBlack(markbit));
markbit.Clear();
}
INLINE(static void GreyToWhite(MarkBit markbit)) {
DCHECK(IsGrey(markbit));
markbit.Clear();
markbit.Next().Clear();
}
INLINE(static void BlackToGrey(MarkBit markbit)) {
DCHECK(IsBlack(markbit));
markbit.Next().Set();
}
INLINE(static void WhiteToGrey(MarkBit markbit)) {
DCHECK(IsWhite(markbit));
markbit.Set();
markbit.Next().Set();
}
INLINE(static void GreyToBlack(MarkBit markbit)) { markbit.Next().Clear(); }
INLINE(static void WhiteToBlack(MarkBit markbit)) {
DCHECK(IsWhite(markbit));
markbit.Set();
}
INLINE(static void GreyToBlack(MarkBit markbit)) {
DCHECK(IsGrey(markbit));
markbit.Next().Clear();
}
INLINE(static void BlackToGrey(HeapObject* obj)) {
BlackToGrey(MarkBitFrom(obj));
......@@ -81,6 +116,10 @@ class Marking {
markbit.Next().Set();
}
static void SetAllMarkBitsInRange(MarkBit start, MarkBit end);
static void ClearAllMarkBitsOfCellsContainedInRange(MarkBit start,
MarkBit end);
void TransferMark(Address old_start, Address new_start);
#ifdef DEBUG
......
......@@ -680,7 +680,7 @@ bool StaticMarkingVisitor<StaticVisitor>::IsFlushable(Heap* heap,
// Code is either on stack, in compilation cache or referenced
// by optimized version of function.
MarkBit code_mark = Marking::MarkBitFrom(function->code());
if (code_mark.Get()) {
if (Marking::IsBlackOrGrey(code_mark)) {
return false;
}
......@@ -709,7 +709,7 @@ bool StaticMarkingVisitor<StaticVisitor>::IsFlushable(
// Code is either on stack, in compilation cache or referenced
// by optimized version of function.
MarkBit code_mark = Marking::MarkBitFrom(shared_info->code());
if (code_mark.Get()) {
if (Marking::IsBlackOrGrey(code_mark)) {
return false;
}
......
......@@ -2971,8 +2971,8 @@ void LargeObjectSpace::FreeUnmarkedObjects() {
// pointer object is this big.
bool is_pointer_object = object->IsFixedArray();
MarkBit mark_bit = Marking::MarkBitFrom(object);
if (mark_bit.Get()) {
mark_bit.Clear();
if (Marking::IsBlackOrGrey(mark_bit)) {
Marking::BlackToWhite(mark_bit);
Page::FromAddress(object->address())->ResetProgressBar();
Page::FromAddress(object->address())->ResetLiveBytes();
previous = current;
......@@ -3127,7 +3127,7 @@ void Page::Print() {
unsigned mark_size = 0;
for (HeapObject* object = objects.Next(); object != NULL;
object = objects.Next()) {
bool is_marked = Marking::MarkBitFrom(object).Get();
bool is_marked = Marking::IsBlackOrGrey(Marking::MarkBitFrom(object));
PrintF(" %c ", (is_marked ? '!' : ' ')); // Indent a little.
if (is_marked) {
mark_size += heap()->GcSafeSizeOfOldObjectFunction()(object);
......
......@@ -104,19 +104,15 @@ class MarkBit {
inline MarkBit(CellType* cell, CellType mask) : cell_(cell), mask_(mask) {}
inline CellType* cell() { return cell_; }
inline CellType mask() { return mask_; }
#ifdef DEBUG
bool operator==(const MarkBit& other) {
return cell_ == other.cell_ && mask_ == other.mask_;
}
#endif
inline void Set() { *cell_ |= mask_; }
inline bool Get() { return (*cell_ & mask_) != 0; }
inline void Clear() { *cell_ &= ~mask_; }
private:
inline CellType* cell() { return cell_; }
inline CellType mask() { return mask_; }
inline MarkBit Next() {
CellType new_mask = mask_ << 1;
......@@ -127,9 +123,14 @@ class MarkBit {
}
}
private:
inline void Set() { *cell_ |= mask_; }
inline bool Get() { return (*cell_ & mask_) != 0; }
inline void Clear() { *cell_ &= ~mask_; }
CellType* cell_;
CellType mask_;
friend class Marking;
};
......
......@@ -382,7 +382,8 @@ void StoreBuffer::ClearInvalidStoreBufferEntries() {
LargeObjectIterator it(heap_->lo_space());
for (HeapObject* object = it.Next(); object != NULL; object = it.Next()) {
MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
if (chunk->scan_on_scavenge() && !Marking::MarkBitFrom(object).Get()) {
if (chunk->scan_on_scavenge() &&
Marking::IsWhite(Marking::MarkBitFrom(object))) {
chunk->set_scan_on_scavenge(false);
}
}
......
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