Chronicle Software
-
UnsafeAccessreflects onsun.misc.Unsafe.theUnsafeto obtain the singleton and uses it for raw array access, field offsets, and direct memory loads (UnsafeAccess.java:40-118). This keeps hashing allocation-free but depends on thejdk.unsupportedmodule. -
Direct buffer handling casts to
sun.nio.ch.DirectBufferto retrieve native addresses forhashBytes(ByteBuffer)andhashMemory(Util.java:65-68,LongHashFunction.java:430-470). The code path assumes the buffer is direct; heap buffers are copied through array access instead. -
String hashing inspects
java.lang.String.valueand, on compact-string VMs, treats the backingbyte[]as Latin-1 usingCompactLatin1CharSequenceAccess(ModernCompactStringHash.java:10-62). Older HotSpot builds and other JVMs fall back to UTF-16 behaviour throughModernHotSpotStringHashorHotSpotPrior7u6StringHash.
-
On Java 9 and newer, strong encapsulation may block reflective access to the JDK internals above. Add the following opens/exports when running with a strict module layer:
-
--add-opens java.base/sun.misc=ALL-UNNAMED(access toUnsafe.theUnsafe). -
--add-exports java.base/sun.nio.ch=ALL-UNNAMED(casts toDirectBuffer). -
--add-opens java.base/java.lang=ALL-UNNAMED(readingString.valuefor compact strings).
-
-
The library does not automatically request these permissions. Applications embedding Zero-Allocation Hashing must configure the JVM command line or module descriptors accordingly.
-
All algorithms canonicalise multi-byte reads to little-endian using
Access.byteOrderandPrimitives.nativeToLittleEndian. Hash outputs therefore match across architectures, but big-endian CPUs incur additional byte swap overhead (seeXxHash.java:14-19,XXH3.java:23-28,WyHash.java:9-15). -
When targeting non-HotSpot JVMs,
Util.VALID_STRING_HASHfalls back to a conservative implementation (UnknownJvmStringHash) if the VM name or version is unrecognised. This ensures correctness at the cost of potential performance; review the decision log before altering the detection logic (Util.java:29-63). -
Passing invalid pointers to
hashMemoryor misreportingAccessbyte order is undefined and can crash the JVM. Always validate foreign memory addresses and keep access strategies consistent with the underlying storage layout.