use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class HSCompilableTruffleAST method cancelCompilation.
@TruffleFromLibGraal(CancelCompilation)
@Override
public boolean cancelCompilation(CharSequence reason) {
JNIEnv env = env();
JString jniReason = JNIUtil.createHSString(env, reason.toString());
return callCancelCompilation(env, getHandle(), jniReason);
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class HSCompilableTruffleAST method toString.
@TruffleFromLibGraal(CompilableToString)
@Override
public String toString() {
String res = cachedString;
if (res == null) {
JNIEnv env = JNIMethodScope.env();
JString value = callCompilableToString(env, getHandle());
res = createString(env, value);
cachedString = res;
}
return res;
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class HSCompilableTruffleAST method getName.
@TruffleFromLibGraal(GetCompilableName)
@Override
public String getName() {
String res = cachedName;
if (res == null) {
JNIEnv env = JNIMethodScope.env();
JString name = callGetCompilableName(env, getHandle());
res = createString(env, name);
cachedName = res;
}
return res;
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class HSTruffleCompilerRuntime method log.
@TruffleFromLibGraal(Log)
@Override
public void log(String loggerId, CompilableTruffleAST compilable, String message) {
JNIEnv env = env();
JString jniLoggerId = JNIUtil.createHSString(env, loggerId);
JString jniMessage = JNIUtil.createHSString(env, message);
callLog(env, getHandle(), jniLoggerId, ((HSCompilableTruffleAST) compilable).getHandle(), jniMessage);
}
use of org.graalvm.jniutils.JNI.JString in project graal by oracle.
the class JNIExceptionWrapper method createHSException.
/**
* Crates an exception in HotSpot representing the given {@code original} exception.
*
* @param env the {@link JNIEnv}
* @param original an exception to be created in HotSpot
*/
public static JThrowable createHSException(JNIEnv env, Throwable original) {
JThrowable hsThrowable;
if (original instanceof JNIExceptionWrapper) {
JNIExceptionWrapper jniExceptionWrapper = (JNIExceptionWrapper) original;
hsThrowable = jniExceptionWrapper.throwableHandle;
if (jniExceptionWrapper.throwableRequiresStackTraceUpdate) {
hsThrowable = updateStackTrace(env, hsThrowable, jniExceptionWrapper.getStackTrace());
}
} else {
hsThrowable = createExceptionOfSameType(env, original);
boolean hasSameExceptionType = hsThrowable.isNonNull();
if (!hasSameExceptionType) {
String message = formatExceptionMessage(original.getClass().getName(), original.getMessage());
JString hsMessage = createHSString(env, message);
hsThrowable = callCreateException(env, hsMessage);
}
StackTraceElement[] nativeStack = original.getStackTrace();
if (nativeStack.length != 0) {
// Update stack trace only for exceptions which have stack trace.
// For exceptions which override fillInStackTrace merging stack traces only adds
// useless JNI calls.
StackTraceElement[] hsStack = getJNIExceptionStackTrace(env, hsThrowable);
StackTraceElement[] mergedStack = mergeStackTraces(hsStack, nativeStack, // exception with same exception
hasSameExceptionType ? 0 : 1, // type has no factory method
0, false);
hsThrowable = updateStackTrace(env, hsThrowable, mergedStack);
}
}
return hsThrowable;
}
Aggregations