store-buffer.cc 2.41 KB
Newer Older
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#include "src/heap/store-buffer.h"
6

7
#include <algorithm>
8

9
#include "src/counters.h"
10
#include "src/heap/incremental-marking.h"
11 12
#include "src/isolate.h"
#include "src/objects-inl.h"
13
#include "src/v8.h"
14 15 16 17 18

namespace v8 {
namespace internal {

StoreBuffer::StoreBuffer(Heap* heap)
19 20 21 22 23
    : heap_(heap),
      top_(nullptr),
      start_(nullptr),
      limit_(nullptr),
      virtual_memory_(nullptr) {}
24

25
void StoreBuffer::SetUp() {
26 27 28
  // Allocate 3x the buffer size, so that we can start the new store buffer
  // aligned to 2x the size.  This lets us use a bit test to detect the end of
  // the area.
29
  virtual_memory_ = new base::VirtualMemory(kStoreBufferSize * 2);
30 31
  uintptr_t start_as_int =
      reinterpret_cast<uintptr_t>(virtual_memory_->address());
32
  start_ = reinterpret_cast<Address*>(RoundUp(start_as_int, kStoreBufferSize));
33 34
  limit_ = start_ + (kStoreBufferSize / kPointerSize);

35 36
  DCHECK(reinterpret_cast<Address>(start_) >= virtual_memory_->address());
  DCHECK(reinterpret_cast<Address>(limit_) >= virtual_memory_->address());
37 38
  Address* vm_limit = reinterpret_cast<Address*>(
      reinterpret_cast<char*>(virtual_memory_->address()) +
39
      virtual_memory_->size());
40 41
  DCHECK(start_ <= vm_limit);
  DCHECK(limit_ <= vm_limit);
42
  USE(vm_limit);
43
  DCHECK((reinterpret_cast<uintptr_t>(limit_) & kStoreBufferMask) == 0);
44

45 46 47 48 49
  if (!virtual_memory_->Commit(reinterpret_cast<Address>(start_),
                               kStoreBufferSize,
                               false)) {  // Not executable.
    V8::FatalProcessOutOfMemory("StoreBuffer::SetUp");
  }
50
  top_ = start_;
51 52 53 54 55
}


void StoreBuffer::TearDown() {
  delete virtual_memory_;
56
  top_ = start_ = limit_ = nullptr;
57 58 59 60
}


void StoreBuffer::StoreBufferOverflow(Isolate* isolate) {
61
  isolate->heap()->store_buffer()->MoveEntriesToRememberedSet();
62
  isolate->counters()->store_buffer_overflows()->Increment();
63 64
}

65
void StoreBuffer::MoveEntriesToRememberedSet() {
66 67 68
  if (top_ == start_) return;
  DCHECK(top_ <= limit_);
  for (Address* current = start_; current < top_; current++) {
ulan's avatar
ulan committed
69 70
    DCHECK(!heap_->code_space()->Contains(*current));
    Address addr = *current;
71 72
    Page* page = Page::FromAnyPointerAddress(heap_, addr);
    RememberedSet<OLD_TO_NEW>::Insert(page, addr);
73
  }
74
  top_ = start_;
75 76
}

77 78
}  // namespace internal
}  // namespace v8