Skip to content

Commit

Permalink
8333886: Explicitly specify that asSlice and reinterpret return a mem…
Browse files Browse the repository at this point in the history
…ory segment backed by the same region of memory.

Reviewed-by: sundar
Backport-of: c80e2eb
  • Loading branch information
JornVernee committed Jul 10, 2024
1 parent 70ad622 commit 5b9ecb1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/java.base/share/classes/java/lang/foreign/MemorySegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* {@snippet lang=java :
* asSlice(offset, newSize, 1);
* }
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @see #asSlice(long, long, long)
*
Expand All @@ -646,6 +649,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* Returns a slice of this memory segment, at the given offset, with the provided
* alignment constraint. The returned segment's address is the address of this
* segment plus the given offset; its size is specified by the given argument.
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @param offset The new segment base offset (relative to the address of this segment),
* specified in bytes
Expand All @@ -670,6 +676,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* {@snippet lang=java :
* asSlice(offset, layout.byteSize(), layout.byteAlignment());
* }
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @see #asSlice(long, long, long)
*
Expand All @@ -693,6 +702,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* {@snippet lang=java :
* asSlice(offset, byteSize() - offset);
* }
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @see #asSlice(long, long)
*
Expand All @@ -706,6 +718,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
/**
* Returns a new memory segment that has the same address and scope as this segment,
* but with the provided size.
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @param newSize the size of the returned segment
* @return a new memory segment that has the same address and scope as
Expand Down Expand Up @@ -741,6 +756,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* That is, the cleanup action receives a segment that is associated with the global
* scope, and is accessible from any thread. The size of the segment accepted by the
* cleanup action is {@link #byteSize()}.
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @apiNote The cleanup action (if present) should take care not to leak the received
* segment to external clients that might access the segment after its
Expand Down Expand Up @@ -786,6 +804,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* That is, the cleanup action receives a segment that is associated with the global
* scope, and is accessible from any thread. The size of the segment accepted by the
* cleanup action is {@code newSize}.
* <p>
* The returned memory segment shares a region of backing memory with this segment.
* Hence, no memory will be allocated or freed by this method.
*
* @apiNote The cleanup action (if present) should take care not to leak the received
* segment to external clients that might access the segment after its
Expand Down

1 comment on commit 5b9ecb1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.