Search in sources :

Example 6 with JString

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);
}
Also used : JNIEnv(org.graalvm.jniutils.JNI.JNIEnv) JString(org.graalvm.jniutils.JNI.JString) TruffleFromLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)

Example 7 with JString

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;
}
Also used : HSCompilableTruffleASTGen.callCompilableToString(org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSCompilableTruffleASTGen.callCompilableToString) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString) JString(org.graalvm.jniutils.JNI.JString) CompilableToString(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString) JNIEnv(org.graalvm.jniutils.JNI.JNIEnv) JString(org.graalvm.jniutils.JNI.JString) TruffleFromLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)

Example 8 with JString

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;
}
Also used : HSCompilableTruffleASTGen.callCompilableToString(org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSCompilableTruffleASTGen.callCompilableToString) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString) JString(org.graalvm.jniutils.JNI.JString) CompilableToString(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString) JNIEnv(org.graalvm.jniutils.JNI.JNIEnv) JString(org.graalvm.jniutils.JNI.JString) TruffleFromLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)

Example 9 with JString

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);
}
Also used : JNIEnv(org.graalvm.jniutils.JNI.JNIEnv) JString(org.graalvm.jniutils.JNI.JString) TruffleFromLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)

Example 10 with JString

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;
}
Also used : JThrowable(org.graalvm.jniutils.JNI.JThrowable) 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) JString(org.graalvm.jniutils.JNI.JString)

Aggregations

JString (org.graalvm.jniutils.JNI.JString)14 JNIUtil.createString (org.graalvm.jniutils.JNIUtil.createString)9 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)7 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)6 GetSuppliedString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString)6 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)6 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)6 TruffleFromLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)5 JNIEnv (org.graalvm.jniutils.JNI.JNIEnv)5 CompilableToString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString)2 TruffleCompilationIdentifier (org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier)2 HSCompilableTruffleASTGen.callCompilableToString (org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSCompilableTruffleASTGen.callCompilableToString)2 CTypeConversion.toCString (org.graalvm.nativeimage.c.type.CTypeConversion.toCString)2 IOException (java.io.IOException)1 CompilerConfigurationFactory (org.graalvm.compiler.hotspot.CompilerConfigurationFactory)1 HotSpotGraalOptionValues (org.graalvm.compiler.hotspot.HotSpotGraalOptionValues)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)1 TruffleDebugJavaMethod (org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod)1 HotSpotTruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl)1