31 import java.io.File;
32 import java.io.IOException;
33 import java.io.InterruptedIOException;
34 import java.net.InetSocketAddress;
35 import java.net.Socket;
36 import java.nio.channels.ClosedByInterruptException;
37 import java.nio.channels.FileChannel;
38 import java.nio.channels.SocketChannel;
39 import java.nio.file.FileAlreadyExistsException;
40 import java.nio.file.Files;
41 import java.nio.file.InvalidPathException;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.nio.file.StandardOpenOption;
45 import java.util.ArrayList;
46 import java.util.List;
47 import java.util.concurrent.atomic.AtomicInteger;
48
49 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
50 import org.graalvm.compiler.core.common.CompilationIdentifier;
51 import org.graalvm.compiler.debug.DebugContext;
52 import org.graalvm.compiler.debug.DebugDumpHandler;
53 import org.graalvm.compiler.debug.DebugHandler;
54 import org.graalvm.compiler.debug.DebugHandlersFactory;
55 import org.graalvm.compiler.debug.DebugOptions;
56 import org.graalvm.compiler.debug.TTY;
57 import org.graalvm.compiler.debug.PathUtilities;
58 import org.graalvm.compiler.graph.Graph;
59 import org.graalvm.compiler.graph.Node;
60 import org.graalvm.compiler.nodeinfo.Verbosity;
61 import org.graalvm.compiler.nodes.StructuredGraph;
62 import org.graalvm.compiler.nodes.util.GraphUtil;
63 import org.graalvm.compiler.options.OptionValues;
64 import org.graalvm.compiler.serviceprovider.ServiceProvider;
65
66 @ServiceProvider(DebugHandlersFactory.class)
67 public class GraalDebugHandlersFactory implements DebugHandlersFactory {
68
69 private final SnippetReflectionProvider snippetReflection;
70
186 */
187 static Path createDumpPath(OptionValues options, Graph graph, String extension, boolean createDirectory) throws IOException {
188 CompilationIdentifier compilationId = CompilationIdentifier.INVALID_COMPILATION_ID;
189 String id = null;
190 String label = null;
191 if (graph instanceof StructuredGraph) {
192 StructuredGraph sgraph = (StructuredGraph) graph;
193 label = getGraphName(sgraph);
194 compilationId = sgraph.compilationId();
195 if (compilationId == CompilationIdentifier.INVALID_COMPILATION_ID) {
196 id = graph.getClass().getSimpleName() + "-" + sgraph.graphId();
197 } else {
198 id = compilationId.toString(CompilationIdentifier.Verbosity.ID);
199 }
200 } else {
201 label = graph == null ? null : graph.name != null ? graph.name : graph.toString();
202 id = "UnknownCompilation-" + unknownCompilationId.incrementAndGet();
203 }
204 String ext = PathUtilities.formatExtension(extension);
205 Path result = createUnique(DebugOptions.getDumpDirectory(options), id, label, ext, createDirectory);
206 if (ShowDumpFiles.getValue(options)) {
207 TTY.println("Dumping debug output to %s", result.toAbsolutePath().toString());
208 }
209 return result;
210 }
211
212 /**
213 * A maximum file name length supported by most file systems. There is no platform independent
214 * way to get this in Java.
215 */
216 private static final int MAX_FILE_NAME_LENGTH = 255;
217
218 private static final String ELLIPSIS = "...";
219
220 private static Path createUnique(Path dumpDir, String id, String label, String ext, boolean createDirectory) throws IOException {
221 String timestamp = "";
222 for (;;) {
223 int fileNameLengthWithoutLabel = timestamp.length() + ext.length() + id.length() + "[]".length();
224 int labelLengthLimit = MAX_FILE_NAME_LENGTH - fileNameLengthWithoutLabel;
225 String fileName;
226 if (labelLengthLimit < ELLIPSIS.length()) {
|
31 import java.io.File;
32 import java.io.IOException;
33 import java.io.InterruptedIOException;
34 import java.net.InetSocketAddress;
35 import java.net.Socket;
36 import java.nio.channels.ClosedByInterruptException;
37 import java.nio.channels.FileChannel;
38 import java.nio.channels.SocketChannel;
39 import java.nio.file.FileAlreadyExistsException;
40 import java.nio.file.Files;
41 import java.nio.file.InvalidPathException;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.nio.file.StandardOpenOption;
45 import java.util.ArrayList;
46 import java.util.List;
47 import java.util.concurrent.atomic.AtomicInteger;
48
49 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
50 import org.graalvm.compiler.core.common.CompilationIdentifier;
51 import org.graalvm.compiler.debug.Assertions;
52 import org.graalvm.compiler.debug.DebugContext;
53 import org.graalvm.compiler.debug.DebugDumpHandler;
54 import org.graalvm.compiler.debug.DebugHandler;
55 import org.graalvm.compiler.debug.DebugHandlersFactory;
56 import org.graalvm.compiler.debug.DebugOptions;
57 import org.graalvm.compiler.debug.TTY;
58 import org.graalvm.compiler.debug.PathUtilities;
59 import org.graalvm.compiler.graph.Graph;
60 import org.graalvm.compiler.graph.Node;
61 import org.graalvm.compiler.nodeinfo.Verbosity;
62 import org.graalvm.compiler.nodes.StructuredGraph;
63 import org.graalvm.compiler.nodes.util.GraphUtil;
64 import org.graalvm.compiler.options.OptionValues;
65 import org.graalvm.compiler.serviceprovider.ServiceProvider;
66
67 @ServiceProvider(DebugHandlersFactory.class)
68 public class GraalDebugHandlersFactory implements DebugHandlersFactory {
69
70 private final SnippetReflectionProvider snippetReflection;
71
187 */
188 static Path createDumpPath(OptionValues options, Graph graph, String extension, boolean createDirectory) throws IOException {
189 CompilationIdentifier compilationId = CompilationIdentifier.INVALID_COMPILATION_ID;
190 String id = null;
191 String label = null;
192 if (graph instanceof StructuredGraph) {
193 StructuredGraph sgraph = (StructuredGraph) graph;
194 label = getGraphName(sgraph);
195 compilationId = sgraph.compilationId();
196 if (compilationId == CompilationIdentifier.INVALID_COMPILATION_ID) {
197 id = graph.getClass().getSimpleName() + "-" + sgraph.graphId();
198 } else {
199 id = compilationId.toString(CompilationIdentifier.Verbosity.ID);
200 }
201 } else {
202 label = graph == null ? null : graph.name != null ? graph.name : graph.toString();
203 id = "UnknownCompilation-" + unknownCompilationId.incrementAndGet();
204 }
205 String ext = PathUtilities.formatExtension(extension);
206 Path result = createUnique(DebugOptions.getDumpDirectory(options), id, label, ext, createDirectory);
207 if (ShowDumpFiles.getValue(options) || Assertions.assertionsEnabled()) {
208 TTY.println("Dumping debug output to %s", result.toAbsolutePath().toString());
209 }
210 return result;
211 }
212
213 /**
214 * A maximum file name length supported by most file systems. There is no platform independent
215 * way to get this in Java.
216 */
217 private static final int MAX_FILE_NAME_LENGTH = 255;
218
219 private static final String ELLIPSIS = "...";
220
221 private static Path createUnique(Path dumpDir, String id, String label, String ext, boolean createDirectory) throws IOException {
222 String timestamp = "";
223 for (;;) {
224 int fileNameLengthWithoutLabel = timestamp.length() + ext.length() + id.length() + "[]".length();
225 int labelLengthLimit = MAX_FILE_NAME_LENGTH - fileNameLengthWithoutLabel;
226 String fileName;
227 if (labelLengthLimit < ELLIPSIS.length()) {
|