public abstract class VMThreads extends Object
IsolateThread
s.Modifier and Type | Class and Description |
---|---|
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 |
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 |
---|---|
abstract org.graalvm.nativeimage.IsolateThread |
allocateIsolateThread(int isolateThreadSize)
Allocate native memory for a
IsolateThread . |
void |
attachThread(org.graalvm.nativeimage.IsolateThread thread)
Creates a new
IsolateThread and adds it to the list of running threads. |
protected void |
cleanupExitedOsThreads() |
void |
detachThread(org.graalvm.nativeimage.IsolateThread current)
Remove an
IsolateThread from the thread list. |
void |
detachThreads(org.graalvm.nativeimage.IsolateThread[] threads) |
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() |
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. |
abstract 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. |
protected static void |
setTearingDown()
Note that threading is being torn down.
|
static VMThreads |
singleton() |
void |
tearDown() |
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.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()
protected static void setTearingDown()
public static boolean ensureInitialized()
protected abstract boolean initializeOnce()
public abstract org.graalvm.nativeimage.IsolateThread allocateIsolateThread(int isolateThreadSize)
IsolateThread
. The returned memory must be initialized
to 0.public abstract 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 void 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 current)
IsolateThread
from the thread list. This method must be the last method
called in every thread.protected void cleanupExitedOsThreads()
public void tearDown()
public void detachThreads(org.graalvm.nativeimage.IsolateThread[] threads)
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 org.graalvm.nativeimage.IsolateThread findIsolateThreadforCurrentOSThread()
public static void guaranteeOwnsThreadMutex(String message)