blob: e7e9c985eb4c79c544033e722aed9d1f21eb4115 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2011 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004
5#ifndef V8_STORE_BUFFER_H_
6#define V8_STORE_BUFFER_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/allocation.h"
9#include "src/base/logging.h"
10#include "src/base/platform/platform.h"
11#include "src/globals.h"
Ben Murdoch109988c2016-05-18 11:27:45 +010012#include "src/heap/slot-set.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +010013
14namespace v8 {
15namespace internal {
16
Ben Murdoch109988c2016-05-18 11:27:45 +010017// Intermediate buffer that accumulates old-to-new stores from the generated
18// code. On buffer overflow the slots are moved to the remembered set.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010019class StoreBuffer {
20 public:
21 explicit StoreBuffer(Heap* heap);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010022 static void StoreBufferOverflow(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010023 void SetUp();
24 void TearDown();
25
Ben Murdoch3ef787d2012-04-12 10:51:47 +010026 static const int kStoreBufferOverflowBit = 1 << (14 + kPointerSizeLog2);
27 static const int kStoreBufferSize = kStoreBufferOverflowBit;
28 static const int kStoreBufferLength = kStoreBufferSize / sizeof(Address);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010029
Ben Murdoch109988c2016-05-18 11:27:45 +010030 void MoveEntriesToRememberedSet();
Ben Murdoch014dc512016-03-22 12:00:34 +000031
Ben Murdoch3ef787d2012-04-12 10:51:47 +010032 private:
33 Heap* heap_;
34
Ben Murdoch109988c2016-05-18 11:27:45 +010035 // The start and the limit of the buffer that contains store slots
36 // added from the generated code.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010037 Address* start_;
38 Address* limit_;
39
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040 base::VirtualMemory* virtual_memory_;
Ben Murdoch014dc512016-03-22 12:00:34 +000041};
42
43
Ben Murdoch109988c2016-05-18 11:27:45 +010044class LocalStoreBuffer BASE_EMBEDDED {
Ben Murdoch014dc512016-03-22 12:00:34 +000045 public:
Ben Murdoch109988c2016-05-18 11:27:45 +010046 explicit LocalStoreBuffer(Heap* heap)
47 : top_(new Node(nullptr)), heap_(heap) {}
Ben Murdoch014dc512016-03-22 12:00:34 +000048
Ben Murdoch109988c2016-05-18 11:27:45 +010049 ~LocalStoreBuffer() {
50 Node* current = top_;
51 while (current != nullptr) {
52 Node* tmp = current->next;
53 delete current;
54 current = tmp;
55 }
56 }
57
58 inline void Record(Address addr);
59 inline void Process(StoreBuffer* store_buffer);
Ben Murdoch014dc512016-03-22 12:00:34 +000060
61 private:
Ben Murdoch109988c2016-05-18 11:27:45 +010062 static const int kBufferSize = 16 * KB;
Ben Murdoch014dc512016-03-22 12:00:34 +000063
Ben Murdoch109988c2016-05-18 11:27:45 +010064 struct Node : Malloced {
65 explicit Node(Node* next_node) : next(next_node), count(0) {}
66
67 inline bool is_full() { return count == kBufferSize; }
68
69 Node* next;
70 Address buffer[kBufferSize];
71 int count;
72 };
73
74 Node* top_;
75 Heap* heap_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +010076};
77
Ben Murdoch014dc512016-03-22 12:00:34 +000078} // namespace internal
79} // namespace v8
Ben Murdoch3ef787d2012-04-12 10:51:47 +010080
81#endif // V8_STORE_BUFFER_H_