@@ -19,13 +19,22 @@ fast single primitive access and bulk transfer methods as the Slice class.
1919Slice provides a library for interacting UTF-8 data stored in byte arrays. The UTF-8 library provides
2020functions to count code points, substring, trim, case change, and so on.
2121
22- ## Unsafe Usage
22+ ## Byte Order and Platform Compatibility
2323
24- The Slice Library uses ` sun.misc.Unsafe ` to bulk transfer data between byte arrays and other array types
25- directly as there is no other way to do this in Java today. The proposed Memory Access API (JEP 370) may
26- provide support for this feature, and assuming performance is good, this library will be updated to use
27- once it is available. Due to the direct usage of Unsafe, this library can only be used on a little endian
28- CPU.
24+ This library stores multi-byte values in little-endian byte order. This is distinct from
25+ the endianness of the CPU running the code.
26+
27+ Previous versions used ` sun.misc.Unsafe ` to read and write multi-byte values directly
28+ to memory. This bypassed Java's abstractions and assumed the underlying CPU was
29+ little-endian. On a big-endian CPU, values would be silently corrupted.
30+
31+ This version uses VarHandles and MemorySegment, which explicitly specify little-endian
32+ byte order. These APIs handle the conversion transparently—on a big-endian CPU, Java
33+ automatically swaps bytes when reading or writing. The data format remains little-endian
34+ for compatibility, but the library now works correctly on any CPU architecture.
35+
36+ The hash functions (XxHash64, Murmur3) also use little-endian byte order, as required
37+ by their specifications.
2938
3039# Legacy Slice
3140
0 commit comments