v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
incremental-marking.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_INCREMENTAL_MARKING_H_
29 #define V8_INCREMENTAL_MARKING_H_
30 
31 
32 #include "execution.h"
33 #include "mark-compact.h"
34 #include "objects.h"
35 
36 namespace v8 {
37 namespace internal {
38 
39 
41  public:
42  enum State {
47  };
48 
52  };
53 
54  explicit IncrementalMarking(Heap* heap);
55 
56  static void Initialize();
57 
58  void TearDown();
59 
61  ASSERT(state_ == STOPPED || FLAG_incremental_marking);
62  return state_;
63  }
64 
65  bool should_hurry() { return should_hurry_; }
66  void set_should_hurry(bool val) { should_hurry_ = val; }
67 
68  inline bool IsStopped() { return state() == STOPPED; }
69 
70  INLINE(bool IsMarking()) { return state() >= MARKING; }
71 
72  inline bool IsMarkingIncomplete() { return state() == MARKING; }
73 
74  inline bool IsComplete() { return state() == COMPLETE; }
75 
76  bool WorthActivating();
77 
79 
81 
82  void Stop();
83 
84  void PrepareForScavenge();
85 
87 
88  void Hurry();
89 
90  void Finalize();
91 
92  void Abort();
93 
94  void MarkingComplete(CompletionAction action);
95 
96  // It's hard to know how much work the incremental marker should do to make
97  // progress in the face of the mutator creating new work for it. We start
98  // of at a moderate rate of work and gradually increase the speed of the
99  // incremental marker until it completes.
100  // Do some marking every time this much memory has been allocated or that many
101  // heavy (color-checking) write barriers have been invoked.
102  static const intptr_t kAllocatedThreshold = 65536;
103  static const intptr_t kWriteBarriersInvokedThreshold = 32768;
104  // Start off by marking this many times more memory than has been allocated.
105  static const intptr_t kInitialMarkingSpeed = 1;
106  // But if we are promoting a lot of data we need to mark faster to keep up
107  // with the data that is entering the old space through promotion.
108  static const intptr_t kFastMarking = 3;
109  // After this many steps we increase the marking/allocating factor.
110  static const intptr_t kMarkingSpeedAccellerationInterval = 1024;
111  // This is how much we increase the marking/allocating factor by.
112  static const intptr_t kMarkingSpeedAccelleration = 2;
113  static const intptr_t kMaxMarkingSpeed = 1000;
114 
115  void OldSpaceStep(intptr_t allocated);
116 
117  void Step(intptr_t allocated, CompletionAction action);
118 
119  inline void RestartIfNotMarking() {
120  if (state_ == COMPLETE) {
121  state_ = MARKING;
122  if (FLAG_trace_incremental_marking) {
123  PrintF("[IncrementalMarking] Restarting (new grey objects)\n");
124  }
125  }
126  }
127 
128  static void RecordWriteFromCode(HeapObject* obj,
129  Object** slot,
130  Isolate* isolate);
131 
132  // Record a slot for compaction. Returns false for objects that are
133  // guaranteed to be rescanned or not guaranteed to survive.
134  //
135  // No slots in white objects should be recorded, as some slots are typed and
136  // cannot be interpreted correctly if the underlying object does not survive
137  // the incremental cycle (stays white).
138  INLINE(bool BaseRecordWrite(HeapObject* obj, Object** slot, Object* value));
139  INLINE(void RecordWrite(HeapObject* obj, Object** slot, Object* value));
140  INLINE(void RecordWriteIntoCode(HeapObject* obj,
141  RelocInfo* rinfo,
142  Object* value));
143  INLINE(void RecordWriteOfCodeEntry(JSFunction* host,
144  Object** slot,
145  Code* value));
146 
147 
148  void RecordWriteSlow(HeapObject* obj, Object** slot, Object* value);
150  RelocInfo* rinfo,
151  Object* value);
152  void RecordWriteOfCodeEntrySlow(JSFunction* host, Object** slot, Code* value);
153  void RecordCodeTargetPatch(Code* host, Address pc, HeapObject* value);
155 
156  inline void RecordWrites(HeapObject* obj);
157 
158  inline void BlackToGreyAndUnshift(HeapObject* obj, MarkBit mark_bit);
159 
160  inline void WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit);
161 
162  inline int steps_count() {
163  return steps_count_;
164  }
165 
166  inline double steps_took() {
167  return steps_took_;
168  }
169 
170  inline double longest_step() {
171  return longest_step_;
172  }
173 
175  return steps_count_since_last_gc_;
176  }
177 
178  inline double steps_took_since_last_gc() {
179  return steps_took_since_last_gc_;
180  }
181 
182  inline void SetOldSpacePageFlags(MemoryChunk* chunk) {
183  SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting());
184  }
185 
186  inline void SetNewSpacePageFlags(NewSpacePage* chunk) {
187  SetNewSpacePageFlags(chunk, IsMarking());
188  }
189 
190  MarkingDeque* marking_deque() { return &marking_deque_; }
191 
192  bool IsCompacting() { return IsMarking() && is_compacting_; }
193 
194  void ActivateGeneratedStub(Code* stub);
195 
197  if (IsMarking()) {
198  if (marking_speed_ < kFastMarking) {
199  if (FLAG_trace_gc) {
200  PrintPID("Increasing marking speed to %d "
201  "due to high promotion rate\n",
202  static_cast<int>(kFastMarking));
203  }
204  marking_speed_ = kFastMarking;
205  }
206  }
207  }
208 
210  no_marking_scope_depth_++;
211  }
212 
214  no_marking_scope_depth_--;
215  }
216 
217  void UncommitMarkingDeque();
218 
219  void NotifyIncompleteScanOfObject(int unscanned_bytes) {
220  unscanned_bytes_of_large_object_ = unscanned_bytes;
221  }
222 
223  private:
224  int64_t SpaceLeftInOldSpace();
225 
226  void ResetStepCounters();
227 
228  void StartMarking(CompactionFlag flag);
229 
230  void ActivateIncrementalWriteBarrier(PagedSpace* space);
231  static void ActivateIncrementalWriteBarrier(NewSpace* space);
232  void ActivateIncrementalWriteBarrier();
233 
234  static void DeactivateIncrementalWriteBarrierForSpace(PagedSpace* space);
235  static void DeactivateIncrementalWriteBarrierForSpace(NewSpace* space);
236  void DeactivateIncrementalWriteBarrier();
237 
238  static void SetOldSpacePageFlags(MemoryChunk* chunk,
239  bool is_marking,
240  bool is_compacting);
241 
242  static void SetNewSpacePageFlags(NewSpacePage* chunk, bool is_marking);
243 
244  void EnsureMarkingDequeIsCommitted();
245 
246  INLINE(void ProcessMarkingDeque());
247 
248  INLINE(void ProcessMarkingDeque(intptr_t bytes_to_process));
249 
250  INLINE(void VisitObject(Map* map, HeapObject* obj, int size));
251 
252  Heap* heap_;
253 
254  State state_;
255  bool is_compacting_;
256 
257  VirtualMemory* marking_deque_memory_;
258  bool marking_deque_memory_committed_;
259  MarkingDeque marking_deque_;
260 
261  int steps_count_;
262  double steps_took_;
263  double longest_step_;
264  int64_t old_generation_space_available_at_start_of_incremental_;
265  int64_t old_generation_space_used_at_start_of_incremental_;
266  int steps_count_since_last_gc_;
267  double steps_took_since_last_gc_;
268  int64_t bytes_rescanned_;
269  bool should_hurry_;
270  int marking_speed_;
271  intptr_t bytes_scanned_;
272  intptr_t allocated_;
273  intptr_t write_barriers_invoked_since_last_step_;
274 
275  int no_marking_scope_depth_;
276 
277  int unscanned_bytes_of_large_object_;
278 
279  DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking);
280 };
281 
282 } } // namespace v8::internal
283 
284 #endif // V8_INCREMENTAL_MARKING_H_
byte * Address
Definition: globals.h:186
void PrintF(const char *format,...)
Definition: v8utils.cc:40
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
Definition: flags.cc:350
static const intptr_t kWriteBarriersInvokedThreshold
void SetNewSpacePageFlags(NewSpacePage *chunk)
#define ASSERT(condition)
Definition: checks.h:329
static const intptr_t kMarkingSpeedAccelleration
void RecordWriteIntoCodeSlow(HeapObject *obj, RelocInfo *rinfo, Object *value)
void Step(intptr_t allocated, CompletionAction action)
void RecordCodeTargetPatch(Code *host, Address pc, HeapObject *value)
static const intptr_t kMarkingSpeedAccellerationInterval
static const intptr_t kMaxMarkingSpeed
kInstanceClassNameOffset flag
Definition: objects-inl.h:5115
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
Definition: flags.cc:211
void MarkingComplete(CompletionAction action)
void Start(CompactionFlag flag=ALLOW_COMPACTION)
void RecordWriteOfCodeEntrySlow(JSFunction *host, Object **slot, Code *value)
const Register pc
void SetOldSpacePageFlags(MemoryChunk *chunk)
void WhiteToGreyAndPush(HeapObject *obj, MarkBit mark_bit)
void PrintPID(const char *format,...)
Definition: v8utils.cc:56
static void RecordWriteFromCode(HeapObject *obj, Object **slot, Isolate *isolate)
void RecordWriteSlow(HeapObject *obj, Object **slot, Object *value)
HeapObject * obj
static const intptr_t kAllocatedThreshold
void OldSpaceStep(intptr_t allocated)
void NotifyIncompleteScanOfObject(int unscanned_bytes)
static const intptr_t kInitialMarkingSpeed
void BlackToGreyAndUnshift(HeapObject *obj, MarkBit mark_bit)