mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8333884: MemorySegment::reinterpret removes read-only property
Reviewed-by: jvernee, mcimadamore
This commit is contained in:
parent
b83766e590
commit
6f7f0f1de0
4 changed files with 37 additions and 8 deletions
|
@ -633,6 +633,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
|||
* asSlice(offset, newSize, 1);
|
||||
* }
|
||||
* <p>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
@ -652,6 +655,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
|||
* 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>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
@ -679,6 +685,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
|||
* asSlice(offset, layout.byteSize(), layout.byteAlignment());
|
||||
* }
|
||||
* <p>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
@ -705,6 +714,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
|||
* asSlice(offset, byteSize() - offset);
|
||||
* }
|
||||
* <p>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
@ -721,6 +733,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>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
@ -759,6 +774,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
|||
* scope, and is accessible from any thread. The size of the segment accepted by the
|
||||
* cleanup action is {@link #byteSize()}.
|
||||
* <p>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
@ -807,6 +825,9 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
|
|||
* scope, and is accessible from any thread. The size of the segment accepted by the
|
||||
* cleanup action is {@code newSize}.
|
||||
* <p>
|
||||
* If this segment is {@linkplain MemorySegment#isReadOnly() read-only},
|
||||
* the returned segment is also {@linkplain MemorySegment#isReadOnly() read-only}.
|
||||
* <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.
|
||||
*
|
||||
|
|
|
@ -159,7 +159,7 @@ public abstract sealed class AbstractMemorySegmentImpl
|
|||
() -> cleanup.accept(SegmentFactories.makeNativeSegmentUnchecked(address(), newSize)) :
|
||||
null;
|
||||
return SegmentFactories.makeNativeSegmentUnchecked(address(), newSize,
|
||||
(MemorySessionImpl)scope, action);
|
||||
(MemorySessionImpl)scope, readOnly, action);
|
||||
}
|
||||
|
||||
private AbstractMemorySegmentImpl asSliceNoCheck(long offset, long newSize) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -57,14 +57,18 @@ public class SegmentFactories {
|
|||
// associated with MemorySegment::ofAddress.
|
||||
|
||||
@ForceInline
|
||||
public static MemorySegment makeNativeSegmentUnchecked(long min, long byteSize, MemorySessionImpl sessionImpl, Runnable action) {
|
||||
public static MemorySegment makeNativeSegmentUnchecked(long min,
|
||||
long byteSize,
|
||||
MemorySessionImpl sessionImpl,
|
||||
boolean readOnly,
|
||||
Runnable action) {
|
||||
ensureInitialized();
|
||||
if (action == null) {
|
||||
sessionImpl.checkValidState();
|
||||
} else {
|
||||
sessionImpl.addCloseAction(action);
|
||||
}
|
||||
return new NativeMemorySegmentImpl(min, byteSize, false, sessionImpl);
|
||||
return new NativeMemorySegmentImpl(min, byteSize, readOnly, sessionImpl);
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue