use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ReplaceConstantNodesPhase method findFixedWithValidState.
/**
* Find first dominating {@link FixedWithNextNode} that has a valid state reaching it starting
* from the given node.
*
* @param graph
* @param stateMapper
* @param node
* @return {@link FixedWithNextNode} that we can use as an insertion point
*/
private static FixedWithNextNode findFixedWithValidState(StructuredGraph graph, FrameStateMapperClosure stateMapper, FixedWithNextNode node) {
ScheduleResult schedule = graph.getLastSchedule();
NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
Block block = nodeToBlock.get(node);
Node n = node;
do {
if (isFixedWithValidState(stateMapper, n)) {
return (FixedWithNextNode) n;
}
while (n != block.getBeginNode()) {
n = n.predecessor();
if (isFixedWithValidState(stateMapper, n)) {
return (FixedWithNextNode) n;
}
}
block = block.getDominator();
if (block != null) {
n = block.getEndNode();
}
} while (block != null);
return graph.start();
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ReplaceConstantNodesPhase method replaceWithResolution.
/**
* Replace the uses of a constant with either {@link LoadConstantIndirectlyNode} or
* {@link ResolveConstantNode}.
*
* @param graph
* @param stateMapper
* @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
* resolution.
*/
private static void replaceWithResolution(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) node.asConstant();
HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) metaspaceConstant.asResolvedJavaType();
ResolvedJavaType topMethodHolder = graph.method().getDeclaringClass();
ValueNode replacement;
if (type.isArray() && type.getComponentType().isPrimitive()) {
// Special case for primitive arrays. The AOT runtime pre-resolves them, so we may
// omit the resolution call.
replacement = graph.addOrUnique(new LoadConstantIndirectlyNode(node));
} else if (type.equals(topMethodHolder) || (type.isAssignableFrom(topMethodHolder) && !type.isInterface())) {
// If it's a supertype of or the same class that declares the top method, we are
// guaranteed to have it resolved already. If it's an interface, we just test for
// equality.
replacement = graph.addOrUnique(new LoadConstantIndirectlyNode(node));
} else {
FixedWithNextNode fixedReplacement;
if (builtIns.contains(type.mirror())) {
// Special case of klass constants that come from {@link BoxingSnippets}.
fixedReplacement = graph.add(new ResolveConstantNode(node, HotSpotConstantLoadAction.INITIALIZE));
} else {
fixedReplacement = graph.add(new ResolveConstantNode(node));
}
insertReplacement(graph, stateMapper, node, fixedReplacement);
replacement = fixedReplacement;
}
node.replaceAtUsages(replacement, n -> !isReplacementNode(n));
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ReplaceConstantNodesPhase method findInsertionPoint.
/**
* Find a good place to insert a stateful fixed node that is above the given node. A good
* insertion point should have a valid FrameState reaching it.
*
* @param graph
* @param stateMapper
* @param node start search from this node up
* @return an insertion point
*/
private static FixedWithNextNode findInsertionPoint(StructuredGraph graph, FrameStateMapperClosure stateMapper, FloatingNode node) {
FixedWithNextNode fixed = findFixedBeforeFloating(graph, node);
FixedWithNextNode result = findFixedWithValidState(graph, stateMapper, fixed);
return result;
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ReplaceConstantNodesPhase method findFixedBeforeFloating.
/**
* Find the first {@link FixedWithNextNode} that is currently scheduled before the given
* floating node.
*
* @param graph
* @param node start search from this node up
* @return the first {@link FixedWithNextNode}
*/
private static FixedWithNextNode findFixedBeforeFloating(StructuredGraph graph, FloatingNode node) {
ScheduleResult schedule = graph.getLastSchedule();
NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
Block block = nodeToBlock.get(node);
BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
FixedWithNextNode result = null;
for (Node n : blockToNodes.get(block)) {
if (n.equals(node)) {
break;
}
if (n instanceof FixedWithNextNode) {
result = (FixedWithNextNode) n;
}
}
assert result != null;
return result;
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class WriteBarrierVerificationPhase method validateWrite.
private void validateWrite(Node write) {
/*
* The currently validated write is checked in order to discover if it has an appropriate
* attached write barrier.
*/
if (hasAttachedBarrier((FixedWithNextNode) write)) {
return;
}
NodeFlood frontier = write.graph().createNodeFlood();
expandFrontier(frontier, write);
Iterator<Node> iterator = frontier.iterator();
while (iterator.hasNext()) {
Node currentNode = iterator.next();
if (isSafepoint(currentNode)) {
throw new AssertionError("Write barrier must be present " + write.toString(Verbosity.All) + " / " + write.inputs());
}
if (useG1GC()) {
if (!(currentNode instanceof G1PostWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode))) {
expandFrontier(frontier, currentNode);
}
} else {
if (!(currentNode instanceof SerialWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode)) || ((currentNode instanceof SerialWriteBarrier) && !validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode))) {
expandFrontier(frontier, currentNode);
}
}
}
}
Aggregations