This commit is contained in:
Jesper Wilhelmsson 2022-12-15 06:36:55 +00:00
commit 10bc86cc26
20 changed files with 132 additions and 132 deletions

View File

@ -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 abstract sealed class AbstractMemorySegmentImpl
}
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 abstract sealed class AbstractMemorySegmentImpl
@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 abstract sealed class AbstractMemorySegmentImpl
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 abstract sealed class AbstractMemorySegmentImpl
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);
}
}

View File

@ -79,7 +79,7 @@ public abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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 abstract sealed class HeapMemorySegmentImpl extends AbstractMemorySegment
}
@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);
}

View File

@ -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

View File

@ -175,9 +175,9 @@ public abstract sealed class MemorySessionImpl
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

View File

@ -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 sealed class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl pe
@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 sealed class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl pe
// 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 sealed class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl pe
}
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 sealed class NativeMemorySegmentImpl extends AbstractMemorySegmentImpl pe
// 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

View File

@ -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 interface Binding {
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 interface Binding {
* 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 interface Binding {
}
@Override
public SegmentScope session() {
public SegmentScope scope() {
throw new UnsupportedOperationException();
}
@ -678,10 +678,10 @@ public interface Binding {
/**
* 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 interface Binding {
@Override
public void interpret(Deque<Object> 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));
}
}

View File

@ -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 @@ public class BindingSpecializer {
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 @@ public class BindingSpecializer {
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 @@ public class BindingSpecializer {
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() {

View File

@ -288,21 +288,21 @@ public final class SharedUtils {
throw new IllegalArgumentException("Symbol is NULL: " + symbol);
}
public static VaList newVaList(Consumer<VaList.Builder> actions, SegmentScope session) {
public static VaList newVaList(Consumer<VaList.Builder> 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);
};
}

View File

@ -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 class UpcallLinker {
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 @@ public class UpcallLinker {
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()];

View File

@ -50,13 +50,13 @@ public final class UpcallStubs {
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);
}
}

View File

@ -65,14 +65,14 @@ public final class LinuxAArch64Linker extends AbstractLinker {
return CallArranger.LINUX.arrangeUpcall(target, targetType, function, scope);
}
public static VaList newVaList(Consumer<VaList.Builder> actions, SegmentScope session) {
LinuxAArch64VaList.Builder builder = LinuxAArch64VaList.builder(session);
public static VaList newVaList(Consumer<VaList.Builder> 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() {

View File

@ -120,11 +120,11 @@ public non-sealed class LinuxAArch64VaList implements VaList {
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 non-sealed class LinuxAArch64VaList implements VaList {
}
}
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 non-sealed class LinuxAArch64VaList implements VaList {
}
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 non-sealed class LinuxAArch64VaList implements VaList {
private long currentFPOffset = 0;
private final List<SimpleVaArg> 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 non-sealed class LinuxAArch64VaList implements VaList {
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);

View File

@ -65,14 +65,14 @@ public final class MacOsAArch64Linker extends AbstractLinker {
return CallArranger.MACOS.arrangeUpcall(target, targetType, function, scope);
}
public static VaList newVaList(Consumer<VaList.Builder> actions, SegmentScope session) {
MacOsAArch64VaList.Builder builder = MacOsAArch64VaList.builder(session);
public static VaList newVaList(Consumer<VaList.Builder> 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() {

View File

@ -132,14 +132,14 @@ public class CallArranger {
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<MemoryLayout> returnLayout) {

View File

@ -130,8 +130,8 @@ public non-sealed class SysVVaList implements VaList {
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 non-sealed class SysVVaList implements VaList {
}
}
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 non-sealed class SysVVaList implements VaList {
}
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<SimpleVaArg> 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 non-sealed class SysVVaList implements VaList {
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) {

View File

@ -68,8 +68,8 @@ public final class SysVx64Linker extends AbstractLinker {
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() {

View File

@ -131,14 +131,14 @@ public class CallArranger {
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<MemoryLayout> returnLayout) {

View File

@ -149,12 +149,12 @@ public non-sealed class WinVaList implements VaList {
}
}
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 non-sealed class WinVaList implements VaList {
public static non-sealed class Builder implements VaList.Builder {
private final SegmentScope session;
private final SegmentScope scope;
private final List<SimpleVaArg> 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 non-sealed class WinVaList implements VaList {
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 non-sealed class WinVaList implements VaList {
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);
}

View File

@ -68,8 +68,8 @@ public final class Windowsx64Linker extends AbstractLinker {
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() {

View File

@ -30,7 +30,7 @@ package gc;
* @comment Shenandoah has "ExplicitGCInvokesConcurrent" on by default
* @requires !(vm.gc == "Shenandoah" & vm.opt.ExplicitGCInvokesConcurrent != false)
* @comment G1 has separate counters for STW Full GC and concurrent GC.
* @requires !(vm.gc == "G1" & vm.opt.ExplicitGCInvokesConcurrent)
* @requires !(vm.gc.G1 & vm.opt.ExplicitGCInvokesConcurrent == true)
* @requires vm.gc != "Z"
* @modules java.management
* @run main/othervm -Xlog:gc gc.TestFullGCCount