Commit 866d5b2d authored by hpayer's avatar hpayer Committed by Commit bot

[heap] Ensure consistency between store buffer mode and moving all entries to remembered set.

BUG=chromium:673308

Review-Url: https://codereview.chromium.org/2696563003
Cr-Commit-Position: refs/heads/master@{#43159}
parent 2d9b9faf
......@@ -295,7 +295,6 @@ GarbageCollector Heap::SelectGarbageCollector(AllocationSpace space,
void Heap::SetGCState(HeapState state) {
gc_state_ = state;
store_buffer_->SetMode(gc_state_);
}
// TODO(1238405): Combine the infrastructure for --heap-stats and
......@@ -447,7 +446,6 @@ void Heap::GarbageCollectionPrologue() {
}
CheckNewSpaceExpansionCriteria();
UpdateNewSpaceAllocationCounter();
store_buffer()->MoveAllEntriesToRememberedSet();
}
size_t Heap::SizeOfObjects() {
......@@ -515,6 +513,22 @@ void Heap::MergeAllocationSitePretenuringFeedback(
}
}
class Heap::SkipStoreBufferScope {
public:
explicit SkipStoreBufferScope(StoreBuffer* store_buffer)
: store_buffer_(store_buffer) {
store_buffer_->MoveAllEntriesToRememberedSet();
store_buffer_->SetMode(StoreBuffer::IN_GC);
}
~SkipStoreBufferScope() {
DCHECK(store_buffer_->Empty());
store_buffer_->SetMode(StoreBuffer::NOT_IN_GC);
}
private:
StoreBuffer* store_buffer_;
};
class Heap::PretenuringScope {
public:
......@@ -1324,6 +1338,7 @@ bool Heap::PerformGarbageCollection(
{
Heap::PretenuringScope pretenuring_scope(this);
Heap::SkipStoreBufferScope skip_store_buffer_scope(store_buffer_);
switch (collector) {
case MARK_COMPACTOR:
......
......@@ -1523,6 +1523,7 @@ class Heap {
GarbageCollectionReason gc_reason);
private:
class SkipStoreBufferScope;
class PretenuringScope;
// External strings table is a place where all external strings are
......
......@@ -16,7 +16,11 @@ namespace v8 {
namespace internal {
StoreBuffer::StoreBuffer(Heap* heap)
: heap_(heap), top_(nullptr), current_(0), virtual_memory_(nullptr) {
: heap_(heap),
top_(nullptr),
current_(0),
mode_(NOT_IN_GC),
virtual_memory_(nullptr) {
for (int i = 0; i < kStoreBuffers; i++) {
start_[i] = nullptr;
limit_[i] = nullptr;
......
......@@ -24,6 +24,8 @@ namespace internal {
// slots are moved to the remembered set.
class StoreBuffer {
public:
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;
......@@ -74,7 +76,7 @@ class StoreBuffer {
Address start, Address end) {
// In GC the store buffer has to be empty at any time.
DCHECK(store_buffer->Empty());
DCHECK(store_buffer->heap()->gc_state() != Heap::NOT_IN_GC);
DCHECK(store_buffer->mode() != StoreBuffer::NOT_IN_GC);
Page* page = Page::FromAddress(start);
if (end) {
RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end,
......@@ -86,7 +88,7 @@ class StoreBuffer {
static void DeleteDuringRuntime(StoreBuffer* store_buffer, Address start,
Address end) {
DCHECK(store_buffer->heap()->gc_state() == Heap::NOT_IN_GC);
DCHECK(store_buffer->mode() == StoreBuffer::NOT_IN_GC);
store_buffer->InsertDeletionIntoStoreBuffer(start, end);
}
......@@ -102,12 +104,12 @@ class StoreBuffer {
static void InsertDuringGarbageCollection(StoreBuffer* store_buffer,
Address slot) {
DCHECK(store_buffer->heap()->gc_state() != Heap::NOT_IN_GC);
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->heap()->gc_state() == Heap::NOT_IN_GC);
DCHECK(store_buffer->mode() == StoreBuffer::NOT_IN_GC);
store_buffer->InsertIntoStoreBuffer(slot);
}
......@@ -126,8 +128,9 @@ class StoreBuffer {
insertion_callback(this, slot);
}
void SetMode(Heap::HeapState state) {
if (state == Heap::NOT_IN_GC) {
void SetMode(StoreBufferMode mode) {
mode_ = mode;
if (mode == NOT_IN_GC) {
insertion_callback = &InsertDuringRuntime;
deletion_callback = &DeleteDuringRuntime;
} else {
......@@ -175,6 +178,8 @@ class StoreBuffer {
DISALLOW_COPY_AND_ASSIGN(Task);
};
StoreBufferMode mode() const { return mode_; }
void FlipStoreBuffers();
Heap* heap_;
......@@ -198,6 +203,11 @@ 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment