OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/globals.h" | 7 #include "src/globals.h" |
8 #include "src/heap/marking.h" | 8 #include "src/heap/marking.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 CHECK(Marking::IsGrey(mark_bit)); | 103 CHECK(Marking::IsGrey(mark_bit)); |
104 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 104 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
105 CHECK(!Marking::IsImpossible(mark_bit)); | 105 CHECK(!Marking::IsImpossible(mark_bit)); |
106 Marking::MarkWhite(mark_bit); | 106 Marking::MarkWhite(mark_bit); |
107 CHECK(Marking::IsWhite(mark_bit)); | 107 CHECK(Marking::IsWhite(mark_bit)); |
108 CHECK(!Marking::IsImpossible(mark_bit)); | 108 CHECK(!Marking::IsImpossible(mark_bit)); |
109 } | 109 } |
110 free(bitmap); | 110 free(bitmap); |
111 } | 111 } |
112 | 112 |
113 TEST(Marking, SetAndClearRange) { | |
114 Bitmap* bitmap = reinterpret_cast<Bitmap*>( | |
115 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); | |
116 for (int i = 0; i < 3; i++) { | |
117 bitmap->SetRange(i, Bitmap::kBitsPerCell + i); | |
118 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xffffffff << i); | |
119 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], (1 << i) - 1); | |
120 bitmap->ClearRange(i, Bitmap::kBitsPerCell + i); | |
121 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0x0); | |
122 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0x0); | |
123 } | |
124 free(bitmap); | |
125 } | |
126 | |
127 TEST(Marking, ClearMultipleRanges) { | |
128 Bitmap* bitmap = reinterpret_cast<Bitmap*>( | |
129 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); | |
130 CHECK(bitmap->AllBitsClearInRange(0, Bitmap::kBitsPerCell * 3)); | |
131 bitmap->SetRange(0, Bitmap::kBitsPerCell * 3); | |
132 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xffffffff); | |
133 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0xffffffff); | |
134 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xffffffff); | |
135 CHECK(bitmap->AllBitsSetInRange(0, Bitmap::kBitsPerCell * 3)); | |
136 bitmap->ClearRange(Bitmap::kBitsPerCell / 2, Bitmap::kBitsPerCell); | |
137 bitmap->ClearRange(Bitmap::kBitsPerCell, | |
138 Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2); | |
139 bitmap->ClearRange(Bitmap::kBitsPerCell * 2 + 8, | |
140 Bitmap::kBitsPerCell * 2 + 16); | |
141 bitmap->ClearRange(Bitmap::kBitsPerCell * 2 + 24, Bitmap::kBitsPerCell * 3); | |
142 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xffff); | |
143 CHECK(bitmap->AllBitsSetInRange(0, Bitmap::kBitsPerCell / 2)); | |
144 CHECK(bitmap->AllBitsClearInRange(Bitmap::kBitsPerCell / 2, | |
145 Bitmap::kBitsPerCell)); | |
146 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0xffff0000); | |
147 CHECK( | |
148 bitmap->AllBitsSetInRange(Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2, | |
149 2 * Bitmap::kBitsPerCell)); | |
150 CHECK(bitmap->AllBitsClearInRange( | |
151 Bitmap::kBitsPerCell, Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2)); | |
152 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xff00ff); | |
153 CHECK(bitmap->AllBitsSetInRange(2 * Bitmap::kBitsPerCell, | |
154 2 * Bitmap::kBitsPerCell + 8)); | |
155 CHECK(bitmap->AllBitsClearInRange(2 * Bitmap::kBitsPerCell + 24, | |
156 Bitmap::kBitsPerCell * 3)); | |
157 free(bitmap); | |
158 } | |
159 } // namespace internal | 113 } // namespace internal |
160 } // namespace v8 | 114 } // namespace v8 |
OLD | NEW |