RFR: 8139457: Array bases are aligned at HeapWord granularity [v52]

Hannes Greule hgreule at openjdk.org
Wed Aug 23 10:23:39 UTC 2023


On Wed, 23 Aug 2023 10:11:42 GMT, Roman Kennke <rkennke at openjdk.org> wrote:

> I don't see anywhere in that statement regarding the alignment with respects to the index value, only to the underlying memory address.
> 
> The following section even goes into details about obtaining the misalignment of the array base using byte buffer, which leads to me believing that the only requirement is that the congruence class of the base modulo 8 should be consistent.

Yes, from my understanding, it is spec-conformant as long as all byte arrays have the same offset at runtime. And with the following change, the code also works:


int offset = ByteBuffer.wrap(new byte[0]).alignmentOffset(0, Long.BYTES);
System.out.println("Offset: " + offset); // prints 4
var handle = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.nativeOrder());
byte[] array = new byte[64];
handle.compareAndSet(array, offset, 0, 1234567890L);
System.out.println(Arrays.toString(array)); // different result due to the offset


My comment was more about the observable change in behavior, especially as people might relying on the (currently "right", but actually wrong) assumption that all arrays are aligned. Maybe this PR needs a CSR?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/11044#issuecomment-1689697316


More information about the hotspot-dev mailing list