Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: src/heap/slots-buffer.h

Issue 1343043002: [heap] Move slots buffer into a separate file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_SLOTS_BUFFER_H_
6 #define V8_SLOTS_BUFFER_H_
7
8 #include "src/objects.h"
9
10 namespace v8 {
11 namespace internal {
12
13 // Forward declarations.
14 class SlotsBuffer;
15
16
17 class SlotsBufferAllocator {
18 public:
19 SlotsBuffer* AllocateBuffer(SlotsBuffer* next_buffer);
20 void DeallocateBuffer(SlotsBuffer* buffer);
21
22 void DeallocateChain(SlotsBuffer** buffer_address);
23 };
24
25
26 // SlotsBuffer records a sequence of slots that has to be updated
27 // after live objects were relocated from evacuation candidates.
28 // All slots are either untyped or typed:
29 // - Untyped slots are expected to contain a tagged object pointer.
30 // They are recorded by an address.
31 // - Typed slots are expected to contain an encoded pointer to a heap
32 // object where the way of encoding depends on the type of the slot.
33 // They are recorded as a pair (SlotType, slot address).
34 // We assume that zero-page is never mapped this allows us to distinguish
35 // untyped slots from typed slots during iteration by a simple comparison:
36 // if element of slots buffer is less than NUMBER_OF_SLOT_TYPES then it
37 // is the first element of typed slot's pair.
38 class SlotsBuffer {
39 public:
40 typedef Object** ObjectSlot;
41
42 explicit SlotsBuffer(SlotsBuffer* next_buffer)
43 : idx_(0), chain_length_(1), next_(next_buffer) {
44 if (next_ != NULL) {
45 chain_length_ = next_->chain_length_ + 1;
46 }
47 }
48
49 ~SlotsBuffer() {}
50
51 void Add(ObjectSlot slot) {
52 DCHECK(0 <= idx_ && idx_ < kNumberOfElements);
53 #ifdef DEBUG
54 if (slot >= reinterpret_cast<ObjectSlot>(NUMBER_OF_SLOT_TYPES)) {
55 DCHECK_NOT_NULL(*slot);
56 }
57 #endif
58 slots_[idx_++] = slot;
59 }
60
61 ObjectSlot Get(intptr_t i) {
62 DCHECK(i >= 0 && i < kNumberOfElements);
63 return slots_[i];
64 }
65
66 size_t Size() {
67 DCHECK(idx_ <= kNumberOfElements);
68 return idx_;
69 }
70
71 enum SlotType {
72 EMBEDDED_OBJECT_SLOT,
73 OBJECT_SLOT,
74 RELOCATED_CODE_OBJECT,
75 CELL_TARGET_SLOT,
76 CODE_TARGET_SLOT,
77 CODE_ENTRY_SLOT,
78 DEBUG_TARGET_SLOT,
79 NUMBER_OF_SLOT_TYPES
80 };
81
82 static const char* SlotTypeToString(SlotType type) {
83 switch (type) {
84 case EMBEDDED_OBJECT_SLOT:
85 return "EMBEDDED_OBJECT_SLOT";
86 case OBJECT_SLOT:
87 return "OBJECT_SLOT";
88 case RELOCATED_CODE_OBJECT:
89 return "RELOCATED_CODE_OBJECT";
90 case CELL_TARGET_SLOT:
91 return "CELL_TARGET_SLOT";
92 case CODE_TARGET_SLOT:
93 return "CODE_TARGET_SLOT";
94 case CODE_ENTRY_SLOT:
95 return "CODE_ENTRY_SLOT";
96 case DEBUG_TARGET_SLOT:
97 return "DEBUG_TARGET_SLOT";
98 case NUMBER_OF_SLOT_TYPES:
99 return "NUMBER_OF_SLOT_TYPES";
100 }
101 return "UNKNOWN SlotType";
102 }
103
104 SlotsBuffer* next() { return next_; }
105
106 static int SizeOfChain(SlotsBuffer* buffer) {
107 if (buffer == NULL) return 0;
108 return static_cast<int>(buffer->idx_ +
109 (buffer->chain_length_ - 1) * kNumberOfElements);
110 }
111
112 inline bool IsFull() { return idx_ == kNumberOfElements; }
113
114 inline bool HasSpaceForTypedSlot() { return idx_ < kNumberOfElements - 1; }
115
116 enum AdditionMode { FAIL_ON_OVERFLOW, IGNORE_OVERFLOW };
117
118 static bool ChainLengthThresholdReached(SlotsBuffer* buffer) {
119 return buffer != NULL && buffer->chain_length_ >= kChainLengthThreshold;
120 }
121
122 INLINE(static bool AddToSynchronized(SlotsBufferAllocator* allocator,
123 SlotsBuffer** buffer_address,
124 base::Mutex* buffer_mutex,
125 ObjectSlot slot, AdditionMode mode)) {
126 base::LockGuard<base::Mutex> lock_guard(buffer_mutex);
127 return AddTo(allocator, buffer_address, slot, mode);
128 }
129
130 INLINE(static bool AddTo(SlotsBufferAllocator* allocator,
131 SlotsBuffer** buffer_address, ObjectSlot slot,
132 AdditionMode mode)) {
133 SlotsBuffer* buffer = *buffer_address;
134 if (buffer == NULL || buffer->IsFull()) {
135 if (mode == FAIL_ON_OVERFLOW && ChainLengthThresholdReached(buffer)) {
136 allocator->DeallocateChain(buffer_address);
137 return false;
138 }
139 buffer = allocator->AllocateBuffer(buffer);
140 *buffer_address = buffer;
141 }
142 buffer->Add(slot);
143 return true;
144 }
145
146 static bool IsTypedSlot(ObjectSlot slot);
147
148 static bool AddToSynchronized(SlotsBufferAllocator* allocator,
149 SlotsBuffer** buffer_address,
150 base::Mutex* buffer_mutex, SlotType type,
151 Address addr, AdditionMode mode);
152
153 static bool AddTo(SlotsBufferAllocator* allocator,
154 SlotsBuffer** buffer_address, SlotType type, Address addr,
155 AdditionMode mode);
156
157 // Eliminates all stale entries from the slots buffer, i.e., slots that
158 // are not part of live objects anymore. This method must be called after
159 // marking, when the whole transitive closure is known and must be called
160 // before sweeping when mark bits are still intact.
161 static void RemoveInvalidSlots(Heap* heap, SlotsBuffer* buffer);
162
163 // Eliminate all slots that are within the given address range.
164 static void RemoveObjectSlots(Heap* heap, SlotsBuffer* buffer,
165 Address start_slot, Address end_slot);
166
167 // Ensures that there are no invalid slots in the chain of slots buffers.
168 static void VerifySlots(Heap* heap, SlotsBuffer* buffer);
169
170 static const int kNumberOfElements = 1021;
171
172 private:
173 static const int kChainLengthThreshold = 15;
174
175 intptr_t idx_;
176 intptr_t chain_length_;
177 SlotsBuffer* next_;
178 ObjectSlot slots_[kNumberOfElements];
179 };
180
181
182 } // namespace internal
183 } // namespace v8
184
185 #endif // V8_SLOTS_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698