< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/CompilationWrapper.java
Print this page
rev 52509 : [mq]: graal2
@@ -39,11 +39,10 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;
-import org.graalvm.compiler.debug.DebugCloseable;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.DiagnosticsOutputDirectory;
import org.graalvm.compiler.debug.PathUtilities;
import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.options.EnumOptionKey;
@@ -161,12 +160,13 @@
/**
* Creates the {@link DebugContext} to use when retrying a compilation.
*
* @param options the options for configuring the debug context
+ * @param logStream the log stream to use in the debug context
*/
- protected abstract DebugContext createRetryDebugContext(OptionValues options);
+ protected abstract DebugContext createRetryDebugContext(OptionValues options, PrintStream logStream);
@SuppressWarnings("try")
public final T run(DebugContext initialDebug) {
try {
return performCompilation(initialDebug);
@@ -225,41 +225,54 @@
// If dumping is explicitly enabled, Graal is being debugged
// so don't interfere with what the user is expecting to see.
return handleException(cause);
}
+ File dumpPath = null;
+ try {
String dir = this.outputDirectory.getPath();
- if (dir == null) {
- return handleException(cause);
- }
+ if (dir != null) {
String dumpName = PathUtilities.sanitizeFileName(toString());
- File dumpPath = new File(dir, dumpName);
+ dumpPath = new File(dir, dumpName);
dumpPath.mkdirs();
if (!dumpPath.exists()) {
TTY.println("Warning: could not create diagnostics directory " + dumpPath);
- return handleException(cause);
+ dumpPath = null;
+ }
+ }
+ } catch (Throwable t) {
+ TTY.println("Warning: could not create Graal diagnostic directory");
+ t.printStackTrace(TTY.out);
}
String message;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream ps = new PrintStream(baos)) {
- ps.printf("%s: Compilation of %s failed: ", Thread.currentThread(), this);
+ ps.printf("%s: Compilation of %s failed:%n", Thread.currentThread(), this);
cause.printStackTrace(ps);
ps.printf("To disable compilation %s notifications, set %s to %s (e.g., -Dgraal.%s=%s).%n",
causeType,
actionKey.getName(), ExceptionAction.Silent,
actionKey.getName(), ExceptionAction.Silent);
ps.printf("To print a message for a compilation %s without retrying the compilation, " +
"set %s to %s (e.g., -Dgraal.%s=%s).%n",
causeType,
actionKey.getName(), ExceptionAction.Print,
actionKey.getName(), ExceptionAction.Print);
+ if (dumpPath != null) {
ps.println("Retrying compilation of " + this);
+ } else {
+ ps.println("Not retrying compilation of " + this + " as the dump path could not be created.");
+ }
message = baos.toString();
}
TTY.print(message);
+ if (dumpPath == null) {
+ return handleException(cause);
+ }
+
File retryLogFile = new File(dumpPath, "retry.log");
try (PrintStream ps = new PrintStream(new FileOutputStream(retryLogFile))) {
ps.print(message);
} catch (IOException ioe) {
TTY.printf("Error writing to %s: %s%n", retryLogFile, ioe);
@@ -268,19 +281,31 @@
OptionValues retryOptions = new OptionValues(initialOptions,
Dump, ":" + VERBOSE_LEVEL,
MethodFilter, null,
DumpPath, dumpPath.getPath());
- try (DebugContext retryDebug = createRetryDebugContext(retryOptions); DebugCloseable s = retryDebug.disableIntercept()) {
+ ByteArrayOutputStream logBaos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(logBaos);
+ try (DebugContext retryDebug = createRetryDebugContext(retryOptions, ps)) {
T res = performCompilation(retryDebug);
+ ps.println("There was no exception during retry.");
maybeExitVM(action);
return res;
- } catch (Throwable ignore) {
+ } catch (Throwable e) {
+ ps.println("Exception during retry:");
+ e.printStackTrace(ps);
// Failures during retry are silent
T res = handleException(cause);
maybeExitVM(action);
return res;
+ } finally {
+ ps.close();
+ try (FileOutputStream fos = new FileOutputStream(retryLogFile, true)) {
+ fos.write(logBaos.toByteArray());
+ } catch (Throwable e) {
+ TTY.printf("Error writing to %s: %s%n", retryLogFile, e);
+ }
}
}
}
}
< prev index next >