Search in sources :

Example 1 with CompilableTruffleAST

use of org.graalvm.compiler.truffle.common.CompilableTruffleAST in project graal by oracle.

the class TruffleToLibGraalEntryPoints method initializeCompiler.

@TruffleToLibGraal(InitializeCompiler)
@SuppressWarnings("unused")
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeCompiler")
public static void initializeCompiler(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle, JByteArray hsOptions, JObject hsCompilable, boolean firstInitialization) {
    try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, InitializeCompiler, env)) {
        HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class);
        Map<String, Object> options = decodeOptions(env, hsOptions);
        CompilableTruffleAST compilable = new HSCompilableTruffleAST(s, hsCompilable);
        compiler.initialize(options, compilable, firstInitialization);
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
    }
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) HSObject(org.graalvm.jniutils.HSObject) JObject(org.graalvm.jniutils.JNI.JObject) 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) CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST) HotSpotTruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 2 with CompilableTruffleAST

use of org.graalvm.compiler.truffle.common.CompilableTruffleAST in project graal by oracle.

the class ExpansionStatistics method printHistogram.

private static <T, S> void printHistogram(CompilableTruffleAST ast, CompilationTier tier, Map<T, Stats> statsMap, Function<T, String> labelFunction, Map<S, Stats> subGroupMap, Function<S, String> subGroupLabelFunction, Function<S, T> subGroupToGroup, String kind) {
    StringWriter writer = new StringWriter();
    try (PrintWriter w = new PrintWriter(writer)) {
        List<Entry<T, Stats>> entries = statsMap.entrySet().stream().sorted(ExpansionStatistics::orderBySumDesc).collect(Collectors.toList());
        Map<T, List<Entry<S, Stats>>> subGroups = null;
        if (subGroupMap != null) {
            List<Entry<S, Stats>> subEntries = subGroupMap.entrySet().stream().sorted(ExpansionStatistics::orderBySumDesc).collect(Collectors.toList());
            subGroups = new HashMap<>();
            for (Entry<S, Stats> entry : subEntries) {
                List<Entry<S, Stats>> subGroup = subGroups.computeIfAbsent(subGroupToGroup.apply(entry.getKey()), (k) -> new ArrayList<>());
                subGroup.add(entry);
            }
        }
        String indent = "  ";
        int maxLabelLength = 50;
        for (Entry<T, Stats> entry : entries) {
            String label = labelFunction.apply(entry.getKey());
            int labelLength = label.length();
            if (subGroups != null) {
                List<Entry<S, Stats>> subGroup = subGroups.get(entry.getKey());
                for (Entry<S, Stats> sub : subGroup) {
                    maxLabelLength = Math.max(subGroupLabelFunction.apply(sub.getKey()).length(), maxLabelLength);
                }
            }
            maxLabelLength = Math.max(labelLength, maxLabelLength);
        }
        maxLabelLength += indent.length();
        w.printf("%-" + (maxLabelLength) + "s    Count IR Nodes (min avg max)        Size (min avg max)      Cycles (min avg max)       Ifs  Loops Invokes Allocs | Max IRNode ASTNode Unit:Lang:File:Line:Chars%n", "Name");
        for (Entry<T, Stats> entry : entries) {
            String label = labelFunction.apply(entry.getKey());
            Stats stats = entry.getValue();
            printHistogramStats(w, indent, maxLabelLength, label, stats);
            if (subGroups != null) {
                List<Entry<S, Stats>> subGroup = subGroups.get(entry.getKey());
                if (subGroup != null && subGroup.size() > 0) {
                    for (Entry<S, Stats> subEntry : subGroup) {
                        String subLabel = subGroupLabelFunction.apply(subEntry.getKey());
                        if (subGroup.size() == 1 && subLabel.equals("<unknown>")) {
                            // no need to print if only unknown specializations
                            break;
                        }
                        printHistogramStats(w, indent + "  ", maxLabelLength, subLabel, subEntry.getValue());
                    }
                }
            }
        }
    }
    TruffleCompilerRuntime.getRuntime().log(ast, String.format("%s expansion statistics after %s:%n%s", kind, tier.toString(), writer.toString()));
}
Also used : Entry(java.util.Map.Entry) StringWriter(java.io.StringWriter) CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST) ArrayList(java.util.ArrayList) List(java.util.List) PrintWriter(java.io.PrintWriter)

Example 3 with CompilableTruffleAST

use of org.graalvm.compiler.truffle.common.CompilableTruffleAST in project graal by oracle.

the class TruffleTreeDumper method dumpInlinedASTs.

private static void dumpInlinedASTs(TruffleDebugContext debug, Set<CompilableTruffleAST> inlinedTargets, TruffleNodeSources nodeSources) throws IOException {
    final GraphOutput<AST, ?> astOutput = debug.buildOutput(GraphOutput.newBuilder(AST_DUMP_STRUCTURE).blocks(AST_DUMP_STRUCTURE));
    astOutput.beginGroup(null, "Inlined ASTs", "Inlined", null, 0, debug.getVersionProperties());
    for (CompilableTruffleAST target : inlinedTargets) {
        AST ast = new AST((RootCallTarget) target, nodeSources);
        astOutput.print(ast, Collections.emptyMap(), 0, target.getName());
    }
    // Inlined
    astOutput.endGroup();
    astOutput.close();
}
Also used : CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST) CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST)

Example 4 with CompilableTruffleAST

use of org.graalvm.compiler.truffle.common.CompilableTruffleAST in project graal by oracle.

the class IgvSupport method scope.

@Override
public Closeable scope(String name, Object context) {
    CompilableTruffleAST compilable = context instanceof TruffleDebugJavaMethod ? ((TruffleDebugJavaMethod) context).getCompilable() : null;
    long compilationHandle;
    if (compilable == null) {
        compilationHandle = 0;
    } else {
        LibGraalTruffleCompilation compilation = owner.getActiveCompilation();
        assert compilation != null : compilable;
        compilationHandle = compilation.getHandle();
    }
    long scopeHandle = TruffleToLibGraalCalls.openDebugContextScope(getIsolateThread(), getHandle(), name, compilationHandle);
    return scopeHandle == 0 ? null : new Scope(scopeHandle);
}
Also used : LibGraalScope(org.graalvm.libgraal.LibGraalScope) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST)

Example 5 with CompilableTruffleAST

use of org.graalvm.compiler.truffle.common.CompilableTruffleAST in project graal by oracle.

the class LibGraalTruffleCompilation method getCompilable.

@Override
public CompilableTruffleAST getCompilable() {
    CompilableTruffleAST compilable = cachedCompilableTruffleAST;
    if (compilable == null) {
        compilable = TruffleToLibGraalCalls.getTruffleCompilationTruffleAST(getIsolateThread(), getHandle());
        cachedCompilableTruffleAST = compilable;
    }
    return compilable;
}
Also used : CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST)

Aggregations

CompilableTruffleAST (org.graalvm.compiler.truffle.common.CompilableTruffleAST)12 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)6 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)3 SubstrateCompilableTruffleAST (com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST)3 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)3 HotSpotTruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl)3 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)3 Assumption (com.oracle.truffle.api.Assumption)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Builder (org.graalvm.compiler.debug.DebugContext.Builder)1 Scope (org.graalvm.compiler.debug.DebugContext.Scope)1 TruffleCallNode (org.graalvm.compiler.truffle.common.TruffleCallNode)1