Search in sources :

Example 21 with JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope in project graal by oracle.

the class JMXToLibGraalEntryPoints method getMBeanInfo.

/**
 * Returns the {@link MBeanInfo} encoded as a byte array using {@link OptionsEncoder}.
 */
@JMXToLibGraal(GetMBeanInfo)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_getMBeanInfo")
@SuppressWarnings({ "try", "unused" })
static JNI.JByteArray getMBeanInfo(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, GetMBeanInfo, env);
    try (JNIMethodScope s = scope) {
        ObjectHandles globalHandles = ObjectHandles.getGlobal();
        MBeanProxy<?> registration = globalHandles.get(WordFactory.pointer(handle));
        MBeanInfo info = registration.getBean().getMBeanInfo();
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("bean.class", info.getClassName());
        map.put("bean.description", info.getDescription());
        for (MBeanAttributeInfo attr : info.getAttributes()) {
            putAttributeInfo(map, attr);
        }
        int opCounter = 0;
        for (MBeanOperationInfo op : info.getOperations()) {
            putOperationInfo(map, op, ++opCounter);
        }
        scope.setObjectResult(mapToRaw(env, map));
    }
    return scope.getObjectResult();
}
Also used : ObjectHandles(org.graalvm.nativeimage.ObjectHandles) GetMBeanInfo(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal.Id.GetMBeanInfo) MBeanInfo(javax.management.MBeanInfo) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) LinkedHashMap(java.util.LinkedHashMap) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

Example 22 with JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope in project graal by oracle.

the class TruffleToLibGraalEntryPoints method doCompile.

@TruffleToLibGraal(DoCompile)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_doCompile")
public static void doCompile(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle, long debugContextHandle, long compilationHandle, JByteArray hsOptions, JObject hsTask, JObject hsListener) {
    try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, DoCompile, env)) {
        TruffleCompilationIdentifier compilation = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilationIdentifier.class);
        try (CompilationContext hotSpotObjectConstantScope = HotSpotGraalServices.openLocalCompilationContext(compilation)) {
            HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class);
            TruffleDebugContext debugContext = LibGraalObjectHandles.resolve(debugContextHandle, TruffleDebugContext.class);
            Map<String, Object> options = decodeOptions(env, hsOptions);
            TruffleCompilationTask task = hsTask.isNull() ? null : new HSTruffleCompilationTask(hsTask);
            TruffleCompilerListener listener = hsListener.isNull() ? null : new HSTruffleCompilerListener(scope, hsListener);
            compiler.doCompile(debugContext, compilation, options, task, listener);
        }
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
    }
}
Also used : TruffleCompilationIdentifier(org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString) JString(org.graalvm.jniutils.JNI.JString) GetSuppliedString(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString) JNIUtil.createHSString(org.graalvm.jniutils.JNIUtil.createHSString) TruffleCompilationTask(org.graalvm.compiler.truffle.common.TruffleCompilationTask) HotSpotTruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl) CompilationContext(org.graalvm.compiler.hotspot.CompilationContext) HSObject(org.graalvm.jniutils.HSObject) JObject(org.graalvm.jniutils.JNI.JObject) TruffleCompilerListener(org.graalvm.compiler.truffle.common.TruffleCompilerListener) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 23 with JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope in project graal by oracle.

the class TruffleToLibGraalEntryPoints method pendingTransferToInterpreterOffset.

@TruffleToLibGraal(PendingTransferToInterpreterOffset)
@SuppressWarnings("unused")
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_pendingTransferToInterpreterOffset")
public static int pendingTransferToInterpreterOffset(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, JObject hsCompilable) {
    try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, PendingTransferToInterpreterOffset, env)) {
        HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(handle, HotSpotTruffleCompilerImpl.class);
        CompilableTruffleAST compilable = new HSCompilableTruffleAST(scope, hsCompilable);
        return compiler.pendingTransferToInterpreterOffset(compilable);
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        return 0;
    }
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST) HotSpotTruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 24 with JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope in project graal by oracle.

the class TruffleToLibGraalEntryPoints method openDebugContext.

@TruffleToLibGraal(OpenDebugContext)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_openDebugContext")
@SuppressWarnings({ "unused", "try" })
public static long openDebugContext(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle, long compilationHandle, JByteArray hsOptions) {
    try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, OpenDebugContext, env)) {
        HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class);
        TruffleCompilation compilation = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilation.class);
        Map<String, Object> options = decodeOptions(env, hsOptions);
        TruffleDebugContext debugContext = compiler.openDebugContext(options, compilation);
        long handle = LibGraalObjectHandles.create(debugContext);
        return handle;
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        return 0;
    }
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) HSObject(org.graalvm.jniutils.HSObject) JObject(org.graalvm.jniutils.JNI.JObject) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString) JString(org.graalvm.jniutils.JNI.JString) GetSuppliedString(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString) JNIUtil.createHSString(org.graalvm.jniutils.JNIUtil.createHSString) HotSpotTruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 25 with JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope in project graal by oracle.

the class TruffleToLibGraalEntryPoints method isPrintGraphEnabled.

@TruffleToLibGraal(IsPrintGraphEnabled)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_isPrintGraphEnabled")
public static boolean isPrintGraphEnabled(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long truffleRuntimeHandle) {
    try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, IsPrintGraphEnabled, env)) {
        HSTruffleCompilerRuntime hsTruffleRuntime = LibGraalObjectHandles.resolve(truffleRuntimeHandle, HSTruffleCompilerRuntime.class);
        assert TruffleCompilerRuntime.getRuntime() == hsTruffleRuntime;
        OptionValues graalOptions = hsTruffleRuntime.getGraalOptions(OptionValues.class);
        return DebugOptions.PrintGraph.getValue(graalOptions) != DebugOptions.PrintGraphTarget.Disable;
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        return false;
    }
}
Also used : HotSpotGraalOptionValues(org.graalvm.compiler.hotspot.HotSpotGraalOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Aggregations

JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)36 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)32 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)25 GetSuppliedString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString)12 JString (org.graalvm.jniutils.JNI.JString)12 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)12 JNIUtil.createString (org.graalvm.jniutils.JNIUtil.createString)12 HotSpotTruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl)9 JMXToLibGraal (org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)7 JObject (org.graalvm.jniutils.JNI.JObject)7 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)5 TruffleCompilationIdentifier (org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier)4 HSObject (org.graalvm.jniutils.HSObject)4 ObjectHandles (org.graalvm.nativeimage.ObjectHandles)4 AttributeList (javax.management.AttributeList)3 CompilableTruffleAST (org.graalvm.compiler.truffle.common.CompilableTruffleAST)3 TruffleCompilation (org.graalvm.compiler.truffle.common.TruffleCompilation)3 TruffleFromLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)3 JNI (org.graalvm.jniutils.JNI)3 JObjectArray (org.graalvm.jniutils.JNI.JObjectArray)3