| 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_H_ | 5 #ifndef V8_HEAP_INCREMENTAL_MARKING_H_ |
| 6 #define V8_INCREMENTAL_MARKING_H_ | 6 #define V8_HEAP_INCREMENTAL_MARKING_H_ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "src/execution.h" | 9 #include "src/execution.h" |
| 10 #include "src/mark-compact.h" | 10 #include "src/heap/mark-compact.h" |
| 11 #include "src/objects.h" | 11 #include "src/objects.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 | 16 |
| 17 class IncrementalMarking { | 17 class IncrementalMarking { |
| 18 public: | 18 public: |
| 19 enum State { | 19 enum State { STOPPED, SWEEPING, MARKING, COMPLETE }; |
| 20 STOPPED, | |
| 21 SWEEPING, | |
| 22 MARKING, | |
| 23 COMPLETE | |
| 24 }; | |
| 25 | 20 |
| 26 enum CompletionAction { | 21 enum CompletionAction { GC_VIA_STACK_GUARD, NO_GC_VIA_STACK_GUARD }; |
| 27 GC_VIA_STACK_GUARD, | |
| 28 NO_GC_VIA_STACK_GUARD | |
| 29 }; | |
| 30 | 22 |
| 31 explicit IncrementalMarking(Heap* heap); | 23 explicit IncrementalMarking(Heap* heap); |
| 32 | 24 |
| 33 static void Initialize(); | 25 static void Initialize(); |
| 34 | 26 |
| 35 void TearDown(); | 27 void TearDown(); |
| 36 | 28 |
| 37 State state() { | 29 State state() { |
| 38 DCHECK(state_ == STOPPED || FLAG_incremental_marking); | 30 DCHECK(state_ == STOPPED || FLAG_incremental_marking); |
| 39 return state_; | 31 return state_; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 87 |
| 96 inline void RestartIfNotMarking() { | 88 inline void RestartIfNotMarking() { |
| 97 if (state_ == COMPLETE) { | 89 if (state_ == COMPLETE) { |
| 98 state_ = MARKING; | 90 state_ = MARKING; |
| 99 if (FLAG_trace_incremental_marking) { | 91 if (FLAG_trace_incremental_marking) { |
| 100 PrintF("[IncrementalMarking] Restarting (new grey objects)\n"); | 92 PrintF("[IncrementalMarking] Restarting (new grey objects)\n"); |
| 101 } | 93 } |
| 102 } | 94 } |
| 103 } | 95 } |
| 104 | 96 |
| 105 static void RecordWriteFromCode(HeapObject* obj, | 97 static void RecordWriteFromCode(HeapObject* obj, Object** slot, |
| 106 Object** slot, | |
| 107 Isolate* isolate); | 98 Isolate* isolate); |
| 108 | 99 |
| 109 // Record a slot for compaction. Returns false for objects that are | 100 // Record a slot for compaction. Returns false for objects that are |
| 110 // guaranteed to be rescanned or not guaranteed to survive. | 101 // guaranteed to be rescanned or not guaranteed to survive. |
| 111 // | 102 // |
| 112 // No slots in white objects should be recorded, as some slots are typed and | 103 // No slots in white objects should be recorded, as some slots are typed and |
| 113 // cannot be interpreted correctly if the underlying object does not survive | 104 // cannot be interpreted correctly if the underlying object does not survive |
| 114 // the incremental cycle (stays white). | 105 // the incremental cycle (stays white). |
| 115 INLINE(bool BaseRecordWrite(HeapObject* obj, Object** slot, Object* value)); | 106 INLINE(bool BaseRecordWrite(HeapObject* obj, Object** slot, Object* value)); |
| 116 INLINE(void RecordWrite(HeapObject* obj, Object** slot, Object* value)); | 107 INLINE(void RecordWrite(HeapObject* obj, Object** slot, Object* value)); |
| 117 INLINE(void RecordWriteIntoCode(HeapObject* obj, | 108 INLINE(void RecordWriteIntoCode(HeapObject* obj, RelocInfo* rinfo, |
| 118 RelocInfo* rinfo, | |
| 119 Object* value)); | 109 Object* value)); |
| 120 INLINE(void RecordWriteOfCodeEntry(JSFunction* host, | 110 INLINE(void RecordWriteOfCodeEntry(JSFunction* host, Object** slot, |
| 121 Object** slot, | |
| 122 Code* value)); | 111 Code* value)); |
| 123 | 112 |
| 124 | 113 |
| 125 void RecordWriteSlow(HeapObject* obj, Object** slot, Object* value); | 114 void RecordWriteSlow(HeapObject* obj, Object** slot, Object* value); |
| 126 void RecordWriteIntoCodeSlow(HeapObject* obj, | 115 void RecordWriteIntoCodeSlow(HeapObject* obj, RelocInfo* rinfo, |
| 127 RelocInfo* rinfo, | |
| 128 Object* value); | 116 Object* value); |
| 129 void RecordWriteOfCodeEntrySlow(JSFunction* host, Object** slot, Code* value); | 117 void RecordWriteOfCodeEntrySlow(JSFunction* host, Object** slot, Code* value); |
| 130 void RecordCodeTargetPatch(Code* host, Address pc, HeapObject* value); | 118 void RecordCodeTargetPatch(Code* host, Address pc, HeapObject* value); |
| 131 void RecordCodeTargetPatch(Address pc, HeapObject* value); | 119 void RecordCodeTargetPatch(Address pc, HeapObject* value); |
| 132 | 120 |
| 133 inline void RecordWrites(HeapObject* obj); | 121 inline void RecordWrites(HeapObject* obj); |
| 134 | 122 |
| 135 inline void BlackToGreyAndUnshift(HeapObject* obj, MarkBit mark_bit); | 123 inline void BlackToGreyAndUnshift(HeapObject* obj, MarkBit mark_bit); |
| 136 | 124 |
| 137 inline void WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit); | 125 inline void WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit); |
| 138 | 126 |
| 139 inline void SetOldSpacePageFlags(MemoryChunk* chunk) { | 127 inline void SetOldSpacePageFlags(MemoryChunk* chunk) { |
| 140 SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting()); | 128 SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting()); |
| 141 } | 129 } |
| 142 | 130 |
| 143 inline void SetNewSpacePageFlags(NewSpacePage* chunk) { | 131 inline void SetNewSpacePageFlags(NewSpacePage* chunk) { |
| 144 SetNewSpacePageFlags(chunk, IsMarking()); | 132 SetNewSpacePageFlags(chunk, IsMarking()); |
| 145 } | 133 } |
| 146 | 134 |
| 147 MarkingDeque* marking_deque() { return &marking_deque_; } | 135 MarkingDeque* marking_deque() { return &marking_deque_; } |
| 148 | 136 |
| 149 bool IsCompacting() { return IsMarking() && is_compacting_; } | 137 bool IsCompacting() { return IsMarking() && is_compacting_; } |
| 150 | 138 |
| 151 void ActivateGeneratedStub(Code* stub); | 139 void ActivateGeneratedStub(Code* stub); |
| 152 | 140 |
| 153 void NotifyOfHighPromotionRate() { | 141 void NotifyOfHighPromotionRate() { |
| 154 if (IsMarking()) { | 142 if (IsMarking()) { |
| 155 if (marking_speed_ < kFastMarking) { | 143 if (marking_speed_ < kFastMarking) { |
| 156 if (FLAG_trace_gc) { | 144 if (FLAG_trace_gc) { |
| 157 PrintPID("Increasing marking speed to %d " | 145 PrintPID( |
| 158 "due to high promotion rate\n", | 146 "Increasing marking speed to %d " |
| 159 static_cast<int>(kFastMarking)); | 147 "due to high promotion rate\n", |
| 148 static_cast<int>(kFastMarking)); |
| 160 } | 149 } |
| 161 marking_speed_ = kFastMarking; | 150 marking_speed_ = kFastMarking; |
| 162 } | 151 } |
| 163 } | 152 } |
| 164 } | 153 } |
| 165 | 154 |
| 166 void EnterNoMarkingScope() { | 155 void EnterNoMarkingScope() { no_marking_scope_depth_++; } |
| 167 no_marking_scope_depth_++; | |
| 168 } | |
| 169 | 156 |
| 170 void LeaveNoMarkingScope() { | 157 void LeaveNoMarkingScope() { no_marking_scope_depth_--; } |
| 171 no_marking_scope_depth_--; | |
| 172 } | |
| 173 | 158 |
| 174 void UncommitMarkingDeque(); | 159 void UncommitMarkingDeque(); |
| 175 | 160 |
| 176 void NotifyIncompleteScanOfObject(int unscanned_bytes) { | 161 void NotifyIncompleteScanOfObject(int unscanned_bytes) { |
| 177 unscanned_bytes_of_large_object_ = unscanned_bytes; | 162 unscanned_bytes_of_large_object_ = unscanned_bytes; |
| 178 } | 163 } |
| 179 | 164 |
| 180 private: | 165 private: |
| 181 int64_t SpaceLeftInOldSpace(); | 166 int64_t SpaceLeftInOldSpace(); |
| 182 | 167 |
| 183 void ResetStepCounters(); | 168 void ResetStepCounters(); |
| 184 | 169 |
| 185 void StartMarking(CompactionFlag flag); | 170 void StartMarking(CompactionFlag flag); |
| 186 | 171 |
| 187 void ActivateIncrementalWriteBarrier(PagedSpace* space); | 172 void ActivateIncrementalWriteBarrier(PagedSpace* space); |
| 188 static void ActivateIncrementalWriteBarrier(NewSpace* space); | 173 static void ActivateIncrementalWriteBarrier(NewSpace* space); |
| 189 void ActivateIncrementalWriteBarrier(); | 174 void ActivateIncrementalWriteBarrier(); |
| 190 | 175 |
| 191 static void DeactivateIncrementalWriteBarrierForSpace(PagedSpace* space); | 176 static void DeactivateIncrementalWriteBarrierForSpace(PagedSpace* space); |
| 192 static void DeactivateIncrementalWriteBarrierForSpace(NewSpace* space); | 177 static void DeactivateIncrementalWriteBarrierForSpace(NewSpace* space); |
| 193 void DeactivateIncrementalWriteBarrier(); | 178 void DeactivateIncrementalWriteBarrier(); |
| 194 | 179 |
| 195 static void SetOldSpacePageFlags(MemoryChunk* chunk, | 180 static void SetOldSpacePageFlags(MemoryChunk* chunk, bool is_marking, |
| 196 bool is_marking, | |
| 197 bool is_compacting); | 181 bool is_compacting); |
| 198 | 182 |
| 199 static void SetNewSpacePageFlags(NewSpacePage* chunk, bool is_marking); | 183 static void SetNewSpacePageFlags(NewSpacePage* chunk, bool is_marking); |
| 200 | 184 |
| 201 void EnsureMarkingDequeIsCommitted(); | 185 void EnsureMarkingDequeIsCommitted(); |
| 202 | 186 |
| 203 INLINE(void ProcessMarkingDeque()); | 187 INLINE(void ProcessMarkingDeque()); |
| 204 | 188 |
| 205 INLINE(intptr_t ProcessMarkingDeque(intptr_t bytes_to_process)); | 189 INLINE(intptr_t ProcessMarkingDeque(intptr_t bytes_to_process)); |
| 206 | 190 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 224 intptr_t bytes_scanned_; | 208 intptr_t bytes_scanned_; |
| 225 intptr_t allocated_; | 209 intptr_t allocated_; |
| 226 intptr_t write_barriers_invoked_since_last_step_; | 210 intptr_t write_barriers_invoked_since_last_step_; |
| 227 | 211 |
| 228 int no_marking_scope_depth_; | 212 int no_marking_scope_depth_; |
| 229 | 213 |
| 230 int unscanned_bytes_of_large_object_; | 214 int unscanned_bytes_of_large_object_; |
| 231 | 215 |
| 232 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking); | 216 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking); |
| 233 }; | 217 }; |
| 218 } |
| 219 } // namespace v8::internal |
| 234 | 220 |
| 235 } } // namespace v8::internal | 221 #endif // V8_HEAP_INCREMENTAL_MARKING_H_ |
| 236 | |
| 237 #endif // V8_INCREMENTAL_MARKING_H_ | |
| OLD | NEW |