In HotSpot we have (at least) two hashtable designs in the C++ code:
- share/utilities/hashtable.hpp
- share/utilities/resourceHash.hpp
Of the two, the ResourceHashtable API is much cleaner and most new code has been written with it. However, one issue is that the SIZE of ResourceHashtable is a compile-time constant. This makes the hash-to-index computation very fast on x64 (gcc can avoid using the slow divq instruction for modulo). However, the downside is we cannot use ResourceHashtable when we need a hashtable whose size is determined at run time (and, optionally, resizeable).
We should implement a new ResizableResourceHashtable template class that has the same design, but uses a instance variable to store its current size.
See https://github.com/iklam/tools/tree/main/bench/resourceHash for a prototype. And also the comparison of hashing function speed.
- share/utilities/hashtable.hpp
- share/utilities/resourceHash.hpp
Of the two, the ResourceHashtable API is much cleaner and most new code has been written with it. However, one issue is that the SIZE of ResourceHashtable is a compile-time constant. This makes the hash-to-index computation very fast on x64 (gcc can avoid using the slow divq instruction for modulo). However, the downside is we cannot use ResourceHashtable when we need a hashtable whose size is determined at run time (and, optionally, resizeable).
We should implement a new ResizableResourceHashtable template class that has the same design, but uses a instance variable to store its current size.
See https://github.com/iklam/tools/tree/main/bench/resourceHash for a prototype. And also the comparison of hashing function speed.
- relates to
-
JDK-8270059 Remove KVHashtable
-
- Resolved
-
-
JDK-8267935 Replace BasicHashtable and Hashtable
-
- Resolved
-