Search in sources :

Example 16 with JNIMethodScope

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

the class TruffleToLibGraalEntryPoints method getCompilerConfigurationName.

@TruffleToLibGraal(GetCompilerConfigurationName)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getCompilerConfigurationName")
public static JString getCompilerConfigurationName(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateId, long handle) {
    JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetCompilerConfigurationName, env);
    try (JNIMethodScope s = scope) {
        HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(handle, HotSpotTruffleCompilerImpl.class);
        String name = compiler.getCompilerConfigurationName();
        scope.setObjectResult(createHSString(env, name));
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        scope.setObjectResult(WordFactory.nullPointer());
    }
    return scope.getObjectResult();
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) 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 17 with JNIMethodScope

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

the class TruffleToLibGraalEntryPoints method getString.

@TruffleToLibGraal(GetSuppliedString)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getSuppliedString")
@SuppressWarnings({ "unused", "unchecked", "try" })
public static JString getString(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) {
    JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetSuppliedString, env);
    try (JNIMethodScope s = scope) {
        Supplier<String> orig = LibGraalObjectHandles.resolve(handle, Supplier.class);
        if (orig != null) {
            String stackTrace = orig.get();
            scope.setObjectResult(JNIUtil.createHSString(env, stackTrace));
        } else {
            scope.setObjectResult(WordFactory.nullPointer());
        }
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        scope.setObjectResult(WordFactory.nullPointer());
    }
    return scope.getObjectResult();
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) 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) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 18 with JNIMethodScope

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

the class HSCompilableTruffleAST method getCallNodes.

@TruffleFromLibGraal(GetCallNodes)
@Override
public TruffleCallNode[] getCallNodes() {
    JNIMethodScope scope = scope();
    JNIEnv env = scope.getEnv();
    JObjectArray peerArr = callGetCallNodes(env, getHandle());
    int len = JNIUtil.GetArrayLength(env, peerArr);
    TruffleCallNode[] res = new TruffleCallNode[len];
    for (int i = 0; i < len; i++) {
        JObject peerTruffleCallNode = JNIUtil.GetObjectArrayElement(env, peerArr, i);
        res[i] = new HSTruffleCallNode(scope, peerTruffleCallNode);
    }
    return res;
}
Also used : TruffleCallNode(org.graalvm.compiler.truffle.common.TruffleCallNode) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) JObjectArray(org.graalvm.jniutils.JNI.JObjectArray) JObject(org.graalvm.jniutils.JNI.JObject) JNIEnv(org.graalvm.jniutils.JNI.JNIEnv) TruffleFromLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)

Example 19 with JNIMethodScope

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

the class HSTruffleCompilerRuntime method asCompilableTruffleAST.

@TruffleFromLibGraal(AsCompilableTruffleAST)
@Override
public CompilableTruffleAST asCompilableTruffleAST(JavaConstant constant) {
    JNIMethodScope scope = JNIMethodScope.scopeOrNull();
    if (scope == null) {
        return null;
    }
    long constantHandle = LibGraal.translate(constant);
    JObject hsCompilable = callAsCompilableTruffleAST(scope.getEnv(), getHandle(), constantHandle);
    if (hsCompilable.isNull()) {
        return null;
    } else {
        return new HSCompilableTruffleAST(scope, hsCompilable);
    }
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) JObject(org.graalvm.jniutils.JNI.JObject) TruffleFromLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)

Example 20 with JNIMethodScope

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

the class JMXToLibGraalEntryPoints method pollRegistrations.

/**
 * Returns the pending {@link DynamicMBean} registrations.
 */
@JMXToLibGraal(PollRegistrations)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_pollRegistrations")
@SuppressWarnings({ "try", "unused" })
static JNI.JLongArray pollRegistrations(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, PollRegistrations, env);
    try (JNIMethodScope s = scope) {
        List<MBeanProxy<?>> registrations = MBeanProxy.drainRegistrations();
        JNI.JLongArray res = JNIUtil.NewLongArray(env, registrations.size());
        CLongPointer elems = JNIUtil.GetLongArrayElements(env, res, WordFactory.nullPointer());
        try {
            ObjectHandles globalHandles = ObjectHandles.getGlobal();
            for (int i = 0; i < registrations.size(); i++) {
                long handle = globalHandles.create(registrations.get(i)).rawValue();
                elems.write(i, handle);
            }
        } finally {
            JNIUtil.ReleaseLongArrayElements(env, res, elems, JNI.JArray.MODE_WRITE_RELEASE);
        }
        scope.setObjectResult(res);
    }
    return scope.getObjectResult();
}
Also used : ObjectHandles(org.graalvm.nativeimage.ObjectHandles) JNI(org.graalvm.jniutils.JNI) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) CLongPointer(org.graalvm.nativeimage.c.type.CLongPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

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