5 #include "src/heap/marking.h" 10 void Bitmap::Clear() {
11 base::Atomic32* cell_base =
reinterpret_cast<base::Atomic32*
>(cells());
12 for (
int i = 0;
i < CellsCount();
i++) {
13 base::Relaxed_Store(cell_base +
i, 0);
17 base::SeqCst_MemoryFence();
20 void Bitmap::MarkAllBits() {
21 base::Atomic32* cell_base =
reinterpret_cast<base::Atomic32*
>(cells());
22 for (
int i = 0;
i < CellsCount();
i++) {
23 base::Relaxed_Store(cell_base +
i, 0xffffffff);
27 base::SeqCst_MemoryFence();
31 if (start_index >= end_index)
return;
34 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2;
35 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index);
36 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2;
37 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index);
38 if (start_cell_index != end_cell_index) {
41 SetBitsInCell<AccessMode::ATOMIC>(start_cell_index,
42 ~(start_index_mask - 1));
44 base::Atomic32* cell_base =
reinterpret_cast<base::Atomic32*
>(cells());
45 for (
unsigned int i = start_cell_index + 1;
i < end_cell_index;
i++) {
46 base::Relaxed_Store(cell_base +
i, ~0u);
49 SetBitsInCell<AccessMode::ATOMIC>(end_cell_index,
50 end_index_mask | (end_index_mask - 1));
52 SetBitsInCell<AccessMode::ATOMIC>(
53 start_cell_index, end_index_mask | (end_index_mask - start_index_mask));
57 base::SeqCst_MemoryFence();
61 if (start_index >= end_index)
return;
64 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2;
65 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index);
67 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2;
68 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index);
70 if (start_cell_index != end_cell_index) {
73 ClearBitsInCell<AccessMode::ATOMIC>(start_cell_index,
74 ~(start_index_mask - 1));
76 base::Atomic32* cell_base =
reinterpret_cast<base::Atomic32*
>(cells());
77 for (
unsigned int i = start_cell_index + 1;
i < end_cell_index;
i++) {
78 base::Relaxed_Store(cell_base +
i, 0);
81 ClearBitsInCell<AccessMode::ATOMIC>(end_cell_index,
82 end_index_mask | (end_index_mask - 1));
84 ClearBitsInCell<AccessMode::ATOMIC>(
85 start_cell_index, end_index_mask | (end_index_mask - start_index_mask));
89 base::SeqCst_MemoryFence();
93 if (start_index >= end_index)
return false;
96 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2;
97 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index);
99 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2;
100 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index);
102 MarkBit::CellType matching_mask;
103 if (start_cell_index != end_cell_index) {
104 matching_mask = ~(start_index_mask - 1);
105 if ((cells()[start_cell_index] & matching_mask) != matching_mask) {
108 for (
unsigned int i = start_cell_index + 1;
i < end_cell_index;
i++) {
109 if (cells()[
i] != ~0u)
return false;
111 matching_mask = end_index_mask | (end_index_mask - 1);
112 return ((cells()[end_cell_index] & matching_mask) == matching_mask);
114 matching_mask = end_index_mask | (end_index_mask - start_index_mask);
115 return (cells()[end_cell_index] & matching_mask) == matching_mask;
119 bool Bitmap::AllBitsClearInRange(
uint32_t start_index,
uint32_t end_index) {
120 if (start_index >= end_index)
return true;
123 unsigned int start_cell_index = start_index >> Bitmap::kBitsPerCellLog2;
124 MarkBit::CellType start_index_mask = 1u << Bitmap::IndexInCell(start_index);
126 unsigned int end_cell_index = end_index >> Bitmap::kBitsPerCellLog2;
127 MarkBit::CellType end_index_mask = 1u << Bitmap::IndexInCell(end_index);
129 MarkBit::CellType matching_mask;
130 if (start_cell_index != end_cell_index) {
131 matching_mask = ~(start_index_mask - 1);
132 if ((cells()[start_cell_index] & matching_mask))
return false;
133 for (
unsigned int i = start_cell_index + 1;
i < end_cell_index;
i++) {
134 if (cells()[
i])
return false;
136 matching_mask = end_index_mask | (end_index_mask - 1);
137 return !(cells()[end_cell_index] & matching_mask);
139 matching_mask = end_index_mask | (end_index_mask - start_index_mask);
140 return !(cells()[end_cell_index] & matching_mask);
147 for (
uint32_t mask = 1; mask != 0; mask <<= 1) {
148 if ((mask & himask) != 0) PrintF(
"[");
149 PrintF((mask & word) ?
"1" :
"0");
150 if ((mask & himask) != 0) PrintF(
"]");
156 CellPrinter() : seq_start(0), seq_type(0), seq_length(0) {}
159 if (cell == seq_type) {
179 if (seq_length > 0) {
180 PrintF(
"%d: %dx%d\n", seq_start, seq_type == 0 ? 0 : 1,
181 seq_length * Bitmap::kBitsPerCell);
186 static bool IsSeq(
uint32_t cell) {
return cell == 0 || cell == 0xFFFFFFFF; }
196 void Bitmap::Print() {
198 for (
int i = 0;
i < CellsCount();
i++) {
199 printer.Print(
i, cells()[
i]);
205 bool Bitmap::IsClean() {
206 for (
int i = 0;
i < CellsCount();
i++) {
207 if (cells()[
i] != 0) {