V8 Project
incremental-marking.h
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_HEAP_INCREMENTAL_MARKING_H_
6 #define V8_HEAP_INCREMENTAL_MARKING_H_
7 
8 
9 #include "src/execution.h"
10 #include "src/heap/mark-compact.h"
11 #include "src/objects.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 
18  public:
20 
22 
23  explicit IncrementalMarking(Heap* heap);
24 
25  static void Initialize();
26 
27  void TearDown();
28 
30  DCHECK(state_ == STOPPED || FLAG_incremental_marking);
31  return state_;
32  }
33 
34  bool should_hurry() { return should_hurry_; }
35  void set_should_hurry(bool val) { should_hurry_ = val; }
36 
37  inline bool IsStopped() { return state() == STOPPED; }
38 
39  INLINE(bool IsMarking()) { return state() >= MARKING; }
40 
41  inline bool IsMarkingIncomplete() { return state() == MARKING; }
42 
43  inline bool IsComplete() { return state() == COMPLETE; }
44 
45  bool WorthActivating();
46 
47  bool ShouldActivate();
48 
50 
52 
53  void Stop();
54 
55  void PrepareForScavenge();
56 
58 
59  void Hurry();
60 
61  void Finalize();
62 
63  void Abort();
64 
65  void MarkingComplete(CompletionAction action);
66 
67  // It's hard to know how much work the incremental marker should do to make
68  // progress in the face of the mutator creating new work for it. We start
69  // of at a moderate rate of work and gradually increase the speed of the
70  // incremental marker until it completes.
71  // Do some marking every time this much memory has been allocated or that many
72  // heavy (color-checking) write barriers have been invoked.
73  static const intptr_t kAllocatedThreshold = 65536;
74  static const intptr_t kWriteBarriersInvokedThreshold = 32768;
75  // Start off by marking this many times more memory than has been allocated.
76  static const intptr_t kInitialMarkingSpeed = 1;
77  // But if we are promoting a lot of data we need to mark faster to keep up
78  // with the data that is entering the old space through promotion.
79  static const intptr_t kFastMarking = 3;
80  // After this many steps we increase the marking/allocating factor.
81  static const intptr_t kMarkingSpeedAccellerationInterval = 1024;
82  // This is how much we increase the marking/allocating factor by.
83  static const intptr_t kMarkingSpeedAccelleration = 2;
84  static const intptr_t kMaxMarkingSpeed = 1000;
85 
86  void OldSpaceStep(intptr_t allocated);
87 
88  void Step(intptr_t allocated, CompletionAction action,
89  bool force_marking = false);
90 
91  inline void RestartIfNotMarking() {
92  if (state_ == COMPLETE) {
93  state_ = MARKING;
94  if (FLAG_trace_incremental_marking) {
95  PrintF("[IncrementalMarking] Restarting (new grey objects)\n");
96  }
97  }
98  }
99 
100  static void RecordWriteFromCode(HeapObject* obj, Object** slot,
101  Isolate* isolate);
102 
103  // Record a slot for compaction. Returns false for objects that are
104  // guaranteed to be rescanned or not guaranteed to survive.
105  //
106  // No slots in white objects should be recorded, as some slots are typed and
107  // cannot be interpreted correctly if the underlying object does not survive
108  // the incremental cycle (stays white).
109  INLINE(bool BaseRecordWrite(HeapObject* obj, Object** slot, Object* value));
110  INLINE(void RecordWrite(HeapObject* obj, Object** slot, Object* value));
111  INLINE(void RecordWriteIntoCode(HeapObject* obj, RelocInfo* rinfo,
112  Object* value));
113  INLINE(void RecordWriteOfCodeEntry(JSFunction* host, Object** slot,
114  Code* value));
115 
116 
117  void RecordWriteSlow(HeapObject* obj, Object** slot, Object* value);
118  void RecordWriteIntoCodeSlow(HeapObject* obj, RelocInfo* rinfo,
119  Object* value);
120  void RecordWriteOfCodeEntrySlow(JSFunction* host, Object** slot, Code* value);
121  void RecordCodeTargetPatch(Code* host, Address pc, HeapObject* value);
123 
124  inline void RecordWrites(HeapObject* obj);
125 
126  inline void BlackToGreyAndUnshift(HeapObject* obj, MarkBit mark_bit);
127 
128  inline void WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit);
129 
130  inline void SetOldSpacePageFlags(MemoryChunk* chunk) {
131  SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting());
132  }
133 
134  inline void SetNewSpacePageFlags(NewSpacePage* chunk) {
135  SetNewSpacePageFlags(chunk, IsMarking());
136  }
137 
139 
140  bool IsCompacting() { return IsMarking() && is_compacting_; }
141 
142  void ActivateGeneratedStub(Code* stub);
143 
145  if (IsMarking()) {
147  if (FLAG_trace_gc) {
148  PrintPID(
149  "Increasing marking speed to %d "
150  "due to high promotion rate\n",
151  static_cast<int>(kFastMarking));
152  }
154  }
155  }
156  }
157 
159 
161 
162  void UncommitMarkingDeque();
163 
164  void NotifyIncompleteScanOfObject(int unscanned_bytes) {
165  unscanned_bytes_of_large_object_ = unscanned_bytes;
166  }
167 
168  private:
169  int64_t SpaceLeftInOldSpace();
170 
171  void SpeedUp();
172 
173  void ResetStepCounters();
174 
176 
180 
184 
185  static void SetOldSpacePageFlags(MemoryChunk* chunk, bool is_marking,
186  bool is_compacting);
187 
188  static void SetNewSpacePageFlags(NewSpacePage* chunk, bool is_marking);
189 
191 
192  INLINE(void ProcessMarkingDeque());
193 
194  INLINE(intptr_t ProcessMarkingDeque(intptr_t bytes_to_process));
195 
196  INLINE(void VisitObject(Map* map, HeapObject* obj, int size));
197 
199 
202 
206 
213  intptr_t bytes_scanned_;
214  intptr_t allocated_;
216 
218 
220 
222 };
223 }
224 } // namespace v8::internal
225 
226 #endif // V8_HEAP_INCREMENTAL_MARKING_H_
void RecordWriteSlow(HeapObject *obj, Object **slot, Object *value)
static const intptr_t kAllocatedThreshold
INLINE(intptr_t ProcessMarkingDeque(intptr_t bytes_to_process))
void WhiteToGreyAndPush(HeapObject *obj, MarkBit mark_bit)
void Step(intptr_t allocated, CompletionAction action, bool force_marking=false)
base::VirtualMemory * marking_deque_memory_
void OldSpaceStep(intptr_t allocated)
static const intptr_t kMaxMarkingSpeed
DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking)
void RecordWriteOfCodeEntrySlow(JSFunction *host, Object **slot, Code *value)
static void RecordWriteFromCode(HeapObject *obj, Object **slot, Isolate *isolate)
static void DeactivateIncrementalWriteBarrierForSpace(PagedSpace *space)
INLINE(void VisitObject(Map *map, HeapObject *obj, int size))
void SetOldSpacePageFlags(MemoryChunk *chunk)
void RecordCodeTargetPatch(Code *host, Address pc, HeapObject *value)
INLINE(void RecordWriteIntoCode(HeapObject *obj, RelocInfo *rinfo, Object *value))
void NotifyIncompleteScanOfObject(int unscanned_bytes)
void BlackToGreyAndUnshift(HeapObject *obj, MarkBit mark_bit)
static const intptr_t kMarkingSpeedAccellerationInterval
INLINE(void ProcessMarkingDeque())
void Start(CompactionFlag flag=ALLOW_COMPACTION)
static const intptr_t kMarkingSpeedAccelleration
void StartMarking(CompactionFlag flag)
static const intptr_t kWriteBarriersInvokedThreshold
INLINE(bool BaseRecordWrite(HeapObject *obj, Object **slot, Object *value))
INLINE(void RecordWriteOfCodeEntry(JSFunction *host, Object **slot, Code *value))
void RecordWriteIntoCodeSlow(HeapObject *obj, RelocInfo *rinfo, Object *value)
void SetNewSpacePageFlags(NewSpacePage *chunk)
INLINE(void RecordWrite(HeapObject *obj, Object **slot, Object *value))
static const intptr_t kInitialMarkingSpeed
void MarkingComplete(CompletionAction action)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
#define DCHECK(condition)
Definition: logging.h:205
void PrintPID(const char *format,...)
Definition: utils.cc:96
const Register pc
byte * Address
Definition: globals.h:101
void PrintF(const char *format,...)
Definition: utils.cc:80
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20