use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class NodePosIteratorTest method testInputs.
@Test
public void testInputs() {
TestNode n = new TestNode();
ConstantNode i1 = ConstantNode.forInt(1);
ConstantNode i2 = ConstantNode.forDouble(1.0d);
ConstantNode i3 = ConstantNode.forInt(4);
ConstantNode i4 = ConstantNode.forInt(14);
n.itail = new NodeInputList<>(n, new ValueNode[] { i3, i4 });
n.i1 = i1;
n.i2 = i2;
NodeIterable<Node> inputs = n.inputs();
Iterator<Node> iterator = inputs.iterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i1);
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i2);
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i3);
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
Assert.assertFalse(iterator.hasNext());
Assert.assertFalse(iterator.hasNext());
Iterator<Position> positionIterator = n.inputPositions().iterator();
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("ConstantNode:i1", positionIterator.next().toString());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("FloatingNode:i2", positionIterator.next().toString());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("NodeInputList:itail[0]", positionIterator.next().toString());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("NodeInputList:itail[1]", positionIterator.next().toString());
Assert.assertFalse(positionIterator.hasNext());
Assert.assertFalse(positionIterator.hasNext());
iterator = inputs.iterator();
n.i1 = i4;
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
n.i2 = i1;
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i1);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i3);
n.itail.initialize(1, i4);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
Assert.assertFalse(iterator.hasNext());
iterator = inputs.iterator();
n.i1 = null;
n.i2 = i2;
n.itail.initialize(0, null);
n.itail.initialize(1, i4);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i2);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
Assert.assertFalse(iterator.hasNext());
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class StableArrayReadFoldingTest method parseForCompile.
@Override
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
StructuredGraph graph = super.parseForCompile(method, compilationId, options);
// Mimic @Stable array constants.
for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
ConstantNode newConstantNode = graph.unique(ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess()));
constantNode.replaceAndDelete(newConstantNode);
}
}
return graph;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class IfCanonicalizerTest method test.
private void test(String snippet) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
DebugContext debug = graph.getDebug();
ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
ConstantNode constant = ConstantNode.forInt(0, graph);
for (Node n : param.usages().snapshot()) {
if (!(n instanceof FrameState)) {
n.replaceFirstInput(param, constant);
}
}
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
fs.replaceFirstInput(param, null);
param.safeDelete();
}
StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
assertEquals(referenceGraph, graph);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class ClassCastBytecodeExceptionTest method registerInvocationPlugins.
@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
invocationPlugins.register(new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode obj, ValueNode classNode) {
ResolvedJavaType type = b.getConstantReflection().asJavaType(classNode.asConstant());
Constant hub = b.getConstantReflection().asObjectHub(type);
Stamp hubStamp = b.getStampProvider().createHubStamp(StampFactory.object(TypeReference.createExactTrusted(type)));
ConstantNode hubConst = b.add(ConstantNode.forConstant(hubStamp, hub, b.getMetaAccess()));
return throwBytecodeException(b, ClassCastException.class, obj, hubConst);
}
}, Exceptions.class, "throwClassCast", Object.class, Class.class);
super.registerInvocationPlugins(invocationPlugins);
}
use of org.graalvm.compiler.nodes.ConstantNode 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