Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include <stdlib.h>
6 :
7 : #include "src/globals.h"
8 : #include "src/heap/marking.h"
9 : #include "test/unittests/heap/bitmap-test-utils.h"
10 : #include "testing/gtest/include/gtest/gtest.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : template <typename T>
16 : using MarkingTest = TestWithBitmap<T>;
17 :
18 : TYPED_TEST_SUITE(MarkingTest, BitmapTypes);
19 :
20 12338 : TYPED_TEST(MarkingTest, TransitionWhiteBlackWhite) {
21 : auto bitmap = this->bitmap();
22 : const int kLocationsSize = 3;
23 : int position[kLocationsSize] = {
24 2 : Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell};
25 14 : for (int i = 0; i < kLocationsSize; i++) {
26 6 : MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]);
27 6 : CHECK(Marking::IsWhite(mark_bit));
28 6 : CHECK(!Marking::IsImpossible(mark_bit));
29 : Marking::WhiteToBlack<AccessMode::NON_ATOMIC>(mark_bit);
30 6 : CHECK(Marking::IsBlack(mark_bit));
31 6 : CHECK(!Marking::IsImpossible(mark_bit));
32 : Marking::MarkWhite(mark_bit);
33 6 : CHECK(Marking::IsWhite(mark_bit));
34 6 : CHECK(!Marking::IsImpossible(mark_bit));
35 : }
36 2 : }
37 :
38 12338 : TYPED_TEST(MarkingTest, TransitionWhiteGreyBlack) {
39 : auto bitmap = this->bitmap();
40 : const int kLocationsSize = 3;
41 : int position[kLocationsSize] = {
42 2 : Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell};
43 14 : for (int i = 0; i < kLocationsSize; i++) {
44 6 : MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]);
45 6 : CHECK(Marking::IsWhite(mark_bit));
46 6 : CHECK(!Marking::IsBlackOrGrey(mark_bit));
47 6 : CHECK(!Marking::IsImpossible(mark_bit));
48 : Marking::WhiteToGrey<AccessMode::NON_ATOMIC>(mark_bit);
49 6 : CHECK(Marking::IsGrey(mark_bit));
50 6 : CHECK(Marking::IsBlackOrGrey(mark_bit));
51 6 : CHECK(!Marking::IsImpossible(mark_bit));
52 : Marking::GreyToBlack<AccessMode::NON_ATOMIC>(mark_bit);
53 6 : CHECK(Marking::IsBlack(mark_bit));
54 6 : CHECK(Marking::IsBlackOrGrey(mark_bit));
55 6 : CHECK(!Marking::IsImpossible(mark_bit));
56 : Marking::MarkWhite(mark_bit);
57 6 : CHECK(Marking::IsWhite(mark_bit));
58 6 : CHECK(!Marking::IsImpossible(mark_bit));
59 : }
60 2 : }
61 :
62 : } // namespace internal
63 9249 : } // namespace v8
|