Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: test/unittests/heap/marking-unittest.cc

Issue 2139133003: [heap] Untangle Marking and friends from heap dependencies. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: clear liveness Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/unittests/heap/marking-unittest.cc
diff --git a/test/unittests/heap/marking-unittest.cc b/test/unittests/heap/marking-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f316e151cd66b4e1df5c818c1fe2902640e0e5d9
--- /dev/null
+++ b/test/unittests/heap/marking-unittest.cc
@@ -0,0 +1,100 @@
+// 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, MarkWhiteBlackWhite) {
+ Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0));
+ 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));
+ Marking::MarkBlack(mark_bit);
+ CHECK(Marking::IsBlack(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ Marking::MarkWhite(mark_bit);
+ CHECK(Marking::IsWhite(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ }
Michael Lippautz 2016/07/12 14:22:31 free(bitmap) or you will get mail from leak saniti
Hannes Payer (out of office) 2016/07/12 14:44:26 Done.
+}
+
+TEST(Marking, TransitionWhiteBlackWhite) {
+ Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0));
+ 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));
+ Marking::WhiteToBlack(mark_bit);
+ CHECK(Marking::IsBlack(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ Marking::BlackToWhite(mark_bit);
+ CHECK(Marking::IsWhite(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ }
+}
+
+TEST(Marking, TransitionAnyToGrey) {
+ Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0));
+ 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));
+ Marking::AnyToGrey(mark_bit);
+ CHECK(Marking::IsGrey(mark_bit));
+ CHECK(Marking::IsBlackOrGrey(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ Marking::MarkBlack(mark_bit);
+ CHECK(Marking::IsBlack(mark_bit));
+ CHECK(Marking::IsBlackOrGrey(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ Marking::AnyToGrey(mark_bit);
+ CHECK(Marking::IsGrey(mark_bit));
+ CHECK(Marking::IsBlackOrGrey(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ }
+}
+
+TEST(Marking, TransitionWhiteGreyBlackGrey) {
+ Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0));
+ 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));
+ Marking::WhiteToGrey(mark_bit);
+ CHECK(Marking::IsGrey(mark_bit));
+ CHECK(Marking::IsBlackOrGrey(mark_bit));
+ CHECK(!Marking::IsImpossible(mark_bit));
+ Marking::GreyToBlack(mark_bit);
+ 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));
+ }
+}
+
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698