Skip to content

Commit

Permalink
8293972: runtime/NMT/NMTInitializationTest.java#default_long-off fail…
Browse files Browse the repository at this point in the history
…ed with "Suspiciously long bucket chains in lookup table."

Reviewed-by: stuefe, dholmes
  • Loading branch information
Gerard Ziemski committed Jul 31, 2023
1 parent 97b6883 commit 78f6799
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/hotspot/share/services/nmtPreInit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

1 comment on commit 78f6799

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.