8310644: Make panama memory segment close use async handshakes

Reviewed-by: jvernee, mcimadamore, pchilanomate
This commit is contained in:
Erik Österlund 2023-11-29 12:40:21 +00:00
parent 65dfcae6d6
commit 159465324f
8 changed files with 162 additions and 149 deletions

View file

@ -55,8 +55,7 @@ public abstract sealed class MemorySessionImpl
implements Scope
permits ConfinedSession, GlobalSession, SharedSession {
static final int OPEN = 0;
static final int CLOSING = -1;
static final int CLOSED = -2;
static final int CLOSED = -1;
static final VarHandle STATE;
static final int MAX_FORKS = Integer.MAX_VALUE;

View file

@ -77,17 +77,13 @@ sealed class SharedSession extends MemorySessionImpl permits ImplicitSession {
}
void justClose() {
int prevState = (int) STATE.compareAndExchange(this, OPEN, CLOSING);
int prevState = (int) STATE.compareAndExchange(this, OPEN, CLOSED);
if (prevState < 0) {
throw alreadyClosed();
} else if (prevState != OPEN) {
throw alreadyAcquired(prevState);
}
boolean success = SCOPED_MEMORY_ACCESS.closeScope(this);
STATE.setVolatile(this, success ? CLOSED : OPEN);
if (!success) {
throw alreadyAcquired(1);
}
SCOPED_MEMORY_ACCESS.closeScope(this, ALREADY_CLOSED);
}
/**

View file

@ -83,11 +83,11 @@ public class ScopedMemoryAccess {
registerNatives();
}
public boolean closeScope(MemorySessionImpl session) {
return closeScope0(session);
public void closeScope(MemorySessionImpl session, ScopedAccessError error) {
closeScope0(session, error);
}
native boolean closeScope0(MemorySessionImpl session);
native void closeScope0(MemorySessionImpl session, ScopedAccessError error);
private ScopedMemoryAccess() {}