6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.printer;
24
25 import static org.graalvm.compiler.debug.DebugOptions.PrintCFG;
26 import static org.graalvm.compiler.printer.GraalDebugHandlersFactory.createDumpPath;
27
28 import java.io.BufferedOutputStream;
29 import java.io.File;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
36
37 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
38 import org.graalvm.compiler.code.CompilationResult;
39 import org.graalvm.compiler.code.DisassemblerProvider;
40 import org.graalvm.compiler.core.common.CompilationIdentifier;
41 import org.graalvm.compiler.core.common.alloc.Trace;
42 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
43 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
44 import org.graalvm.compiler.core.gen.NodeLIRBuilder;
45 import org.graalvm.compiler.debug.DebugContext;
46 import org.graalvm.compiler.debug.DebugDumpHandler;
47 import org.graalvm.compiler.debug.DebugDumpScope;
48 import org.graalvm.compiler.debug.GraalError;
49 import org.graalvm.compiler.debug.TTY;
50 import org.graalvm.compiler.graph.Graph;
51 import org.graalvm.compiler.java.BciBlockMapping;
52 import org.graalvm.compiler.lir.LIR;
136 curDecorators = decorators;
137 return true;
138 }
139
140 private static boolean isFrontendObject(Object object) {
141 return object instanceof Graph || object instanceof BciBlockMapping;
142 }
143
144 private LIR lastLIR = null;
145 private IntervalDumper delayedIntervals = null;
146
147 public void dumpSandboxed(DebugContext debug, Object object, String message) {
148 OptionValues options = debug.getOptions();
149 boolean dumpFrontend = PrintCFG.getValue(options);
150 if (!dumpFrontend && isFrontendObject(object)) {
151 return;
152 }
153
154 if (cfgPrinter == null) {
155 try {
156 Graph graph = debug.contextLookupTopdown(Graph.class);
157 cfgFile = createDumpPath(options, graph, "cfg", false).toFile();
158 OutputStream out = new BufferedOutputStream(new FileOutputStream(cfgFile));
159 cfgPrinter = new CFGPrinter(out);
160 } catch (IOException e) {
161 throw (GraalError) new GraalError("Could not open %s", cfgFile == null ? "[null]" : cfgFile.getAbsolutePath()).initCause(e);
162 }
163 }
164
165 if (!checkMethodScope(debug)) {
166 return;
167 }
168 try {
169 if (curMethod instanceof ResolvedJavaMethod) {
170 cfgPrinter.method = (ResolvedJavaMethod) curMethod;
171 }
172
173 if (object instanceof LIR) {
174 cfgPrinter.lir = (LIR) object;
175 } else {
176 cfgPrinter.lir = debug.contextLookup(LIR.class);
177 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.printer;
24
25 import static org.graalvm.compiler.debug.DebugOptions.PrintCFG;
26
27 import java.io.BufferedOutputStream;
28 import java.io.File;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.OutputStream;
32 import java.nio.file.Path;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
36
37 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
38 import org.graalvm.compiler.code.CompilationResult;
39 import org.graalvm.compiler.code.DisassemblerProvider;
40 import org.graalvm.compiler.core.common.CompilationIdentifier;
41 import org.graalvm.compiler.core.common.alloc.Trace;
42 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
43 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
44 import org.graalvm.compiler.core.gen.NodeLIRBuilder;
45 import org.graalvm.compiler.debug.DebugContext;
46 import org.graalvm.compiler.debug.DebugDumpHandler;
47 import org.graalvm.compiler.debug.DebugDumpScope;
48 import org.graalvm.compiler.debug.GraalError;
49 import org.graalvm.compiler.debug.TTY;
50 import org.graalvm.compiler.graph.Graph;
51 import org.graalvm.compiler.java.BciBlockMapping;
52 import org.graalvm.compiler.lir.LIR;
136 curDecorators = decorators;
137 return true;
138 }
139
140 private static boolean isFrontendObject(Object object) {
141 return object instanceof Graph || object instanceof BciBlockMapping;
142 }
143
144 private LIR lastLIR = null;
145 private IntervalDumper delayedIntervals = null;
146
147 public void dumpSandboxed(DebugContext debug, Object object, String message) {
148 OptionValues options = debug.getOptions();
149 boolean dumpFrontend = PrintCFG.getValue(options);
150 if (!dumpFrontend && isFrontendObject(object)) {
151 return;
152 }
153
154 if (cfgPrinter == null) {
155 try {
156 Path dumpFile = debug.getDumpPath(".cfg", false);
157 cfgFile = dumpFile.toFile();
158 OutputStream out = new BufferedOutputStream(new FileOutputStream(cfgFile));
159 cfgPrinter = new CFGPrinter(out);
160 } catch (IOException e) {
161 throw (GraalError) new GraalError("Could not open %s", cfgFile == null ? "[null]" : cfgFile.getAbsolutePath()).initCause(e);
162 }
163 }
164
165 if (!checkMethodScope(debug)) {
166 return;
167 }
168 try {
169 if (curMethod instanceof ResolvedJavaMethod) {
170 cfgPrinter.method = (ResolvedJavaMethod) curMethod;
171 }
172
173 if (object instanceof LIR) {
174 cfgPrinter.lir = (LIR) object;
175 } else {
176 cfgPrinter.lir = debug.contextLookup(LIR.class);
177 }
|