< prev index next >

test/hotspot/gtest/metaspace/test_binlist.cpp

Print this page

  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #include "precompiled.hpp"
 27 #include "memory/metaspace/binList.hpp"
 28 #include "memory/metaspace/counters.hpp"

 29 //#define LOG_PLEASE
 30 #include "metaspaceGtestCommon.hpp"
 31 
 32 using metaspace::BinList32;
 33 using metaspace::BinListImpl;
 34 using metaspace::MemRangeCounter;

 35 
 36 #define CHECK_BL_CONTENT(bl, expected_num, expected_size) { \
 37   EXPECT_EQ(bl.count(), (unsigned)expected_num); \
 38   EXPECT_EQ(bl.total_size(), (size_t)expected_size); \
 39   if (expected_num == 0) { \
 40     EXPECT_TRUE(bl.is_empty()); \
 41   } else { \
 42     EXPECT_FALSE(bl.is_empty()); \
 43   } \
 44 }
 45 













 46 template <class BINLISTTYPE>
 47 struct BinListBasicTest {
 48 
 49   static const size_t maxws;
 50 
 51   static void basic_test() {
 52 
 53     BINLISTTYPE bl;
 54 
 55     CHECK_BL_CONTENT(bl, 0, 0);
 56 
 57     MetaWord arr[1000];
 58 
 59     size_t innocous_size = MAX2((size_t)1, maxws / 2);
 60 
 61     // Try to get a block from an empty list.
 62     size_t real_size = 4711;
 63     MetaWord* p = bl.remove_block(innocous_size, &real_size);
 64     EXPECT_EQ(p, (MetaWord*)nullptr);
 65     EXPECT_EQ((size_t)0, real_size);

189         ASSERT_GE(real_size, (size_t)1);
190         ASSERT_TRUE(fb.is_valid_range(p, real_size));
191 
192         // This must hold true since we always return the smallest fit.
193         ASSERT_GE(real_size, last_size);
194         if (real_size > last_size) {
195           last_size = real_size;
196         }
197 
198         cnt[which].sub(real_size);
199 
200         CHECK_COUNTERS;
201       }
202     }
203 
204   }
205 };
206 
207 template <typename BINLISTTYPE> const size_t BinListBasicTest<BINLISTTYPE>::maxws = BINLISTTYPE::MaxWordSize;
208 
209 TEST_VM(metaspace, BinList_basic_1)     { BinListBasicTest< BinListImpl<1> >::basic_test(); }
210 TEST_VM(metaspace, BinList_basic_8)     { BinListBasicTest< BinListImpl<8> >::basic_test(); }
211 TEST_VM(metaspace, BinList_basic_32)    { BinListBasicTest<BinList32>::basic_test(); }
212 
213 TEST_VM(metaspace, BinList_basic_2_1)     { BinListBasicTest< BinListImpl<1> >::basic_test_2(); }
214 TEST_VM(metaspace, BinList_basic_2_8)     { BinListBasicTest< BinListImpl<8> >::basic_test_2(); }
215 TEST_VM(metaspace, BinList_basic_2_32)    { BinListBasicTest<BinList32>::basic_test_2(); }
216 
217 TEST_VM(metaspace, BinList_basic_rand_1)     { BinListBasicTest< BinListImpl<1> >::random_test(); }
218 TEST_VM(metaspace, BinList_basic_rand_8)     { BinListBasicTest< BinListImpl<8> >::random_test(); }
219 TEST_VM(metaspace, BinList_basic_rand_32)    { BinListBasicTest<BinList32>::random_test(); }

  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #include "precompiled.hpp"
 27 #include "memory/metaspace/binList.hpp"
 28 #include "memory/metaspace/counters.hpp"
 29 #include "memory/metaspace/metablock.hpp"
 30 //#define LOG_PLEASE
 31 #include "metaspaceGtestCommon.hpp"
 32 
 33 using metaspace::BinList32;
 34 using metaspace::BinListImpl;
 35 using metaspace::MemRangeCounter;
 36 using metaspace::MetaBlock;
 37 
 38 #define CHECK_BL_CONTENT(bl, expected_num, expected_size) { \
 39   EXPECT_EQ(bl.count(), (unsigned)expected_num); \
 40   EXPECT_EQ(bl.total_size(), (size_t)expected_size); \
 41   if (expected_num == 0) { \
 42     EXPECT_TRUE(bl.is_empty()); \
 43   } else { \
 44     EXPECT_FALSE(bl.is_empty()); \
 45   } \
 46 }
 47 
 48 template <int num_lists>
 49 struct TestedBinList : public BinListImpl<num_lists> {
 50   typedef BinListImpl<num_lists> ListType;
 51   void add_block(MetaWord* p, size_t word_size) {
 52     ListType::add_block(MetaBlock(p, word_size));
 53   }
 54   MetaWord* remove_block(size_t requested_size, size_t* real_size) {
 55     MetaBlock result = ListType::remove_block(requested_size);
 56     (*real_size) = result.word_size();
 57     return result.base();
 58   }
 59 };
 60 
 61 template <class BINLISTTYPE>
 62 struct BinListBasicTest {
 63 
 64   static const size_t maxws;
 65 
 66   static void basic_test() {
 67 
 68     BINLISTTYPE bl;
 69 
 70     CHECK_BL_CONTENT(bl, 0, 0);
 71 
 72     MetaWord arr[1000];
 73 
 74     size_t innocous_size = MAX2((size_t)1, maxws / 2);
 75 
 76     // Try to get a block from an empty list.
 77     size_t real_size = 4711;
 78     MetaWord* p = bl.remove_block(innocous_size, &real_size);
 79     EXPECT_EQ(p, (MetaWord*)nullptr);
 80     EXPECT_EQ((size_t)0, real_size);

204         ASSERT_GE(real_size, (size_t)1);
205         ASSERT_TRUE(fb.is_valid_range(p, real_size));
206 
207         // This must hold true since we always return the smallest fit.
208         ASSERT_GE(real_size, last_size);
209         if (real_size > last_size) {
210           last_size = real_size;
211         }
212 
213         cnt[which].sub(real_size);
214 
215         CHECK_COUNTERS;
216       }
217     }
218 
219   }
220 };
221 
222 template <typename BINLISTTYPE> const size_t BinListBasicTest<BINLISTTYPE>::maxws = BINLISTTYPE::MaxWordSize;
223 
224 TEST_VM(metaspace, BinList_basic_1)     { BinListBasicTest< TestedBinList<1> >::basic_test(); }
225 TEST_VM(metaspace, BinList_basic_8)     { BinListBasicTest< TestedBinList<8> >::basic_test(); }
226 TEST_VM(metaspace, BinList_basic_32)    { BinListBasicTest< TestedBinList<32> >::basic_test(); }
227 
228 TEST_VM(metaspace, BinList_basic_2_1)     { BinListBasicTest< TestedBinList<1> >::basic_test_2(); }
229 TEST_VM(metaspace, BinList_basic_2_8)     { BinListBasicTest< TestedBinList<8> >::basic_test_2(); }
230 TEST_VM(metaspace, BinList_basic_2_32)    { BinListBasicTest< TestedBinList<32> >::basic_test_2(); }
231 
232 TEST_VM(metaspace, BinList_basic_rand_1)     { BinListBasicTest< TestedBinList<1> >::random_test(); }
233 TEST_VM(metaspace, BinList_basic_rand_8)     { BinListBasicTest< TestedBinList<8> >::random_test(); }
234 TEST_VM(metaspace, BinList_basic_rand_32)    { BinListBasicTest< TestedBinList<32> >::random_test(); }
< prev index next >