V8 Project
store-buffer.h
Go to the documentation of this file.
1 // Copyright 2011 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_STORE_BUFFER_H_
6 #define V8_STORE_BUFFER_H_
7 
8 #include "src/allocation.h"
9 #include "src/base/logging.h"
11 #include "src/globals.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 class Page;
17 class PagedSpace;
18 class StoreBuffer;
19 
20 typedef void (*ObjectSlotCallback)(HeapObject** from, HeapObject* to);
21 
22 typedef void (StoreBuffer::*RegionCallback)(Address start, Address end,
23  ObjectSlotCallback slot_callback,
24  bool clear_maps);
25 
26 // Used to implement the write barrier by collecting addresses of pointers
27 // between spaces.
28 class StoreBuffer {
29  public:
30  explicit StoreBuffer(Heap* heap);
31 
32  static void StoreBufferOverflow(Isolate* isolate);
33 
34  inline Address TopAddress();
35 
36  void SetUp();
37  void TearDown();
38 
39  // This is used by the mutator to enter addresses into the store buffer.
40  inline void Mark(Address addr);
41 
42  // This is used by the heap traversal to enter the addresses into the store
43  // buffer that should still be in the store buffer after GC. It enters
44  // addresses directly into the old buffer because the GC starts by wiping the
45  // old buffer and thereafter only visits each cell once so there is no need
46  // to attempt to remove any dupes. During the first part of a GC we
47  // are using the store buffer to access the old spaces and at the same time
48  // we are rebuilding the store buffer using this function. There is, however
49  // no issue of overwriting the buffer we are iterating over, because this
50  // stage of the scavenge can only reduce the number of addresses in the store
51  // buffer (some objects are promoted so pointers to them do not need to be in
52  // the store buffer). The later parts of the GC scan the pages that are
53  // exempt from the store buffer and process the promotion queue. These steps
54  // can overflow this buffer. We check for this and on overflow we call the
55  // callback set up with the StoreBufferRebuildScope object.
56  inline void EnterDirectlyIntoStoreBuffer(Address addr);
57 
58  // Iterates over all pointers that go from old space to new space. It will
59  // delete the store buffer as it starts so the callback should reenter
60  // surviving old-to-new pointers into the store buffer to rebuild it.
62 
63  // Same as IteratePointersToNewSpace but additonally clears maps in objects
64  // referenced from the store buffer that do not contain a forwarding pointer.
66 
67  static const int kStoreBufferOverflowBit = 1 << (14 + kPointerSizeLog2);
69  static const int kStoreBufferLength = kStoreBufferSize / sizeof(Address);
70  static const int kOldStoreBufferLength = kStoreBufferLength * 16;
71  static const int kHashSetLengthLog2 = 12;
72  static const int kHashSetLength = 1 << kHashSetLengthLog2;
73 
74  void Compact();
75 
76  void GCPrologue();
77  void GCEpilogue();
78 
79  Object*** Limit() { return reinterpret_cast<Object***>(old_limit_); }
80  Object*** Start() { return reinterpret_cast<Object***>(old_start_); }
81  Object*** Top() { return reinterpret_cast<Object***>(old_top_); }
82  void SetTop(Object*** top) {
83  DCHECK(top >= Start());
84  DCHECK(top <= Limit());
85  old_top_ = reinterpret_cast<Address*>(top);
86  }
87 
90 
91  // Goes through the store buffer removing pointers to things that have
92  // been promoted. Rebuilds the store buffer completely if it overflowed.
93  void SortUniq();
94 
95  void EnsureSpace(intptr_t space_needed);
96  void Verify();
97 
98  bool PrepareForIteration();
99 
100 #ifdef DEBUG
101  void Clean();
102  // Slow, for asserts only.
103  bool CellIsInStoreBuffer(Address cell);
104 #endif
105 
106  void Filter(int flag);
107 
108  private:
110 
111  // The store buffer is divided up into a new buffer that is constantly being
112  // filled by mutator activity and an old buffer that is filled with the data
113  // from the new buffer after compression.
116 
122 
126  // The garbage collector iterates over many pointers to new space that are not
127  // handled by the store buffer. This flag indicates whether the pointers
128  // found by the callbacks should be added to the store buffer or not.
132 
134 
135  // Two hash sets used for filtering.
136  // If address is in the hash set then it is guaranteed to be in the
137  // old part of the store buffer.
141 
142  void ClearFilteringHashSets();
143 
144  bool SpaceAvailable(intptr_t space_needed);
145  void Uniq();
146  void ExemptPopularPages(int prime_sample_step, int threshold);
147 
148  // Set the map field of the object to NULL if contains a map.
149  inline void ClearDeadObject(HeapObject* object);
150 
151  void IteratePointersToNewSpace(ObjectSlotCallback callback, bool clear_maps);
152 
154  ObjectSlotCallback slot_callback,
155  bool clear_maps);
156 
157  // For each region of pointers on a page in use from an old space call
158  // visit_pointer_region callback.
159  // If either visit_pointer_region or callback can cause an allocation
160  // in old space and changes in allocation watermark then
161  // can_preallocate_during_iteration should be set to true.
163  RegionCallback region_callback,
164  ObjectSlotCallback slot_callback);
165 
167  bool clear_maps);
168 
169 #ifdef VERIFY_HEAP
170  void VerifyPointers(LargeObjectSpace* space);
171 #endif
172 
175 };
176 
177 
179  public:
180  explicit StoreBufferRebuildScope(Heap* heap, StoreBuffer* store_buffer,
181  StoreBufferCallback callback)
182  : store_buffer_(store_buffer),
183  stored_state_(store_buffer->store_buffer_rebuilding_enabled_),
184  stored_callback_(store_buffer->callback_) {
186  store_buffer_->callback_ = callback;
187  (*callback)(heap, NULL, kStoreBufferStartScanningPagesEvent);
188  }
189 
193  }
194 
195  private:
199 };
200 
201 
203  public:
205  : store_buffer_(store_buffer),
206  stored_state_(store_buffer->may_move_store_buffer_entries_) {
208  }
209 
212  }
213 
214  private:
217 };
218 }
219 } // namespace v8::internal
220 
221 #endif // V8_STORE_BUFFER_H_
DontMoveStoreBufferEntriesScope(StoreBuffer *store_buffer)
Definition: store-buffer.h:204
StoreBufferRebuildScope(Heap *heap, StoreBuffer *store_buffer, StoreBufferCallback callback)
Definition: store-buffer.h:180
static const int kHashSetLength
Definition: store-buffer.h:72
void EnterDirectlyIntoStoreBuffer(Address addr)
void FindPointersToNewSpaceInRegion(Address start, Address end, ObjectSlotCallback slot_callback, bool clear_maps)
static const int kStoreBufferOverflowBit
Definition: store-buffer.h:67
void ExemptPopularPages(int prime_sample_step, int threshold)
void IteratePointersToNewSpace(ObjectSlotCallback callback)
StoreBufferCallback callback_
Definition: store-buffer.h:130
base::VirtualMemory * virtual_memory_
Definition: store-buffer.h:133
void IteratePointersInStoreBuffer(ObjectSlotCallback slot_callback, bool clear_maps)
bool SpaceAvailable(intptr_t space_needed)
static void StoreBufferOverflow(Isolate *isolate)
Definition: store-buffer.cc:98
static const int kOldStoreBufferLength
Definition: store-buffer.h:70
void IteratePointersToNewSpaceAndClearMaps(ObjectSlotCallback callback)
void Mark(Address addr)
static const int kStoreBufferLength
Definition: store-buffer.h:69
void IteratePointersOnPage(PagedSpace *space, Page *page, RegionCallback region_callback, ObjectSlotCallback slot_callback)
void EnsureSpace(intptr_t space_needed)
void ClearDeadObject(HeapObject *object)
static const int kStoreBufferSize
Definition: store-buffer.h:68
static const int kHashSetLengthLog2
Definition: store-buffer.h:71
void SetTop(Object ***top)
Definition: store-buffer.h:82
base::VirtualMemory * old_virtual_memory_
Definition: store-buffer.h:121
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 the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
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)
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 NULL
#define DCHECK(condition)
Definition: logging.h:205
void(* ObjectSlotCallback)(HeapObject **from, HeapObject *to)
Definition: store-buffer.h:20
const int kPointerSizeLog2
Definition: globals.h:147
@ kStoreBufferStartScanningPagesEvent
Definition: globals.h:495
void(StoreBuffer::* RegionCallback)(Address start, Address end, ObjectSlotCallback slot_callback, bool clear_maps)
Definition: store-buffer.h:22
byte * Address
Definition: globals.h:101
void(* StoreBufferCallback)(Heap *heap, MemoryChunk *page, StoreBufferEvent event)
Definition: globals.h:500
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20