Quality Outreach Heads-up - Java Array Element Alignment: Weakening of Some Methods Guarantees ?

The OpenJDK Quality Group is promoting the testing of FOSS projects with OpenJDK builds as a way to improve the overall quality of the release. This heads-up is part of a regular communication sent to the projects involved. To learn more about the program, and how-to join, please check here.

Java Array Element Alignment: Weakening of Some Methods Guarantees ?

Some methods make promises about Java array element alignment that are too strong. There are some ongoing reflexions to change the implementation (and the specification) of MethodHandles::byteArrayViewVarHandle, MethodHandles::byteBufferViewVarHandle, ByteBuffer::alignedSlice, and ByteBuffer::alignmentOffset to weaken the guarantees they make about the alignment of Java array elements, in order to bring them in line with the guarantees made by an arbitrary JVM implementation.

For more details, make sure to check JDK-8320247 and the related pull request but in a nutshell, the new behaviour would be :

  • The VarHandle returned by MethodHandles::byteArrayViewVarHandle would only support get and set methods, and all other access methods would throw an exception.
  • The VarHandle returned by MethodHandles::byteBufferViewHandle would only support the get and set access methods when a heap buffer is used, and all other access methods would throw an exception when used with a heap buffer. Direct byte buffers will continue to work the same way.
  • The ByteBuffer::alignmentOffset and ByteBuffer::alignedSlice methods would throw an exception if the buffer is a heap buffer, and the given unitSize is greater than 1.

If you have relevant feedback about this potential change, please make sure to bring it to the core-libs-dev mailing list, or leave a comment on the pull request.

~