< prev index next >

test/hotspot/gtest/metaspace/test_commitmask.cpp

Print this page
rev 60811 : imported patch jep387-all.patch
rev 60812 : [mq]: diff1

*** 1,8 **** /* ! * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. ! * Copyright (c) 2018, 2020 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,8 ---- /* ! * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. ! * Copyright (c) 2020 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 22,35 **** * questions. * */ #include "precompiled.hpp" #include "runtime/os.hpp" ! #include "metaspaceTestsCommon.hpp" ! #include "metaspace/metaspace_rangehelpers.hpp" static int get_random(int limit) { return os::random() % limit; } class CommitMaskTest { const MetaWord* const _base; --- 22,43 ---- * questions. * */ #include "precompiled.hpp" + + #include "memory/metaspace/msCommitMask.hpp" + #include "memory/metaspace/msSettings.hpp" #include "runtime/os.hpp" + #include "utilities/align.hpp" + #include "utilities/debug.hpp" + + #include "metaspaceGtestCommon.hpp" + #include "metaspaceGtestRangeHelpers.hpp" ! using metaspace::CommitMask; ! using metaspace::Settings; static int get_random(int limit) { return os::random() % limit; } class CommitMaskTest { const MetaWord* const _base;
*** 38,48 **** CommitMask _mask; void verify_mask() { // Note: we omit the touch test since we operate on fictional // memory ! DEBUG_ONLY(_mask.verify(false);) } // Return a random sub range within [_base.._base + word_size), // aligned to granule size const MetaWord* calc_random_subrange(size_t* p_word_size) { --- 46,56 ---- CommitMask _mask; void verify_mask() { // Note: we omit the touch test since we operate on fictional // memory ! DEBUG_ONLY(_mask.verify();) } // Return a random sub range within [_base.._base + word_size), // aligned to granule size const MetaWord* calc_random_subrange(size_t* p_word_size) {
*** 83,93 **** ASSERT_EQ(_mask.get_committed_size(), _word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), _word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p ++) { ASSERT_TRUE(_mask.is_committed_address(p)); } // Now make an uncommitted hole size_t sr_word_size; --- 91,101 ---- ASSERT_EQ(_mask.get_committed_size(), _word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), _word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p++) { ASSERT_TRUE(_mask.is_committed_address(p)); } // Now make an uncommitted hole size_t sr_word_size;
*** 109,119 **** (size_t)0); ASSERT_EQ(_mask.get_committed_size(), _word_size - sr_word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), _word_size - sr_word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p ++) { if (p >= sr_base && p < sr_base + sr_word_size) { ASSERT_FALSE(_mask.is_committed_address(p)); } else { ASSERT_TRUE(_mask.is_committed_address(p)); } --- 117,127 ---- (size_t)0); ASSERT_EQ(_mask.get_committed_size(), _word_size - sr_word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), _word_size - sr_word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p++) { if (p >= sr_base && p < sr_base + sr_word_size) { ASSERT_FALSE(_mask.is_committed_address(p)); } else { ASSERT_TRUE(_mask.is_committed_address(p)); }
*** 128,138 **** sr_word_size); ASSERT_EQ(_mask.get_committed_size(), _word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), _word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p ++) { ASSERT_TRUE(_mask.is_committed_address(p)); } } --- 136,146 ---- sr_word_size); ASSERT_EQ(_mask.get_committed_size(), _word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), _word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p++) { ASSERT_TRUE(_mask.is_committed_address(p)); } }
*** 161,171 **** LOG("subrange " PTR_FORMAT "-" PTR_FORMAT ".", p2i(sr_base), p2i(sr_base + sr_word_size)); ASSERT_EQ(_mask.get_committed_size_in_range(sr_base, sr_word_size), (size_t)0); ! for (const MetaWord* p = _base; p < _base + _word_size; p ++) { ASSERT_FALSE(_mask.is_committed_address(p)); } size_t prior_committed = _mask.mark_range_as_committed(sr_base, sr_word_size); verify_mask(); --- 169,179 ---- LOG("subrange " PTR_FORMAT "-" PTR_FORMAT ".", p2i(sr_base), p2i(sr_base + sr_word_size)); ASSERT_EQ(_mask.get_committed_size_in_range(sr_base, sr_word_size), (size_t)0); ! for (const MetaWord* p = _base; p < _base + _word_size; p++) { ASSERT_FALSE(_mask.is_committed_address(p)); } size_t prior_committed = _mask.mark_range_as_committed(sr_base, sr_word_size); verify_mask();
*** 180,190 **** sr_word_size); ASSERT_EQ(_mask.get_committed_size(), sr_word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), sr_word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p ++) { if (p >= sr_base && p < sr_base + sr_word_size) { ASSERT_TRUE(_mask.is_committed_address(p)); } else { ASSERT_FALSE(_mask.is_committed_address(p)); } --- 188,198 ---- sr_word_size); ASSERT_EQ(_mask.get_committed_size(), sr_word_size); ASSERT_EQ(_mask.get_committed_size_in_range(_base, _word_size), sr_word_size); ! for (const MetaWord* p = _base; p < _base + _word_size; p++) { if (p >= sr_base && p < sr_base + sr_word_size) { ASSERT_TRUE(_mask.is_committed_address(p)); } else { ASSERT_FALSE(_mask.is_committed_address(p)); }
*** 199,223 **** (size_t)0); EXPECT_EQ(_mask.get_committed_size(), (size_t)0); EXPECT_EQ(_mask.get_committed_size_in_range(_base, _word_size), (size_t)0); ! for (const MetaWord* p = _base; p < _base + _word_size; p ++) { ASSERT_FALSE(_mask.is_committed_address(p)); } } - void test3() { // arbitrary ranges are set and cleared and compared with the test map TestMap map(_word_size); _mask.clear_large(); ! for (int run = 0; run < 100; run ++) { // A random range SizeRange r = SizeRange(_word_size).random_aligned_subrange(Settings::commit_granule_words()); if (os::random() % 100 < 50) { --- 207,230 ---- (size_t)0); EXPECT_EQ(_mask.get_committed_size(), (size_t)0); EXPECT_EQ(_mask.get_committed_size_in_range(_base, _word_size), (size_t)0); ! for (const MetaWord* p = _base; p < _base + _word_size; p++) { ASSERT_FALSE(_mask.is_committed_address(p)); } } void test3() { // arbitrary ranges are set and cleared and compared with the test map TestMap map(_word_size); _mask.clear_large(); ! for (int run = 0; run < 100; run++) { // A random range SizeRange r = SizeRange(_word_size).random_aligned_subrange(Settings::commit_granule_words()); if (os::random() % 100 < 50) {
*** 235,261 **** } } - public: CommitMaskTest(const MetaWord* base, size_t size) : _base(base), _word_size(size), _mask(base, size) {} void test() { LOG("mask range: " PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT " words).", p2i(_base), p2i(_base + _word_size), _word_size); ! for (int i = 0; i < 5; i ++) { test1(); test2(); test3(); } } - }; TEST_VM(metaspace, commit_mask_basics) { const MetaWord* const base = (const MetaWord*) 0x100000; --- 242,266 ---- } } public: CommitMaskTest(const MetaWord* base, size_t size) : _base(base), _word_size(size), _mask(base, size) {} void test() { LOG("mask range: " PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT " words).", p2i(_base), p2i(_base + _word_size), _word_size); ! for (int i = 0; i < 5; i++) { test1(); test2(); test3(); } } }; TEST_VM(metaspace, commit_mask_basics) { const MetaWord* const base = (const MetaWord*) 0x100000;
*** 271,281 **** mask3.mark_range_as_committed(base, Settings::commit_granule_words()); mask3.mark_range_as_committed(base + (Settings::commit_granule_words() * 42), Settings::commit_granule_words()); ASSERT_EQ(mask3.at(0), 1); ! for (int i = 1; i < 42; i ++) { ASSERT_EQ(mask3.at(i), 0); } ASSERT_EQ(mask3.at(42), 1); } --- 276,286 ---- mask3.mark_range_as_committed(base, Settings::commit_granule_words()); mask3.mark_range_as_committed(base + (Settings::commit_granule_words() * 42), Settings::commit_granule_words()); ASSERT_EQ(mask3.at(0), 1); ! for (int i = 1; i < 42; i++) { ASSERT_EQ(mask3.at(i), 0); } ASSERT_EQ(mask3.at(42), 1); }
*** 324,337 **** } } } - TEST_VM(metaspace, commit_mask_random) { ! for (int i = 0; i < 5; i ++) { // make up a range out of thin air const MetaWord* const base = align_down( (const MetaWord*) ((uintptr_t) os::random() * os::random()), Settings::commit_granule_bytes()); --- 329,341 ---- } } } TEST_VM(metaspace, commit_mask_random) { ! for (int i = 0; i < 5; i++) { // make up a range out of thin air const MetaWord* const base = align_down( (const MetaWord*) ((uintptr_t) os::random() * os::random()), Settings::commit_granule_bytes());
< prev index next >