Class LibGraal
java.lang.Object
com.oracle.truffle.runtime.hotspot.libgraal.LibGraal
Access to libgraal, a shared library containing an AOT compiled version of Graal produced by
GraalVM Native Image. The libgraal library is only available if the HotSpot
UseJVMCINativeLibrary flag is true and the current runtime includes the relevant JVMCI
API additions for accessing libgraal.
The 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:
The typical usage of this class is to link and call
CEntryPoints in libgraal. Each call to a CEntryPoint requires an
IsolateThread argument which can be obtained
from a LibGraalScope.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic jdk.vm.ci.hotspot.HotSpotResolvedJavaTypeasResolvedJavaType(org.graalvm.word.PointerBase pointer) static booleanattachCurrentThread(boolean isDaemon, long[] isolate) Ensures the current thread is attached to the peer runtime.static booleandetachCurrentThread(boolean release) Detaches the current thread from the peer runtime.static longgetFailedSpeculationsAddress(jdk.vm.ci.hotspot.HotSpotSpeculationLog log) Invokes the methodgetFailedSpeculationsAddresson aHotSpotSpeculationLog, if the method exists.static <T extends org.graalvm.word.PointerBase>
TgetJObjectValue(jdk.vm.ci.hotspot.HotSpotObjectConstant constant) static booleanDetermines if libgraal is available for use.static booleanDetermines if the current runtime supports building a libgraal image.static voidregisterNativeMethods(Class<?> clazz) Links each native method inclazzto aCEntryPointin libgraal.static longCreates or retrieves an object in the peer runtime that mirrorsobj.static <T> TDereferences and returns the object referred to by the JNI global referencehandle.
-
Constructor Details
-
LibGraal
public LibGraal()
-
-
Method Details
-
isAvailable
public static boolean isAvailable()Determines if libgraal is available for use. -
isSupported
public static boolean isSupported()Determines if the current runtime supports building a libgraal image. -
registerNativeMethods
Links each native method inclazzto aCEntryPointin libgraal.- Throws:
NullPointerException- ifclazz == nullUnsupportedOperationException- if libgraal is not enabled (i.e.-XX:-UseJVMCINativeLibrary)IllegalArgumentException- ifclazzisClass.isPrimitive()IllegalStateException- if libgraal is unavailableUnsatisfiedLinkError- if there's a problem linking a native method inclazz(no matching JNI symbol or the native method is already linked to a different address)
-
translate
Creates or retrieves an object in the peer runtime that mirrorsobj. 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 withunhand.- Parameters:
obj- an object for which an equivalent instance in the peer runtime is requested- Returns:
- a JNI global reference to the mirror of
objin the peer runtime - Throws:
IllegalArgumentException- ifobjis not of a translatable type
-
unhand
Dereferences and returns the object referred to by the JNI global referencehandle. The global reference is deleted prior to returning. Any further use ofhandleis invalid.- Parameters:
handle- a JNI global reference to an object in the current runtime- Returns:
- the object referred to by
handle - Throws:
ClassCastException- if the returned object cannot be cast totype
-
getJObjectValue
public static <T extends org.graalvm.word.PointerBase> T getJObjectValue(jdk.vm.ci.hotspot.HotSpotObjectConstant constant) - See Also:
-
asResolvedJavaType
public static jdk.vm.ci.hotspot.HotSpotResolvedJavaType asResolvedJavaType(org.graalvm.word.PointerBase pointer) - See Also:
-
attachCurrentThread
public static boolean attachCurrentThread(boolean isDaemon, long[] isolate) Ensures the current thread is attached to the peer runtime.- Parameters:
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 0- Returns:
trueif this call attached the current thread,falseif the current thread was already attached
-
detachCurrentThread
public static boolean detachCurrentThread(boolean release) Detaches the current thread from the peer runtime.- Parameters:
release- iftrueand the VM supports releasing theJavaVMassociated with libgraal runtimes and this is the last thread attached to a libgraal runtime, then this call destroys the associatedJavaVMinstance, releasing its resources- Returns:
trueif theJavaVMassociated with the libgraal runtime was destroyed as a result of this call
-
getFailedSpeculationsAddress
public static long getFailedSpeculationsAddress(jdk.vm.ci.hotspot.HotSpotSpeculationLog log) Invokes the methodgetFailedSpeculationsAddresson aHotSpotSpeculationLog, if the method exists.- Returns:
- the address of the pointer to the native failed speculations list.
- Throws:
UnsupportedOperationException- if unsupported
-