use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class ObjectCloneNode method getLoweredSnippetGraph.
@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
ResolvedJavaType type = StampTool.typeOrNull(getObject());
if (type != null) {
if (type.isArray()) {
Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
if (method != null) {
final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
final Replacements replacements = tool.getReplacements();
StructuredGraph snippetGraph = null;
DebugContext debug = getDebug();
try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
} catch (Throwable e) {
throw debug.handle(e);
}
assert snippetGraph != null : "ObjectCloneSnippets should be installed";
assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
}
assert false : "unhandled array type " + type.getComponentType().getJavaKind();
} else {
Assumptions assumptions = graph().getAssumptions();
type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
if (type != null) {
StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
newGraph.addAfterFixed(newGraph.start(), newInstance);
ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
newGraph.addAfterFixed(newInstance, returnNode);
for (ResolvedJavaField field : type.getInstanceFields(true)) {
LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
newGraph.addBeforeFixed(returnNode, load);
newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
}
assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
return lowerReplacement(newGraph, tool);
}
}
}
assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
return null;
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class BasicObjectCloneNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode originalAlias = tool.getAlias(getObject());
if (originalAlias instanceof VirtualObjectNode) {
VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias;
if (originalVirtual.type().isCloneableWithAllocation()) {
ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()];
for (int i = 0; i < newEntryState.length; i++) {
newEntryState[i] = tool.getEntry(originalVirtual, i);
}
VirtualObjectNode newVirtual = originalVirtual.duplicate();
tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(newVirtual);
}
} else {
ResolvedJavaType type = getConcreteType(originalAlias.stamp(NodeView.DEFAULT));
if (type != null && !type.isArray()) {
VirtualInstanceNode newVirtual = createVirtualInstanceNode(type, true);
ResolvedJavaField[] fields = newVirtual.getFields();
ValueNode[] state = new ValueNode[fields.length];
final LoadFieldNode[] loads = new LoadFieldNode[fields.length];
for (int i = 0; i < fields.length; i++) {
state[i] = loads[i] = genLoadFieldNode(graph().getAssumptions(), originalAlias, fields[i]);
tool.addNode(loads[i]);
}
tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(newVirtual);
}
}
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class SimplifyingGraphDecoder method canonicalizeFixedNode.
/**
* Canonicalizes the provided node, which was originally a {@link FixedNode} but can already be
* canonicalized (and therefore be a non-fixed node).
*
* @param methodScope The current method.
* @param node The node to be canonicalized.
*/
protected Node canonicalizeFixedNode(MethodScope methodScope, Node node) {
if (node instanceof LoadFieldNode) {
LoadFieldNode loadFieldNode = (LoadFieldNode) node;
return loadFieldNode.canonical(canonicalizerTool);
} else if (node instanceof FixedGuardNode) {
FixedGuardNode guard = (FixedGuardNode) node;
if (guard.getCondition() instanceof LogicConstantNode) {
LogicConstantNode condition = (LogicConstantNode) guard.getCondition();
if (condition.getValue() == guard.isNegated()) {
DeoptimizeNode deopt = new DeoptimizeNode(guard.getAction(), guard.getReason(), guard.getSpeculation());
if (guard.stateBefore() != null) {
deopt.setStateBefore(guard.stateBefore());
}
return deopt;
} else {
return null;
}
}
return node;
} else if (node instanceof IfNode) {
IfNode ifNode = (IfNode) node;
if (ifNode.condition() instanceof LogicNegationNode) {
ifNode.eliminateNegation();
}
if (ifNode.condition() instanceof LogicConstantNode) {
boolean condition = ((LogicConstantNode) ifNode.condition()).getValue();
AbstractBeginNode survivingSuccessor = ifNode.getSuccessor(condition);
AbstractBeginNode deadSuccessor = ifNode.getSuccessor(!condition);
graph.removeSplit(ifNode, survivingSuccessor);
assert deadSuccessor.next() == null : "must not be parsed yet";
deadSuccessor.safeDelete();
}
return node;
} else if (node instanceof LoadIndexedNode) {
LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
return loadIndexedNode.canonical(canonicalizerTool);
} else if (node instanceof ArrayLengthNode) {
ArrayLengthNode arrayLengthNode = (ArrayLengthNode) node;
return arrayLengthNode.canonical(canonicalizerTool);
} else if (node instanceof IntegerSwitchNode && ((IntegerSwitchNode) node).value().isConstant()) {
IntegerSwitchNode switchNode = (IntegerSwitchNode) node;
int value = switchNode.value().asJavaConstant().asInt();
AbstractBeginNode survivingSuccessor = switchNode.successorAtKey(value);
List<Node> allSuccessors = switchNode.successors().snapshot();
graph.removeSplit(switchNode, survivingSuccessor);
for (Node successor : allSuccessors) {
if (successor != survivingSuccessor) {
assert ((AbstractBeginNode) successor).next() == null : "must not be parsed yet";
successor.safeDelete();
}
}
return node;
} else if (node instanceof Canonicalizable) {
return ((Canonicalizable) node).canonical(canonicalizerTool);
} else {
return node;
}
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class MethodTypeFlowBuilder method registerUsedElements.
public static void registerUsedElements(BigBang bb, StructuredGraph graph, MethodTypeFlow methodFlow) {
for (Node n : graph.getNodes()) {
if (n instanceof InstanceOfNode) {
InstanceOfNode node = (InstanceOfNode) n;
AnalysisType type = (AnalysisType) node.type().getType();
type.registerAsInTypeCheck();
} else if (n instanceof NewInstanceNode) {
NewInstanceNode node = (NewInstanceNode) n;
AnalysisType type = (AnalysisType) node.instanceClass();
type.registerAsAllocated(node);
} else if (n instanceof NewArrayNode) {
NewArrayNode node = (NewArrayNode) n;
AnalysisType type = ((AnalysisType) node.elementType()).getArrayClass();
type.registerAsAllocated(node);
} else if (n instanceof NewMultiArrayNode) {
NewMultiArrayNode node = (NewMultiArrayNode) n;
AnalysisType type = ((AnalysisType) node.type());
for (int i = 0; i < node.dimensionCount(); i++) {
type.registerAsAllocated(node);
type = type.getComponentType();
}
} else if (n instanceof BoxNode) {
BoxNode node = (BoxNode) n;
AnalysisType type = (AnalysisType) StampTool.typeOrNull(node);
type.registerAsAllocated(node);
} else if (n instanceof LoadFieldNode) {
LoadFieldNode node = (LoadFieldNode) n;
AnalysisField field = (AnalysisField) node.field();
field.registerAsRead(methodFlow);
} else if (n instanceof StoreFieldNode) {
StoreFieldNode node = (StoreFieldNode) n;
AnalysisField field = (AnalysisField) node.field();
field.registerAsWritten(methodFlow);
} else if (n instanceof StoreIndexedNode) {
StoreIndexedNode node = (StoreIndexedNode) n;
AnalysisType arrayType = (AnalysisType) StampTool.typeOrNull(node.array());
if (arrayType != null) {
assert arrayType.isArray();
arrayType.getComponentType().registerAsInTypeCheck();
}
} else if (n instanceof BytecodeExceptionNode) {
BytecodeExceptionNode node = (BytecodeExceptionNode) n;
AnalysisType type = bb.getMetaAccess().lookupJavaType(node.getExceptionClass());
type.registerAsInHeap();
} else if (n instanceof ConstantNode) {
ConstantNode cn = (ConstantNode) n;
if (cn.hasUsages() && cn.asJavaConstant().getJavaKind() == JavaKind.Object && cn.asJavaConstant().isNonNull()) {
assert StampTool.isExactType(cn);
AnalysisType type = (AnalysisType) StampTool.typeOrNull(cn);
type.registerAsInHeap();
}
} else if (n instanceof ForeignCallNode) {
ForeignCallNode node = (ForeignCallNode) n;
registerForeignCall(bb, node.getDescriptor());
} else if (n instanceof UnaryMathIntrinsicNode) {
UnaryMathIntrinsicNode node = (UnaryMathIntrinsicNode) n;
registerForeignCall(bb, node.getOperation().foreignCallDescriptor);
} else if (n instanceof BinaryMathIntrinsicNode) {
BinaryMathIntrinsicNode node = (BinaryMathIntrinsicNode) n;
registerForeignCall(bb, node.getOperation().foreignCallDescriptor);
}
}
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class UnsafeEATest method testMergedDouble.
@Test
public void testMergedDouble() {
testEscapeAnalysis("testMergedDoubleSnippet", null, false);
Assert.assertEquals(1, returnNodes.size());
Assert.assertTrue(returnNodes.get(0).result() instanceof ValuePhiNode);
PhiNode phi = (PhiNode) returnNodes.get(0).result();
Assert.assertTrue(phi.valueAt(0) instanceof LoadFieldNode);
Assert.assertTrue(phi.valueAt(1) instanceof LoadFieldNode);
}
Aggregations