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);
}
}
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()));
}
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();
}
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);
}
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;
}
Aggregations