Skip to content

Commit c80e2eb

Browse files
committedJun 12, 2024
8333886: Explicitly specify that asSlice and reinterpret return a memory segment backed by the same region of memory.
Reviewed-by: jvernee, mcimadamore
1 parent a0318bc commit c80e2eb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎src/java.base/share/classes/java/lang/foreign/MemorySegment.java

+21
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
630630
* {@snippet lang=java :
631631
* asSlice(offset, newSize, 1);
632632
* }
633+
* <p>
634+
* The returned memory segment shares a region of backing memory with this segment.
635+
* Hence, no memory will be allocated or freed by this method.
633636
*
634637
* @see #asSlice(long, long, long)
635638
*
@@ -646,6 +649,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
646649
* Returns a slice of this memory segment, at the given offset, with the provided
647650
* alignment constraint. The returned segment's address is the address of this
648651
* segment plus the given offset; its size is specified by the given argument.
652+
* <p>
653+
* The returned memory segment shares a region of backing memory with this segment.
654+
* Hence, no memory will be allocated or freed by this method.
649655
*
650656
* @param offset The new segment base offset (relative to the address of this segment),
651657
* specified in bytes
@@ -670,6 +676,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
670676
* {@snippet lang=java :
671677
* asSlice(offset, layout.byteSize(), layout.byteAlignment());
672678
* }
679+
* <p>
680+
* The returned memory segment shares a region of backing memory with this segment.
681+
* Hence, no memory will be allocated or freed by this method.
673682
*
674683
* @see #asSlice(long, long, long)
675684
*
@@ -693,6 +702,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
693702
* {@snippet lang=java :
694703
* asSlice(offset, byteSize() - offset);
695704
* }
705+
* <p>
706+
* The returned memory segment shares a region of backing memory with this segment.
707+
* Hence, no memory will be allocated or freed by this method.
696708
*
697709
* @see #asSlice(long, long)
698710
*
@@ -706,6 +718,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
706718
/**
707719
* Returns a new memory segment that has the same address and scope as this segment,
708720
* but with the provided size.
721+
* <p>
722+
* The returned memory segment shares a region of backing memory with this segment.
723+
* Hence, no memory will be allocated or freed by this method.
709724
*
710725
* @param newSize the size of the returned segment
711726
* @return a new memory segment that has the same address and scope as
@@ -741,6 +756,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
741756
* That is, the cleanup action receives a segment that is associated with the global
742757
* scope, and is accessible from any thread. The size of the segment accepted by the
743758
* cleanup action is {@link #byteSize()}.
759+
* <p>
760+
* The returned memory segment shares a region of backing memory with this segment.
761+
* Hence, no memory will be allocated or freed by this method.
744762
*
745763
* @apiNote The cleanup action (if present) should take care not to leak the received
746764
* segment to external clients that might access the segment after its
@@ -786,6 +804,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
786804
* That is, the cleanup action receives a segment that is associated with the global
787805
* scope, and is accessible from any thread. The size of the segment accepted by the
788806
* cleanup action is {@code newSize}.
807+
* <p>
808+
* The returned memory segment shares a region of backing memory with this segment.
809+
* Hence, no memory will be allocated or freed by this method.
789810
*
790811
* @apiNote The cleanup action (if present) should take care not to leak the received
791812
* segment to external clients that might access the segment after its

0 commit comments

Comments
 (0)
Please sign in to comment.