< 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,49 ****
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;
--- 39,48 ----
*** 161,172 ****
/**
* Creates the {@link DebugContext} to use when retrying a compilation.
*
* @param options the options for configuring the debug context
*/
! protected abstract DebugContext createRetryDebugContext(OptionValues options);
@SuppressWarnings("try")
public final T run(DebugContext initialDebug) {
try {
return performCompilation(initialDebug);
--- 160,172 ----
/**
* 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, PrintStream logStream);
@SuppressWarnings("try")
public final T run(DebugContext initialDebug) {
try {
return performCompilation(initialDebug);
*** 225,265 ****
// If dumping is explicitly enabled, Graal is being debugged
// so don't interfere with what the user is expecting to see.
return handleException(cause);
}
String dir = this.outputDirectory.getPath();
! if (dir == null) {
! return handleException(cause);
! }
String dumpName = PathUtilities.sanitizeFileName(toString());
! File dumpPath = new File(dir, dumpName);
dumpPath.mkdirs();
if (!dumpPath.exists()) {
TTY.println("Warning: could not create diagnostics directory " + dumpPath);
! return handleException(cause);
}
String message;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream ps = new PrintStream(baos)) {
! ps.printf("%s: Compilation of %s failed: ", 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);
ps.println("Retrying compilation of " + this);
message = baos.toString();
}
TTY.print(message);
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);
--- 225,278 ----
// 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) {
String dumpName = PathUtilities.sanitizeFileName(toString());
! dumpPath = new File(dir, dumpName);
dumpPath.mkdirs();
if (!dumpPath.exists()) {
TTY.println("Warning: could not create diagnostics directory " + dumpPath);
! 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:%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,286 ****
OptionValues retryOptions = new OptionValues(initialOptions,
Dump, ":" + VERBOSE_LEVEL,
MethodFilter, null,
DumpPath, dumpPath.getPath());
! try (DebugContext retryDebug = createRetryDebugContext(retryOptions); DebugCloseable s = retryDebug.disableIntercept()) {
T res = performCompilation(retryDebug);
maybeExitVM(action);
return res;
! } catch (Throwable ignore) {
// Failures during retry are silent
T res = handleException(cause);
maybeExitVM(action);
return res;
}
}
}
}
--- 281,311 ----
OptionValues retryOptions = new OptionValues(initialOptions,
Dump, ":" + VERBOSE_LEVEL,
MethodFilter, null,
DumpPath, dumpPath.getPath());
! 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 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 >