use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class GraalCompilerTest method getCanonicalGraphString.
protected static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.EARLIEST);
schedule.apply(graph);
ScheduleResult scheduleResult = graph.getLastSchedule();
NodeMap<Integer> canonicalId = graph.createNodeMap();
int nextId = 0;
List<String> constantsLines = new ArrayList<>();
StringBuilder result = new StringBuilder();
for (Block block : scheduleResult.getCFG().getBlocks()) {
result.append("Block ").append(block).append(' ');
if (block == scheduleResult.getCFG().getStartBlock()) {
result.append("* ");
}
result.append("-> ");
for (Block succ : block.getSuccessors()) {
result.append(succ).append(' ');
}
result.append('\n');
for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
if (node instanceof ValueNode && node.isAlive()) {
if (!excludeVirtual || !(node instanceof VirtualObjectNode || node instanceof ProxyNode || node instanceof FullInfopointNode || node instanceof ParameterNode)) {
if (node instanceof ConstantNode) {
String name = checkConstants ? node.toString(Verbosity.Name) : node.getClass().getSimpleName();
if (excludeVirtual) {
constantsLines.add(name);
} else {
constantsLines.add(name + " (" + filteredUsageCount(node) + ")");
}
} else {
int id;
if (canonicalId.get(node) != null) {
id = canonicalId.get(node);
} else {
id = nextId++;
canonicalId.set(node, id);
}
String name = node.getClass().getSimpleName();
result.append(" ").append(id).append('|').append(name);
if (node instanceof AccessFieldNode) {
result.append('#');
result.append(((AccessFieldNode) node).field());
}
if (!excludeVirtual) {
result.append(" (");
result.append(filteredUsageCount(node));
result.append(')');
}
result.append('\n');
}
}
}
}
}
StringBuilder constantsLinesResult = new StringBuilder();
constantsLinesResult.append(constantsLines.size()).append(" constants:\n");
Collections.sort(constantsLines);
for (String s : constantsLines) {
constantsLinesResult.append(s);
constantsLinesResult.append('\n');
}
return constantsLinesResult.toString() + result.toString();
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode 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);
}
}
Aggregations