/* * 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. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
class CommitMaskTest { const MetaWord* const _base; const size_t _word_size;
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) {
size_t l1 = get_random((int)_word_size);
size_t l2 = get_random((int)_word_size); if (l1 > l2) {
size_t l = l1;
l1 = l2;
l2 = l;
}
l1 = align_down(l1, Settings::commit_granule_words());
l2 = align_up(l2, Settings::commit_granule_words());
const MetaWord* p = _base + l1; const size_t len = l2 - l1;
assert(p >= _base && p + len <= _base + _word_size, "Sanity");
*p_word_size = len;
return p;
}
void test1() {
LOG("test1");
// Commit everything
size_t prior_committed = _mask.mark_range_as_committed(_base, _word_size);
verify_mask();
ASSERT_LE(prior_committed, _word_size); // We do not really know
// Commit everything again, should be a noop
prior_committed = _mask.mark_range_as_committed(_base, _word_size);
verify_mask();
ASSERT_EQ(prior_committed, _word_size);
// Again, for fun, should be a noop now.
prior_uncommitted = _mask.mark_range_as_uncommitted(sr_base, sr_word_size);
verify_mask();
ASSERT_EQ(prior_uncommitted, sr_word_size);
ASSERT_EQ(_mask.get_committed_size_in_range(sr_base, sr_word_size),
(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));
}
}
// Uncommit everything again, should be a noop
prior_uncommitted = _mask.mark_range_as_uncommitted(_base, _word_size);
verify_mask();
ASSERT_EQ(prior_uncommitted, _word_size);
// Again, for fun, should be a noop now.
prior_committed = _mask.mark_range_as_committed(sr_base, sr_word_size);
verify_mask();
ASSERT_EQ(prior_committed, sr_word_size);
ASSERT_EQ(_mask.get_committed_size_in_range(sr_base, sr_word_size),
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));
}
}
size_t l = mask.mark_range_as_committed(base, len);
ASSERT_LE(l, len);
for (const MetaWord* p = base; p <= end - Settings::commit_granule_words();
p += Settings::commit_granule_words()) { for (const MetaWord* p2 = p + Settings::commit_granule_words();
p2 <= end; p2 += Settings::commit_granule_words()) {
LOG(PTR_FORMAT "-" PTR_FORMAT "\n", p2i(p), p2i(p2));
EXPECT_EQ(mask.get_committed_size_in_range(p, p2 - p),
(size_t)(p2 - p));
}
}
l = mask.mark_range_as_uncommitted(base, len);
ASSERT_EQ(l, (size_t)0);
for (const MetaWord* p = base; p <= end - Settings::commit_granule_words();
p += Settings::commit_granule_words()) { for (const MetaWord* p2 = p + Settings::commit_granule_words();
p2 <= end; p2 += Settings::commit_granule_words()) {
LOG(PTR_FORMAT "-" PTR_FORMAT "\n", p2i(p), p2i(p2));
EXPECT_EQ(mask.get_committed_size_in_range(p, p2 - p),
(size_t)(0));
}
}
}
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()); const size_t len = align_up( 1 + (os::random() % M),
Settings::commit_granule_words());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.