1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 4 */ 5 6 #include "precompiled.hpp" 7 #include "gc/z/zBitMap.inline.hpp" 8 #include "unittest.hpp" 9 10 class ZBitMapTest : public ::testing::Test { 11 protected: 12 static void test_set_pair_unset(size_t size, bool finalizable) { 13 ZBitMap bitmap(size); 14 15 for (BitMap::idx_t i = 0; i < size - 1; i++) { 16 if ((i + 1) % BitsPerWord == 0) { 17 // Can't set pairs of bits in different words. 18 continue; 19 } 20 21 // ZBitMaps are not cleared when constructed. 22 bitmap.clear(); 23 24 bool inc_live = false; 25 26 bool ret = bitmap.par_set_bit_pair(i, finalizable, inc_live); 27 EXPECT_TRUE(ret) << "Failed to set bit"; 28 EXPECT_TRUE(inc_live) << "Should have set inc_live"; 29 30 // First bit should always be set 31 EXPECT_TRUE(bitmap.at(i)) << "Should be set"; 32 33 // Second bit should only be set when marking strong 34 EXPECT_NE(bitmap.at(i + 1), finalizable); 35 } 36 } 37 38 static void test_set_pair_set(size_t size, bool finalizable) { 39 ZBitMap bitmap(size); 40 41 for (BitMap::idx_t i = 0; i < size - 1; i++) { 42 if ((i + 1) % BitsPerWord == 0) { 43 // Can't set pairs of bits in different words. 44 continue; 45 } 46 47 // Fill the bitmap with ones. 48 bitmap.set_range(0, size); 49 50 bool inc_live = false; 51 52 bool ret = bitmap.par_set_bit_pair(i, finalizable, inc_live); 53 EXPECT_FALSE(ret) << "Should not succeed setting bit"; 54 EXPECT_FALSE(inc_live) << "Should not have set inc_live"; 55 56 // Both bits were pre-set. 57 EXPECT_TRUE(bitmap.at(i)) << "Should be set"; 58 EXPECT_TRUE(bitmap.at(i + 1)) << "Should be set"; 59 } 60 } 61 62 static void test_set_pair_set(bool finalizable) { 63 test_set_pair_set(2, finalizable); 64 test_set_pair_set(62, finalizable); 65 test_set_pair_set(64, finalizable); 66 test_set_pair_set(66, finalizable); 67 test_set_pair_set(126, finalizable); 68 test_set_pair_set(128, finalizable); 69 } 70 71 static void test_set_pair_unset(bool finalizable) { 72 test_set_pair_unset(2, finalizable); 73 test_set_pair_unset(62, finalizable); 74 test_set_pair_unset(64, finalizable); 75 test_set_pair_unset(66, finalizable); 76 test_set_pair_unset(126, finalizable); 77 test_set_pair_unset(128, finalizable); 78 } 79 80 }; 81 82 TEST_F(ZBitMapTest, test_set_pair_set) { 83 test_set_pair_set(false); 84 test_set_pair_set(true); 85 } 86 87 TEST_F(ZBitMapTest, test_set_pair_unset) { 88 test_set_pair_unset(false); 89 test_set_pair_unset(true); 90 }