From 78f67993f89792d2f0d8dcf04ba12ee93b336a13 Mon Sep 17 00:00:00 2001 From: Gerard Ziemski Date: Mon, 31 Jul 2023 15:12:22 +0000 Subject: [PATCH] 8293972: runtime/NMT/NMTInitializationTest.java#default_long-off failed with "Suspiciously long bucket chains in lookup table." Reviewed-by: stuefe, dholmes --- src/hotspot/share/services/nmtPreInit.hpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/services/nmtPreInit.hpp b/src/hotspot/share/services/nmtPreInit.hpp index f104b0a2600..c6c504e99cd 100644 --- a/src/hotspot/share/services/nmtPreInit.hpp +++ b/src/hotspot/share/services/nmtPreInit.hpp @@ -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; }