use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class RuntimeStrengthenStampsPhase method registerDeoptEntries.
private static void registerDeoptEntries(CallTreeNode node) {
for (FrameState frameState : node.graph.getNodes(FrameState.TYPE)) {
if (node.level > 0 && frameState.usages().count() == 1 && frameState.usages().first() == node.graph.start()) {
/*
* During method inlining, the FrameState associated with the StartNode disappears.
* Therefore, this frame state cannot be a deoptimization target.
*/
continue;
}
/*
* We need to make sure that all inlined caller frames are available for deoptimization
* too.
*/
for (FrameState inlineState = frameState; inlineState != null; inlineState = inlineState.outerFrameState()) {
if (inlineState.bci >= 0) {
CompilationInfoSupport.singleton().registerDeoptEntry(inlineState.getMethod(), inlineState.bci, inlineState.duringCall(), inlineState.rethrowException());
}
}
}
for (Node n : node.graph.getNodes()) {
/*
* graph.getInvokes() only iterates invokes that have a MethodCallTarget, so by using it
* we would miss invocations that are already intrinsified to an indirect call.
*/
if (n instanceof Invoke) {
Invoke invoke = (Invoke) n;
/*
* The FrameState for the invoke (which is visited by the above loop) is the state
* after the call (where deoptimization that happens after the call has returned
* will continue execution). We also need to register the state during the call
* (where deoptimization while the call is on the stack will continue execution).
*
* Note that the bci of the Invoke and the bci of the FrameState of the Invoke are
* different: the Invoke has the bci of the invocation bytecode, the FrameState has
* the bci of the next bytecode after the invoke.
*/
CompilationInfoSupport.singleton().registerDeoptEntry(invoke.stateAfter().getMethod(), invoke.bci(), true, false);
}
}
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class MonitorGraphTest method parseAndProcess.
private StructuredGraph parseAndProcess(String snippet) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
ParameterNode param = graph.getNodes(ParameterNode.TYPE).first();
if (param != null) {
ConstantNode constant = ConstantNode.forInt(0, graph);
for (Node n : param.usages().snapshot()) {
if (!(n instanceof FrameState)) {
n.replaceFirstInput(param, constant);
}
}
}
Map<Invoke, Double> hints = new HashMap<>();
for (Invoke invoke : graph.getInvokes()) {
hints.put(invoke, 1000d);
}
HighTierContext context = getDefaultHighTierContext();
new InliningPhase(hints, new CanonicalizerPhase()).apply(graph, context);
new CanonicalizerPhase().apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
return graph;
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class PushThroughIfTest method test.
private void test(String snippet, String reference) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
DebugContext debug = graph.getDebug();
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
fs.replaceAtUsages(null);
GraphUtil.killWithUnusedFloatingInputs(fs);
}
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
for (FrameState fs : referenceGraph.getNodes(FrameState.TYPE).snapshot()) {
fs.replaceAtUsages(null);
GraphUtil.killWithUnusedFloatingInputs(fs);
}
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
assertEquals(referenceGraph, graph);
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class CEntryPointCallStubMethod method adaptParameterTypes.
private EnumInfo[] adaptParameterTypes(HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, JavaType[] parameterTypes, JavaType[] parameterLoadTypes, Purpose purpose) {
EnumInfo[] parameterEnumInfos = null;
for (int i = 0; i < parameterTypes.length; i++) {
if (!parameterTypes[i].getJavaKind().isPrimitive() && !providers.getWordTypes().isWord(parameterTypes[i])) {
ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
if (typeInfo instanceof EnumInfo) {
UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumLookupInfo.class::isInstance), "Enum class " + parameterTypes[i].toJavaName() + " needs a method that is annotated with @" + CEnumLookup.class + " because it is used as a parameter of an entry point method: " + targetMethod.format("%H.%n(%p)"));
if (parameterEnumInfos == null) {
parameterEnumInfos = new EnumInfo[parameterTypes.length];
}
parameterEnumInfos[i] = (EnumInfo) typeInfo;
parameterLoadTypes[i] = providers.getMetaAccess().lookupJavaType(cEnumParameterKind.toJavaClass());
final int parameterIndex = i;
FrameState initialState = kit.getGraph().start().stateAfter();
Iterator<ValueNode> matchingNodes = initialState.values().filter(node -> ((ParameterNode) node).index() == parameterIndex).iterator();
ValueNode parameterNode = matchingNodes.next();
assert !matchingNodes.hasNext() && parameterNode.usages().filter(n -> n != initialState).isEmpty();
parameterNode.setStamp(StampFactory.forKind(cEnumParameterKind));
} else if (purpose != Purpose.ANALYSIS) {
// for analysis test cases: abort only during compilation
throw UserError.abort("Entry point method parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + targetMethod.format("%H.%n(%p)"));
}
}
}
return parameterEnumInfos;
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class InliningUtilities method recursionDepth.
public static int recursionDepth(Invoke invoke, ResolvedJavaMethod callee) {
FrameState state = invoke.stateAfter();
int result = 0;
do {
if (state.getMethod().equals(callee)) {
result++;
}
state = state.outerFrameState();
} while (state != null);
return result;
}
Aggregations