use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class DebugInfoBuilder method toJavaValue.
protected JavaValue toJavaValue(ValueNode value) {
try {
if (value instanceof VirtualObjectNode) {
VirtualObjectNode obj = (VirtualObjectNode) value;
EscapeObjectState state = objectStates.get(obj);
if (state == null && obj.entryCount() > 0) {
// null states occur for objects with 0 fields
throw new GraalError("no mapping found for virtual object %s", obj);
}
if (state instanceof MaterializedObjectState) {
return toJavaValue(((MaterializedObjectState) state).materializedValue());
} else {
assert obj.entryCount() == 0 || state instanceof VirtualObjectState;
VirtualObject vobject = virtualObjects.get(obj);
if (vobject == null) {
vobject = VirtualObject.get(obj.type(), virtualObjects.size());
virtualObjects.put(obj, vobject);
pendingVirtualObjects.add(obj);
}
STATE_VIRTUAL_OBJECTS.increment(debug);
return vobject;
}
} else {
// Remove proxies from constants so the constant can be directly embedded.
ValueNode unproxied = GraphUtil.unproxify(value);
if (unproxied instanceof ConstantNode) {
STATE_CONSTANTS.increment(debug);
return unproxied.asJavaConstant();
} else if (value != null) {
STATE_VARIABLES.increment(debug);
Value operand = nodeValueMap.operand(value);
if (operand instanceof ConstantValue && ((ConstantValue) operand).isJavaConstant()) {
return ((ConstantValue) operand).getJavaConstant();
} else {
assert operand instanceof Variable : operand + " for " + value;
return (JavaValue) operand;
}
} else {
// return a dummy value because real value not needed
STATE_ILLEGALS.increment(debug);
return Value.ILLEGAL;
}
}
} catch (GraalError e) {
throw e.addContext("toValue: ", value);
}
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class CFGPrinterObserver method dumpSandboxed.
public void dumpSandboxed(DebugContext debug, Object object, String message) {
OptionValues options = debug.getOptions();
boolean dumpFrontend = PrintCFG.getValue(options);
if (!dumpFrontend && isFrontendObject(object)) {
return;
}
if (cfgPrinter == null) {
try {
Path dumpFile = debug.getDumpPath(".cfg", false);
cfgFile = dumpFile.toFile();
OutputStream out = new BufferedOutputStream(new FileOutputStream(cfgFile));
cfgPrinter = new CFGPrinter(out);
} catch (IOException e) {
throw (GraalError) new GraalError("Could not open %s", cfgFile == null ? "[null]" : cfgFile.getAbsolutePath()).initCause(e);
}
}
if (!checkMethodScope(debug)) {
return;
}
try {
if (curMethod instanceof ResolvedJavaMethod) {
cfgPrinter.method = (ResolvedJavaMethod) curMethod;
}
if (object instanceof LIR) {
cfgPrinter.lir = (LIR) object;
} else {
cfgPrinter.lir = debug.contextLookup(LIR.class);
}
cfgPrinter.nodeLirGenerator = debug.contextLookup(NodeLIRBuilder.class);
cfgPrinter.livenessInfo = debug.contextLookup(GlobalLivenessInfo.class);
cfgPrinter.res = debug.contextLookup(LIRGenerationResult.class);
if (cfgPrinter.nodeLirGenerator != null) {
cfgPrinter.target = cfgPrinter.nodeLirGenerator.getLIRGeneratorTool().target();
}
if (cfgPrinter.lir != null && cfgPrinter.lir.getControlFlowGraph() instanceof ControlFlowGraph) {
cfgPrinter.cfg = (ControlFlowGraph) cfgPrinter.lir.getControlFlowGraph();
}
CodeCacheProvider codeCache = debug.contextLookup(CodeCacheProvider.class);
if (codeCache != null) {
cfgPrinter.target = codeCache.getTarget();
}
if (object instanceof BciBlockMapping) {
BciBlockMapping blockMap = (BciBlockMapping) object;
cfgPrinter.printCFG(message, blockMap);
if (blockMap.code.getCode() != null) {
cfgPrinter.printBytecodes(new BytecodeDisassembler(false).disassemble(blockMap.code));
}
} else if (object instanceof LIR) {
// Currently no node printing for lir
cfgPrinter.printCFG(message, cfgPrinter.lir.codeEmittingOrder(), false);
lastLIR = (LIR) object;
if (delayedIntervals != null) {
cfgPrinter.printIntervals(message, delayedIntervals);
delayedIntervals = null;
}
} else if (object instanceof ScheduleResult) {
cfgPrinter.printSchedule(message, (ScheduleResult) object);
} else if (object instanceof StructuredGraph) {
if (cfgPrinter.cfg == null) {
StructuredGraph graph = (StructuredGraph) object;
cfgPrinter.cfg = ControlFlowGraph.compute(graph, true, true, true, false);
cfgPrinter.printCFG(message, cfgPrinter.cfg.getBlocks(), true);
} else {
cfgPrinter.printCFG(message, cfgPrinter.cfg.getBlocks(), true);
}
} else if (object instanceof CompilationResult) {
final CompilationResult compResult = (CompilationResult) object;
cfgPrinter.printMachineCode(disassemble(codeCache, compResult, null), message);
} else if (object instanceof InstalledCode) {
CompilationResult compResult = debug.contextLookup(CompilationResult.class);
if (compResult != null) {
cfgPrinter.printMachineCode(disassemble(codeCache, compResult, (InstalledCode) object), message);
}
} else if (object instanceof IntervalDumper) {
if (lastLIR == cfgPrinter.lir) {
cfgPrinter.printIntervals(message, (IntervalDumper) object);
} else {
if (delayedIntervals != null) {
debug.log("Some delayed intervals were dropped (%s)", delayedIntervals);
}
delayedIntervals = (IntervalDumper) object;
}
} else if (object instanceof AbstractBlockBase<?>[]) {
cfgPrinter.printCFG(message, (AbstractBlockBase<?>[]) object, false);
} else if (object instanceof Trace) {
cfgPrinter.printCFG(message, ((Trace) object).getBlocks(), false);
} else if (object instanceof TraceBuilderResult) {
cfgPrinter.printTraces(message, (TraceBuilderResult) object);
}
} finally {
cfgPrinter.target = null;
cfgPrinter.lir = null;
cfgPrinter.res = null;
cfgPrinter.nodeLirGenerator = null;
cfgPrinter.livenessInfo = null;
cfgPrinter.cfg = null;
cfgPrinter.flush();
}
}
Aggregations