2016-07-12 15:08:55 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/common/globals.h"
|
2016-07-12 15:08:55 +00:00
|
|
|
#include "src/heap/marking.h"
|
2019-02-22 17:34:05 +00:00
|
|
|
#include "test/unittests/heap/bitmap-test-utils.h"
|
2016-07-12 15:08:55 +00:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2019-02-22 17:34:05 +00:00
|
|
|
template <typename T>
|
|
|
|
using MarkingTest = TestWithBitmap<T>;
|
2016-07-12 15:08:55 +00:00
|
|
|
|
2019-02-22 17:34:05 +00:00
|
|
|
TYPED_TEST_SUITE(MarkingTest, BitmapTypes);
|
|
|
|
|
|
|
|
TYPED_TEST(MarkingTest, TransitionWhiteBlackWhite) {
|
|
|
|
auto bitmap = this->bitmap();
|
2016-07-12 15:08:55 +00:00
|
|
|
const int kLocationsSize = 3;
|
|
|
|
int position[kLocationsSize] = {
|
|
|
|
Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell};
|
|
|
|
for (int i = 0; i < kLocationsSize; i++) {
|
|
|
|
MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]);
|
|
|
|
CHECK(Marking::IsWhite(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
2017-06-13 16:54:42 +00:00
|
|
|
Marking::WhiteToBlack<AccessMode::NON_ATOMIC>(mark_bit);
|
2016-07-12 15:08:55 +00:00
|
|
|
CHECK(Marking::IsBlack(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
2017-03-06 12:10:05 +00:00
|
|
|
Marking::MarkWhite(mark_bit);
|
2016-07-12 15:08:55 +00:00
|
|
|
CHECK(Marking::IsWhite(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 17:34:05 +00:00
|
|
|
TYPED_TEST(MarkingTest, TransitionWhiteGreyBlack) {
|
|
|
|
auto bitmap = this->bitmap();
|
2016-07-12 15:08:55 +00:00
|
|
|
const int kLocationsSize = 3;
|
|
|
|
int position[kLocationsSize] = {
|
|
|
|
Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell};
|
|
|
|
for (int i = 0; i < kLocationsSize; i++) {
|
|
|
|
MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]);
|
|
|
|
CHECK(Marking::IsWhite(mark_bit));
|
|
|
|
CHECK(!Marking::IsBlackOrGrey(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
2017-06-13 16:54:42 +00:00
|
|
|
Marking::WhiteToGrey<AccessMode::NON_ATOMIC>(mark_bit);
|
2016-07-12 15:08:55 +00:00
|
|
|
CHECK(Marking::IsGrey(mark_bit));
|
|
|
|
CHECK(Marking::IsBlackOrGrey(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
2017-06-13 16:54:42 +00:00
|
|
|
Marking::GreyToBlack<AccessMode::NON_ATOMIC>(mark_bit);
|
2016-07-12 15:08:55 +00:00
|
|
|
CHECK(Marking::IsBlack(mark_bit));
|
|
|
|
CHECK(Marking::IsBlackOrGrey(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
2017-03-06 12:10:05 +00:00
|
|
|
Marking::MarkWhite(mark_bit);
|
2016-07-12 15:08:55 +00:00
|
|
|
CHECK(Marking::IsWhite(mark_bit));
|
|
|
|
CHECK(!Marking::IsImpossible(mark_bit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|