Quality Outreach Heads-up - Java Array Element Alignment: Weakening of Some Methods Guarantees ?
David Delabassee on February 6, 2024
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
VarHandlereturned byMethodHandles::byteArrayViewVarHandlewould only supportgetandsetmethods, and all other access methods would throw an exception. - The
VarHandlereturned byMethodHandles::byteBufferViewHandlewould only support thegetandsetaccess 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::alignmentOffsetandByteBuffer::alignedSlicemethods would throw an exception if the buffer is a heap buffer, and the givenunitSizeis 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.
