The unsafe methods are intrinsic on x86, they are essentially aliases to the equivalent Unsafe.get/put*. For platforms that do not support misaligned access the methods are more efficient than the functionally equivalent methods in java.nio.Bits, since the widest atomic access is utlized depending on the result of the alignment, specifically address to the first byte modulo the unit size.
Direct ByteBuffers should be updated to use these methods, rather than doing this:
private int getInt(long a) {
if (unaligned) {
int x = unsafe.getInt(a);
return (nativeByteOrder ? x : Bits.swap(x));
}
return Bits.getInt(a, bigEndian);
}
private ByteBuffer putInt(long a, int x) {
if (unaligned) {
int y = (x);
unsafe.putInt(a, (nativeByteOrder ? y : Bits.swap(y)));
} else {
Bits.putInt(a, x, bigEndian);
}
return this;
}
This then will ensure that any architecture that can intrinsify the unaligned accessor will further benefit without requiring modification to buffer code.
Furthermore, the wider views of ByteBuffer can also be consolidated using such access. The int view for a heap ByteBuffer performs per-byte access leveraging code in java.nio.Bits. The int view for a direct ByteBuffer has four separate implementations (a cross product of alignment and endianess), and at least one axis can be removed.
- is blocked by
-
JDK-8149469 ByteBuffer API and implementation enhancements for VarHandles
- Resolved
- relates to
-
JDK-6509032 (bf) Monomorphic implementations for Direct and Heap versions of X-Buffer
- Open
-
JDK-8282665 [REDO] ByteBufferTest.java: replace endless recursion with RuntimeException in void ck(double x, double y)
- Resolved
-
JDK-8282573 ByteBufferTest.java: replace endless recursion with RuntimeException in void ck(double x, double y)
- Closed
-
JDK-8162458 Buffer view implementations use incorrect offset for Unsafe access
- Closed
-
JDK-8159257 unsafe.cpp: assert(byte_offset < p_size) failed: Unsafe access: offset 32767 > object's size 16
- Closed
-
JDK-8154453 Improve Unsafe.get*Unaligned on SPARC
- Closed