// This tests the NMTPreInitAllocationTable hash table used to store C-heap allocations before NMT initialization ran.
static size_t small_random_nonzero_size() { // We keep the sizes random but not too random; the more regular the sizes, the // more regular the malloc return pointers and the better we see how our hash // function copes in the NMT preinit lu table. switch (os::random() % 4) { case0: return0x10; case1: return0x42; case2: return0x20; case3: return0x80;
} return1;
}
TEST_VM(NMTPreInit, stress_test_map) {
NMTPreInitAllocationTable table; constint num_allocs = 32 * K; // about factor 100 more than normally expected
NMTPreInitAllocation** allocations = NEW_C_HEAP_ARRAY(NMTPreInitAllocation*, num_allocs, mtTest);
// Fill table with allocations for (int i = 0; i < num_allocs; i++) {
NMTPreInitAllocation* a = NMTPreInitAllocation::do_alloc(small_random_nonzero_size());
table.add(a);
allocations[i] = a;
}
print_and_check_table(table, num_allocs);
// look them all up for (int i = 0; i < num_allocs; i++) { const NMTPreInitAllocation* a = table.find(allocations[i]->payload());
ASSERT_EQ(a, allocations[i]);
}
// look them all up for (int i = 0; i < num_allocs; i++) { const NMTPreInitAllocation* a = table.find(allocations[i]->payload());
ASSERT_EQ(a, allocations[i]);
}
// free all for (int i = 0; i < num_allocs; i++) {
NMTPreInitAllocation* a = table.find_and_remove(allocations[i]->payload());
ASSERT_EQ(a, allocations[i]);
NMTPreInitAllocation::do_free(a);
allocations[i] = NULL;
}
#ifdef ASSERT // Test that we will assert if the lookup table is seriously over-booked.
TEST_VM_ASSERT_MSG(NMTPreInit, assert_on_lu_table_overflow, ".*NMT preinit lookup table degenerated.*") {
NMTPreInitAllocationTable table; constint num_allocs = 400 * 1000; // anything above ~250K entries should trigger the assert (note: normal number of entries is ~500) for (int i = 0; i < num_allocs; i++) {
NMTPreInitAllocation* a = NMTPreInitAllocation::do_alloc(1);
table.add(a);
} #ifdef VERBOSE
table.print_state(tty);
tty->cr(); #endif
table.verify();
} #endif// ASSERT
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.