use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class JNIUtil method createString.
/**
* Decodes a string in the HotSpot heap to a local {@link String}.
*/
public static String createString(JNIEnv env, JString hsString) {
if (hsString.isNull()) {
return null;
}
int len = env.getFunctions().getGetStringLength().call(env, hsString);
CShortPointer unicode = env.getFunctions().getGetStringChars().call(env, hsString, WordFactory.nullPointer());
try {
char[] data = new char[len];
for (int i = 0; i < len; i++) {
data[i] = (char) unicode.read(i);
}
return new String(data);
} finally {
env.getFunctions().getReleaseStringChars().call(env, hsString, unicode);
}
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class TruffleToLibGraalEntryPoints method getTruffleCompilationId.
@TruffleToLibGraal(GetTruffleCompilationId)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTruffleCompilationId")
@SuppressWarnings({ "unused", "try" })
public static JString getTruffleCompilationId(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilationHandle) {
JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetTruffleCompilationId, env);
try (JNIMethodScope s = scope) {
String compilationId = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilationIdentifier.class).toString(CompilationIdentifier.Verbosity.ID);
scope.setObjectResult(createHSString(env, compilationId));
} catch (Throwable t) {
JNIExceptionWrapper.throwInHotSpot(env, t);
scope.setObjectResult(WordFactory.nullPointer());
}
return scope.getObjectResult();
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class HSTruffleCompilerListener method onFailure.
@TruffleFromLibGraal(OnFailure)
@Override
public void onFailure(CompilableTruffleAST compilable, String serializedException, boolean bailout, boolean permanentBailout, int tier) {
JObject hsCompilable = ((HSCompilableTruffleAST) compilable).getHandle();
JNIEnv env = JNIMethodScope.env();
JString hsReason = createHSString(env, serializedException);
callOnFailure(env, getHandle(), hsCompilable, hsReason, bailout, permanentBailout, tier);
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class TruffleToLibGraalEntryPoints method getCompilerConfigurationFactoryName.
@TruffleToLibGraal(GetCompilerConfigurationFactoryName)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getCompilerConfigurationFactoryName")
public static JString getCompilerConfigurationFactoryName(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long truffleRuntimeHandle) {
JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetCompilerConfigurationFactoryName, env);
try (JNIMethodScope s = scope) {
HSTruffleCompilerRuntime hsTruffleRuntime = LibGraalObjectHandles.resolve(truffleRuntimeHandle, HSTruffleCompilerRuntime.class);
assert TruffleCompilerRuntime.getRuntime() == hsTruffleRuntime;
OptionValues graalOptions = hsTruffleRuntime.getGraalOptions(OptionValues.class);
String compConfig = Options.TruffleCompilerConfiguration.getValue(graalOptions);
CompilerConfigurationFactory compilerConfigurationFactory = CompilerConfigurationFactory.selectFactory(compConfig, graalOptions, HotSpotJVMCIRuntime.runtime());
String name = compilerConfigurationFactory.getName();
scope.setObjectResult(createHSString(env, name));
} catch (Throwable t) {
JNIExceptionWrapper.throwInHotSpot(env, t);
scope.setObjectResult(WordFactory.nullPointer());
}
return scope.getObjectResult();
}
Aggregations