Path: blob/master/test/hotspot/gtest/utilities/test_bitMap_large.cpp
41145 views
/*1* Copyright (c) 2018, Red Hat Inc. 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 "utilities/bitMap.inline.hpp"25#include "unittest.hpp"2627// Bitmap size should be large enough to accept large operations.28static const BitMap::idx_t BITMAP_SIZE = 8192;2930// The test would like to fuzz indexes in this window. Having the fuzz31// window at bitmap word size makes sure the test would touch every combination32// of indexes (un)aligned on word boundary.33static const BitMap::idx_t FUZZ_WINDOW = sizeof(BitMap::bm_word_t) * 8;3435static void verify_set(CHeapBitMap& map, BitMap::idx_t l, BitMap::idx_t r) {36for (BitMap::idx_t c = l; c < r; c++) {37EXPECT_TRUE(map.at(c));38}39}4041static void verify_unset(CHeapBitMap& map, BitMap::idx_t l, BitMap::idx_t r) {42for (BitMap::idx_t c = l; c < r; c++) {43EXPECT_FALSE(map.at(c));44}45}4647TEST(BitMap, clear_large_range) {48CHeapBitMap map(BITMAP_SIZE);4950map.set_range(0, BITMAP_SIZE);51verify_set(map, 0, BITMAP_SIZE);5253for (size_t size_class = 0; size_class <= BITMAP_SIZE; size_class = MAX2<size_t>(1, size_class*2)) {54for (BitMap::idx_t l = 0; l < FUZZ_WINDOW; l++) {55for (BitMap::idx_t tr = l; tr < FUZZ_WINDOW; tr++) {56BitMap::idx_t r = MIN2(BITMAP_SIZE, size_class + tr); // avoid overflow5758map.clear_large_range(l, r);59verify_unset(map, l, r);60verify_set(map, 0, l);61verify_set(map, r, BITMAP_SIZE);6263// Restore cleared64map.set_range(l, r);65verify_set(map, l, r);66}67}68}69}7071TEST(BitMap, set_large_range) {72CHeapBitMap map(BITMAP_SIZE);7374map.clear();75verify_unset(map, 0, BITMAP_SIZE);7677for (size_t size_class = 0; size_class <= BITMAP_SIZE; size_class = MAX2<size_t>(1, size_class*2)) {78for (BitMap::idx_t l = 0; l < FUZZ_WINDOW; l++) {79for (BitMap::idx_t tr = l; tr < FUZZ_WINDOW; tr++) {80BitMap::idx_t r = MIN2(BITMAP_SIZE, size_class + tr); // avoid overflow8182map.set_large_range(l, r);83verify_set(map, l, r);84verify_unset(map, 0, l);85verify_unset(map, r, BITMAP_SIZE);8687// Restore set88map.clear_range(l, r);89verify_unset(map, l, r);90}91}92}93}9495TEST(BitMap, par_at_put_large_range) {96CHeapBitMap map(BITMAP_SIZE);9798map.clear();99verify_unset(map, 0, BITMAP_SIZE);100101for (size_t size_class = 0; size_class <= BITMAP_SIZE; size_class = MAX2<size_t>(1, size_class*2)) {102for (BitMap::idx_t l = 0; l < FUZZ_WINDOW; l++) {103for (BitMap::idx_t tr = l; tr < FUZZ_WINDOW; tr++) {104BitMap::idx_t r = MIN2(BITMAP_SIZE, size_class + tr); // avoid overflow105106map.par_at_put_large_range(l, r, true);107verify_set(map, l, r);108verify_unset(map, 0, l);109verify_unset(map, r, BITMAP_SIZE);110111// Restore set112map.clear_range(l, r);113verify_unset(map, l, r);114}115}116}117}118119120