Search in sources :

Example 11 with JString

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);
    }
}
Also used : CShortPointer(org.graalvm.nativeimage.c.type.CShortPointer) JString(org.graalvm.jniutils.JNI.JString) CTypeConversion.toCString(org.graalvm.nativeimage.c.type.CTypeConversion.toCString)

Example 12 with JString

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();
}
Also used : TruffleCompilationIdentifier(org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) 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) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 13 with JString

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

Example 14 with JString

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();
}
Also used : CompilerConfigurationFactory(org.graalvm.compiler.hotspot.CompilerConfigurationFactory) HotSpotGraalOptionValues(org.graalvm.compiler.hotspot.HotSpotGraalOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) 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) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

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