use of com.oracle.truffle.espresso.impl.SuppressFBWarnings in project graal by oracle.
the class VM method JVM_MonitorWait.
@VmImpl(isJni = true)
@TruffleBoundary
@SuppressFBWarnings(value = { "IMSE" }, justification = "Not dubious, .wait is just forwarded from the guest.")
@SuppressWarnings("try")
public void JVM_MonitorWait(@JavaType(Object.class) StaticObject self, long timeout, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
EspressoContext context = getContext();
StaticObject currentThread = context.getCurrentThread();
State state = timeout > 0 ? State.TIMED_WAITING : State.WAITING;
try (Transition transition = Transition.transition(context, state)) {
if (context.EnableManagement) {
// Locks bookkeeping.
meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(currentThread, self);
Target_java_lang_Thread.incrementThreadCounter(currentThread, meta.HIDDEN_THREAD_WAITED_COUNT);
}
final boolean report = context.shouldReportVMEvents();
if (report) {
context.reportMonitorWait(self, timeout);
}
boolean timedOut = !InterpreterToVM.monitorWait(self.getLock(getContext()), timeout);
if (report) {
context.reportMonitorWaited(self, timedOut);
}
} catch (GuestInterruptedException e) {
profiler.profile(0);
if (getThreadAccess().isInterrupted(currentThread, true)) {
throw meta.throwExceptionWithMessage(meta.java_lang_InterruptedException, e.getMessage());
}
getThreadAccess().fullSafePoint(currentThread);
} catch (IllegalMonitorStateException e) {
profiler.profile(1);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalMonitorStateException, e.getMessage());
} catch (IllegalArgumentException e) {
profiler.profile(2);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, e.getMessage());
} finally {
if (context.EnableManagement) {
meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(currentThread, null);
}
}
}
use of com.oracle.truffle.espresso.impl.SuppressFBWarnings in project graal by oracle.
the class EspressoThreadRegistry method unregisterThread.
/**
* Once a thread terminates, remove it from the active set, and notify any thread waiting for VM
* teardown that it should check again for all non-daemon thread completion.
*/
@SuppressFBWarnings(value = "NN", justification = "Removing a thread from the active set is the state change we need.")
public void unregisterThread(StaticObject thread) {
logger.fine(() -> {
String guestName = getThreadAccess().getThreadName(thread);
long guestId = getThreadAccess().getThreadId(thread);
return String.format("unregisterThread([GUEST:%s, %d])", guestName, guestId);
});
activeThreads.remove(thread);
Thread hostThread = getThreadAccess().getHost(thread);
int id = Math.toIntExact(hostThread.getId());
synchronized (activeThreadLock) {
if (id == mainThreadId) {
mainThreadId = -1;
guestMainThread = null;
} else if (id == finalizerThreadId) {
guestFinalizerThread = null;
finalizerThreadId = -1;
} else if (id == referenceHandlerThreadId) {
guestReferenceHandlerThread = null;
referenceHandlerThreadId = -1;
} else {
Object[] threads = guestThreads;
int threadIndex = getThreadIndex(id, threads);
if (getThreadAccess().isAlive(thread)) {
assert threads[threadIndex] == thread;
threads[threadIndex] = null;
} else {
/*
* Non-alive threads may have been removed from guestThreads by
* refactorGuestThreads => threadIndex may be invalid/outdated and the slot
* could be populated by another thread.
*/
if (0 <= threadIndex && threadIndex < threads.length) {
if (threads[threadIndex] == thread) {
threads[threadIndex] = null;
}
}
}
}
}
Object sync = context.getShutdownSynchronizer();
synchronized (sync) {
sync.notifyAll();
}
}
use of com.oracle.truffle.espresso.impl.SuppressFBWarnings in project graal by oracle.
the class StaticObject method getLock.
/**
* Returns an {@link EspressoLock} instance for use with this {@link StaticObject} instance.
*
* <p>
* The {@link EspressoLock} instance will be unique and cached. Calling this method on
* {@link StaticObject#NULL} is an invalid operation.
*
* <p>
* The returned {@link EspressoLock} instance supports the same usages as do the {@link Object}
* monitor methods ({@link Object#wait() wait}, {@link Object#notify notify}, and
* {@link Object#notifyAll notifyAll}) when used with the built-in monitor lock.
*
* @param context
*/
@SuppressFBWarnings(value = "DC", justification = "Implementations of EspressoLock have only final and volatile fields")
public final EspressoLock getLock(EspressoContext context) {
checkNotForeign();
if (isNull(this)) {
CompilerDirectives.transferToInterpreter();
throw EspressoError.shouldNotReachHere("StaticObject.NULL.getLock()");
}
EspressoLock l = lockOrForeignMarker;
if (l == null) {
synchronized (this) {
l = lockOrForeignMarker;
if (l == null) {
lockOrForeignMarker = l = EspressoLock.create(context.getBlockingSupport());
}
}
}
return l;
}
use of com.oracle.truffle.espresso.impl.SuppressFBWarnings in project graal by oracle.
the class VM method JVM_FindLibraryEntry.
@VmImpl
@TruffleBoundary
@SuppressFBWarnings(value = "AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", justification = "benign race")
@Pointer
public TruffleObject JVM_FindLibraryEntry(@Pointer TruffleObject libraryPtr, @Pointer TruffleObject namePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
long nativePtr = NativeUtils.interopAsPointer(libraryPtr);
TruffleObject library = handle2Lib.get(nativePtr);
if (library == null) {
if (nativePtr == rtldDefaultValue || nativePtr == processHandleValue) {
library = getNativeAccess().loadDefaultLibrary();
if (library == null) {
getLogger().warning("JVM_FindLibraryEntry from default/global namespace is not supported: " + name);
return RawPointer.nullInstance();
}
handle2Lib.put(nativePtr, library);
} else {
getLogger().warning("JVM_FindLibraryEntry with unknown handle (" + libraryPtr + " / " + Long.toHexString(nativePtr) + "): " + name);
return RawPointer.nullInstance();
}
}
try {
TruffleObject function = getNativeAccess().lookupSymbol(library, name);
if (function == null) {
// not found
return RawPointer.nullInstance();
}
if (!getUncached().isPointer(function)) {
getUncached().toNative(function);
}
long handle = getUncached().asPointer(function);
handle2Sym.put(handle, function);
return function;
} catch (UnsupportedMessageException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
Aggregations