public abstract class VMThreads extends Object
IsolateThreads.| Modifier and Type | Class and Description |
|---|---|
static class |
VMThreads.ActionOnExitSafepointSupport
This follows
VMThreads.ActionOnTransitionToJavaSupport, but only for exiting safepoint. |
static class |
VMThreads.ActionOnTransitionToJavaSupport
A thread-local enum conveying any actions needed before thread begins executing Java code.
|
static interface |
VMThreads.OSThreadHandle |
static interface |
VMThreads.OSThreadId |
static class |
VMThreads.SafepointBehavior |
static class |
VMThreads.StatusSupport
A thread-local enum giving the thread status of a VMThread.
|
| Modifier and Type | Field and Description |
|---|---|
static FastThreadLocalWord<org.graalvm.nativeimage.Isolate> |
IsolateTL |
static FastThreadLocalWord<org.graalvm.nativeimage.IsolateThread> |
nextTL
The next element in the linked list of
IsolateThreads. |
protected static FastThreadLocalWord<VMThreads.OSThreadHandle> |
OSThreadHandleTL |
static FastThreadLocalWord<org.graalvm.word.UnsignedWord> |
StackBase
The highest stack address.
|
static FastThreadLocalWord<org.graalvm.word.UnsignedWord> |
StackEnd
The lowest stack address.
|
protected static VMCondition |
THREAD_LIST_CONDITION
A condition variable for waiting for and notifying on changes to the
IsolateThread
list. |
protected static VMMutex |
THREAD_MUTEX
Only use this mutex if it is absolutely necessary to operate on the linked list of
IsolateThreads. |
| Constructor and Description |
|---|
VMThreads() |
| Modifier and Type | Method and Description |
|---|---|
org.graalvm.nativeimage.IsolateThread |
allocateIsolateThread(int isolateThreadSize)
Allocate native memory for a
IsolateThread. |
int |
attachThread(org.graalvm.nativeimage.IsolateThread thread)
Creates a new
IsolateThread and adds it to the list of running threads. |
protected void |
cleanupExitedOsThreads() |
void |
detachAllThreadsExceptCurrentWithoutCleanupForTearDown()
Detaches all manually attached native threads, but not those threads that were launched from
Java, which must be notified to individually exit in the immediately following tear-down.
|
void |
detachThread(org.graalvm.nativeimage.IsolateThread thread)
Remove an
IsolateThread from the thread list. |
static boolean |
ensureInitialized()
Make sure the runtime is initialized for threading.
|
abstract void |
failFatally(int code,
org.graalvm.nativeimage.c.type.CCharPointer message)
Report a fatal error to the user and exit.
|
org.graalvm.nativeimage.IsolateThread |
findIsolateThreadForCurrentOSThread(boolean inCrashHandler) |
static org.graalvm.nativeimage.IsolateThread |
firstThread()
Iteration of all
IsolateThreads that are currently running. |
static org.graalvm.nativeimage.IsolateThread |
firstThreadUnsafe()
Like
VMThreads.firstThread() but without the check that VMThreads.THREAD_MUTEX is locked by the
current thread. |
void |
freeIsolateThread(org.graalvm.nativeimage.IsolateThread thread)
Free the native memory allocated by
VMThreads.allocateIsolateThread(int). |
protected abstract VMThreads.OSThreadHandle |
getCurrentOSThreadHandle()
Returns a platform-specific handle to the current thread.
|
protected abstract VMThreads.OSThreadId |
getCurrentOSThreadId()
Returns a unique identifier for the current thread.
|
static void |
guaranteeOwnsThreadMutex(String message) |
protected abstract boolean |
initializeOnce()
Invoked exactly once early during the startup of an isolate.
|
static boolean |
isInitialized() |
static boolean |
isTearingDown()
Is threading being torn down?
|
protected abstract void |
joinNoTransition(VMThreads.OSThreadHandle osThreadHandle)
Executes a non-multithreading-safe low-level (i.e., non-Java-level) join operation on the
given native thread.
|
void |
nativeSleep(int milliseconds)
Puts this thread to sleep on the operating-system level and does not care about Java
semantics.
|
static org.graalvm.nativeimage.IsolateThread |
nextThread(org.graalvm.nativeimage.IsolateThread cur)
Iteration of all
IsolateThreads that are currently running. |
static boolean |
ownsThreadMutex() |
static boolean |
printLocationInfo(Log log,
org.graalvm.word.UnsignedWord value,
boolean allowUnsafeOperations) |
static VMThreads |
singleton() |
boolean |
supportsPatientSafepoints() |
void |
tearDown() |
boolean |
verifyIsCurrentThread(org.graalvm.nativeimage.IsolateThread thread) |
boolean |
verifyThreadIsAttached(org.graalvm.nativeimage.IsolateThread thread) |
void |
yield() |
protected static final VMMutex THREAD_MUTEX
IsolateThreads. This mutex is especially dangerous because it is used by the
application, the GC, and the safepoint mechanism. To avoid potential deadlocks, all places
that acquire this mutex must do one of the following:
VMThreads.THREAD_MUTEX second). If
the VM operation causes a safepoint, then it is possible that the VMThreads.THREAD_MUTEX was
already acquired for safepoint reasons.VMThreads.StatusSupport.STATUS_CREATED or currently in native code
(VMThreads.StatusSupport.STATUS_IN_NATIVE).VMThreads.THREAD_MUTEX.VMThreads.THREAD_MUTEX and is blocked because thread A holds that mutex.VMThreads.THREAD_MUTEX.VMThreads.THREAD_MUTEX and is blocked because thread A
still holds that mutex.protected static final VMCondition THREAD_LIST_CONDITION
IsolateThread
list.public static final FastThreadLocalWord<org.graalvm.nativeimage.IsolateThread> nextTL
IsolateThreads. A thread points to itself with
this field after being removed from the linked list.protected static final FastThreadLocalWord<VMThreads.OSThreadHandle> OSThreadHandleTL
public static final FastThreadLocalWord<org.graalvm.nativeimage.Isolate> IsolateTL
public static final FastThreadLocalWord<org.graalvm.word.UnsignedWord> StackBase
public static final FastThreadLocalWord<org.graalvm.word.UnsignedWord> StackEnd
public static VMThreads singleton()
public static boolean isInitialized()
public static boolean isTearingDown()
public static boolean ensureInitialized()
protected abstract boolean initializeOnce()
public org.graalvm.nativeimage.IsolateThread allocateIsolateThread(int isolateThreadSize)
IsolateThread. The returned memory must be initialized
to 0.public void freeIsolateThread(org.graalvm.nativeimage.IsolateThread thread)
VMThreads.allocateIsolateThread(int).public abstract void failFatally(int code,
org.graalvm.nativeimage.c.type.CCharPointer message)
public static org.graalvm.nativeimage.IsolateThread firstThread()
IsolateThreads that are currently running. VMThreads.THREAD_MUTEX
must be held when iterating the list.
Use the following pattern to iterate all running threads. It is allocation free and can
therefore be used during GC:
for (VMThread thread = VMThreads.firstThread(); thread.isNonNull(); thread = VMThreads.nextThread(thread)) {
public static org.graalvm.nativeimage.IsolateThread firstThreadUnsafe()
VMThreads.firstThread() but without the check that VMThreads.THREAD_MUTEX is locked by the
current thread. Only use this method if absolutely necessary (e.g., for printing diagnostics
on a fatal error).public static org.graalvm.nativeimage.IsolateThread nextThread(org.graalvm.nativeimage.IsolateThread cur)
IsolateThreads that are currently running. See
VMThreads.firstThread() for details.public int attachThread(org.graalvm.nativeimage.IsolateThread thread)
IsolateThread and adds it to the list of running threads. This method
must be the first method called in every thread.public void detachThread(org.graalvm.nativeimage.IsolateThread thread)
IsolateThread from the thread list. This method must be the last method
called in every thread.protected void cleanupExitedOsThreads()
public void tearDown()
public void detachAllThreadsExceptCurrentWithoutCleanupForTearDown()
protected abstract void joinNoTransition(VMThreads.OSThreadHandle osThreadHandle)
protected abstract VMThreads.OSThreadHandle getCurrentOSThreadHandle()
VMThreads.attachThread(IsolateThread), when
VMThreads.OSThreadHandleTL is not set yet.protected abstract VMThreads.OSThreadId getCurrentOSThreadId()
public void nativeSleep(int milliseconds)
public void yield()
public boolean supportsPatientSafepoints()
public boolean verifyThreadIsAttached(org.graalvm.nativeimage.IsolateThread thread)
public boolean verifyIsCurrentThread(org.graalvm.nativeimage.IsolateThread thread)
public org.graalvm.nativeimage.IsolateThread findIsolateThreadForCurrentOSThread(boolean inCrashHandler)
public static void guaranteeOwnsThreadMutex(String message)
public static boolean ownsThreadMutex()
public static boolean printLocationInfo(Log log, org.graalvm.word.UnsignedWord value, boolean allowUnsafeOperations)