| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_INCREMENTAL_MARKING_INL_H_ | 5 #ifndef V8_HEAP_INCREMENTAL_MARKING_INL_H_ |
| 6 #define V8_INCREMENTAL_MARKING_INL_H_ | 6 #define V8_HEAP_INCREMENTAL_MARKING_INL_H_ |
| 7 | 7 |
| 8 #include "src/incremental-marking.h" | 8 #include "src/heap/incremental-marking.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 | 13 |
| 14 bool IncrementalMarking::BaseRecordWrite(HeapObject* obj, | 14 bool IncrementalMarking::BaseRecordWrite(HeapObject* obj, Object** slot, |
| 15 Object** slot, | |
| 16 Object* value) { | 15 Object* value) { |
| 17 HeapObject* value_heap_obj = HeapObject::cast(value); | 16 HeapObject* value_heap_obj = HeapObject::cast(value); |
| 18 MarkBit value_bit = Marking::MarkBitFrom(value_heap_obj); | 17 MarkBit value_bit = Marking::MarkBitFrom(value_heap_obj); |
| 19 if (Marking::IsWhite(value_bit)) { | 18 if (Marking::IsWhite(value_bit)) { |
| 20 MarkBit obj_bit = Marking::MarkBitFrom(obj); | 19 MarkBit obj_bit = Marking::MarkBitFrom(obj); |
| 21 if (Marking::IsBlack(obj_bit)) { | 20 if (Marking::IsBlack(obj_bit)) { |
| 22 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); | 21 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
| 23 if (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) { | 22 if (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) { |
| 24 if (chunk->IsLeftOfProgressBar(slot)) { | 23 if (chunk->IsLeftOfProgressBar(slot)) { |
| 25 WhiteToGreyAndPush(value_heap_obj, value_bit); | 24 WhiteToGreyAndPush(value_heap_obj, value_bit); |
| 26 RestartIfNotMarking(); | 25 RestartIfNotMarking(); |
| 27 } else { | 26 } else { |
| 28 return false; | 27 return false; |
| 29 } | 28 } |
| 30 } else { | 29 } else { |
| 31 BlackToGreyAndUnshift(obj, obj_bit); | 30 BlackToGreyAndUnshift(obj, obj_bit); |
| 32 RestartIfNotMarking(); | 31 RestartIfNotMarking(); |
| 33 return false; | 32 return false; |
| 34 } | 33 } |
| 35 } else { | 34 } else { |
| 36 return false; | 35 return false; |
| 37 } | 36 } |
| 38 } | 37 } |
| 39 if (!is_compacting_) return false; | 38 if (!is_compacting_) return false; |
| 40 MarkBit obj_bit = Marking::MarkBitFrom(obj); | 39 MarkBit obj_bit = Marking::MarkBitFrom(obj); |
| 41 return Marking::IsBlack(obj_bit); | 40 return Marking::IsBlack(obj_bit); |
| 42 } | 41 } |
| 43 | 42 |
| 44 | 43 |
| 45 void IncrementalMarking::RecordWrite(HeapObject* obj, | 44 void IncrementalMarking::RecordWrite(HeapObject* obj, Object** slot, |
| 46 Object** slot, | |
| 47 Object* value) { | 45 Object* value) { |
| 48 if (IsMarking() && value->IsHeapObject()) { | 46 if (IsMarking() && value->IsHeapObject()) { |
| 49 RecordWriteSlow(obj, slot, value); | 47 RecordWriteSlow(obj, slot, value); |
| 50 } | 48 } |
| 51 } | 49 } |
| 52 | 50 |
| 53 | 51 |
| 54 void IncrementalMarking::RecordWriteOfCodeEntry(JSFunction* host, | 52 void IncrementalMarking::RecordWriteOfCodeEntry(JSFunction* host, Object** slot, |
| 55 Object** slot, | |
| 56 Code* value) { | 53 Code* value) { |
| 57 if (IsMarking()) RecordWriteOfCodeEntrySlow(host, slot, value); | 54 if (IsMarking()) RecordWriteOfCodeEntrySlow(host, slot, value); |
| 58 } | 55 } |
| 59 | 56 |
| 60 | 57 |
| 61 void IncrementalMarking::RecordWriteIntoCode(HeapObject* obj, | 58 void IncrementalMarking::RecordWriteIntoCode(HeapObject* obj, RelocInfo* rinfo, |
| 62 RelocInfo* rinfo, | |
| 63 Object* value) { | 59 Object* value) { |
| 64 if (IsMarking() && value->IsHeapObject()) { | 60 if (IsMarking() && value->IsHeapObject()) { |
| 65 RecordWriteIntoCodeSlow(obj, rinfo, value); | 61 RecordWriteIntoCodeSlow(obj, rinfo, value); |
| 66 } | 62 } |
| 67 } | 63 } |
| 68 | 64 |
| 69 | 65 |
| 70 void IncrementalMarking::RecordWrites(HeapObject* obj) { | 66 void IncrementalMarking::RecordWrites(HeapObject* obj) { |
| 71 if (IsMarking()) { | 67 if (IsMarking()) { |
| 72 MarkBit obj_bit = Marking::MarkBitFrom(obj); | 68 MarkBit obj_bit = Marking::MarkBitFrom(obj); |
| 73 if (Marking::IsBlack(obj_bit)) { | 69 if (Marking::IsBlack(obj_bit)) { |
| 74 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); | 70 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
| 75 if (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) { | 71 if (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) { |
| 76 chunk->set_progress_bar(0); | 72 chunk->set_progress_bar(0); |
| 77 } | 73 } |
| 78 BlackToGreyAndUnshift(obj, obj_bit); | 74 BlackToGreyAndUnshift(obj, obj_bit); |
| 79 RestartIfNotMarking(); | 75 RestartIfNotMarking(); |
| 80 } | 76 } |
| 81 } | 77 } |
| 82 } | 78 } |
| 83 | 79 |
| 84 | 80 |
| 85 void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj, | 81 void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj, |
| 86 MarkBit mark_bit) { | 82 MarkBit mark_bit) { |
| 87 DCHECK(Marking::MarkBitFrom(obj) == mark_bit); | 83 DCHECK(Marking::MarkBitFrom(obj) == mark_bit); |
| 88 DCHECK(obj->Size() >= 2*kPointerSize); | 84 DCHECK(obj->Size() >= 2 * kPointerSize); |
| 89 DCHECK(IsMarking()); | 85 DCHECK(IsMarking()); |
| 90 Marking::BlackToGrey(mark_bit); | 86 Marking::BlackToGrey(mark_bit); |
| 91 int obj_size = obj->Size(); | 87 int obj_size = obj->Size(); |
| 92 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), -obj_size); | 88 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), -obj_size); |
| 93 bytes_scanned_ -= obj_size; | 89 bytes_scanned_ -= obj_size; |
| 94 int64_t old_bytes_rescanned = bytes_rescanned_; | 90 int64_t old_bytes_rescanned = bytes_rescanned_; |
| 95 bytes_rescanned_ = old_bytes_rescanned + obj_size; | 91 bytes_rescanned_ = old_bytes_rescanned + obj_size; |
| 96 if ((bytes_rescanned_ >> 20) != (old_bytes_rescanned >> 20)) { | 92 if ((bytes_rescanned_ >> 20) != (old_bytes_rescanned >> 20)) { |
| 97 if (bytes_rescanned_ > 2 * heap_->PromotedSpaceSizeOfObjects()) { | 93 if (bytes_rescanned_ > 2 * heap_->PromotedSpaceSizeOfObjects()) { |
| 98 // If we have queued twice the heap size for rescanning then we are | 94 // If we have queued twice the heap size for rescanning then we are |
| 99 // going around in circles, scanning the same objects again and again | 95 // going around in circles, scanning the same objects again and again |
| 100 // as the program mutates the heap faster than we can incrementally | 96 // as the program mutates the heap faster than we can incrementally |
| 101 // trace it. In this case we switch to non-incremental marking in | 97 // trace it. In this case we switch to non-incremental marking in |
| 102 // order to finish off this marking phase. | 98 // order to finish off this marking phase. |
| 103 if (FLAG_trace_gc) { | 99 if (FLAG_trace_gc) { |
| 104 PrintPID("Hurrying incremental marking because of lack of progress\n"); | 100 PrintPID("Hurrying incremental marking because of lack of progress\n"); |
| 105 } | 101 } |
| 106 marking_speed_ = kMaxMarkingSpeed; | 102 marking_speed_ = kMaxMarkingSpeed; |
| 107 } | 103 } |
| 108 } | 104 } |
| 109 | 105 |
| 110 marking_deque_.UnshiftGrey(obj); | 106 marking_deque_.UnshiftGrey(obj); |
| 111 } | 107 } |
| 112 | 108 |
| 113 | 109 |
| 114 void IncrementalMarking::WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit) { | 110 void IncrementalMarking::WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit) { |
| 115 Marking::WhiteToGrey(mark_bit); | 111 Marking::WhiteToGrey(mark_bit); |
| 116 marking_deque_.PushGrey(obj); | 112 marking_deque_.PushGrey(obj); |
| 117 } | 113 } |
| 114 } |
| 115 } // namespace v8::internal |
| 118 | 116 |
| 119 | 117 #endif // V8_HEAP_INCREMENTAL_MARKING_INL_H_ |
| 120 } } // namespace v8::internal | |
| 121 | |
| 122 #endif // V8_INCREMENTAL_MARKING_INL_H_ | |
| OLD | NEW |