--- old/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java 2020-04-30 16:03:59.000000000 +0100 +++ new/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java 2020-04-30 16:03:59.000000000 +0100 @@ -177,7 +177,8 @@ * The returned spliterator splits the segment according to the specified sequence layout; that is, * if the supplied layout is a sequence layout whose element count is {@code N}, then calling {@link Spliterator#trySplit()} * will result in a spliterator serving approximatively {@code N/2} elements (depending on whether N is even or not). - * As such, splitting is possible as long as {@code N >= 2}. + * As such, splitting is possible as long as {@code N >= 2}. The spliterator returns segments that feature the same + * access modes as the given segment less the {@link #CLOSE} access mode. *

* The returned spliterator effectively allows to slice a segment into disjoint sub-segments, which can then * be processed in parallel by multiple threads (if the access mode {@link #ACQUIRE} is set). @@ -320,6 +321,10 @@ * buffer. The segment starts relative to the buffer's position (inclusive) * and ends relative to the buffer's limit (exclusive). *

+ * The segment will feature all access modes, unless the given + * buffer is {@linkplain ByteBuffer#isReadOnly() read-only} in which case the segment will + * not feature the {@link #WRITE} access mode. + *

* The resulting memory segment keeps a reference to the backing buffer, to ensure it remains reachable * for the life-time of the segment. * @@ -334,7 +339,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated byte array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -347,7 +352,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated char array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -360,7 +365,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated short array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -373,7 +378,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated int array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -386,7 +391,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated float array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -399,7 +404,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated long array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -412,7 +417,7 @@ * Creates a new array memory segment that models the memory associated with a given heap-allocated double array. *

* The resulting memory segment keeps a reference to the backing array, to ensure it remains reachable - * for the life-time of the segment. + * for the life-time of the segment. The segment will feature all access modes. * * @param arr the primitive array backing the array memory segment. * @return a new array memory segment. @@ -463,6 +468,10 @@ /** * Creates a new mapped memory segment that models a memory-mapped region of a file from a given path. + *

+ * The segment will feature all access modes, unless the given mapping mode + * is {@linkplain FileChannel.MapMode#READ_ONLY READ_ONLY}, in which case the segment will not feature + * the {@link #WRITE} access mode. * * @implNote When obtaining a mapped segment from a newly created file, the initialization state of the contents of the block * of mapped memory associated with the returned mapped memory segment is unspecified and should not be relied upon. @@ -482,7 +491,7 @@ /** * Creates a new native memory segment that models a newly allocated block of off-heap memory with given size and - * alignment constraint (in bytes). + * alignment constraint (in bytes). The segment will feature all access modes. * * @implNote The block of off-heap memory associated with the returned native memory segment is initialized to zero. * Moreover, a client is responsible to call the {@link MemorySegment#close()} on a native memory segment, @@ -512,7 +521,7 @@ * bounds, and can therefore be closed; closing such a segment can optionally result in calling an user-provided cleanup * action. This method can be very useful when interacting with custom native memory sources (e.g. custom allocators, * GPU memory, etc.), where an address to some underlying memory region is typically obtained from native code - * (often as a plain {@code long} value). + * (often as a plain {@code long} value). The segment will feature all access modes. *

* This method is restricted. Restricted method are unsafe, and, if used incorrectly, their use might crash * the JVM crash or, worse, silently result in memory corruption. Thus, clients should refrain from depending on