-
Sub-task
-
Resolution: Delivered
-
P4
-
23
Array element bases are no longer unconditionally aligned to eight bytes. Instead, they are now aligned to their element type size. This improves the footprint in some JVM modes. As Java array element alignment is not exposed to users, there is no impact on regular Java code that accesses individual elements.
There are implications for bulk access methods. Unsafe accesses to arrays could now be unaligned. For example, `Unsafe.getLong(byteArray, BYTE_ARRAY_BASE_OFFSET + 0)` is not guaranteed to work on platforms that do not allow unaligned accesses. A workaround is the `Unsafe.{get, put}Unaligned*` family of methods. The `ByteBuffer` and `VarHandle` APIs that allow views of `byte[]` are updated to reflect this change (JDK-8318966). Arrays that are acquired via `GetPrimitiveArrayCritical` should not be operated upon under the assumption of a particular array base alignment.
There are implications for bulk access methods. Unsafe accesses to arrays could now be unaligned. For example, `Unsafe.getLong(byteArray, BYTE_ARRAY_BASE_OFFSET + 0)` is not guaranteed to work on platforms that do not allow unaligned accesses. A workaround is the `Unsafe.{get, put}Unaligned*` family of methods. The `ByteBuffer` and `VarHandle` APIs that allow views of `byte[]` are updated to reflect this change (