8293972: runtime/NMT/NMTInitializationTest.java#default_long-off failed with "Suspiciously long bucket chains in lookup table."

Reviewed-by: stuefe, dholmes
This commit is contained in:
Gerard Ziemski 2023-07-31 15:12:22 +00:00
parent 97b688340e
commit 78f67993f8

View File

@ -143,22 +143,25 @@ class NMTPreInitAllocationTable {
// VMs with insanely long command lines maybe ~700-1000. Which gives us an expected
// load factor of ~.1. Hash collisions should be very rare.
// ~8000 entries cost us ~64K for this table (64-bit), which is acceptable.
static const int table_size = 7919;
// We chose 8191, as this is a Mersenne prime (2^x - 1), which for a random
// polynomial modulo p = (2^x - 1) is uniformily distributed in [p], so each
// bit has the same distribution.
static const int table_size = 8191; // i.e. 8191==(2^13 - 1);
NMTPreInitAllocation* _entries[table_size];
typedef int index_t;
const index_t invalid_index = -1;
static unsigned calculate_hash(const void* p) {
uintptr_t tmp = p2i(p);
unsigned hash = (unsigned)tmp
LP64_ONLY( ^ (unsigned)(tmp >> 32));
return hash;
static uint64_t calculate_hash(const void* p) {
// Keep hash function simple, the modulo
// operation in index function will do the "heavy lifting".
return (uint64_t)(p);
}
static index_t index_for_key(const void* p) {
const unsigned hash = calculate_hash(p);
const uint64_t hash = calculate_hash(p);
// "table_size" is a Mersenne prime, so "modulo" is all we need here.
return hash % table_size;
}