Skip to content

Commit

Permalink
change helper methods for creating stub and full deopt/runtime methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
teshull committed Apr 24, 2024
1 parent 01ad47e commit 2b2b0ab
Showing 1 changed file with 35 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public SubstrateMethod prepareMethodForRuntimeCompilation(ResolvedJavaMethod met
* make the entire flow for the deopt version until we see what FrameStates exist within
* the runtime version.
*/
aMethod.getOrCreateMultiMethod(DEOPT_TARGET_METHOD, (newMethod) -> ((PointsToAnalysisMethod) newMethod).getTypeFlow().setAsStubFlow());
getStubDeoptVersion(aMethod);
config.registerAsRoot(aMethod, true, "Runtime compilation, registered in " + RuntimeCompilationFeature.class, RUNTIME_COMPILED_METHOD, DEOPT_TARGET_METHOD);
}

Expand Down Expand Up @@ -747,6 +747,9 @@ public boolean validateGraph(PointsToAnalysis bb, StructuredGraph graph) {
/*
* Because this graph will have its flowgraph immediately updated after this, there
* is no reason to make this method's flowgraph a stub on creation.
*
* We intentionally do not call getFullDeoptVersion because we want to wait until
* all deopt entries are registered before triggering the flow update.
*/
Collection<ResolvedJavaMethod> recomputeMethods = DeoptimizationUtils.registerDeoptEntries(graph, registeredRuntimeCompilations.contains(origMethod),
(deoptEntryMethod -> ((PointsToAnalysisMethod) deoptEntryMethod).getOrCreateMultiMethod(DEOPT_TARGET_METHOD)));
Expand Down Expand Up @@ -896,7 +899,7 @@ protected InlineInvokePlugin.InlineInfo createInvokeInfo(AnalysisMethod method)
* (i.e., all calls to this method are inlined), then the method's full flow will not
* need to be created.
*/
AnalysisMethod runtimeMethod = method.getOrCreateMultiMethod(RUNTIME_COMPILED_METHOD, (newMethod) -> ((PointsToAnalysisMethod) newMethod).getTypeFlow().setAsStubFlow());
AnalysisMethod runtimeMethod = getStubRuntimeVersion(method);
return InlineInvokePlugin.InlineInfo.createStandardInlineInfo(runtimeMethod);
}

Expand Down Expand Up @@ -938,6 +941,32 @@ protected AbstractPolicyScope openCalleeScope(AbstractPolicyScope outer, Analysi
}
}

@SuppressWarnings("unchecked")
private static <T extends AnalysisMethod> T getStubDeoptVersion(T implementation) {
return (T) implementation.getOrCreateMultiMethod(DEOPT_TARGET_METHOD, (newMethod) -> ((PointsToAnalysisMethod) newMethod).getTypeFlow().setAsStubFlow());
}

@SuppressWarnings("unchecked")
private static <T extends AnalysisMethod> T getFullDeoptVersion(BigBang bb, T implementation, InvokeTypeFlow parsingReason) {
PointsToAnalysisMethod runtimeMethod = (PointsToAnalysisMethod) implementation.getOrCreateMultiMethod(DEOPT_TARGET_METHOD);
PointsToAnalysis analysis = (PointsToAnalysis) bb;
runtimeMethod.getTypeFlow().updateFlowsGraph(analysis, MethodFlowsGraph.GraphKind.FULL, parsingReason, true);
return (T) runtimeMethod;
}

@SuppressWarnings("unchecked")
private static <T extends AnalysisMethod> T getStubRuntimeVersion(T implementation) {
return (T) implementation.getOrCreateMultiMethod(RUNTIME_COMPILED_METHOD, (newMethod) -> ((PointsToAnalysisMethod) newMethod).getTypeFlow().setAsStubFlow());
}

@SuppressWarnings("unchecked")
private static <T extends AnalysisMethod> T getFullRuntimeVersion(BigBang bb, T implementation, InvokeTypeFlow parsingReason) {
PointsToAnalysisMethod runtimeMethod = (PointsToAnalysisMethod) implementation.getOrCreateMultiMethod(RUNTIME_COMPILED_METHOD);
PointsToAnalysis analysis = (PointsToAnalysis) bb;
runtimeMethod.getTypeFlow().updateFlowsGraph(analysis, MethodFlowsGraph.GraphKind.FULL, parsingReason, false);
return (T) runtimeMethod;
}

private class RuntimeCompilationAnalysisPolicy implements HostVM.MultiMethodAnalysisPolicy {

@Override
Expand Down Expand Up @@ -967,9 +996,9 @@ public <T extends AnalysisMethod> Collection<T> determineCallees(BigBang bb, T i
* method, so deopt targets must be created for them as well.
*/
if (registeredRuntimeCompilation) {
return List.of(implementation, getStubDeoptVersion(implementation), getRuntimeVersion(bb, implementation, true, invokeFlow));
return List.of(implementation, getStubDeoptVersion(implementation), getFullRuntimeVersion(bb, implementation, invokeFlow));
} else if (SubstrateCompilationDirectives.singleton().isFrameInformationRequired(implementation)) {
return List.of(implementation, getDeoptVersion(bb, implementation, true, invokeFlow));
return List.of(implementation, getFullDeoptVersion(bb, implementation, invokeFlow));
} else if (DeoptimizationUtils.canDeoptForTesting(implementation, false, () -> false)) {
/*
* If the target is registered for deoptimization, then we must also make a
Expand All @@ -991,7 +1020,7 @@ public <T extends AnalysisMethod> Collection<T> determineCallees(BigBang bb, T i
* runtime deoptimizes).
*/
if (runtimeCompilationCandidate) {
return List.of(implementation, getStubDeoptVersion(implementation), getRuntimeVersion(bb, implementation, true, invokeFlow));
return List.of(implementation, getStubDeoptVersion(implementation), getFullRuntimeVersion(bb, implementation, invokeFlow));
} else {
/*
* If this method cannot be jitted, then only the original implementation is
Expand All @@ -1011,7 +1040,7 @@ public <T extends AnalysisMethod> Collection<T> determineCallees(BigBang bb, T i
* runtime compiled method's invoke.
*/
if (runtimeCompilationCandidate) {
return List.of(implementation, getStubDeoptVersion(implementation), getRuntimeVersion(bb, implementation, false, invokeFlow));
return List.of(implementation, getStubDeoptVersion(implementation), getStubRuntimeVersion(implementation));
} else {
/*
* If this method cannot be jitted, then only the original implementation is
Expand All @@ -1024,44 +1053,6 @@ public <T extends AnalysisMethod> Collection<T> determineCallees(BigBang bb, T i

}

protected <T extends AnalysisMethod> T getStubDeoptVersion(T implementation) {
/*
* Flows for deopt versions are only created once a frame state for the method is seen
* within a runtime compiled method.
*/
return getDeoptVersion(null, implementation, false, null);
}

@SuppressWarnings("unchecked")
protected <T extends AnalysisMethod> T getDeoptVersion(BigBang bb, T implementation, boolean createFlow, InvokeTypeFlow parsingReason) {
if (createFlow) {
PointsToAnalysisMethod runtimeMethod = (PointsToAnalysisMethod) implementation.getOrCreateMultiMethod(DEOPT_TARGET_METHOD);
PointsToAnalysis analysis = (PointsToAnalysis) bb;
runtimeMethod.getTypeFlow().updateFlowsGraph(analysis, MethodFlowsGraph.GraphKind.FULL, parsingReason, true);
return (T) runtimeMethod;
} else {
/*
* If a flow is not needed then temporarily a stub can be created.
*/
return (T) implementation.getOrCreateMultiMethod(DEOPT_TARGET_METHOD, (newMethod) -> ((PointsToAnalysisMethod) newMethod).getTypeFlow().setAsStubFlow());
}
}

@SuppressWarnings("unchecked")
protected <T extends AnalysisMethod> T getRuntimeVersion(BigBang bb, T implementation, boolean createFlow, InvokeTypeFlow parsingReason) {
if (createFlow) {
PointsToAnalysisMethod runtimeMethod = (PointsToAnalysisMethod) implementation.getOrCreateMultiMethod(RUNTIME_COMPILED_METHOD);
PointsToAnalysis analysis = (PointsToAnalysis) bb;
runtimeMethod.getTypeFlow().updateFlowsGraph(analysis, MethodFlowsGraph.GraphKind.FULL, parsingReason, false);
return (T) runtimeMethod;
} else {
/*
* If a flow is not needed then temporarily a stub can be created.
*/
return (T) implementation.getOrCreateMultiMethod(RUNTIME_COMPILED_METHOD, (newMethod) -> ((PointsToAnalysisMethod) newMethod).getTypeFlow().setAsStubFlow());
}
}

@Override
public boolean performParameterLinking(MultiMethod.MultiMethodKey callerMultiMethodKey, MultiMethod.MultiMethodKey calleeMultiMethodKey) {
if (callerMultiMethodKey == RUNTIME_COMPILED_METHOD) {
Expand Down

0 comments on commit 2b2b0ab

Please sign in to comment.