| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 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 | 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_STORE_BUFFER_H_ | 5 #ifndef V8_STORE_BUFFER_H_ |
| 6 #define V8_STORE_BUFFER_H_ | 6 #define V8_STORE_BUFFER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| 11 #include "src/cancelable-task.h" | 11 #include "src/cancelable-task.h" |
| 12 #include "src/globals.h" | 12 #include "src/globals.h" |
| 13 #include "src/heap/remembered-set.h" |
| 13 #include "src/heap/slot-set.h" | 14 #include "src/heap/slot-set.h" |
| 14 | 15 |
| 15 namespace v8 { | 16 namespace v8 { |
| 16 namespace internal { | 17 namespace internal { |
| 17 | 18 |
| 18 // Intermediate buffer that accumulates old-to-new stores from the generated | 19 // Intermediate buffer that accumulates old-to-new stores from the generated |
| 19 // code. Moreover, it stores invalid old-to-new slots with two entries. | 20 // code. Moreover, it stores invalid old-to-new slots with two entries. |
| 20 // The first is a tagged address of the start of the invalid range, the second | 21 // The first is a tagged address of the start of the invalid range, the second |
| 21 // one is the end address of the invalid range or null if there is just one slot | 22 // one is the end address of the invalid range or null if there is just one slot |
| 22 // that needs to be removed from the remembered set. On buffer overflow the | 23 // that needs to be removed from the remembered set. On buffer overflow the |
| 23 // slots are moved to the remembered set. | 24 // slots are moved to the remembered set. |
| 24 class StoreBuffer { | 25 class StoreBuffer { |
| 25 public: | 26 public: |
| 26 static const int kStoreBufferSize = 1 << (14 + kPointerSizeLog2); | 27 static const int kStoreBufferSize = 1 << (14 + kPointerSizeLog2); |
| 27 static const int kStoreBufferMask = kStoreBufferSize - 1; | 28 static const int kStoreBufferMask = kStoreBufferSize - 1; |
| 28 static const int kStoreBuffers = 2; | 29 static const int kStoreBuffers = 2; |
| 29 static const intptr_t kDeletionTag = 1; | 30 static const intptr_t kDeletionTag = 1; |
| 30 | 31 |
| 31 static void StoreBufferOverflow(Isolate* isolate); | 32 V8_EXPORT_PRIVATE static void StoreBufferOverflow(Isolate* isolate); |
| 32 | 33 |
| 33 explicit StoreBuffer(Heap* heap); | 34 explicit StoreBuffer(Heap* heap); |
| 34 void SetUp(); | 35 void SetUp(); |
| 35 void TearDown(); | 36 void TearDown(); |
| 36 | 37 |
| 37 // Used to add entries from generated code. | 38 // Used to add entries from generated code. |
| 38 inline Address* top_address() { return reinterpret_cast<Address*>(&top_); } | 39 inline Address* top_address() { return reinterpret_cast<Address*>(&top_); } |
| 39 | 40 |
| 40 // Moves entries from a specific store buffer to the remembered set. This | 41 // Moves entries from a specific store buffer to the remembered set. This |
| 41 // method takes a lock. | 42 // method takes a lock. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 inline Address UnmarkDeletionAddress(Address address) { | 58 inline Address UnmarkDeletionAddress(Address address) { |
| 58 return reinterpret_cast<Address>(reinterpret_cast<intptr_t>(address) & | 59 return reinterpret_cast<Address>(reinterpret_cast<intptr_t>(address) & |
| 59 ~kDeletionTag); | 60 ~kDeletionTag); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // If we only want to delete a single slot, end should be set to null which | 63 // If we only want to delete a single slot, end should be set to null which |
| 63 // will be written into the second field. When processing the store buffer | 64 // will be written into the second field. When processing the store buffer |
| 64 // the more efficient Remove method will be called in this case. | 65 // the more efficient Remove method will be called in this case. |
| 65 void DeleteEntry(Address start, Address end = nullptr); | 66 void DeleteEntry(Address start, Address end = nullptr); |
| 66 | 67 |
| 68 void InsertEntry(Address slot) { |
| 69 // Insertions coming from the GC are directly inserted into the remembered |
| 70 // set. Insertions coming from the runtime are added to the store buffer to |
| 71 // allow concurrent processing. |
| 72 if (heap_->gc_state() == Heap::NOT_IN_GC) { |
| 73 if (top_ + sizeof(Address) > limit_[current_]) { |
| 74 StoreBufferOverflow(heap_->isolate()); |
| 75 } |
| 76 *top_ = slot; |
| 77 top_++; |
| 78 } else { |
| 79 // In GC the store buffer has to be empty at any time. |
| 80 DCHECK(Empty()); |
| 81 RememberedSet<OLD_TO_NEW>::Insert(Page::FromAddress(slot), slot); |
| 82 } |
| 83 } |
| 84 |
| 67 // Used by the concurrent processing thread to transfer entries from the | 85 // Used by the concurrent processing thread to transfer entries from the |
| 68 // store buffer to the remembered set. | 86 // store buffer to the remembered set. |
| 69 void ConcurrentlyProcessStoreBuffer(); | 87 void ConcurrentlyProcessStoreBuffer(); |
| 70 | 88 |
| 71 bool Empty() { | 89 bool Empty() { |
| 72 for (int i = 0; i < kStoreBuffers; i++) { | 90 for (int i = 0; i < kStoreBuffers; i++) { |
| 73 if (lazy_top_[i]) { | 91 if (lazy_top_[i]) { |
| 74 return false; | 92 return false; |
| 75 } | 93 } |
| 76 } | 94 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // Points to the current buffer in use. | 142 // Points to the current buffer in use. |
| 125 int current_; | 143 int current_; |
| 126 | 144 |
| 127 base::VirtualMemory* virtual_memory_; | 145 base::VirtualMemory* virtual_memory_; |
| 128 }; | 146 }; |
| 129 | 147 |
| 130 } // namespace internal | 148 } // namespace internal |
| 131 } // namespace v8 | 149 } // namespace v8 |
| 132 | 150 |
| 133 #endif // V8_STORE_BUFFER_H_ | 151 #endif // V8_STORE_BUFFER_H_ |
| OLD | NEW |