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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 TEST(Marking, MarkWhiteBlackWhite) { | |
15 Bitmap* bitmap = reinterpret_cast<Bitmap*>( | |
16 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); | |
17 const int kLocationsSize = 3; | |
18 int position[kLocationsSize] = { | |
19 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; | |
20 for (int i = 0; i < kLocationsSize; i++) { | |
21 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); | |
22 CHECK(Marking::IsWhite(mark_bit)); | |
23 CHECK(!Marking::IsImpossible(mark_bit)); | |
24 Marking::MarkBlack(mark_bit); | |
25 CHECK(Marking::IsBlack(mark_bit)); | |
26 CHECK(!Marking::IsImpossible(mark_bit)); | |
27 Marking::MarkWhite(mark_bit); | |
28 CHECK(Marking::IsWhite(mark_bit)); | |
29 CHECK(!Marking::IsImpossible(mark_bit)); | |
30 } | |
31 free(bitmap); | |
32 } | |
33 | 14 |
34 TEST(Marking, TransitionWhiteBlackWhite) { | 15 TEST(Marking, TransitionWhiteBlackWhite) { |
35 Bitmap* bitmap = reinterpret_cast<Bitmap*>( | 16 Bitmap* bitmap = reinterpret_cast<Bitmap*>( |
36 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); | 17 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); |
37 const int kLocationsSize = 3; | 18 const int kLocationsSize = 3; |
38 int position[kLocationsSize] = { | 19 int position[kLocationsSize] = { |
39 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; | 20 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
40 for (int i = 0; i < kLocationsSize; i++) { | 21 for (int i = 0; i < kLocationsSize; i++) { |
41 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); | 22 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
42 CHECK(Marking::IsWhite(mark_bit)); | 23 CHECK(Marking::IsWhite(mark_bit)); |
(...skipping 15 matching lines...) Expand all Loading... |
58 int position[kLocationsSize] = { | 39 int position[kLocationsSize] = { |
59 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; | 40 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
60 for (int i = 0; i < kLocationsSize; i++) { | 41 for (int i = 0; i < kLocationsSize; i++) { |
61 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); | 42 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
62 CHECK(Marking::IsWhite(mark_bit)); | 43 CHECK(Marking::IsWhite(mark_bit)); |
63 CHECK(!Marking::IsImpossible(mark_bit)); | 44 CHECK(!Marking::IsImpossible(mark_bit)); |
64 Marking::AnyToGrey(mark_bit); | 45 Marking::AnyToGrey(mark_bit); |
65 CHECK(Marking::IsGrey(mark_bit)); | 46 CHECK(Marking::IsGrey(mark_bit)); |
66 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 47 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
67 CHECK(!Marking::IsImpossible(mark_bit)); | 48 CHECK(!Marking::IsImpossible(mark_bit)); |
68 Marking::MarkBlack(mark_bit); | 49 Marking::GreyToBlack(mark_bit); |
69 CHECK(Marking::IsBlack(mark_bit)); | 50 CHECK(Marking::IsBlack(mark_bit)); |
70 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 51 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
71 CHECK(!Marking::IsImpossible(mark_bit)); | 52 CHECK(!Marking::IsImpossible(mark_bit)); |
72 Marking::AnyToGrey(mark_bit); | 53 Marking::AnyToGrey(mark_bit); |
73 CHECK(Marking::IsGrey(mark_bit)); | 54 CHECK(Marking::IsGrey(mark_bit)); |
74 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 55 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
75 CHECK(!Marking::IsImpossible(mark_bit)); | 56 CHECK(!Marking::IsImpossible(mark_bit)); |
76 Marking::MarkWhite(mark_bit); | 57 Marking::GreyToWhite(mark_bit); |
77 CHECK(Marking::IsWhite(mark_bit)); | 58 CHECK(Marking::IsWhite(mark_bit)); |
78 CHECK(!Marking::IsImpossible(mark_bit)); | 59 CHECK(!Marking::IsImpossible(mark_bit)); |
79 } | 60 } |
80 free(bitmap); | 61 free(bitmap); |
81 } | 62 } |
82 | 63 |
83 TEST(Marking, TransitionWhiteGreyBlackGrey) { | 64 TEST(Marking, TransitionWhiteGreyBlackGrey) { |
84 Bitmap* bitmap = reinterpret_cast<Bitmap*>( | 65 Bitmap* bitmap = reinterpret_cast<Bitmap*>( |
85 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); | 66 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); |
86 const int kLocationsSize = 3; | 67 const int kLocationsSize = 3; |
87 int position[kLocationsSize] = { | 68 int position[kLocationsSize] = { |
88 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; | 69 Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
89 for (int i = 0; i < kLocationsSize; i++) { | 70 for (int i = 0; i < kLocationsSize; i++) { |
90 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); | 71 MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
91 CHECK(Marking::IsWhite(mark_bit)); | 72 CHECK(Marking::IsWhite(mark_bit)); |
92 CHECK(!Marking::IsBlackOrGrey(mark_bit)); | 73 CHECK(!Marking::IsBlackOrGrey(mark_bit)); |
93 CHECK(!Marking::IsImpossible(mark_bit)); | 74 CHECK(!Marking::IsImpossible(mark_bit)); |
94 Marking::WhiteToGrey(mark_bit); | 75 Marking::WhiteToGrey(mark_bit); |
95 CHECK(Marking::IsGrey(mark_bit)); | 76 CHECK(Marking::IsGrey(mark_bit)); |
96 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 77 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
97 CHECK(!Marking::IsImpossible(mark_bit)); | 78 CHECK(!Marking::IsImpossible(mark_bit)); |
98 Marking::GreyToBlack(mark_bit); | 79 Marking::GreyToBlack(mark_bit); |
99 CHECK(Marking::IsBlack(mark_bit)); | 80 CHECK(Marking::IsBlack(mark_bit)); |
100 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 81 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
101 CHECK(!Marking::IsImpossible(mark_bit)); | 82 CHECK(!Marking::IsImpossible(mark_bit)); |
102 Marking::BlackToGrey(mark_bit); | 83 Marking::BlackToGrey(mark_bit); |
103 CHECK(Marking::IsGrey(mark_bit)); | 84 CHECK(Marking::IsGrey(mark_bit)); |
104 CHECK(Marking::IsBlackOrGrey(mark_bit)); | 85 CHECK(Marking::IsBlackOrGrey(mark_bit)); |
105 CHECK(!Marking::IsImpossible(mark_bit)); | 86 CHECK(!Marking::IsImpossible(mark_bit)); |
106 Marking::MarkWhite(mark_bit); | 87 Marking::GreyToWhite(mark_bit); |
107 CHECK(Marking::IsWhite(mark_bit)); | 88 CHECK(Marking::IsWhite(mark_bit)); |
108 CHECK(!Marking::IsImpossible(mark_bit)); | 89 CHECK(!Marking::IsImpossible(mark_bit)); |
109 } | 90 } |
110 free(bitmap); | 91 free(bitmap); |
111 } | 92 } |
112 | 93 |
113 TEST(Marking, SetAndClearRange) { | 94 TEST(Marking, SetAndClearRange) { |
114 Bitmap* bitmap = reinterpret_cast<Bitmap*>( | 95 Bitmap* bitmap = reinterpret_cast<Bitmap*>( |
115 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); | 96 calloc(Bitmap::kSize / kPointerSize, kPointerSize)); |
116 for (int i = 0; i < 3; i++) { | 97 for (int i = 0; i < 3; i++) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 Bitmap::kBitsPerCell, Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2)); | 132 Bitmap::kBitsPerCell, Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2)); |
152 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xff00ffu); | 133 CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xff00ffu); |
153 CHECK(bitmap->AllBitsSetInRange(2 * Bitmap::kBitsPerCell, | 134 CHECK(bitmap->AllBitsSetInRange(2 * Bitmap::kBitsPerCell, |
154 2 * Bitmap::kBitsPerCell + 8)); | 135 2 * Bitmap::kBitsPerCell + 8)); |
155 CHECK(bitmap->AllBitsClearInRange(2 * Bitmap::kBitsPerCell + 24, | 136 CHECK(bitmap->AllBitsClearInRange(2 * Bitmap::kBitsPerCell + 24, |
156 Bitmap::kBitsPerCell * 3)); | 137 Bitmap::kBitsPerCell * 3)); |
157 free(bitmap); | 138 free(bitmap); |
158 } | 139 } |
159 } // namespace internal | 140 } // namespace internal |
160 } // namespace v8 | 141 } // namespace v8 |
OLD | NEW |