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>
|
|
|
|
|
|
|
|
#include "src/globals.h"
|
|
|
|
#include "src/heap/marking.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Marking, TransitionWhiteBlackWhite) {
|
|
|
|
Bitmap* bitmap = reinterpret_cast<Bitmap*>(
|
|
|
|
calloc(Bitmap::kSize / kPointerSize, kPointerSize));
|
|
|
|
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-03-08 16:31:18 +00:00
|
|
|
Marking::WhiteToBlack<MarkBit::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));
|
|
|
|
}
|
|
|
|
free(bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Marking, TransitionWhiteGreyBlackGrey) {
|
|
|
|
Bitmap* bitmap = reinterpret_cast<Bitmap*>(
|
|
|
|
calloc(Bitmap::kSize / kPointerSize, kPointerSize));
|
|
|
|
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-03-08 16:31:18 +00:00
|
|
|
Marking::WhiteToGrey<MarkBit::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-03-08 16:31:18 +00:00
|
|
|
Marking::GreyToBlack<MarkBit::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));
|
|
|
|
Marking::BlackToGrey(mark_bit);
|
|
|
|
CHECK(Marking::IsGrey(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));
|
|
|
|
}
|
|
|
|
free(bitmap);
|
|
|
|
}
|
|
|
|
|
2016-08-01 09:03:01 +00:00
|
|
|
TEST(Marking, SetAndClearRange) {
|
|
|
|
Bitmap* bitmap = reinterpret_cast<Bitmap*>(
|
|
|
|
calloc(Bitmap::kSize / kPointerSize, kPointerSize));
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
bitmap->SetRange(i, Bitmap::kBitsPerCell + i);
|
2016-11-10 10:16:21 +00:00
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xffffffffu << i);
|
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], (1u << i) - 1);
|
2016-08-01 09:03:01 +00:00
|
|
|
bitmap->ClearRange(i, Bitmap::kBitsPerCell + i);
|
2016-11-11 14:55:47 +00:00
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0x0u);
|
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0x0u);
|
2016-08-01 09:03:01 +00:00
|
|
|
}
|
|
|
|
free(bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Marking, ClearMultipleRanges) {
|
|
|
|
Bitmap* bitmap = reinterpret_cast<Bitmap*>(
|
|
|
|
calloc(Bitmap::kSize / kPointerSize, kPointerSize));
|
|
|
|
CHECK(bitmap->AllBitsClearInRange(0, Bitmap::kBitsPerCell * 3));
|
|
|
|
bitmap->SetRange(0, Bitmap::kBitsPerCell * 3);
|
2016-11-10 10:16:21 +00:00
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xffffffffu);
|
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0xffffffffu);
|
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xffffffffu);
|
2016-08-01 09:03:01 +00:00
|
|
|
CHECK(bitmap->AllBitsSetInRange(0, Bitmap::kBitsPerCell * 3));
|
|
|
|
bitmap->ClearRange(Bitmap::kBitsPerCell / 2, Bitmap::kBitsPerCell);
|
|
|
|
bitmap->ClearRange(Bitmap::kBitsPerCell,
|
|
|
|
Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2);
|
|
|
|
bitmap->ClearRange(Bitmap::kBitsPerCell * 2 + 8,
|
|
|
|
Bitmap::kBitsPerCell * 2 + 16);
|
|
|
|
bitmap->ClearRange(Bitmap::kBitsPerCell * 2 + 24, Bitmap::kBitsPerCell * 3);
|
2016-11-11 14:55:47 +00:00
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[0], 0xffffu);
|
2016-08-01 09:03:01 +00:00
|
|
|
CHECK(bitmap->AllBitsSetInRange(0, Bitmap::kBitsPerCell / 2));
|
|
|
|
CHECK(bitmap->AllBitsClearInRange(Bitmap::kBitsPerCell / 2,
|
|
|
|
Bitmap::kBitsPerCell));
|
2016-11-10 10:16:21 +00:00
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[1], 0xffff0000u);
|
2016-08-01 09:03:01 +00:00
|
|
|
CHECK(
|
|
|
|
bitmap->AllBitsSetInRange(Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2,
|
|
|
|
2 * Bitmap::kBitsPerCell));
|
|
|
|
CHECK(bitmap->AllBitsClearInRange(
|
|
|
|
Bitmap::kBitsPerCell, Bitmap::kBitsPerCell + Bitmap::kBitsPerCell / 2));
|
2016-11-10 10:16:21 +00:00
|
|
|
CHECK_EQ(reinterpret_cast<uint32_t*>(bitmap)[2], 0xff00ffu);
|
2016-08-01 09:03:01 +00:00
|
|
|
CHECK(bitmap->AllBitsSetInRange(2 * Bitmap::kBitsPerCell,
|
|
|
|
2 * Bitmap::kBitsPerCell + 8));
|
|
|
|
CHECK(bitmap->AllBitsClearInRange(2 * Bitmap::kBitsPerCell + 24,
|
|
|
|
Bitmap::kBitsPerCell * 3));
|
|
|
|
free(bitmap);
|
|
|
|
}
|
2016-07-12 15:08:55 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|