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();
}
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();
}
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);
}
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());
}
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);
}
Aggregations