Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-44201] Check more invariants for @Uninterruptible. #6124

Merged
merged 5 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ static UnsignedWord getAlignment() {
return HeapParameters.getAlignedHeapChunkSize();
}

@Uninterruptible(reason = "Used in uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static UnsignedWord alignUp(UnsignedWord size) {
return UnsignedUtils.roundUp(size, getAlignment());
}

@Uninterruptible(reason = "Used in uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static UnsignedWord alignDown(UnsignedWord size) {
return UnsignedUtils.roundDown(size, getAlignment());
}

@Uninterruptible(reason = "Used in uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static boolean isAligned(UnsignedWord size) {
return UnsignedUtils.isAMultiple(size, getAlignment());
}
Expand All @@ -125,7 +125,7 @@ static UnsignedWord minSpaceSize() {
return getAlignment().multiply(MIN_SPACE_SIZE_IN_ALIGNED_CHUNKS);
}

@Uninterruptible(reason = "Used in uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static UnsignedWord minSpaceSize(UnsignedWord size) {
return UnsignedUtils.max(size, minSpaceSize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.graalvm.word.WordBase;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.AlwaysInline;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.config.ObjectLayout;
Expand Down Expand Up @@ -289,7 +289,7 @@ public Word encodeAsTLABObjectHeader(DynamicHub hub) {
return encodeAsObjectHeader(hub, false, false);
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public Word encodeAsObjectHeader(DynamicHub hub, boolean rememberedSet, boolean unaligned) {
/*
* All DynamicHub instances are in the native image heap and therefore do not move, so we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static UnsignedWord getPageSize() {
return value;
}

@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
protected static int accessAsProt(int access) {
int prot = 0;
if ((access & Access.READ) != 0) {
Expand All @@ -102,13 +102,13 @@ protected static int accessAsProt(int access) {
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public UnsignedWord getGranularity() {
return getPageSize();
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public Pointer reserve(UnsignedWord nbytes, UnsignedWord alignment, boolean executable) {
if (nbytes.equal(0)) {
return WordFactory.nullPointer();
Expand Down Expand Up @@ -145,7 +145,7 @@ public Pointer reserve(UnsignedWord nbytes, UnsignedWord alignment, boolean exec
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public Pointer mapFile(PointerBase start, UnsignedWord nbytes, WordBase fileHandle, UnsignedWord offset, int access) {
if ((start.isNonNull() && !isAligned(start)) || nbytes.equal(0)) {
return WordFactory.nullPointer();
Expand All @@ -161,7 +161,7 @@ public Pointer mapFile(PointerBase start, UnsignedWord nbytes, WordBase fileHand
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public Pointer commit(PointerBase start, UnsignedWord nbytes, int access) {
if ((start.isNonNull() && !isAligned(start)) || nbytes.equal(0)) {
return WordFactory.nullPointer();
Expand All @@ -181,7 +181,7 @@ public Pointer commit(PointerBase start, UnsignedWord nbytes, int access) {
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public int protect(PointerBase start, UnsignedWord nbytes, int access) {
if (start.isNull() || !isAligned(start) || nbytes.equal(0)) {
return -1;
Expand All @@ -191,7 +191,7 @@ public int protect(PointerBase start, UnsignedWord nbytes, int access) {
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public int uncommit(PointerBase start, UnsignedWord nbytes) {
if (start.isNull() || !isAligned(start) || nbytes.equal(0)) {
return -1;
Expand All @@ -202,7 +202,7 @@ public int uncommit(PointerBase start, UnsignedWord nbytes) {
}

@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public int free(PointerBase start, UnsignedWord nbytes) {
if (start.isNull() || !isAligned(start) || nbytes.equal(0)) {
return -1;
Expand All @@ -214,7 +214,7 @@ public int free(PointerBase start, UnsignedWord nbytes) {
return munmap(mappingBegin, mappingSize);
}

@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
private boolean isAligned(PointerBase ptr) {
return ptr.isNonNull() && UnsignedUtils.isAMultiple((UnsignedWord) ptr, getGranularity());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public void dumpRegisters(Log log, Signal.ucontext_t uContext, boolean printLoca
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getHeapBase(Signal.ucontext_t uContext) {
Signal.AArch64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_aarch64();
return WordFactory.pointer(sigcontext.regs().read(27));
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getThreadPointer(Signal.ucontext_t uContext) {
Signal.AArch64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_aarch64();
return WordFactory.pointer(sigcontext.regs().read(28));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public void dumpRegisters(Log log, ucontext_t uContext, boolean printLocationInf
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getHeapBase(ucontext_t uContext) {
GregsPointer regs = uContext.uc_mcontext_linux_aarch64().regs();
return WordFactory.pointer(regs.read(27));
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getThreadPointer(ucontext_t uContext) {
GregsPointer regs = uContext.uc_mcontext_linux_aarch64().regs();
return WordFactory.pointer(regs.read(28));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public void dumpRegisters(Log log, ucontext_t uContext, boolean printLocationInf
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getHeapBase(ucontext_t uContext) {
Signal.AMD64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_amd64();
return ((Pointer) sigcontext).readWord(sigcontext.r14_offset());
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getThreadPointer(ucontext_t uContext) {
Signal.AMD64DarwinMContext64 sigcontext = uContext.uc_mcontext_darwin_amd64();
return ((Pointer) sigcontext).readWord(sigcontext.r15_offset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public void dumpRegisters(Log log, ucontext_t uContext, boolean printLocationInf
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getHeapBase(ucontext_t uContext) {
GregsPointer gregs = uContext.uc_mcontext_linux_amd64_gregs();
return WordFactory.pointer(gregs.read(GregEnumLinuxAMD64.REG_R14()));
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getThreadPointer(ucontext_t uContext) {
GregsPointer gregs = uContext.uc_mcontext_linux_amd64_gregs();
return WordFactory.pointer(gregs.read(GregEnumLinuxAMD64.REG_R15()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public UnsignedWord lookupStackEnd() {
return lookupStackEnd(WordFactory.zero());
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
private static boolean isProtected(int prot) {
return (prot & (VM_PROT_READ() | VM_PROT_WRITE())) == 0;
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
private static UnsignedWord vmComputeStackGuardSize(UnsignedWord stackend) {
UnsignedWord guardsize = WordFactory.zero();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordBase;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.posix.headers.Time.timespec;
import com.oracle.svm.core.thread.VMThreads.OSThreadHandle;
import com.oracle.svm.core.thread.VMThreads.OSThreadId;
Expand Down Expand Up @@ -107,7 +106,6 @@ public interface pthread_key_tPointer extends PointerBase {
public static native int pthread_join_no_transition(pthread_t th, WordPointer thread_return);

@CFunction(transition = Transition.NO_TRANSITION)
@Uninterruptible(reason = "Called from uninterruptible code.")
public static native pthread_t pthread_self();

@CFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ static boolean useMonotonicClockForRelativeWait() {
return Platform.includedIn(Platform.LINUX.class);
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static int initConditionWithAbsoluteTime(pthread_cond_t cond) {
return Pthread.pthread_cond_init(cond, WordFactory.nullPointer());
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static int initConditionWithRelativeTime(pthread_cond_t cond) {
pthread_condattr_t attr = StackValue.get(pthread_condattr_t.class);
int status = Pthread.pthread_condattr_init(attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.heap.UnknownObjectField;
import com.oracle.svm.core.jdk.UninterruptibleUtils;
import com.oracle.svm.core.locks.ClassInstanceReplacer;
import com.oracle.svm.core.locks.VMCondition;
import com.oracle.svm.core.locks.VMLockSupport;
Expand Down Expand Up @@ -184,7 +185,7 @@ public static boolean initialize() {
return PosixVMSemaphoreSupport.singleton().initialize();
}

@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static void checkResult(int result, String functionName) {
if (result != 0) {
fatalError(result, functionName);
Expand Down Expand Up @@ -230,7 +231,7 @@ final class PthreadVMMutex extends VMMutex {
super(name);
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
Pthread.pthread_mutex_t getStructPointer() {
return (Pthread.pthread_mutex_t) Word.objectToUntrackedPointer(PthreadVMLockSupport.singleton().pthreadStructs).add(structOffset);
}
Expand All @@ -244,39 +245,33 @@ public VMMutex lock() {
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", callerMustBe = true)
@Uninterruptible(reason = "Whole critical section needs to be uninterruptible.", callerMustBe = true)
public void lockNoTransition() {
assertNotOwner("Recursive locking is not supported");
PthreadVMLockSupport.checkResult(Pthread.pthread_mutex_lock_no_transition(getStructPointer()), "pthread_mutex_lock");
setOwnerToCurrentThread();
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", callerMustBe = true)
@Uninterruptible(reason = "Whole critical section needs to be uninterruptible.", callerMustBe = true)
public void lockNoTransitionUnspecifiedOwner() {
PthreadVMLockSupport.checkResult(Pthread.pthread_mutex_lock_no_transition(getStructPointer()), "pthread_mutex_lock");
setOwnerToUnspecified();
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public void unlock() {
clearCurrentThreadOwner();
PthreadVMLockSupport.checkResult(Pthread.pthread_mutex_unlock(getStructPointer()), "pthread_mutex_unlock");
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Whole critical section needs to be uninterruptible.")
public void unlockNoTransitionUnspecifiedOwner() {
clearUnspecifiedOwner();
PthreadVMLockSupport.checkResult(Pthread.pthread_mutex_unlock(getStructPointer()), "pthread_mutex_unlock");
}

@Override
public void unlockWithoutChecks() {
clearCurrentThreadOwner();
Pthread.pthread_mutex_unlock(getStructPointer());
}
}

final class PthreadVMCondition extends VMCondition {
Expand All @@ -288,7 +283,7 @@ final class PthreadVMCondition extends VMCondition {
super(mutex);
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
Pthread.pthread_cond_t getStructPointer() {
return (Pthread.pthread_cond_t) Word.objectToUntrackedPointer(PthreadVMLockSupport.singleton().pthreadStructs).add(structOffset);
}
Expand All @@ -301,15 +296,15 @@ public void block() {
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", callerMustBe = true)
@Uninterruptible(reason = "Should only be called if the thread did an explicit transition to native earlier.", callerMustBe = true)
public void blockNoTransition() {
mutex.clearCurrentThreadOwner();
PthreadVMLockSupport.checkResult(Pthread.pthread_cond_wait_no_transition(getStructPointer(), ((PthreadVMMutex) getMutex()).getStructPointer()), "pthread_cond_wait");
mutex.setOwnerToCurrentThread();
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", callerMustBe = true)
@Uninterruptible(reason = "Should only be called if the thread did an explicit transition to native earlier.", callerMustBe = true)
public void blockNoTransitionUnspecifiedOwner() {
mutex.clearUnspecifiedOwner();
PthreadVMLockSupport.checkResult(Pthread.pthread_cond_wait_no_transition(getStructPointer(), ((PthreadVMMutex) getMutex()).getStructPointer()), "pthread_cond_wait");
Expand Down Expand Up @@ -341,7 +336,7 @@ public long block(long waitNanos) {
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.", callerMustBe = true)
@Uninterruptible(reason = "Should only be called if the thread did an explicit transition to native earlier.", callerMustBe = true)
public long blockNoTransition(long waitNanos) {
if (waitNanos <= 0) {
return 0L;
Expand All @@ -365,10 +360,10 @@ public long blockNoTransition(long waitNanos) {
return remainingNanos(waitNanos, startTime);
}

@Uninterruptible(reason = "Called from uninterruptible code.", callerMustBe = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
private static long remainingNanos(long waitNanos, long startNanos) {
long actual = System.nanoTime() - startNanos;
return Math.max(0, waitNanos - actual);
return UninterruptibleUtils.Math.max(0, waitNanos - actual);
}

@Override
Expand All @@ -377,7 +372,7 @@ public void signal() {
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public void broadcast() {
PthreadVMLockSupport.checkResult(Pthread.pthread_cond_broadcast(getStructPointer()), "pthread_cond_broadcast");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ public void dumpRegisters(Log log, Signal.ucontext_t uContext, boolean printLoca
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getHeapBase(ucontext_t uContext) {
GregsPointer regs = uContext.uc_mcontext_linux_riscv64().gregs();
return WordFactory.pointer(regs.read(27));
}

@Override
@Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public PointerBase getThreadPointer(ucontext_t uContext) {
GregsPointer regs = uContext.uc_mcontext_linux_riscv64().gregs();
return WordFactory.pointer(regs.read(23));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected OSThreadId getCurrentOSThreadId() {
return Pthread.pthread_self();
}

@Uninterruptible(reason = "Called from uninterruptible code.")
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
@Override
protected void joinNoTransition(OSThreadHandle osThreadHandle) {
Pthread.pthread_t pthread = (Pthread.pthread_t) osThreadHandle;
Expand Down
Loading