Search in sources :

Example 6 with JClass

use of org.graalvm.jniutils.JNI.JClass in project graal by oracle.

the class JNIUtil method getSystemClassLoader.

/**
 * Returns the {@link ClassLoader#getSystemClassLoader()}.
 */
public static JObject getSystemClassLoader(JNIEnv env) {
    JClass clazz;
    try (CCharPointerHolder className = CTypeConversion.toCString(JNIUtil.getBinaryName(ClassLoader.class.getName()))) {
        clazz = JNIUtil.FindClass(env, className.get());
    }
    if (clazz.isNull()) {
        throw new InternalError("No such class " + ClassLoader.class.getName());
    }
    JMethodID getClassLoaderId = findMethod(env, clazz, true, true, METHOD_GET_SYSTEM_CLASS_LOADER[0], METHOD_GET_SYSTEM_CLASS_LOADER[1]);
    if (getClassLoaderId.isNull()) {
        throw new InternalError(String.format("Cannot find method %s in class %s.", METHOD_GET_SYSTEM_CLASS_LOADER[0], ClassLoader.class.getName()));
    }
    return env.getFunctions().getCallStaticObjectMethodA().call(env, clazz, getClassLoaderId, nullPointer());
}
Also used : JMethodID(org.graalvm.jniutils.JNI.JMethodID) JClass(org.graalvm.jniutils.JNI.JClass) CCharPointerHolder(org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder)

Example 7 with JClass

use of org.graalvm.jniutils.JNI.JClass in project graal by oracle.

the class TruffleToLibGraalEntryPoints method getInfopoints.

@TruffleToLibGraal(GetInfopoints)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopoints")
@SuppressWarnings({ "unused", "try" })
public static JObjectArray getInfopoints(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) {
    JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetInfopoints, env);
    try (JNIMethodScope s = scope) {
        String[] infoPoints = LibGraalObjectHandles.resolve(handle, CompilationResultInfo.class).getInfopoints();
        JClass componentType = FromLibGraalCalls.getJNIClass(env, String.class);
        JObjectArray res = NewObjectArray(env, infoPoints.length, componentType, WordFactory.nullPointer());
        for (int i = 0; i < infoPoints.length; i++) {
            SetObjectArrayElement(env, res, i, createHSString(env, infoPoints[i]));
        }
        scope.setObjectResult(res);
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        scope.setObjectResult(WordFactory.nullPointer());
    }
    return scope.getObjectResult();
}
Also used : CompilationResultInfo(org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) JClass(org.graalvm.jniutils.JNI.JClass) 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) JObjectArray(org.graalvm.jniutils.JNI.JObjectArray) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Aggregations

JClass (org.graalvm.jniutils.JNI.JClass)7 JString (org.graalvm.jniutils.JNI.JString)4 JMethodID (org.graalvm.jniutils.JNI.JMethodID)3 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)3 JNIUtil.createString (org.graalvm.jniutils.JNIUtil.createString)3 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)2 GetSuppliedString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString)2 JObjectArray (org.graalvm.jniutils.JNI.JObjectArray)2 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)2 CCharPointerHolder (org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder)2 CompilationResultInfo (org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo)1 GraphInfo (org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo)1 JNIMethod (org.graalvm.jniutils.HotSpotCalls.JNIMethod)1 JValue (org.graalvm.jniutils.JNI.JValue)1 CTypeConversion.toCString (org.graalvm.nativeimage.c.type.CTypeConversion.toCString)1