diff options
Diffstat (limited to 'deps/v8/src/heap/store-buffer.h')
-rw-r--r-- | deps/v8/src/heap/store-buffer.h | 93 |
1 files changed, 82 insertions, 11 deletions
diff --git a/deps/v8/src/heap/store-buffer.h b/deps/v8/src/heap/store-buffer.h index 09faf4dcbd..be46cb3242 100644 --- a/deps/v8/src/heap/store-buffer.h +++ b/deps/v8/src/heap/store-buffer.h @@ -24,7 +24,9 @@ namespace internal { // slots are moved to the remembered set. class StoreBuffer { public: - static const int kStoreBufferSize = 1 << (14 + kPointerSizeLog2); + enum StoreBufferMode { IN_GC, NOT_IN_GC }; + + static const int kStoreBufferSize = 1 << (11 + kPointerSizeLog2); static const int kStoreBufferMask = kStoreBufferSize - 1; static const int kStoreBuffers = 2; static const intptr_t kDeletionTag = 1; @@ -63,22 +65,77 @@ class StoreBuffer { // If we only want to delete a single slot, end should be set to null which // will be written into the second field. When processing the store buffer // the more efficient Remove method will be called in this case. - void DeleteEntry(Address start, Address end = nullptr); + void DeleteEntry(Address start, Address end = nullptr) { + // Deletions coming from the GC are directly deleted from the remembered + // set. Deletions coming from the runtime are added to the store buffer + // to allow concurrent processing. + deletion_callback(this, start, end); + } + + static void DeleteDuringGarbageCollection(StoreBuffer* store_buffer, + Address start, Address end) { + // In GC the store buffer has to be empty at any time. + DCHECK(store_buffer->Empty()); + DCHECK(store_buffer->mode() != StoreBuffer::NOT_IN_GC); + Page* page = Page::FromAddress(start); + if (end) { + RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end, + SlotSet::PREFREE_EMPTY_BUCKETS); + } else { + RememberedSet<OLD_TO_NEW>::Remove(page, start); + } + } + + static void DeleteDuringRuntime(StoreBuffer* store_buffer, Address start, + Address end) { + DCHECK(store_buffer->mode() == StoreBuffer::NOT_IN_GC); + store_buffer->InsertDeletionIntoStoreBuffer(start, end); + } + + void InsertDeletionIntoStoreBuffer(Address start, Address end) { + if (top_ + sizeof(Address) * 2 > limit_[current_]) { + StoreBufferOverflow(heap_->isolate()); + } + *top_ = MarkDeletionAddress(start); + top_++; + *top_ = end; + top_++; + } + + static void InsertDuringGarbageCollection(StoreBuffer* store_buffer, + Address slot) { + DCHECK(store_buffer->mode() != StoreBuffer::NOT_IN_GC); + RememberedSet<OLD_TO_NEW>::Insert(Page::FromAddress(slot), slot); + } + + static void InsertDuringRuntime(StoreBuffer* store_buffer, Address slot) { + DCHECK(store_buffer->mode() == StoreBuffer::NOT_IN_GC); + store_buffer->InsertIntoStoreBuffer(slot); + } + + void InsertIntoStoreBuffer(Address slot) { + if (top_ + sizeof(Address) > limit_[current_]) { + StoreBufferOverflow(heap_->isolate()); + } + *top_ = slot; + top_++; + } void InsertEntry(Address slot) { // Insertions coming from the GC are directly inserted into the remembered // set. Insertions coming from the runtime are added to the store buffer to // allow concurrent processing. - if (heap_->gc_state() == Heap::NOT_IN_GC) { - if (top_ + sizeof(Address) > limit_[current_]) { - StoreBufferOverflow(heap_->isolate()); - } - *top_ = slot; - top_++; + insertion_callback(this, slot); + } + + void SetMode(StoreBufferMode mode) { + mode_ = mode; + if (mode == NOT_IN_GC) { + insertion_callback = &InsertDuringRuntime; + deletion_callback = &DeleteDuringRuntime; } else { - // In GC the store buffer has to be empty at any time. - DCHECK(Empty()); - RememberedSet<OLD_TO_NEW>::Insert(Page::FromAddress(slot), slot); + insertion_callback = &InsertDuringGarbageCollection; + deletion_callback = &DeleteDuringGarbageCollection; } } @@ -95,6 +152,8 @@ class StoreBuffer { return top_ == start_[current_]; } + Heap* heap() { return heap_; } + private: // There are two store buffers. If one store buffer fills up, the main thread // publishes the top pointer of the store buffer that needs processing in its @@ -119,6 +178,8 @@ class StoreBuffer { DISALLOW_COPY_AND_ASSIGN(Task); }; + StoreBufferMode mode() const { return mode_; } + void FlipStoreBuffers(); Heap* heap_; @@ -142,7 +203,17 @@ class StoreBuffer { // Points to the current buffer in use. int current_; + // During GC, entries are directly added to the remembered set without + // going through the store buffer. This is signaled by a special + // IN_GC mode. + StoreBufferMode mode_; + base::VirtualMemory* virtual_memory_; + + // Callbacks are more efficient than reading out the gc state for every + // store buffer operation. + std::function<void(StoreBuffer*, Address)> insertion_callback; + std::function<void(StoreBuffer*, Address, Address)> deletion_callback; }; } // namespace internal |