1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "memory/resourceArea.hpp" 26 #include "utilities/bitMap.inline.hpp" 27 #include "unittest.hpp" 28 29 class BitMapTest { 30 31 template <class ResizableBitMapClass> 32 static void fillBitMap(ResizableBitMapClass& map) { 33 map.set_bit(1); 34 map.set_bit(3); 35 map.set_bit(17); 36 map.set_bit(512); 37 } 38 39 template <class ResizableBitMapClass> 40 static void testResize(BitMap::idx_t start_size) { 41 ResourceMark rm; 42 43 ResizableBitMapClass map(start_size); 44 map.resize(BITMAP_SIZE); 45 fillBitMap(map); 46 47 ResizableBitMapClass map2(BITMAP_SIZE); 48 fillBitMap(map2); 49 EXPECT_TRUE(map.is_same(map2)) << "With start_size " << start_size; 50 } 51 52 public: 53 const static BitMap::idx_t BITMAP_SIZE = 1024; 54 55 56 template <class ResizableBitMapClass> 57 static void testResizeGrow() { 58 testResize<ResizableBitMapClass>(0); 59 testResize<ResizableBitMapClass>(BITMAP_SIZE >> 3); 60 } 61 62 template <class ResizableBitMapClass> 63 static void testResizeSame() { 64 testResize<ResizableBitMapClass>(BITMAP_SIZE); 65 } 66 67 template <class ResizableBitMapClass> 68 static void testResizeShrink() { 69 testResize<ResizableBitMapClass>(BITMAP_SIZE * 2); 70 } 71 72 template <class InitializableBitMapClass> 73 static void testInitialize() { 74 ResourceMark rm; 75 76 InitializableBitMapClass map; 77 map.initialize(BITMAP_SIZE); 78 fillBitMap(map); 79 80 InitializableBitMapClass map2(BITMAP_SIZE); 81 fillBitMap(map2); 82 EXPECT_TRUE(map.is_same(map2)); 83 } 84 85 86 static void testReinitialize(BitMap::idx_t init_size) { 87 ResourceMark rm; 88 89 ResourceBitMap map(init_size); 90 map.reinitialize(BITMAP_SIZE); 91 fillBitMap(map); 92 93 ResourceBitMap map2(BITMAP_SIZE); 94 fillBitMap(map2); 95 EXPECT_TRUE(map.is_same(map2)) << "With init_size " << init_size; 96 } 97 98 }; 99 100 TEST_VM(BitMap, resize_grow) { 101 BitMapTest::testResizeGrow<ResourceBitMap>(); 102 EXPECT_FALSE(HasFailure()) << "Failed on type ResourceBitMap"; 103 BitMapTest::testResizeGrow<CHeapBitMap>(); 104 EXPECT_FALSE(HasFailure()) << "Failed on type CHeapBitMap"; 105 } 106 107 TEST_VM(BitMap, resize_shrink) { 108 BitMapTest::testResizeShrink<ResourceBitMap>(); 109 EXPECT_FALSE(HasFailure()) << "Failed on type ResourceBitMap"; 110 BitMapTest::testResizeShrink<CHeapBitMap>(); 111 EXPECT_FALSE(HasFailure()) << "Failed on type CHeapBitMap"; 112 } 113 114 TEST_VM(BitMap, resize_same) { 115 BitMapTest::testResizeSame<ResourceBitMap>(); 116 EXPECT_FALSE(HasFailure()) << "Failed on type ResourceBitMap"; 117 BitMapTest::testResizeSame<CHeapBitMap>(); 118 EXPECT_FALSE(HasFailure()) << "Failed on type CHeapBitMap"; 119 } 120 121 TEST_VM(BitMap, initialize) { 122 BitMapTest::testInitialize<ResourceBitMap>(); 123 EXPECT_FALSE(HasFailure()) << "Failed on type ResourceBitMap"; 124 BitMapTest::testInitialize<CHeapBitMap>(); 125 EXPECT_FALSE(HasFailure()) << "Failed on type CHeapBitMap"; 126 } 127 128 TEST_VM(BitMap, reinitialize) { 129 BitMapTest::testReinitialize(0); 130 BitMapTest::testReinitialize(BitMapTest::BITMAP_SIZE >> 3); 131 BitMapTest::testReinitialize(BitMapTest::BITMAP_SIZE); 132 }