3.3.0 SNAPSHOTXALLLinux|macOS|WindowscoreTo find private field offsets of DirectByteBuffer, objects are scanned using Unsafe e.g. see MemoryUtil#getFieldOffset
Scanning objects like that is very fragile, field offsets are just a token/cookie, the physical location remains an implementation detail. The JVM may decide the shuffle fields (packing), or even remove fields that are always constant or unused and provide a "fake" offset instead.
The issue was originally reported/found here. Espresso is an alternative, spec-compliant JVM; it uses the OpenJDK class library but an different object model/layout that is not compatible with this pattern.
A spec-compliant improvement would be to scan all fields (instead of all offsets) while searching for a magic constant. This should be more resilient to object layout changes and alignment issues.
Thanks @mukel!
Most helpful comment
Thanks @mukel!