public class LibGraal extends Object
UseJVMCINativeLibrary
flag is true and the current runtime includes the
relevant JVMCI API additions for accessing libgraal.LibGraal.isAvailable()
method is provided to test these conditions. It must be used to guard
usage of all other methods in this class. In addition, only the following methods can be called
from within libgraal:
LibGraal.isAvailable()
LibGraal.inLibGraal()
LibGraal.translate(Object)
LibGraal.unhand(Class, long)
CEntryPoint
s in libgraal. Each call to a CEntryPoint
requires an
IsolateThread
argument which can be obtained
from a LibGraalScope
.Constructor and Description |
---|
LibGraal() |
Modifier and Type | Method and Description |
---|---|
static boolean |
attachCurrentThread(boolean isDaemon,
long[] isolate)
Ensures the current thread is attached to the peer runtime.
|
static boolean |
detachCurrentThread(boolean release)
Detaches the current thread from the peer runtime.
|
static long |
getFailedSpeculationsAddress(HotSpotSpeculationLog log)
Invokes the method
getFailedSpeculationsAddress on a HotSpotSpeculationLog ,
if the method exists. |
static boolean |
inLibGraal()
Determines if the current runtime is libgraal.
|
static boolean |
isAvailable()
Determines if libgraal is available for use.
|
static boolean |
isSupported()
Determines if the current runtime supports building a libgraal image.
|
static void |
registerNativeMethods(Class<?> clazz)
Links each native method in
clazz to a CEntryPoint in libgraal. |
static long |
translate(Object obj)
Creates or retrieves an object in the peer runtime that mirrors
obj . |
static <T> T |
unhand(Class<T> type,
long handle)
Dereferences and returns the object referred to by the JNI global reference
handle . |
public static boolean isAvailable()
public static boolean isSupported()
public static boolean inLibGraal()
public static void registerNativeMethods(Class<?> clazz)
clazz
to a CEntryPoint
in libgraal.
This cannot be called from within libgraal.NullPointerException
- if clazz == null
UnsupportedOperationException
- if libgraal is not enabled (i.e.
-XX:-UseJVMCINativeLibrary
)IllegalArgumentException
- if clazz
is Class.isPrimitive()
IllegalStateException
- if libgraal is unavailable or
LibGraal.inLibGraal()
returns trueUnsatisfiedLinkError
- if there's a problem linking a native method in clazz
(no matching JNI symbol or the native method is already linked to a different
address)public static long translate(Object obj)
obj
.
This mechanism can be used to pass and return values between the HotSpot and libgraal
runtimes. In the receiving runtime, the value can be converted back to an object with
LibGraal.unhand
.obj
- an object for which an equivalent instance in the peer runtime is requestedobj
in the peer runtimeIllegalArgumentException
- if obj
is not of a translatable typepublic static <T> T unhand(Class<T> type, long handle)
handle
.
The global reference is deleted prior to returning. Any further use of handle
is
invalid.handle
- a JNI global reference to an object in the current runtimehandle
ClassCastException
- if the returned object cannot be cast to type
public static boolean attachCurrentThread(boolean isDaemon, long[] isolate)
isDaemon
- if the thread is not yet attached, should it be attached as a daemonisolate
- if non-null, the isolate for the current thread is returned in element 0true
if this call attached the current thread, false
if the current
thread was already attachedpublic static boolean detachCurrentThread(boolean release)
release
- if true
and the VM supports releasing the JavaVM
associated
with libgraal runtimes and this is the last thread attached to a libgraal runtime,
then this call destroys the associated JavaVM
instance, releasing its
resourcestrue
if the JavaVM
associated with the libgraal runtime was destroyed
as a result of this callpublic static long getFailedSpeculationsAddress(HotSpotSpeculationLog log)
getFailedSpeculationsAddress
on a HotSpotSpeculationLog
,
if the method exists.UnsupportedOperationException
- if unsupported