use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class TruffleCompilerImpl method doCompile.
@Override
@SuppressWarnings("try")
public void doCompile(DebugContext inDebug, CompilationIdentifier inCompilationId, OptionValues options, CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, Cancellable cancellable, TruffleCompilerListener listener) {
CompilationIdentifier compilationId = inCompilationId == null ? getCompilationIdentifier(compilable) : inCompilationId;
DebugContext debug = inDebug == null ? openDebugContext(options, compilationId, compilable) : inDebug;
try (DebugContext debugToClose = debug == inDebug ? null : debug;
DebugContext.Scope s = maybeOpenTruffleScope(compilable, debug)) {
new TruffleCompilationWrapper(getDebugOutputDirectory(), getCompilationProblemsPerAction(), compilable, cancellable, inliningPlan, compilationId, listener).run(debug);
} catch (Throwable e) {
notifyCompilableOfFailure(compilable, e);
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class BasicArrayCopyNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode sourcePosition = tool.getAlias(getSourcePosition());
ValueNode destinationPosition = tool.getAlias(getDestinationPosition());
ValueNode replacedLength = tool.getAlias(getLength());
if (sourcePosition.isConstant() && destinationPosition.isConstant() && replacedLength.isConstant()) {
int srcPosInt = sourcePosition.asJavaConstant().asInt();
int destPosInt = destinationPosition.asJavaConstant().asInt();
int len = replacedLength.asJavaConstant().asInt();
ValueNode destAlias = tool.getAlias(getDestination());
if (destAlias instanceof VirtualArrayNode) {
VirtualArrayNode destVirtual = (VirtualArrayNode) destAlias;
if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) {
return;
}
ValueNode srcAlias = tool.getAlias(getSource());
if (srcAlias instanceof VirtualObjectNode) {
if (!(srcAlias instanceof VirtualArrayNode)) {
return;
}
VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias;
if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) {
return;
}
if (!checkBounds(srcPosInt, len, srcVirtual)) {
return;
}
if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) {
return;
}
for (int i = 0; i < len; i++) {
tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i));
}
tool.delete();
DebugContext debug = getDebug();
if (debug.isLogEnabled()) {
debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len);
}
} else {
ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias);
if (sourceType == null || !sourceType.isArray()) {
return;
}
ResolvedJavaType sourceComponentType = sourceType.getComponentType();
ResolvedJavaType destComponentType = destVirtual.type().getComponentType();
if (!sourceComponentType.equals(destComponentType)) {
return;
}
for (int i = 0; i < len; i++) {
LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind());
tool.addNode(load);
tool.setVirtualEntry(destVirtual, destPosInt + i, load);
}
tool.delete();
}
}
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class GraalTest method afterTest.
@After
public void afterTest() {
List<DebugContext> cached = cachedDebugs.get();
if (cached != null) {
for (DebugContext debug : cached) {
debug.close();
debug.closeDumpHandlers(true);
}
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class GraalTest method getDebugContext.
/**
* Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
* none currently exists. Debug contexts created by this method will have their
* {@link DebugDumpHandler}s closed in {@link #afterTest()}.
*
* @param options currently active options
* @param id identification of the compilation or {@code null}
* @param method method to use for a proper description of the context or {@code null}
* @return configured context for compilation
*/
protected DebugContext getDebugContext(OptionValues options, String id, ResolvedJavaMethod method) {
List<DebugContext> cached = cachedDebugs.get();
if (cached == null) {
cached = new ArrayList<>();
cachedDebugs.set(cached);
}
for (DebugContext debug : cached) {
if (debug.getOptions() == options) {
return debug;
}
}
final DebugContext.Description descr;
if (method == null) {
descr = NO_DESCRIPTION;
} else {
descr = new DebugContext.Description(method, id == null ? method.getName() : id);
}
DebugContext debug = DebugContext.create(options, descr, globalMetrics, DEFAULT_LOG_STREAM, getDebugHandlersFactories());
cached.add(debug);
return debug;
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class SubstrateGraalUtils method compileGraph.
@SuppressWarnings("try")
public static CompilationResult compileGraph(RuntimeConfiguration runtimeConfig, Suites suites, LIRSuites lirSuites, final SharedMethod method, final StructuredGraph graph) {
assert runtimeConfig != null : "no runtime";
if (Options.ForceDumpGraphsBeforeCompilation.getValue()) {
/*
* forceDump is often used during debugging, and we want to make sure that it keeps
* working, i.e., does not lead to image generation problems when adding a call to it.
* This code ensures that forceDump is seen as reachable for all images that include
* Graal, because it is conditional on a runtime option.
*/
graph.getDebug().forceDump(graph, "Force dump before compilation");
}
String methodName = method.format("%h.%n");
try (DebugContext debug = graph.getDebug();
Indent indent = debug.logAndIndent("compile graph %s for method %s", graph, methodName)) {
OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
final Backend backend = runtimeConfig.lookupBackend(method);
try (Indent indent2 = debug.logAndIndent("do compilation")) {
SubstrateCompilationResult result = new SubstrateCompilationResult(graph.compilationId(), method.format("%H.%n(%p)"));
GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, optimisticOpts, null, suites, lirSuites, result, CompilationResultBuilderFactory.Default);
return result;
}
}
}
Aggregations