public abstract class VMThreads extends Object
IsolateThread
s.Modifier and Type | Class and Description |
---|---|
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.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
IsolateThread s. |
protected static FastThreadLocalWord<VMThreads.OSThreadHandle> |
OSThreadHandleTL |
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
IsolateThread s. |
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
IsolateThread s 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.
|
static org.graalvm.nativeimage.IsolateThread |
nextThread(org.graalvm.nativeimage.IsolateThread cur)
Iteration of all
IsolateThread s that are currently running. |
static boolean |
ownsThreadMutex() |
static VMThreads |
singleton() |
void |
tearDown() |
boolean |
verifyIsCurrentThread(org.graalvm.nativeimage.IsolateThread thread) |
boolean |
verifyThreadIsAttached(org.graalvm.nativeimage.IsolateThread thread) |
protected static final VMMutex THREAD_MUTEX
IsolateThread
s. 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.setStatusIgnoreSafepoints()
.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
IsolateThread
s. 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 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()
IsolateThread
s 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)
IsolateThread
s 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 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()