RFR: 8286715: Generalize MemorySegment::ofBuffer [v2]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon May 16 20:56:26 UTC 2022


> This patch makes MemorySegment::ofBuffer more general, by allowing clients to pass *any* `Buffer` instance, not just `ByteBuffer`.
> This allows us to match expressiveness of JNI API, where JNI clients can obtain the address of any direct buffer instance, using the `GetDirectBufferAddress` function.
> 
> We thought about also providing a more general way to view a segment as a buffer (e.g. asIntBuffer) but doing that doesn't seem worth it: direct buffers can only created form `ByteBuffer`.
> So, to create a direct `IntBuffer`, clients have to first create a direct `ByteBuffer` then to view that buffer as an `IntBuffer`.
> 
> In other words, `IntBuffer` and friends are not first-class citizens in the `Buffer` API. As such it would not be possible to map many memory segments into an `IntBuffer`; in fact, the only segment we could safely map into an `IntBuffer` would be an _heap_ segment backed by an `int[]`. As such it doesn't seem worth adding a lot of API surface (in terms of additional overloads) for such a corner case.

Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:

  Update src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
  
  Co-authored-by: Jorn Vernee <JornVernee at users.noreply.github.com>

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/8701/files
  - new: https://git.openjdk.java.net/jdk/pull/8701/files/02494e2f..b6629787

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=8701&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=8701&range=00-01

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8701.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8701/head:pull/8701

PR: https://git.openjdk.java.net/jdk/pull/8701



More information about the security-dev mailing list