RFR 8162458 Buffer view implementations use incorrect offset for Unsafe access

Paul Sandoz paul.sandoz at oracle.com
Wed Jul 27 11:47:12 UTC 2016


I made an embarrassing mistake in the fix for

  All Buffer implementations should leverage Unsafe unaligned accessors

The offset calculation for Unsafe access was incorrect, it’s easy to get confused because for heap buffers the offset is relative to the array, and for direct buffers the address (which can update for slices/duplicates). Disturbingly all existing tests were passing both for core and hotspot when i pushed to hs.

As a penance i wrote a combinatorial test for buffer views to navigate the twisty maze of heap/direct, aligned/unaligned, little/big endian for accessing binary data and views from the source buffer.

Please review:


(This may be a duplicate of [1]).

Test has been verified to fail with the existing code. Focused JPRT runs pass, but i will kick off core/hotspot runs later on today.

I will push to hs since that is where JDK-8151163 and it has not been integrated into jdk9/dev.


[1] https://bugs.openjdk.java.net/browse/JDK-8159257
unsafe.cpp: assert(byte_offset < p_size) failed: Unsafe access: offset 32767 > object's size 16

For the test runtime/Unsafe/RangeCheck.java I can reproduce a crash in jdk9/dev which does not have JDK-8151163, and i can reproduce on jdk9/hs with this fix for JDK-8162458.

More information about the core-libs-dev mailing list