use of jdk.vm.ci.code.BailoutException in project graal by oracle.
the class GraalCompilerTest method getCode.
/**
* Gets installed code for a given method and graph, compiling it first if necessary.
*
* @param installedCodeOwner the method the compiled code will be associated with when installed
* @param graph the graph to be compiled. If null, a graph will be obtained from
* {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
* @param forceCompile specifies whether to ignore any previous code cached for the (method,
* key) pair
* @param installAsDefault specifies whether to install as the default implementation
* @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
*/
@SuppressWarnings("try")
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
boolean useCache = !forceCompile && getArgumentToBind() == null;
if (useCache && graph == null) {
InstalledCode cached = cache.get(installedCodeOwner);
if (cached != null) {
if (cached.isValid()) {
return cached;
}
}
}
// loop for retrying compilation
for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
InstalledCode installedCode = null;
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
DebugContext debug = graphToCompile.getDebug();
try (AllocSpy spy = AllocSpy.open(installedCodeOwner);
DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
printer.finish(compResult);
try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
DebugContext.Activation a = debug.activate()) {
try {
if (installAsDefault) {
installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
} else {
installedCode = addMethod(debug, installedCodeOwner, compResult);
}
if (installedCode == null) {
throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
}
} catch (BailoutException e) {
if (retry < BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
// retry (if there is no predefined graph)
TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
continue;
}
throw e;
}
} catch (Throwable e) {
throw debug.handle(e);
}
} catch (Throwable e) {
throw debug.handle(e);
}
if (useCache) {
cache.put(installedCodeOwner, installedCode);
}
return installedCode;
}
throw GraalError.shouldNotReachHere();
}
use of jdk.vm.ci.code.BailoutException in project graal by oracle.
the class DebugConfigImpl method interceptException.
@Override
public RuntimeException interceptException(DebugContext debug, Throwable e) {
if (e instanceof BailoutException && !DebugOptions.InterceptBailout.getValue(options)) {
return null;
}
OptionValues interceptOptions = new OptionValues(options, DebugOptions.Count, null, DebugOptions.Time, null, DebugOptions.TrackMemUse, null, DebugOptions.Verify, null, DebugOptions.Dump, ":" + BASIC_LEVEL, DebugOptions.Log, ":" + BASIC_LEVEL);
DebugConfigImpl config = new DebugConfigImpl(interceptOptions, output, dumpHandlers, verifyHandlers);
ScopeImpl scope = debug.currentScope;
scope.updateFlags(config);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(baos));
debug.log("Exception raised in scope %s: %s", debug.getCurrentScopeName(), baos);
Map<Object, Object> firstSeen = new IdentityHashMap<>();
for (Object o : debug.context()) {
// Only dump a context object once.
if (!firstSeen.containsKey(o)) {
firstSeen.put(o, o);
if (DebugOptions.DumpOnError.getValue(options) || DebugOptions.Dump.getValue(options) != null) {
debug.dump(DebugContext.BASIC_LEVEL, o, "Exception: %s", e);
}
debug.log("Context obj %s", o);
}
}
} finally {
scope.updateFlags(this);
}
return null;
}
Aggregations