/* * Copyright (c) 2018, 2022, 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.
*/
// Pre-allocate an area as large as the largest allocation // and aligned to the largest alignment we will be testing. const size_t mapping_size = sizes[num_sizes - 1] * 2; char* const mapping = (char*) ::mmap(NULL, mapping_size,
PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,
-1, 0);
ASSERT_TRUE(mapping != MAP_FAILED) << " mmap failed, mapping_size = " << mapping_size; // Unmap the mapping, it will serve as a value for a "good" req_addr
::munmap(mapping, mapping_size);
for (int i = 0; i < num_sizes; i++) { const size_t size = sizes[i]; for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) { // req_addr must be at least large page aligned. char* const req_addr = align_up(mapping, MAX2(alignment, lp)); char* p = HugeTlbfsMemory::reserve_memory_special_huge_tlbfs(size, alignment, lp, req_addr, false); if (p != NULL) {
HugeTlbfsMemory mr(p, size);
ASSERT_EQ(req_addr, p) << " size = " << size << ", alignment = " << alignment;
small_page_write(p, size);
}
}
}
}
TEST_VM(os_linux, reserve_memory_special_huge_tlbfs_size_not_aligned_with_bad_req_addr) { if (!UseHugeTLBFS) { return;
}
size_t lp = os::large_page_size();
size_t ag = os::vm_allocation_granularity();
// Pre-allocate an area as large as the largest allocation // and aligned to the largest alignment we will be testing. const size_t mapping_size = sizes[num_sizes - 1] * 2; char* const mapping = (char*) ::mmap(NULL, mapping_size,
PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,
-1, 0);
ASSERT_TRUE(mapping != MAP_FAILED) << " mmap failed, mapping_size = " << mapping_size; // Leave the mapping intact, it will server as "bad" req_addr
// For each size/alignment combination, we test three scenarios: // 1) with req_addr == NULL // 2) with a non-null req_addr at which we expect to successfully allocate // 3) with a non-null req_addr which contains a pre-existing mapping, at which we // expect the allocation to either fail or to ignore req_addr
// Pre-allocate two areas; they shall be as large as the largest allocation // and aligned to the largest alignment we will be testing. const size_t mapping_size = sizes[num_sizes - 1] * 2; char* const mapping1 = (char*) ::mmap(NULL, mapping_size,
PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,
-1, 0);
EXPECT_NE(mapping1, MAP_FAILED);
// Unmap the first mapping, but leave the second mapping intact: the first // mapping will serve as a value for a "good" req_addr (case 2). The second // mapping, still intact, as "bad" req_addr (case 3).
::munmap(mapping1, mapping_size);
// Case 1 for (int i = 0; i < num_sizes; i++) { const size_t size = sizes[i]; for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { char* p = os::Linux::reserve_memory_special_huge_tlbfs(size, alignment, lp, NULL, false); if (p != NULL) {
EXPECT_TRUE(is_aligned(p, alignment));
small_page_write(p, size);
os::Linux::release_memory_special_huge_tlbfs(p, size);
}
}
}
// Case 2 for (int i = 0; i < num_sizes; i++) { const size_t size = sizes[i]; for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { // req_addr must be at least large page aligned. char* const req_addr = align_up(mapping1, MAX2(alignment, lp)); char* p = os::Linux::reserve_memory_special_huge_tlbfs(size, alignment, lp, req_addr, false); if (p != NULL) {
EXPECT_EQ(p, req_addr);
small_page_write(p, size);
os::Linux::release_memory_special_huge_tlbfs(p, size);
}
}
}
// Case 3 for (int i = 0; i < num_sizes; i++) { const size_t size = sizes[i]; for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { // req_addr must be at least large page aligned. char* const req_addr = align_up(mapping2, MAX2(alignment, lp)); char* p = os::Linux::reserve_memory_special_huge_tlbfs(size, alignment, lp, req_addr, false); // as the area around req_addr contains already existing mappings, the API should always // return NULL (as per contract, it cannot return another address)
EXPECT_TRUE(p == NULL);
}
}
::munmap(mapping2, mapping_size);
}
staticvoid test_reserve_memory_special_huge_tlbfs() { if (!UseHugeTLBFS) { return;
}
#if !defined(__clang_major__) || (__clang_major__ >= 5) // DWARF does not support Clang versions older than 5.0. // Test valid address of method ReportJNIFatalError in jniCheck.hpp. We should get "jniCheck.hpp" in the buffer and a valid line number.
TEST_VM(os_linux, decoder_get_source_info_valid) { char buf[128] = ""; int line = -1;
address valid_function_pointer = (address)ReportJNIFatalError;
ASSERT_TRUE(Decoder::get_source_info(valid_function_pointer, buf, sizeof(buf), &line));
ASSERT_TRUE(strcmp(buf, "jniCheck.hpp") == 0);
ASSERT_TRUE(line > 0);
}
// Test invalid addresses. Should not cause harm and output buffer and line must contain "" and -1, respectively.
TEST_VM(os_linux, decoder_get_source_info_invalid) { char buf[128] = ""; int line = -1;
address invalid_function_pointers[] = { nullptr, (address)1, (address)&line };
for (address addr : invalid_function_pointers) {
strcpy(buf, "somestring");
line = 12; // We should return false but do not crash or fail in any way.
ASSERT_FALSE(Decoder::get_source_info(addr, buf, sizeof(buf), &line));
ASSERT_TRUE(buf[0] == '\0'); // Should contain "" on error
ASSERT_TRUE(line == -1); // Should contain -1 on error
}
}
// Test with valid address but a too small buffer to store the entire filename. Should find generic <OVERFLOW> message // and a valid line number.
TEST_VM(os_linux, decoder_get_source_info_valid_overflow) { char buf[11] = ""; int line = -1;
address valid_function_pointer = (address)ReportJNIFatalError;
ASSERT_TRUE(Decoder::get_source_info(valid_function_pointer, buf, 11, &line));
ASSERT_TRUE(strcmp(buf, "") == 0);
ASSERT_TRUE(line > 0);
}
// Test with valid address but a too small buffer that can neither store the entire filename nor the generic <OVERFLOW> // message. We should find "L" as filename and a valid line number.
TEST_VM(os_linux, decoder_get_source_info_valid_overflow_minimal) { char buf[2] = ""; int line = -1;
address valid_function_pointer = (address)ReportJNIFatalError;
ASSERT_TRUE(Decoder::get_source_info(valid_function_pointer, buf, 2, &line));
ASSERT_TRUE(strcmp(buf, "L") == 0); // Overflow message does not fit, so we fall back to "L:line_number"
ASSERT_TRUE(line > 0); // Line should correctly be found and returned
} #endif// clang
#ifdef __GLIBC__
TEST_VM(os_linux, glibc_mallinfo_wrapper) { // Very basic test. Call it. That proves that resolution and invocation works.
os::Linux::glibc_mallinfo mi; bool did_wrap = false;
os::Linux::get_mallinfo(&mi, &did_wrap);
void* p = os::malloc(2 * K, mtTest);
ASSERT_NOT_NULL(p);
// We should see total allocation values > 0
ASSERT_GE((mi.uordblks + mi.hblkhd), 2 * K);
// These values also should exceed some reasonable size.
ASSERT_LT(mi.fordblks, 2 * G);
ASSERT_LT(mi.uordblks, 2 * G);
ASSERT_LT(mi.hblkhd, 2 * G);
os::free(p);
} #endif// __GLIBC__
#endif// LINUX
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
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.