Path: blob/master/test/hotspot/gtest/gc/z/test_zBitMap.cpp
41152 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/z/zBitMap.inline.hpp"25#include "unittest.hpp"2627class ZBitMapTest : public ::testing::Test {28protected:29static void test_set_pair_unset(size_t size, bool finalizable) {30ZBitMap bitmap(size);3132for (BitMap::idx_t i = 0; i < size - 1; i++) {33if ((i + 1) % BitsPerWord == 0) {34// Can't set pairs of bits in different words.35continue;36}3738// ZBitMaps are not cleared when constructed.39bitmap.clear();4041bool inc_live = false;4243bool ret = bitmap.par_set_bit_pair(i, finalizable, inc_live);44EXPECT_TRUE(ret) << "Failed to set bit";45EXPECT_TRUE(inc_live) << "Should have set inc_live";4647// First bit should always be set48EXPECT_TRUE(bitmap.at(i)) << "Should be set";4950// Second bit should only be set when marking strong51EXPECT_NE(bitmap.at(i + 1), finalizable);52}53}5455static void test_set_pair_set(size_t size, bool finalizable) {56ZBitMap bitmap(size);5758for (BitMap::idx_t i = 0; i < size - 1; i++) {59if ((i + 1) % BitsPerWord == 0) {60// Can't set pairs of bits in different words.61continue;62}6364// Fill the bitmap with ones.65bitmap.set_range(0, size);6667bool inc_live = false;6869bool ret = bitmap.par_set_bit_pair(i, finalizable, inc_live);70EXPECT_FALSE(ret) << "Should not succeed setting bit";71EXPECT_FALSE(inc_live) << "Should not have set inc_live";7273// Both bits were pre-set.74EXPECT_TRUE(bitmap.at(i)) << "Should be set";75EXPECT_TRUE(bitmap.at(i + 1)) << "Should be set";76}77}7879static void test_set_pair_set(bool finalizable) {80test_set_pair_set(2, finalizable);81test_set_pair_set(62, finalizable);82test_set_pair_set(64, finalizable);83test_set_pair_set(66, finalizable);84test_set_pair_set(126, finalizable);85test_set_pair_set(128, finalizable);86}8788static void test_set_pair_unset(bool finalizable) {89test_set_pair_unset(2, finalizable);90test_set_pair_unset(62, finalizable);91test_set_pair_unset(64, finalizable);92test_set_pair_unset(66, finalizable);93test_set_pair_unset(126, finalizable);94test_set_pair_unset(128, finalizable);95}9697};9899TEST_F(ZBitMapTest, test_set_pair_set) {100test_set_pair_set(false);101test_set_pair_set(true);102}103104TEST_F(ZBitMapTest, test_set_pair_unset) {105test_set_pair_unset(false);106test_set_pair_unset(true);107}108109110