Search in sources :

Example 1 with JClass

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

the class TruffleToLibGraalEntryPoints method getNodeTypes.

@TruffleToLibGraal(GetNodeTypes)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeTypes")
@SuppressWarnings({ "unused", "try" })
public static JObjectArray getNodeTypes(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, boolean simpleNames) {
    JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetNodeTypes, env);
    try (JNIMethodScope s = scope) {
        GraphInfo orig = LibGraalObjectHandles.resolve(handle, GraphInfo.class);
        String[] nodeTypes = orig.getNodeTypes(simpleNames);
        JClass componentType = FromLibGraalCalls.getJNIClass(env, String.class);
        JObjectArray res = NewObjectArray(env, nodeTypes.length, componentType, WordFactory.nullPointer());
        for (int i = 0; i < nodeTypes.length; i++) {
            SetObjectArrayElement(env, res, i, JNIUtil.createHSString(env, nodeTypes[i]));
        }
        scope.setObjectResult(res);
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        scope.setObjectResult(WordFactory.nullPointer());
    }
    return scope.getObjectResult();
}
Also used : GraphInfo(org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo) 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)

Example 2 with JClass

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

the class JNIExceptionWrapper method createExceptionOfSameType.

private static <T extends JObject> T createExceptionOfSameType(JNIEnv env, Throwable original) {
    WordFactory.nullPointer();
    String className = original.getClass().getTypeName();
    JClass exceptionClass = JNIUtil.findClass(env, WordFactory.nullPointer(), getBinaryName(className), false);
    if (exceptionClass.isNonNull()) {
        JNIMethod constructor = JNIMethod.findMethod(env, exceptionClass, false, false, "<init>", encodeMethodSignature(void.class, String.class));
        if (constructor != null) {
            JNI.JValue args = StackValue.get(1, JNI.JValue.class);
            args.addressOf(0).setJObject(createHSString(env, original.getMessage()));
            T res = HotSpotCalls.getDefault().callNewObject(env, exceptionClass, constructor, args);
            return res;
        }
        constructor = JNIMethod.findMethod(env, exceptionClass, false, false, "<init>", encodeMethodSignature(void.class));
        if (constructor != null) {
            T res = HotSpotCalls.getDefault().callNewObject(env, exceptionClass, constructor, WordFactory.nullPointer());
            return res;
        }
    }
    return WordFactory.nullPointer();
}
Also used : JNIMethod(org.graalvm.jniutils.HotSpotCalls.JNIMethod) JClass(org.graalvm.jniutils.JNI.JClass) JString(org.graalvm.jniutils.JNI.JString) JNIUtil.createHSString(org.graalvm.jniutils.JNIUtil.createHSString) CTypeConversion.toCString(org.graalvm.nativeimage.c.type.CTypeConversion.toCString) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString)

Example 3 with JClass

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

the class JNIExceptionWrapper method getClassName.

private static String getClassName(JNIEnv env, JThrowable throwableHandle) {
    JClass classHandle = GetObjectClass(env, throwableHandle);
    JString className = callGetClassName(env, classHandle);
    return createString(env, className);
}
Also used : JClass(org.graalvm.jniutils.JNI.JClass) JString(org.graalvm.jniutils.JNI.JString)

Example 4 with JClass

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

the class JNIUtil method getJVMCIClassLoader.

/**
 * Returns a ClassLoader used to load the compiler classes.
 */
public static JObject getJVMCIClassLoader(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_PLATFORM_CLASS_LOADER[0], METHOD_GET_PLATFORM_CLASS_LOADER[1]);
    if (getClassLoaderId.isNull()) {
        throw new InternalError(String.format("Cannot find method %s in class %s.", METHOD_GET_PLATFORM_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 5 with JClass

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

the class JNIUtil method findClass.

/**
 * Finds a class in HotSpot heap using a given {@code ClassLoader}.
 *
 * @param env the {@code JNIEnv}
 * @param binaryName the class binary name
 */
public static JClass findClass(JNIEnv env, JObject classLoader, String binaryName) {
    if (classLoader.isNull()) {
        throw new IllegalArgumentException("ClassLoader must be non null.");
    }
    trace(1, "%s->HS: findClass %s", getFeatureName(), binaryName);
    JMethodID findClassId = findMethod(env, JNIUtil.GetObjectClass(env, classLoader), false, false, METHOD_LOAD_CLASS[0], METHOD_LOAD_CLASS[1]);
    JValue params = StackValue.get(1, JValue.class);
    params.addressOf(0).setJObject(JNIUtil.createHSString(env, binaryName.replace('/', '.')));
    return (JClass) env.getFunctions().getCallObjectMethodA().call(env, classLoader, findClassId, params);
}
Also used : JMethodID(org.graalvm.jniutils.JNI.JMethodID) JValue(org.graalvm.jniutils.JNI.JValue) JClass(org.graalvm.jniutils.JNI.JClass)

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