/* * Copyright (c) 2018, 2021, Oracle and/or its affiliates. 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.
*/
EXPECT_PRED2(is_ptr_aligned, rs.base(), alignment)
<< "aligned sizes should always give aligned addresses";
EXPECT_PRED2(is_ptr_aligned, (void*) rs.size(), alignment)
<< "aligned sizes should always give aligned addresses";
if (rs.special()) {
small_page_write(rs.base(), size);
}
}
staticvoid test_reserved_size_alignment_page_type(size_t size, size_t alignment, boolmaybe_large) { if (size < alignment) { // Tests might set -XX:LargePageSizeInBytes=<small pages> and cause unexpected input arguments for this test.
ASSERT_EQ((size_t) os::vm_page_size(), os::large_page_size()) << "Test needs further refinement"; return;
}
ASSERT_PRED2(is_size_aligned, size, os::vm_allocation_granularity()) << "Must be at least AG aligned";
ASSERT_PRED2(is_size_aligned, size, alignment) << "Must be at least AG aligned";
bool large = maybe_large && UseLargePages && size >= os::large_page_size();
size_t page_size = large ? os::large_page_size() : os::vm_page_size();
if (vs.special()) {
EXPECT_EQ(reserve_size_aligned, vs.actual_committed_size());
} else {
EXPECT_GE(vs.actual_committed_size(), commit_size); // Approximate the commit granularity. // Make sure that we don't commit using large pages // if large pages has been disabled for this VirtualSpace.
size_t commit_granularity = (mode == Disable || !UseLargePages) ?
os::vm_page_size() : os::large_page_size();
EXPECT_LT(vs.actual_committed_size(), commit_size + commit_granularity);
}
}
}
TEST_VM(VirtualSpace, disable_large_pages) { if (!UseLargePages) { return;
} // These test cases verify that if we force VirtualSpace to disable large pages
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Disable));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Reserve));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0, Commit));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K, Commit));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K, Commit));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M, Commit));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M, Commit));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M, Commit));
EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Commit));
}
// ========================= concurrent virtual space memory tests // This class have been imported from the original "internal VM test" with minor modification, // specifically using GTest asserts instead of native HotSpot asserts. class TestReservedSpace : AllStatic { public: staticvoid small_page_write(void* addr, size_t size) {
size_t page_size = os::vm_page_size();
char* end = (char*)addr + size; for (char* p = (char*)addr; p < end; p += page_size) {
*p = 1;
}
}
EXPECT_TRUE(is_aligned(rs.base(), alignment)) << "aligned sizes should always give aligned addresses";
EXPECT_TRUE(is_aligned(rs.size(), alignment)) << "aligned sizes should always give aligned addresses";
if (rs.special()) {
small_page_write(rs.base(), size);
}
release_memory_for_test(rs);
}
staticvoid test_reserved_space2(size_t size) {
ASSERT_TRUE(is_aligned(size, os::vm_allocation_granularity())) << "Must be at least AG aligned";
if (rs.special()) {
small_page_write(rs.base(), size);
}
release_memory_for_test(rs);
}
staticvoid test_reserved_space3(size_t size, size_t alignment, bool maybe_large) { if (size < alignment) { // Tests might set -XX:LargePageSizeInBytes=<small pages> and cause unexpected input arguments for this test.
ASSERT_EQ((size_t)os::vm_page_size(), os::large_page_size()) << "Test needs further refinement"; return;
}
EXPECT_TRUE(is_aligned(size, os::vm_allocation_granularity())) << "Must be at least AG aligned";
EXPECT_TRUE(is_aligned(size, alignment)) << "Must be at least aligned against alignment";
bool large = maybe_large && UseLargePages && size >= os::large_page_size();
size_t page_size = large ? os::large_page_size() : os::vm_page_size();
if (vs.special()) {
EXPECT_EQ(vs.actual_committed_size(), reserve_size_aligned);
} else {
EXPECT_GE(vs.actual_committed_size(), commit_size); // Approximate the commit granularity. // Make sure that we don't commit using large pages // if large pages has been disabled for this VirtualSpace.
size_t commit_granularity = (mode == Disable || !UseLargePages) ?
os::vm_page_size() : os::large_page_size();
EXPECT_LT(vs.actual_committed_size(), commit_size + commit_granularity);
}
reserved.release();
}
staticvoid test_virtual_space_actual_committed_space_one_large_page() { if (!UseLargePages) { return;
}
staticvoid test_virtual_space_disable_large_pages() { if (!UseLargePages) { return;
} // These test cases verify that if we force VirtualSpace to disable large pages
test_virtual_space_actual_committed_space(10 * M, 0, Disable);
test_virtual_space_actual_committed_space(10 * M, 4 * K, Disable);
test_virtual_space_actual_committed_space(10 * M, 8 * K, Disable);
test_virtual_space_actual_committed_space(10 * M, 1 * M, Disable);
test_virtual_space_actual_committed_space(10 * M, 2 * M, Disable);
test_virtual_space_actual_committed_space(10 * M, 5 * M, Disable);
test_virtual_space_actual_committed_space(10 * M, 10 * M, Disable);
test_virtual_space_actual_committed_space(10 * M, 0, Reserve);
test_virtual_space_actual_committed_space(10 * M, 4 * K, Reserve);
test_virtual_space_actual_committed_space(10 * M, 8 * K, Reserve);
test_virtual_space_actual_committed_space(10 * M, 1 * M, Reserve);
test_virtual_space_actual_committed_space(10 * M, 2 * M, Reserve);
test_virtual_space_actual_committed_space(10 * M, 5 * M, Reserve);
test_virtual_space_actual_committed_space(10 * M, 10 * M, Reserve);
test_virtual_space_actual_committed_space(10 * M, 0, Commit);
test_virtual_space_actual_committed_space(10 * M, 4 * K, Commit);
test_virtual_space_actual_committed_space(10 * M, 8 * K, Commit);
test_virtual_space_actual_committed_space(10 * M, 1 * M, Commit);
test_virtual_space_actual_committed_space(10 * M, 2 * M, Commit);
test_virtual_space_actual_committed_space(10 * M, 5 * M, Commit);
test_virtual_space_actual_committed_space(10 * M, 10 * M, Commit);
}
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 ist noch experimentell.