> See the JBS issue for an extended problem description.
> 
> This patch changes the specification and implementation 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 (which makes no guarantees 
> about array element alignment beyond them being aligned to their natural 
> alignment).
> 
> - `MethodHandles::byteArrayViewVarHandle`: we can not guarantee any alignment 
> for the accesses. Which means we can only reliably support plain get and set 
> access modes. The javadoc text explaining which other access modes are 
> supported, or how to compute aligned offsets into the array is dropped, as it 
> is not guaranteed to be correct on all JVM implementations. The 
> implementation of the returned VarHandle is changed to throw an 
> `UnsupportedOperationException` for the unsupported access modes, as mandated 
> by the spec of `VarHandle` [1].
> 
> - `MethodHandles::byteBufferViewVarHandle`: the implementation/spec is 
> incorrect when accessing a heap buffer (wrapping a byte[]), for the same 
> reasons as `byteArrayViewVarHandle`. The spec is changed to specify that when 
> accessing a _heap buffer_, only plain get and set access modes are supported. 
> The implementation of the returned var handle is changed to throw an 
> `IllegalStateException` when an access is attempted on a heap buffer using an 
> access mode other than plain get or set. Note that we don't throw an outright 
> `UnsupportedOperationException` for this case, since whether the access modes 
> are supported depends on the byte buffer instance being used.
> 
> - `ByteBuffer::alignedSlice` and `ByteBuffer::alignmentOffset`: The former 
> method depends directly on the latter for all its alignment computations. We 
> change the implementation of the latter method to throw an 
> `UnsupportedOperationException` for all unit sizes greater than 1, when the 
> buffer is non-direct. This change is largely covered by the existing 
> specification:
> 
> 
>      * @throws UnsupportedOperationException
>      *         If the native platform does not guarantee stable alignment 
> offset
>      *         values for the given unit size when managing the memory regions
>      *         of buffers of the same kind as this buffer (direct or
>      *         non-direct).  For example, if garbage collection would result
>      *         in the mo...

Jorn Vernee has updated the pull request with a new target base due to a merge 
or a rebase. The incremental webrev excludes the unrelated changes brought in 
by the merge/rebase. The pull request contains 12 additional commits since the 
last revision:

 - Merge branch 'master' into AlignedOffset
 - Merge branch 'master' into AlignedOffset
 - Add api note pointing to alternatives for client that require non-plain 
access
 - simplify spec for alignmentOffset and alignedSlice
 - Merge note about misaligned access in byteBufferViewVarHandle
 - updated alignedSlice implNote as well
 - updated alignedOffset implNote
 - Use ISE for bbvvh instead of UOE
 - restore some tests for direct buffers
 - fix BAVV and BBVV impl and tests
 - ... and 2 more: https://git.openjdk.org/jdk/compare/a2273ed0...281deaa5

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/16681/files
  - new: https://git.openjdk.org/jdk/pull/16681/files/eccf4f41..281deaa5

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=16681&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=16681&range=01-02

  Stats: 14804 lines in 723 files changed: 8780 ins; 2698 del; 3326 mod
  Patch: https://git.openjdk.org/jdk/pull/16681.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16681/head:pull/16681

PR: https://git.openjdk.org/jdk/pull/16681

Reply via email to