From 58bcd6ace2644616848a0618469a51d6d303d4e9 Mon Sep 17 00:00:00 2001 From: Per Minborg Date: Wed, 14 Dec 2022 21:40:29 +0000 Subject: [PATCH] 8298277: Replace "session" with "scope" for FFM access Reviewed-by: mcimadamore --- .../foreign/AbstractMemorySegmentImpl.java | 26 ++++++++-------- .../foreign/HeapMemorySegmentImpl.java | 16 +++++----- .../foreign/MappedMemorySegmentImpl.java | 10 +++---- .../internal/foreign/MemorySessionImpl.java | 6 ++-- .../foreign/NativeMemorySegmentImpl.java | 28 ++++++++--------- .../jdk/internal/foreign/abi/Binding.java | 28 ++++++++--------- .../foreign/abi/BindingSpecializer.java | 10 +++---- .../jdk/internal/foreign/abi/SharedUtils.java | 20 ++++++------- .../internal/foreign/abi/UpcallLinker.java | 6 ++-- .../jdk/internal/foreign/abi/UpcallStubs.java | 6 ++-- .../abi/aarch64/linux/LinuxAArch64Linker.java | 8 ++--- .../abi/aarch64/linux/LinuxAArch64VaList.java | 30 +++++++++---------- .../abi/aarch64/macos/MacOsAArch64Linker.java | 8 ++--- .../foreign/abi/x64/sysv/CallArranger.java | 4 +-- .../foreign/abi/x64/sysv/SysVVaList.java | 24 +++++++-------- .../foreign/abi/x64/sysv/SysVx64Linker.java | 4 +-- .../foreign/abi/x64/windows/CallArranger.java | 4 +-- .../foreign/abi/x64/windows/WinVaList.java | 20 ++++++------- .../abi/x64/windows/Windowsx64Linker.java | 4 +-- 19 files changed, 131 insertions(+), 131 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java b/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java index 9080e1482a84e..10dde1f331b11 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java +++ b/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java @@ -77,22 +77,22 @@ public abstract sealed class AbstractMemorySegmentImpl final long length; final boolean readOnly; - final SegmentScope session; + final SegmentScope scope; @ForceInline - AbstractMemorySegmentImpl(long length, boolean readOnly, SegmentScope session) { + AbstractMemorySegmentImpl(long length, boolean readOnly, SegmentScope scope) { this.length = length; this.readOnly = readOnly; - this.session = session; + this.scope = scope; } - abstract AbstractMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope session); + abstract AbstractMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope scope); abstract ByteBuffer makeByteBuffer(); @Override public AbstractMemorySegmentImpl asReadOnly() { - return dup(0, length, true, session); + return dup(0, length, true, scope); } @Override @@ -113,7 +113,7 @@ public AbstractMemorySegmentImpl asSlice(long offset) { } private AbstractMemorySegmentImpl asSliceNoCheck(long offset, long newSize) { - return dup(offset, newSize, readOnly, session); + return dup(offset, newSize, readOnly, scope); } @Override @@ -359,12 +359,12 @@ public RuntimeException apply(String s, List numbers) { @Override public SegmentScope scope() { - return session; + return scope; } @ForceInline public final MemorySessionImpl sessionImpl() { - return (MemorySessionImpl)session; + return (MemorySessionImpl)scope; } private IndexOutOfBoundsException outOfBoundException(long offset, long length) { @@ -481,11 +481,11 @@ public static AbstractMemorySegmentImpl ofBuffer(Buffer bb) { int size = limit - pos; AbstractMemorySegmentImpl bufferSegment = (AbstractMemorySegmentImpl) NIO_ACCESS.bufferSegment(bb); - final SegmentScope bufferSession; + final SegmentScope bufferScope; if (bufferSegment != null) { - bufferSession = bufferSegment.session; + bufferScope = bufferSegment.scope; } else { - bufferSession = MemorySessionImpl.heapSession(bb); + bufferScope = MemorySessionImpl.heapSession(bb); } boolean readOnly = bb.isReadOnly(); int scaleFactor = getScaleFactor(bb); @@ -508,10 +508,10 @@ public static AbstractMemorySegmentImpl ofBuffer(Buffer bb) { throw new AssertionError("Cannot get here"); } } else if (unmapper == null) { - return new NativeMemorySegmentImpl(bbAddress + (pos << scaleFactor), size << scaleFactor, readOnly, bufferSession); + return new NativeMemorySegmentImpl(bbAddress + (pos << scaleFactor), size << scaleFactor, readOnly, bufferScope); } else { // we can ignore scale factor here, a mapped buffer is always a byte buffer, so scaleFactor == 0. - return new MappedMemorySegmentImpl(bbAddress + pos, unmapper, size, readOnly, bufferSession); + return new MappedMemorySegmentImpl(bbAddress + pos, unmapper, size, readOnly, bufferScope); } } diff --git a/src/java.base/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java b/src/java.base/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java index 4967f438c003c..260c41e690754 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java +++ b/src/java.base/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java @@ -79,7 +79,7 @@ public long unsafeGetOffset() { } @Override - abstract HeapMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope session); + abstract HeapMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope scope); @Override ByteBuffer makeByteBuffer() { @@ -99,7 +99,7 @@ public static final class OfByte extends HeapMemorySegmentImpl { } @Override - OfByte dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfByte dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfByte(this.offset + offset, base, size, readOnly); } @@ -132,7 +132,7 @@ public static final class OfChar extends HeapMemorySegmentImpl { } @Override - OfChar dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfChar dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfChar(this.offset + offset, base, size, readOnly); } @@ -165,7 +165,7 @@ public static final class OfShort extends HeapMemorySegmentImpl { } @Override - OfShort dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfShort dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfShort(this.offset + offset, base, size, readOnly); } @@ -198,7 +198,7 @@ public static final class OfInt extends HeapMemorySegmentImpl { } @Override - OfInt dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfInt dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfInt(this.offset + offset, base, size, readOnly); } @@ -231,7 +231,7 @@ public static final class OfLong extends HeapMemorySegmentImpl { } @Override - OfLong dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfLong dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfLong(this.offset + offset, base, size, readOnly); } @@ -264,7 +264,7 @@ public static final class OfFloat extends HeapMemorySegmentImpl { } @Override - OfFloat dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfFloat dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfFloat(this.offset + offset, base, size, readOnly); } @@ -297,7 +297,7 @@ public static final class OfDouble extends HeapMemorySegmentImpl { } @Override - OfDouble dup(long offset, long size, boolean readOnly, SegmentScope session) { + OfDouble dup(long offset, long size, boolean readOnly, SegmentScope scope) { return new OfDouble(this.offset + offset, base, size, readOnly); } diff --git a/src/java.base/share/classes/jdk/internal/foreign/MappedMemorySegmentImpl.java b/src/java.base/share/classes/jdk/internal/foreign/MappedMemorySegmentImpl.java index 1d9465b8b41c3..8b7c799d7adea 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/MappedMemorySegmentImpl.java +++ b/src/java.base/share/classes/jdk/internal/foreign/MappedMemorySegmentImpl.java @@ -43,20 +43,20 @@ public sealed class MappedMemorySegmentImpl extends NativeMemorySegmentImpl { static final ScopedMemoryAccess SCOPED_MEMORY_ACCESS = ScopedMemoryAccess.getScopedMemoryAccess(); - public MappedMemorySegmentImpl(long min, UnmapperProxy unmapper, long length, boolean readOnly, SegmentScope session) { - super(min, length, readOnly, session); + public MappedMemorySegmentImpl(long min, UnmapperProxy unmapper, long length, boolean readOnly, SegmentScope scope) { + super(min, length, readOnly, scope); this.unmapper = unmapper; } @Override ByteBuffer makeByteBuffer() { return NIO_ACCESS.newMappedByteBuffer(unmapper, min, (int)length, null, - session == MemorySessionImpl.GLOBAL ? null : this); + scope == MemorySessionImpl.GLOBAL ? null : this); } @Override - MappedMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope session) { - return new MappedMemorySegmentImpl(min + offset, unmapper, size, readOnly, session); + MappedMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope scope) { + return new MappedMemorySegmentImpl(min + offset, unmapper, size, readOnly, scope); } // mapped segment methods diff --git a/src/java.base/share/classes/jdk/internal/foreign/MemorySessionImpl.java b/src/java.base/share/classes/jdk/internal/foreign/MemorySessionImpl.java index b8d1036baab15..84fa0a5be35c7 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/MemorySessionImpl.java +++ b/src/java.base/share/classes/jdk/internal/foreign/MemorySessionImpl.java @@ -175,9 +175,9 @@ public final Thread ownerThread() { return owner; } - public static boolean sameOwnerThread(SegmentScope session1, SegmentScope session2) { - return ((MemorySessionImpl) session1).ownerThread() == - ((MemorySessionImpl) session2).ownerThread(); + public static boolean sameOwnerThread(SegmentScope scope1, SegmentScope scope2) { + return ((MemorySessionImpl) scope1).ownerThread() == + ((MemorySessionImpl) scope2).ownerThread(); } @Override diff --git a/src/java.base/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java b/src/java.base/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java index 388937b823dfe..6d0e532d2d086 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java +++ b/src/java.base/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java @@ -52,8 +52,8 @@ public sealed class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl pe final long min; @ForceInline - NativeMemorySegmentImpl(long min, long length, boolean readOnly, SegmentScope session) { - super(length, readOnly, session); + NativeMemorySegmentImpl(long min, long length, boolean readOnly, SegmentScope scope) { + super(length, readOnly, scope); this.min = min; } @@ -69,14 +69,14 @@ public Optional array() { @ForceInline @Override - NativeMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope session) { - return new NativeMemorySegmentImpl(min + offset, size, readOnly, session); + NativeMemorySegmentImpl dup(long offset, long size, boolean readOnly, SegmentScope scope) { + return new NativeMemorySegmentImpl(min + offset, size, readOnly, scope); } @Override ByteBuffer makeByteBuffer() { return NIO_ACCESS.newDirectByteBuffer(min, (int) this.length, null, - session == MemorySessionImpl.GLOBAL ? null : this); + scope == MemorySessionImpl.GLOBAL ? null : this); } @Override @@ -101,8 +101,8 @@ public long maxAlignMask() { // factories - public static MemorySegment makeNativeSegment(long byteSize, long byteAlignment, SegmentScope session) { - MemorySessionImpl sessionImpl = (MemorySessionImpl) session; + public static MemorySegment makeNativeSegment(long byteSize, long byteAlignment, SegmentScope scope) { + MemorySessionImpl sessionImpl = (MemorySessionImpl) scope; sessionImpl.checkValidState(); if (VM.isDirectMemoryPageAligned()) { byteAlignment = Math.max(byteAlignment, NIO_ACCESS.pageSize()); @@ -119,7 +119,7 @@ public static MemorySegment makeNativeSegment(long byteSize, long byteAlignment, } long alignedBuf = Utils.alignUp(buf, byteAlignment); AbstractMemorySegmentImpl segment = new NativeMemorySegmentImpl(buf, alignedSize, - false, session); + false, scope); sessionImpl.addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() { @Override public void cleanup() { @@ -138,21 +138,21 @@ public void cleanup() { // associated with MemorySegment::ofAddress. @ForceInline - public static MemorySegment makeNativeSegmentUnchecked(long min, long byteSize, SegmentScope session, Runnable action) { - MemorySessionImpl sessionImpl = (MemorySessionImpl) session; + public static MemorySegment makeNativeSegmentUnchecked(long min, long byteSize, SegmentScope scope, Runnable action) { + MemorySessionImpl sessionImpl = (MemorySessionImpl) scope; if (action == null) { sessionImpl.checkValidState(); } else { sessionImpl.addCloseAction(action); } - return new NativeMemorySegmentImpl(min, byteSize, false, session); + return new NativeMemorySegmentImpl(min, byteSize, false, scope); } @ForceInline - public static MemorySegment makeNativeSegmentUnchecked(long min, long byteSize, SegmentScope session) { - MemorySessionImpl sessionImpl = (MemorySessionImpl) session; + public static MemorySegment makeNativeSegmentUnchecked(long min, long byteSize, SegmentScope scope) { + MemorySessionImpl sessionImpl = (MemorySessionImpl) scope; sessionImpl.checkValidState(); - return new NativeMemorySegmentImpl(min, byteSize, false, session); + return new NativeMemorySegmentImpl(min, byteSize, false, scope); } @ForceInline diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/Binding.java b/src/java.base/share/classes/jdk/internal/foreign/abi/Binding.java index 1949c660832bb..e047cbbd7fec5 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/Binding.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/Binding.java @@ -202,19 +202,19 @@ public interface Binding { */ class Context implements AutoCloseable { private final SegmentAllocator allocator; - private final SegmentScope session; + private final SegmentScope scope; - private Context(SegmentAllocator allocator, SegmentScope session) { + private Context(SegmentAllocator allocator, SegmentScope scope) { this.allocator = allocator; - this.session = session; + this.scope = scope; } public SegmentAllocator allocator() { return allocator; } - public SegmentScope session() { - return session; + public SegmentScope scope() { + return scope; } @Override @@ -242,7 +242,7 @@ public void close() { public static Context ofAllocator(SegmentAllocator allocator) { return new Context(allocator, null) { @Override - public SegmentScope session() { + public SegmentScope scope() { throw new UnsupportedOperationException(); } }; @@ -252,7 +252,7 @@ public SegmentScope session() { * Create a binding context from given scope. The resulting context will throw when * the context's allocator is accessed. */ - public static Context ofSession() { + public static Context ofScope() { Arena arena = Arena.openConfined(); return new Context(null, arena.scope()) { @Override @@ -276,7 +276,7 @@ public SegmentAllocator allocator() { } @Override - public SegmentScope session() { + public SegmentScope scope() { throw new UnsupportedOperationException(); } @@ -678,10 +678,10 @@ public void interpret(Deque stack, BindingInterpreter.StoreFunc storeFun /** * BOX_ADDRESS() - * Pops a 'long' from the operand stack, converts it to a 'MemorySegment', with the given size and memory session - * (either the context session, or the global session), and pushes that onto the operand stack. + * Pops a 'long' from the operand stack, converts it to a 'MemorySegment', with the given size and memory scope + * (either the context scope, or the global scope), and pushes that onto the operand stack. */ - record BoxAddress(long size, boolean needsSession) implements Binding { + record BoxAddress(long size, boolean needsScope) implements Binding { @Override public Tag tag() { @@ -698,9 +698,9 @@ public void verify(Deque> stack) { @Override public void interpret(Deque stack, BindingInterpreter.StoreFunc storeFunc, BindingInterpreter.LoadFunc loadFunc, Context context) { - SegmentScope session = needsSession ? - context.session() : SegmentScope.global(); - stack.push(NativeMemorySegmentImpl.makeNativeSegmentUnchecked((long) stack.pop(), size, session)); + SegmentScope scope = needsScope ? + context.scope() : SegmentScope.global(); + stack.push(NativeMemorySegmentImpl.makeNativeSegmentUnchecked((long) stack.pop(), size, scope)); } } diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java b/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java index 3c5edba244386..33ab093b53c5e 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java @@ -80,9 +80,9 @@ public class BindingSpecializer { private static final String BINDING_CONTEXT_DESC = Binding.Context.class.descriptorString(); private static final String OF_BOUNDED_ALLOCATOR_DESC = methodType(Binding.Context.class, long.class).descriptorString(); - private static final String OF_SESSION_DESC = methodType(Binding.Context.class).descriptorString(); + private static final String OF_SCOPE_DESC = methodType(Binding.Context.class).descriptorString(); private static final String ALLOCATOR_DESC = methodType(SegmentAllocator.class).descriptorString(); - private static final String SESSION_DESC = methodType(SegmentScope.class).descriptorString(); + private static final String SCOPE_DESC = methodType(SegmentScope.class).descriptorString(); private static final String SESSION_IMPL_DESC = methodType(MemorySessionImpl.class).descriptorString(); private static final String CLOSE_DESC = VOID_DESC; private static final String UNBOX_SEGMENT_DESC = methodType(long.class, MemorySegment.class).descriptorString(); @@ -294,7 +294,7 @@ private void specialize() { emitConst(callingSequence.allocationSize()); emitInvokeStatic(Binding.Context.class, "ofBoundedAllocator", OF_BOUNDED_ALLOCATOR_DESC); } else if (callingSequence.forUpcall() && needsSession()) { - emitInvokeStatic(Binding.Context.class, "ofSession", OF_SESSION_DESC); + emitInvokeStatic(Binding.Context.class, "ofScope", OF_SCOPE_DESC); } else { emitGetStatic(Binding.Context.class, "DUMMY", BINDING_CONTEXT_DESC); } @@ -436,7 +436,7 @@ private boolean needsSession() { return callingSequence.argumentBindings() .filter(Binding.BoxAddress.class::isInstance) .map(Binding.BoxAddress.class::cast) - .anyMatch(Binding.BoxAddress::needsSession); + .anyMatch(Binding.BoxAddress::needsScope); } private boolean shouldAcquire(int paramIndex) { @@ -561,7 +561,7 @@ private int newLocal(Class type) { private void emitLoadInternalSession() { assert contextIdx != -1; emitLoad(Object.class, contextIdx); - emitInvokeVirtual(Binding.Context.class, "session", SESSION_DESC); + emitInvokeVirtual(Binding.Context.class, "scope", SCOPE_DESC); } private void emitLoadInternalAllocator() { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java b/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java index 5ca0a6d7ca803..77e4e05659d89 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java @@ -288,21 +288,21 @@ public static void checkSymbol(MemorySegment symbol) { throw new IllegalArgumentException("Symbol is NULL: " + symbol); } - public static VaList newVaList(Consumer actions, SegmentScope session) { + public static VaList newVaList(Consumer actions, SegmentScope scope) { return switch (CABI.current()) { - case WIN_64 -> Windowsx64Linker.newVaList(actions, session); - case SYS_V -> SysVx64Linker.newVaList(actions, session); - case LINUX_AARCH_64 -> LinuxAArch64Linker.newVaList(actions, session); - case MAC_OS_AARCH_64 -> MacOsAArch64Linker.newVaList(actions, session); + case WIN_64 -> Windowsx64Linker.newVaList(actions, scope); + case SYS_V -> SysVx64Linker.newVaList(actions, scope); + case LINUX_AARCH_64 -> LinuxAArch64Linker.newVaList(actions, scope); + case MAC_OS_AARCH_64 -> MacOsAArch64Linker.newVaList(actions, scope); }; } - public static VaList newVaListOfAddress(long address, SegmentScope session) { + public static VaList newVaListOfAddress(long address, SegmentScope scope) { return switch (CABI.current()) { - case WIN_64 -> Windowsx64Linker.newVaListOfAddress(address, session); - case SYS_V -> SysVx64Linker.newVaListOfAddress(address, session); - case LINUX_AARCH_64 -> LinuxAArch64Linker.newVaListOfAddress(address, session); - case MAC_OS_AARCH_64 -> MacOsAArch64Linker.newVaListOfAddress(address, session); + case WIN_64 -> Windowsx64Linker.newVaListOfAddress(address, scope); + case SYS_V -> SysVx64Linker.newVaListOfAddress(address, scope); + case LINUX_AARCH_64 -> LinuxAArch64Linker.newVaListOfAddress(address, scope); + case MAC_OS_AARCH_64 -> MacOsAArch64Linker.newVaListOfAddress(address, scope); }; } diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallLinker.java b/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallLinker.java index 40af3d64dd97c..da42eb53584aa 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallLinker.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallLinker.java @@ -61,7 +61,7 @@ public class UpcallLinker { } } - public static MemorySegment make(ABIDescriptor abi, MethodHandle target, CallingSequence callingSequence, SegmentScope session) { + public static MemorySegment make(ABIDescriptor abi, MethodHandle target, CallingSequence callingSequence, SegmentScope scope) { assert callingSequence.forUpcall(); Binding.VMLoad[] argMoves = argMoveBindings(callingSequence); Binding.VMStore[] retMoves = retMoveBindings(callingSequence); @@ -93,7 +93,7 @@ public static MemorySegment make(ABIDescriptor abi, MethodHandle target, Calling CallRegs conv = new CallRegs(args, rets); long entryPoint = makeUpcallStub(doBindings, abi, conv, callingSequence.needsReturnBuffer(), callingSequence.returnBufferSize()); - return UpcallStubs.makeUpcall(entryPoint, session); + return UpcallStubs.makeUpcall(entryPoint, scope); } private static void checkPrimitive(MethodType type) { @@ -130,7 +130,7 @@ private record InvocationData(MethodHandle leaf, private static Object invokeInterpBindings(Object[] lowLevelArgs, InvocationData invData) throws Throwable { Binding.Context allocator = invData.callingSequence.allocationSize() != 0 ? Binding.Context.ofBoundedAllocator(invData.callingSequence.allocationSize()) - : Binding.Context.ofSession(); + : Binding.Context.ofScope(); try (allocator) { /// Invoke interpreter, got array of high-level arguments back Object[] highLevelArgs = new Object[invData.callingSequence.calleeMethodType().parameterCount()]; diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallStubs.java b/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallStubs.java index 041a96ac1c0fc..50f6a14d8d039 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallStubs.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/UpcallStubs.java @@ -50,13 +50,13 @@ private static void freeUpcallStub(long stubAddress) { registerNatives(); } - static MemorySegment makeUpcall(long entry, SegmentScope session) { - ((MemorySessionImpl) session).addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() { + static MemorySegment makeUpcall(long entry, SegmentScope scope) { + ((MemorySessionImpl) scope).addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() { @Override public void cleanup() { freeUpcallStub(entry); } }); - return MemorySegment.ofAddress(entry, 0, session); + return MemorySegment.ofAddress(entry, 0, scope); } } diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64Linker.java b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64Linker.java index 9114005695d04..acf57f12f0c24 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64Linker.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64Linker.java @@ -65,14 +65,14 @@ protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType return CallArranger.LINUX.arrangeUpcall(target, targetType, function, scope); } - public static VaList newVaList(Consumer actions, SegmentScope session) { - LinuxAArch64VaList.Builder builder = LinuxAArch64VaList.builder(session); + public static VaList newVaList(Consumer actions, SegmentScope scope) { + LinuxAArch64VaList.Builder builder = LinuxAArch64VaList.builder(scope); actions.accept(builder); return builder.build(); } - public static VaList newVaListOfAddress(long address, SegmentScope session) { - return LinuxAArch64VaList.ofAddress(address, session); + public static VaList newVaListOfAddress(long address, SegmentScope scope) { + return LinuxAArch64VaList.ofAddress(address, scope); } public static VaList emptyVaList() { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64VaList.java b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64VaList.java index fc43f0193aee0..ef471294768d1 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64VaList.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/linux/LinuxAArch64VaList.java @@ -120,11 +120,11 @@ private LinuxAArch64VaList(MemorySegment segment, MemorySegment stack, this.fpLimit = fpLimit; } - private static LinuxAArch64VaList readFromAddress(long address, SegmentScope session) { - MemorySegment segment = MemorySegment.ofAddress(address, LAYOUT.byteSize(), session); + private static LinuxAArch64VaList readFromAddress(long address, SegmentScope scope) { + MemorySegment segment = MemorySegment.ofAddress(address, LAYOUT.byteSize(), scope); MemorySegment stack = stackPtr(segment); // size unknown - MemorySegment gpRegsArea = MemorySegment.ofAddress(grTop(segment).address() - MAX_GP_OFFSET, MAX_GP_OFFSET, session); - MemorySegment fpRegsArea = MemorySegment.ofAddress(vrTop(segment).address() - MAX_FP_OFFSET, MAX_FP_OFFSET, session); + MemorySegment gpRegsArea = MemorySegment.ofAddress(grTop(segment).address() - MAX_GP_OFFSET, MAX_GP_OFFSET, scope); + MemorySegment fpRegsArea = MemorySegment.ofAddress(vrTop(segment).address() - MAX_FP_OFFSET, MAX_FP_OFFSET, scope); return new LinuxAArch64VaList(segment, stack, gpRegsArea, MAX_GP_OFFSET, fpRegsArea, MAX_FP_OFFSET); } @@ -384,12 +384,12 @@ public void skip(MemoryLayout... layouts) { } } - static LinuxAArch64VaList.Builder builder(SegmentScope session) { - return new LinuxAArch64VaList.Builder(session); + static LinuxAArch64VaList.Builder builder(SegmentScope scope) { + return new LinuxAArch64VaList.Builder(scope); } - public static VaList ofAddress(long address, SegmentScope session) { - return readFromAddress(address, session); + public static VaList ofAddress(long address, SegmentScope scope) { + return readFromAddress(address, scope); } @Override @@ -432,7 +432,7 @@ public String toString() { } public static non-sealed class Builder implements VaList.Builder { - private final SegmentScope session; + private final SegmentScope scope; private final MemorySegment gpRegs; private final MemorySegment fpRegs; @@ -440,10 +440,10 @@ public static non-sealed class Builder implements VaList.Builder { private long currentFPOffset = 0; private final List stackArgs = new ArrayList<>(); - Builder(SegmentScope session) { - this.session = session; - this.gpRegs = MemorySegment.allocateNative(LAYOUT_GP_REGS, session); - this.fpRegs = MemorySegment.allocateNative(LAYOUT_FP_REGS, session); + Builder(SegmentScope scope) { + this.scope = scope; + this.gpRegs = MemorySegment.allocateNative(LAYOUT_GP_REGS, scope); + this.fpRegs = MemorySegment.allocateNative(LAYOUT_FP_REGS, scope); } @Override @@ -536,12 +536,12 @@ public VaList build() { return EMPTY; } - MemorySegment vaListSegment = MemorySegment.allocateNative(LAYOUT, session); + MemorySegment vaListSegment = MemorySegment.allocateNative(LAYOUT, scope); MemorySegment stackArgsSegment; if (!stackArgs.isEmpty()) { long stackArgsSize = stackArgs.stream() .reduce(0L, (acc, e) -> acc + Utils.alignUp(e.layout.byteSize(), STACK_SLOT_SIZE), Long::sum); - stackArgsSegment = MemorySegment.allocateNative(stackArgsSize, 16, session); + stackArgsSegment = MemorySegment.allocateNative(stackArgsSize, 16, scope); MemorySegment writeCursor = stackArgsSegment; for (SimpleVaArg arg : stackArgs) { final long alignedSize = Utils.alignUp(arg.layout.byteSize(), STACK_SLOT_SIZE); diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/macos/MacOsAArch64Linker.java b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/macos/MacOsAArch64Linker.java index ab478f70faaee..d63adc4c247ed 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/macos/MacOsAArch64Linker.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/macos/MacOsAArch64Linker.java @@ -65,14 +65,14 @@ protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType return CallArranger.MACOS.arrangeUpcall(target, targetType, function, scope); } - public static VaList newVaList(Consumer actions, SegmentScope session) { - MacOsAArch64VaList.Builder builder = MacOsAArch64VaList.builder(session); + public static VaList newVaList(Consumer actions, SegmentScope scope) { + MacOsAArch64VaList.Builder builder = MacOsAArch64VaList.builder(scope); actions.accept(builder); return builder.build(); } - public static VaList newVaListOfAddress(long address, SegmentScope session) { - return MacOsAArch64VaList.ofAddress(address, session); + public static VaList newVaListOfAddress(long address, SegmentScope scope) { + return MacOsAArch64VaList.ofAddress(address, scope); } public static VaList emptyVaList() { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java index 735aabcd1499b..3fd51fb2d617a 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java @@ -132,14 +132,14 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe return handle; } - public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope session) { + public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope scope) { Bindings bindings = getBindings(mt, cDesc, true); if (bindings.isInMemoryReturn) { target = SharedUtils.adaptUpcallForIMR(target, true /* drop return, since we don't have bindings for it */); } - return UpcallLinker.make(CSysV, target, bindings.callingSequence, session); + return UpcallLinker.make(CSysV, target, bindings.callingSequence, scope); } private static boolean isInMemoryReturn(Optional returnLayout) { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVVaList.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVVaList.java index 78264f69ae31f..36b6bf7ba638c 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVVaList.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVVaList.java @@ -130,8 +130,8 @@ private SysVVaList(MemorySegment segment, this.fpLimit = fpLimit; } - private static SysVVaList readFromAddress(long address, SegmentScope session) { - MemorySegment segment = MemorySegment.ofAddress(address, LAYOUT.byteSize(), session); + private static SysVVaList readFromAddress(long address, SegmentScope scope) { + MemorySegment segment = MemorySegment.ofAddress(address, LAYOUT.byteSize(), scope); MemorySegment regSaveArea = getRegSaveArea(segment); MemorySegment overflowArgArea = getArgOverflowArea(segment); return new SysVVaList(segment, overflowArgArea, regSaveArea, MAX_GP_OFFSET, MAX_FP_OFFSET); @@ -322,12 +322,12 @@ public void skip(MemoryLayout... layouts) { } } - static SysVVaList.Builder builder(SegmentScope session) { - return new SysVVaList.Builder(session); + static SysVVaList.Builder builder(SegmentScope scope) { + return new SysVVaList.Builder(scope); } - public static VaList ofAddress(long address, SegmentScope session) { - return readFromAddress(address, session); + public static VaList ofAddress(long address, SegmentScope scope) { + return readFromAddress(address, scope); } @Override @@ -359,15 +359,15 @@ public String toString() { } public static non-sealed class Builder implements VaList.Builder { - private final SegmentScope session; + private final SegmentScope scope; private final MemorySegment reg_save_area; private long currentGPOffset = 0; private long currentFPOffset = FP_OFFSET; private final List stackArgs = new ArrayList<>(); - public Builder(SegmentScope session) { - this.session = session; - this.reg_save_area = MemorySegment.allocateNative(LAYOUT_REG_SAVE_AREA, session); + public Builder(SegmentScope scope) { + this.scope = scope; + this.reg_save_area = MemorySegment.allocateNative(LAYOUT_REG_SAVE_AREA, scope); } @Override @@ -446,12 +446,12 @@ public VaList build() { return EMPTY; } - MemorySegment vaListSegment = MemorySegment.allocateNative(LAYOUT, session); + MemorySegment vaListSegment = MemorySegment.allocateNative(LAYOUT, scope); MemorySegment stackArgsSegment; if (!stackArgs.isEmpty()) { long stackArgsSize = stackArgs.stream().reduce(0L, (acc, e) -> acc + Utils.alignUp(e.layout.byteSize(), STACK_SLOT_SIZE), Long::sum); - stackArgsSegment = MemorySegment.allocateNative(stackArgsSize, 16, session); + stackArgsSegment = MemorySegment.allocateNative(stackArgsSize, 16, scope); MemorySegment writeCursor = stackArgsSegment; for (SimpleVaArg arg : stackArgs) { if (arg.layout.byteSize() > 8) { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java index e181e9182f929..d4694d2fa1010 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java @@ -68,8 +68,8 @@ public static VaList newVaList(Consumer actions, SegmentScope sc return builder.build(); } - public static VaList newVaListOfAddress(long address, SegmentScope session) { - return SysVVaList.ofAddress(address, session); + public static VaList newVaListOfAddress(long address, SegmentScope scope) { + return SysVVaList.ofAddress(address, scope); } public static VaList emptyVaList() { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java index 61a68c4bfc523..612e60b5bb2ff 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java @@ -131,14 +131,14 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe return handle; } - public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope session) { + public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope scope) { Bindings bindings = getBindings(mt, cDesc, true); if (bindings.isInMemoryReturn) { target = SharedUtils.adaptUpcallForIMR(target, false /* need the return value as well */); } - return UpcallLinker.make(CWindows, target, bindings.callingSequence, session); + return UpcallLinker.make(CWindows, target, bindings.callingSequence, scope); } private static boolean isInMemoryReturn(Optional returnLayout) { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/WinVaList.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/WinVaList.java index 6d9bcf82f48b3..6e14248176e8a 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/WinVaList.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/WinVaList.java @@ -149,12 +149,12 @@ public void skip(MemoryLayout... layouts) { } } - static WinVaList ofAddress(long address, SegmentScope session) { - return new WinVaList(MemorySegment.ofAddress(address, Long.MAX_VALUE, session)); + static WinVaList ofAddress(long address, SegmentScope scope) { + return new WinVaList(MemorySegment.ofAddress(address, Long.MAX_VALUE, scope)); } - static Builder builder(SegmentScope session) { - return new Builder(session); + static Builder builder(SegmentScope scope) { + return new Builder(scope); } @Override @@ -171,12 +171,12 @@ public MemorySegment segment() { public static non-sealed class Builder implements VaList.Builder { - private final SegmentScope session; + private final SegmentScope scope; private final List args = new ArrayList<>(); - public Builder(SegmentScope session) { - ((MemorySessionImpl) session).checkValidState(); - this.session = session; + public Builder(SegmentScope scope) { + ((MemorySessionImpl) scope).checkValidState(); + this.scope = scope; } private Builder arg(MemoryLayout layout, Object value) { @@ -216,7 +216,7 @@ public VaList build() { return EMPTY; } - MemorySegment segment = MemorySegment.allocateNative(VA_SLOT_SIZE_BYTES * args.size(), session); + MemorySegment segment = MemorySegment.allocateNative(VA_SLOT_SIZE_BYTES * args.size(), scope); MemorySegment cursor = segment; for (SimpleVaArg arg : args) { @@ -225,7 +225,7 @@ public VaList build() { TypeClass typeClass = TypeClass.typeClassFor(arg.layout, false); switch (typeClass) { case STRUCT_REFERENCE -> { - MemorySegment copy = MemorySegment.allocateNative(arg.layout, session); + MemorySegment copy = MemorySegment.allocateNative(arg.layout, scope); copy.copyFrom(msArg); // by-value VH_address.set(cursor, copy); } diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java index 24d12dd8c560c..8725063fbac8e 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java @@ -68,8 +68,8 @@ public static VaList newVaList(Consumer actions, SegmentScope sc return builder.build(); } - public static VaList newVaListOfAddress(long address, SegmentScope session) { - return WinVaList.ofAddress(address, session); + public static VaList newVaListOfAddress(long address, SegmentScope scope) { + return WinVaList.ofAddress(address, scope); } public static VaList emptyVaList() {