# HG changeset patch # User Christian Wimmer # Date 1440627651 25200 # Node ID 8cf9fa4368def1dc5af49916e7a353f20895507e # Parent b543dd7f2e85f64c79c48f08506442cd3f4a1790 Add option DumpPath to specify directory for IGV and C1Visualizer dump files; simplify file name construction for IGV files diff -r b543dd7f2e85 -r 8cf9fa4368de graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/GraalOptions.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/GraalOptions.java Wed Aug 26 15:19:12 2015 -0700 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/GraalOptions.java Wed Aug 26 15:20:51 2015 -0700 @@ -138,10 +138,6 @@ @Option(help = "Perform platform dependent validation of the Java heap at returns", type = OptionType.Debug) public static final OptionValue VerifyHeapAtReturn = new OptionValue<>(false); - // Ideal graph visualizer output settings - @Option(help = "Dump IdealGraphVisualizer output in binary format", type = OptionType.Debug) - public static final OptionValue PrintBinaryGraphs = new OptionValue<>(true); - @Option(help = "Output probabilities for fixed nodes during binary graph dumping", type = OptionType.Debug) public static final OptionValue PrintGraphProbabilities = new OptionValue<>(false); @@ -154,9 +150,16 @@ @Option(help = "Enable dumping to the IdealGraphVisualizer.", type = OptionType.Debug) public static final OptionValue PrintIdealGraph = new OptionValue<>(true); - @Option(help = "", type = OptionType.Debug) + // Ideal graph visualizer output settings + @Option(help = "Dump IdealGraphVisualizer output in binary format", type = OptionType.Debug) + public static final OptionValue PrintBinaryGraphs = new OptionValue<>(true); + + @Option(help = "Print Ideal graphs as opposed to sending them over the network.", type = OptionType.Debug) public static final OptionValue PrintIdealGraphFile = new OptionValue<>(false); + @Option(help = "The directory into which to dump the Ideal graph files.") + public static final OptionValue DumpPath = new OptionValue<>(""); + @Option(help = "", type = OptionType.Debug) public static final OptionValue PrintIdealGraphAddress = new OptionValue<>("127.0.0.1"); diff -r b543dd7f2e85 -r 8cf9fa4368de graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed Aug 26 15:19:12 2015 -0700 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed Aug 26 15:20:51 2015 -0700 @@ -23,19 +23,20 @@ package com.oracle.graal.printer; import java.io.*; +import java.nio.file.*; import java.util.*; import java.util.concurrent.atomic.*; import jdk.internal.jvmci.code.*; import jdk.internal.jvmci.common.*; -import com.oracle.graal.debug.*; - import jdk.internal.jvmci.meta.*; import jdk.internal.jvmci.service.*; import com.oracle.graal.code.*; +import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.cfg.*; import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.java.*; import com.oracle.graal.lir.*; @@ -110,9 +111,6 @@ return true; } - private static final long timestamp = System.currentTimeMillis(); - private static final AtomicInteger uniqueId = new AtomicInteger(); - private static boolean isFrontendObject(Object object) { return object instanceof Graph || object instanceof BciBlockMapping; } @@ -127,7 +125,7 @@ } if (cfgPrinter == null) { - cfgFile = new File("compilations-" + timestamp + "_" + uniqueId.incrementAndGet() + ".cfg"); + cfgFile = getCFGPath().toFile(); try { OutputStream out = new BufferedOutputStream(new FileOutputStream(cfgFile)); cfgPrinter = new CFGPrinter(out); @@ -224,6 +222,16 @@ return object instanceof List && ((List) object).size() > 0 && ((List) object).get(0) instanceof AbstractBlockBase; } + private static long timestamp; + private static final AtomicInteger uniqueId = new AtomicInteger(); + + private static Path getCFGPath() { + if (timestamp == 0) { + timestamp = System.currentTimeMillis(); + } + return Paths.get(GraalOptions.DumpPath.getValue(), "compilations-" + timestamp + "_" + uniqueId.incrementAndGet() + ".cfg"); + } + /** Lazy initialization to delay service lookup until disassembler is actually needed. */ static class DisassemblerHolder { private static final DisassemblerProvider disassembler; diff -r b543dd7f2e85 -r 8cf9fa4368de graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java Wed Aug 26 15:19:12 2015 -0700 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java Wed Aug 26 15:20:51 2015 -0700 @@ -29,8 +29,8 @@ import java.net.*; import java.nio.channels.*; import java.nio.file.*; -import java.text.*; import java.util.*; +import java.util.concurrent.atomic.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.*; @@ -87,48 +87,37 @@ return dumpIds[depth - 1]++; } - // This field must be lazily initialized as this class may be loaded in a version - // VM startup phase at which not all required features (such as system properties) - // are online. - private static volatile SimpleDateFormat sdf; - private void initializeFilePrinter() { - String ext; - if (PrintBinaryGraphs.getValue()) { - ext = ".bgv"; - } else { - ext = ".gv.xml"; - } - if (sdf == null) { - sdf = new SimpleDateFormat("YYYY-MM-dd-HHmm"); - } - - // DateFormats are inherently unsafe for multi-threaded use. Use a synchronized block. - String prefix; - synchronized (sdf) { - prefix = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()); - } - - String num = ""; - File file; - int i = 0; - while ((file = new File(prefix + num + ext)).exists()) { - num = "-" + Integer.toString(++i); - } + Path path = getFilePrinterPath(); try { if (PrintBinaryGraphs.getValue()) { - printer = new BinaryGraphPrinter(FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)); + printer = new BinaryGraphPrinter(FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)); } else { - printer = new IdealGraphPrinter(new FileOutputStream(file), true); + printer = new IdealGraphPrinter(Files.newOutputStream(path), true); } - TTY.println("Dumping IGV graphs to %s", file.getName()); + TTY.println("Dumping IGV graphs to %s", path.toString()); } catch (IOException e) { - TTY.println("Failed to open %s to dump IGV graphs : %s", file.getName(), e); + TTY.println("Failed to open %s to dump IGV graphs : %s", path.toString(), e); failuresCount++; printer = null; } } + private static long dumpIgvTimestamp; + private static final AtomicInteger dumpIgvId = new AtomicInteger(); + + private static Path getFilePrinterPath() { + // If this is the first time I have constructed a FilePrinterPath, + // get a time stamp in a (weak) attempt to make unique file names. + if (dumpIgvTimestamp == 0) { + dumpIgvTimestamp = System.currentTimeMillis(); + } + // Encode the kind of the file in the extension. + final String ext = (PrintBinaryGraphs.getValue() ? ".bgv" : ".gv.xml"); + // Construct the path to the file. + return Paths.get(DumpPath.getValue(), "runtime-graphs-" + dumpIgvTimestamp + "_" + dumpIgvId.incrementAndGet() + ext); + } + private void initializeNetworkPrinter() { String host = PrintIdealGraphAddress.getValue(); int port = PrintBinaryGraphs.getValue() ? PrintBinaryGraphPort.getValue() : PrintIdealGraphPort.getValue();