v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
marking.cc
Go to the documentation of this file.
1// Copyright 2017 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 <limits>
6
8
9namespace v8 {
10namespace internal {
11
12namespace {
13constexpr MarkBit::CellType kAllBitsSetInCellValue =
14 std::numeric_limits<MarkBit::CellType>::max();
15}
16
18 MarkBitIndex end_index) const {
19 if (start_index >= end_index) return false;
20 end_index--;
21
22 const CellIndex start_cell_index = IndexToCell(start_index);
23 MarkBit::CellType start_index_mask = IndexInCellMask(start_index);
24 const CellIndex end_cell_index = IndexToCell(end_index);
25 MarkBit::CellType end_index_mask = IndexInCellMask(end_index);
26
27 MarkBit::CellType matching_mask;
28 if (start_cell_index != end_cell_index) {
29 matching_mask = ~(start_index_mask - 1);
30 if ((cells()[start_cell_index] & matching_mask) != matching_mask) {
31 return false;
32 }
33 for (unsigned int i = start_cell_index + 1; i < end_cell_index; i++) {
34 if (cells()[i] != kAllBitsSetInCellValue) return false;
35 }
36 matching_mask = end_index_mask | (end_index_mask - 1);
37 return ((cells()[end_cell_index] & matching_mask) == matching_mask);
38 } else {
39 matching_mask = end_index_mask | (end_index_mask - start_index_mask);
40 return (cells()[end_cell_index] & matching_mask) == matching_mask;
41 }
42}
43
45 MarkBitIndex end_index) const {
46 if (start_index >= end_index) return true;
47 end_index--;
48
49 const CellIndex start_cell_index = IndexToCell(start_index);
50 MarkBit::CellType start_index_mask = IndexInCellMask(start_index);
51 const CellIndex end_cell_index = IndexToCell(end_index);
52 MarkBit::CellType end_index_mask = IndexInCellMask(end_index);
53
54 MarkBit::CellType matching_mask;
55 if (start_cell_index != end_cell_index) {
56 matching_mask = ~(start_index_mask - 1);
57 if ((cells()[start_cell_index] & matching_mask)) return false;
58 for (size_t i = start_cell_index + 1; i < end_cell_index; i++) {
59 if (cells()[i]) return false;
60 }
61 matching_mask = end_index_mask | (end_index_mask - 1);
62 return !(cells()[end_cell_index] & matching_mask);
63 } else {
64 matching_mask = end_index_mask | (end_index_mask - start_index_mask);
65 return !(cells()[end_cell_index] & matching_mask);
66 }
67}
68
69namespace {
70
71void PrintWord(MarkBit::CellType word, MarkBit::CellType himask = 0) {
72 for (MarkBit::CellType mask = 1; mask != 0; mask <<= 1) {
73 if ((mask & himask) != 0) PrintF("[");
74 PrintF((mask & word) ? "1" : "0");
75 if ((mask & himask) != 0) PrintF("]");
76 }
77}
78
79class CellPrinter final {
80 public:
81 CellPrinter() = default;
82
83 void Print(size_t pos, MarkBit::CellType cell) {
84 if (cell == seq_type) {
85 seq_length++;
86 return;
87 }
88
89 Flush();
90
91 if (IsSeq(cell)) {
92 seq_start = pos;
93 seq_length = 0;
94 seq_type = cell;
95 return;
96 }
97
98 PrintF("%zu: ", pos);
99 PrintWord(cell);
100 PrintF("\n");
101 }
102
103 void Flush() {
104 if (seq_length > 0) {
105 PrintF("%zu: %dx%zu\n", seq_start, seq_type == 0 ? 0 : 1,
106 seq_length * MarkingBitmap::kBitsPerCell);
107 seq_length = 0;
108 }
109 }
110
111 static bool IsSeq(MarkBit::CellType cell) {
112 return cell == 0 || cell == kAllBitsSetInCellValue;
113 }
114
115 private:
116 size_t seq_start = 0;
118 size_t seq_length = 0;
119};
120
121} // anonymous namespace
122
124 CellPrinter printer;
125 for (size_t i = 0; i < kCellsCount; i++) {
126 printer.Print(i, cells()[i]);
127 }
128 printer.Flush();
129 PrintF("\n");
130}
131
133 for (size_t i = 0; i < kCellsCount; i++) {
134 if (cells()[i] != 0) {
135 return false;
136 }
137 }
138 return true;
139}
140
141// static
145
146// static
150
151} // namespace internal
152} // namespace v8
SourcePosition pos
static V8_ALLOW_UNUSED MarkBit FromForTesting(Address)
Definition marking.cc:142
uintptr_t CellType
Definition marking.h:21
static constexpr size_t kCellsCount
Definition marking.h:109
bool AllBitsSetInRange(MarkBitIndex start_index, MarkBitIndex end_index) const
Definition marking.cc:17
static V8_INLINE MarkBit MarkBitFromAddress(Address address)
V8_INLINE CellType * cells()
Definition marking.h:158
static V8_INLINE constexpr CellIndex IndexToCell(MarkBitIndex index)
Definition marking.h:119
static constexpr uint32_t kBitsPerCell
Definition marking.h:98
bool AllBitsClearInRange(MarkBitIndex start_index, MarkBitIndex end_index) const
Definition marking.cc:44
static V8_INLINE constexpr CellType IndexInCellMask(MarkBitIndex index)
Definition marking.h:135
V8_INLINE constexpr StorageType ptr() const
uint32_t const mask
size_t seq_length
Definition marking.cc:118
size_t seq_start
Definition marking.cc:116
MarkBit::CellType seq_type
Definition marking.cc:117
void PrintF(const char *format,...)
Definition utils.cc:39
void Print(Tagged< Object > obj)
Definition objects.h:774