@@ -4513,48 +4513,18 @@ public static VarHandle arrayElementVarHandle(Class<?> arrayClass) throws Illega
4513
4513
* or greater than the {@code byte[]} array length minus the size (in bytes)
4514
4514
* of {@code T}.
4515
4515
* <p>
4516
- * Access of bytes at an index may be aligned or misaligned for {@code T},
4517
- * with respect to the underlying memory address, {@code A} say, associated
4518
- * with the array and index.
4519
- * If access is misaligned then access for anything other than the
4520
- * {@code get} and {@code set} access modes will result in an
4521
- * {@code IllegalStateException}. In such cases atomic access is only
4522
- * guaranteed with respect to the largest power of two that divides the GCD
4523
- * of {@code A} and the size (in bytes) of {@code T}.
4524
- * If access is aligned then following access modes are supported and are
4525
- * guaranteed to support atomic access:
4526
- * <ul>
4527
- * <li>read write access modes for all {@code T}, with the exception of
4528
- * access modes {@code get} and {@code set} for {@code long} and
4529
- * {@code double} on 32-bit platforms.
4530
- * <li>atomic update access modes for {@code int}, {@code long},
4531
- * {@code float} or {@code double}.
4532
- * (Future major platform releases of the JDK may support additional
4533
- * types for certain currently unsupported access modes.)
4534
- * <li>numeric atomic update access modes for {@code int} and {@code long}.
4535
- * (Future major platform releases of the JDK may support additional
4536
- * numeric types for certain currently unsupported access modes.)
4537
- * <li>bitwise atomic update access modes for {@code int} and {@code long}.
4538
- * (Future major platform releases of the JDK may support additional
4539
- * numeric types for certain currently unsupported access modes.)
4540
- * </ul>
4541
- * <p>
4542
- * Misaligned access, and therefore atomicity guarantees, may be determined
4543
- * for {@code byte[]} arrays without operating on a specific array. Given
4544
- * an {@code index}, {@code T} and its corresponding boxed type,
4545
- * {@code T_BOX}, misalignment may be determined as follows:
4546
- * <pre>{@code
4547
- * int sizeOfT = T_BOX.BYTES; // size in bytes of T
4548
- * int misalignedAtZeroIndex = ByteBuffer.wrap(new byte[0]).
4549
- * alignmentOffset(0, sizeOfT);
4550
- * int misalignedAtIndex = (misalignedAtZeroIndex + index) % sizeOfT;
4551
- * boolean isMisaligned = misalignedAtIndex != 0;
4552
- * }</pre>
4553
- * <p>
4554
- * If the variable type is {@code float} or {@code double} then atomic
4555
- * update access modes compare values using their bitwise representation
4556
- * (see {@link Float#floatToRawIntBits} and
4557
- * {@link Double#doubleToRawLongBits}, respectively).
4516
+ * Only plain {@linkplain VarHandle.AccessMode#GET get} and {@linkplain VarHandle.AccessMode#SET set}
4517
+ * access modes are supported by the returned var handle. For all other access modes, an
4518
+ * {@link UnsupportedOperationException} will be thrown.
4519
+ *
4520
+ * @apiNote if access modes other than plain access are required, clients should
4521
+ * consider using off-heap memory through
4522
+ * {@linkplain java.nio.ByteBuffer#allocateDirect(int) direct byte buffers} or
4523
+ * off-heap {@linkplain java.lang.foreign.MemorySegment memory segments},
4524
+ * or memory segments backed by a
4525
+ * {@linkplain java.lang.foreign.MemorySegment#ofArray(long[]) {@code long[]}},
4526
+ * for which stronger alignment guarantees can be made.
4527
+ *
4558
4528
* @param viewArrayClass the view array class, with a component type of
4559
4529
* type {@code T}
4560
4530
* @param byteOrder the endianness of the view array elements, as
@@ -4600,7 +4570,13 @@ public static VarHandle byteArrayViewVarHandle(Class<?> viewArrayClass,
4600
4570
* or greater than the {@code ByteBuffer} limit minus the size (in bytes) of
4601
4571
* {@code T}.
4602
4572
* <p>
4603
- * Access of bytes at an index may be aligned or misaligned for {@code T},
4573
+ * For heap byte buffers, access is always unaligned. As a result, only the plain
4574
+ * {@linkplain VarHandle.AccessMode#GET get}
4575
+ * and {@linkplain VarHandle.AccessMode#SET set} access modes are supported by the
4576
+ * returned var handle. For all other access modes, an {@link IllegalStateException}
4577
+ * will be thrown.
4578
+ * <p>
4579
+ * For direct buffers only, access of bytes at an index may be aligned or misaligned for {@code T},
4604
4580
* with respect to the underlying memory address, {@code A} say, associated
4605
4581
* with the {@code ByteBuffer} and index.
4606
4582
* If access is misaligned then access for anything other than the
0 commit comments