This commit is contained in:
Jesper Wilhelmsson 2023-01-11 21:50:42 +00:00
commit 33f3bd8fad
16 changed files with 79 additions and 45 deletions

View file

@ -1734,6 +1734,7 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* @throws IndexOutOfBoundsException when the access operation falls outside the <em>spatial bounds</em> of the
* memory segment.
* @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}.
* @throws UnsupportedOperationException if {@code value} is not a {@linkplain #isNative() native} segment.
*/
@ForceInline
default void set(ValueLayout.OfAddress layout, long offset, MemorySegment value) {
@ -2079,6 +2080,7 @@ public sealed interface MemorySegment permits AbstractMemorySegmentImpl {
* @throws IndexOutOfBoundsException when the access operation falls outside the <em>spatial bounds</em> of the
* memory segment.
* @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}.
* @throws UnsupportedOperationException if {@code value} is not a {@linkplain #isNative() native} segment.
*/
@ForceInline
default void setAtIndex(ValueLayout.OfAddress layout, long index, MemorySegment value) {

View file

@ -7931,8 +7931,11 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
* {@code get} and {@code set} access modes will result in an {@code IllegalStateException}. If access is partially aligned,
* atomic access is only guaranteed with respect to the largest power of two that divides the GCD of {@code A} and {@code S}.
* <p>
* Finally, in all other cases, we say that a memory access operation is <em>misaligned</em>; in such cases an
* In all other cases, we say that a memory access operation is <em>misaligned</em>; in such cases an
* {@code IllegalStateException} is thrown, irrespective of the access mode being used.
* <p>
* Finally, if {@code T} is {@code MemorySegment} all write access modes throw {@link IllegalArgumentException}
* unless the value to be written is a {@linkplain MemorySegment#isNative() native} memory segment.
*
* @param layout the value layout for which a memory access handle is to be obtained.
* @return the new memory segment view var handle.

View file

@ -38,6 +38,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import jdk.internal.access.SharedSecrets;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.vm.annotation.ForceInline;
import static java.lang.foreign.ValueLayout.JAVA_BYTE;
@ -62,8 +63,8 @@ public final class Utils {
MethodType.methodType(boolean.class, byte.class));
BOOL_TO_BYTE = lookup.findStatic(Utils.class, "booleanToByte",
MethodType.methodType(byte.class, boolean.class));
ADDRESS_TO_LONG = lookup.findVirtual(MemorySegment.class, "address",
MethodType.methodType(long.class));
ADDRESS_TO_LONG = lookup.findStatic(SharedUtils.class, "unboxSegment",
MethodType.methodType(long.class, MemorySegment.class));
LONG_TO_ADDRESS_SAFE = lookup.findStatic(Utils.class, "longToAddressSafe",
MethodType.methodType(MemorySegment.class, long.class));
LONG_TO_ADDRESS_UNSAFE = lookup.findStatic(Utils.class, "longToAddressUnsafe",

View file

@ -259,7 +259,7 @@ public final class SharedUtils {
}
}
static long unboxSegment(MemorySegment segment) {
public static long unboxSegment(MemorySegment segment) {
if (!segment.isNative()) {
throw new IllegalArgumentException("Heap segment not allowed: " + segment);
}