v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
slot-set.cc
Go to the documentation of this file.
1// Copyright 2018 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#include "src/heap/slot-set.h"
6
7#include "src/base/logging.h"
9
10namespace v8 {
11namespace internal {
12
14 Chunk* chunk = head_;
15 while (chunk != nullptr) {
16 Chunk* next = chunk->next;
17 delete chunk;
18 chunk = next;
19 }
20 head_ = nullptr;
21 tail_ = nullptr;
22}
23
24void TypedSlots::Insert(SlotType type, uint32_t offset) {
26 Chunk* chunk = EnsureChunk();
27 DCHECK_LT(chunk->buffer.size(), chunk->buffer.capacity());
28 chunk->buffer.push_back(slot);
29}
30
32 if (other->head_ == nullptr) {
33 return;
34 }
35 if (head_ == nullptr) {
36 head_ = other->head_;
37 tail_ = other->tail_;
38 } else {
39 tail_->next = other->head_;
40 tail_ = other->tail_;
41 }
42 other->head_ = nullptr;
43 other->tail_ = nullptr;
44}
45
47 if (!head_) {
49 }
50 if (head_->buffer.size() == head_->buffer.capacity()) {
52 }
53 return head_;
54}
55
57 Chunk* chunk = new Chunk;
58 chunk->next = next;
59 chunk->buffer.reserve(capacity);
60 DCHECK_EQ(chunk->buffer.capacity(), capacity);
61 return chunk;
62}
63
65 IterateSlotsInRanges([](TypedSlot* slot) { *slot = ClearedTypedSlot(); },
66 invalid_ranges);
67}
68
71 [](TypedSlot* slot) {
72 CHECK_WITH_MSG(false, "No slot in ranges expected.");
73 },
74 invalid_ranges);
75}
76
77template <typename Callback>
79 const FreeRangesMap& ranges) {
80 if (ranges.empty()) return;
81
82 Chunk* chunk = LoadHead();
83 while (chunk != nullptr) {
84 for (TypedSlot& slot : chunk->buffer) {
86 if (type == SlotType::kCleared) continue;
88 FreeRangesMap::const_iterator upper_bound = ranges.upper_bound(offset);
89 if (upper_bound == ranges.begin()) continue;
90 // upper_bounds points to the invalid range after the given slot. Hence,
91 // we have to go to the previous element.
92 upper_bound--;
93 DCHECK_LE(upper_bound->first, offset);
94 if (upper_bound->second > offset) {
95 callback(&slot);
96 }
97 }
98 chunk = LoadNext(chunk);
99 }
100}
101
102} // namespace internal
103} // namespace v8
static constexpr T decode(U value)
Definition bit-field.h:66
static constexpr U encode(T value)
Definition bit-field.h:55
std::map< uint32_t, uint32_t > FreeRangesMap
Definition slot-set.h:306
void ClearInvalidSlots(const FreeRangesMap &invalid_ranges)
Definition slot-set.cc:64
Chunk * LoadNext(Chunk *chunk)
Definition slot-set.h:375
void AssertNoInvalidSlots(const FreeRangesMap &invalid_ranges)
Definition slot-set.cc:69
static TypedSlot ClearedTypedSlot()
Definition slot-set.h:385
void IterateSlotsInRanges(Callback callback, const FreeRangesMap &invalid_ranges)
Definition slot-set.cc:78
static const size_t kInitialBufferSize
Definition slot-set.h:291
Chunk * NewChunk(Chunk *next, size_t capacity)
Definition slot-set.cc:56
static size_t NextCapacity(size_t capacity)
Definition slot-set.h:293
void Insert(SlotType type, uint32_t offset)
Definition slot-set.cc:24
void Merge(TypedSlots *other)
Definition slot-set.cc:31
int32_t offset
TNode< Object > callback
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK_WITH_MSG(condition, message)
Definition logging.h:118
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
std::vector< TypedSlot > buffer
Definition slot-set.h:289