Skip to content

Commit

Permalink
[GR-45954] Propagate recordInlinedMethods property through EncodedGraph
Browse files Browse the repository at this point in the history
PullRequest: graal/17794
  • Loading branch information
lewurm committed May 29, 2024
2 parents 8f0d1e6 + ee6351d commit d34aafd
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ public void clear() {
protected int[] nodeStartOffsets;

public EncodedGraph(byte[] encoding, int startOffset, Object[] objects, NodeClass<?>[] types, StructuredGraph sourceGraph) {
this(encoding, startOffset, objects, types, sourceGraph.getAssumptions(), sourceGraph.getMethods(), sourceGraph.hasUnsafeAccess(), sourceGraph.trackNodeSourcePosition());
this(encoding,
startOffset,
objects,
types,
sourceGraph.getAssumptions(),
sourceGraph.isRecordingInlinedMethods() ? sourceGraph.getMethods() : null,
sourceGraph.hasUnsafeAccess(),
sourceGraph.trackNodeSourcePosition());
}

public EncodedGraph(byte[] encoding, int startOffset, Object[] objects, NodeClass<?>[] types, Assumptions assumptions, List<ResolvedJavaMethod> inlinedMethods,
Expand Down Expand Up @@ -140,6 +147,10 @@ public Assumptions getAssumptions() {
return assumptions;
}

public boolean isRecordingInlinedMethods() {
return inlinedMethods != null;
}

public List<ResolvedJavaMethod> getInlinedMethods() {
return inlinedMethods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ protected IntrinsicGraphBuilder(OptionValues options,
if (graphBuilderConfig != null && !method.isNative()) {
graph.start().setStateAfter(createStateAfterStartOfReplacementGraph(method, graphBuilderConfig));
}
// Record method dependency in the graph
graph.recordMethod(method);

Signature sig = method.getSignature();
int max = sig.getParameterCount(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static AnalysisParsedGraph parseBytecode(BigBang bb, AnalysisMethod metho

graph = new StructuredGraph.Builder(options, debug)
.method(method)
.recordInlinedMethods(false)
.recordInlinedMethods(bb.getHostVM().recordInlinedMethods(method))
.build();
try (DebugContext.Scope s = debug.scope("ClosedWorldAnalysis", graph, method)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,23 +953,25 @@ public StructuredGraph decodeAnalyzedGraph(DebugContext debug, Iterable<EncodedN
return null;
}

return decodeAnalyzedGraph(debug, nodeReferences, analyzedGraph.trackNodeSourcePosition(), GraphDecoder::new);
return decodeAnalyzedGraph(debug, nodeReferences, analyzedGraph.trackNodeSourcePosition(), analyzedGraph.isRecordingInlinedMethods(), GraphDecoder::new);
}

/**
* Returns the {@link StructuredGraph Graal IR} for the method that has been processed by the
* static analysis.
*/
public StructuredGraph decodeAnalyzedGraph(DebugContext debug, Iterable<EncodedNodeReference> nodeReferences, boolean trackNodeSourcePosition,
public StructuredGraph decodeAnalyzedGraph(DebugContext debug, Iterable<EncodedNodeReference> nodeReferences, boolean trackNodeSourcePosition, boolean recordInlinedMethods,
BiFunction<Architecture, StructuredGraph, GraphDecoder> decoderProvider) {
if (analyzedGraph == null) {
return null;
}

var allowAssumptions = getUniverse().hostVM().allowAssumptions(this);
// Note we never record inlined methods. This is correct even for runtime compiled methods
StructuredGraph result = new StructuredGraph.Builder(debug.getOptions(), debug, allowAssumptions).method(this).recordInlinedMethods(false).trackNodeSourcePosition(
trackNodeSourcePosition).build();
StructuredGraph result = new StructuredGraph.Builder(debug.getOptions(), debug, allowAssumptions)
.method(this)
.trackNodeSourcePosition(trackNodeSourcePosition)
.recordInlinedMethods(recordInlinedMethods)
.build();
GraphDecoder decoder = decoderProvider.apply(AnalysisParsedGraph.HOST_ARCHITECTURE, result);
decoder.decode(analyzedGraph, nodeReferences);
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static StructuredGraph decodeGraph(BigBang bb, AnalysisMethod method, Ana

StructuredGraph result = new StructuredGraph.Builder(bb.getOptions(), debug, bb.getHostVM().allowAssumptions(method))
.method(method)
.recordInlinedMethods(bb.getHostVM().recordInlinedMethods(method))
.trackNodeSourcePosition(analysisParsedGraph.getEncodedGraph().trackNodeSourcePosition())
.recordInlinedMethods(analysisParsedGraph.getEncodedGraph().isRecordingInlinedMethods())
.build();

try (DebugContext.Scope s = debug.scope("InlineBeforeAnalysis", result)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args, bool
StructuredGraph result = new StructuredGraph.Builder(optionValues, debug)
.method(method)
.trackNodeSourcePosition(trackNodeSourcePosition)
.recordInlinedMethods(false)
.recordInlinedMethods(true)
.setIsSubstitution(true)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ public SubstrateGraphKit(DebugContext debug, ResolvedJavaMethod stubMethod, Prov
frameState.initializeForMethodStart(null, true, graphBuilderPlugins, collectedArguments);
initialArguments = Collections.unmodifiableList(collectedArguments);
graph.start().setStateAfter(frameState.create(bci(), graph.start()));
}

public SubstrateGraphKit(DebugContext debug, ResolvedJavaMethod stubMethod, Providers providers, GraphBuilderConfiguration.Plugins graphBuilderPlugins, CompilationIdentifier compilationId) {
this(debug, stubMethod, providers, graphBuilderPlugins, compilationId, false);
// Record method dependency in the graph
graph.recordMethod(graph.method());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void compileRuntimeCompiledMethod(DebugContext debug) {
boolean trackNodeSourcePosition = SubstrateOptions.IncludeNodeSourcePositions.getValue();

AnalysisMethod aMethod = method.getWrapped();
StructuredGraph graph = aMethod.decodeAnalyzedGraph(debug, null, trackNodeSourcePosition,
StructuredGraph graph = aMethod.decodeAnalyzedGraph(debug, null, trackNodeSourcePosition, false,
(arch, analyzedGraph) -> new RuntimeCompilationGraphDecoder(arch, analyzedGraph, compilationState.heapScanner));
if (graph == null) {
throw VMError.shouldNotReachHere("Method not parsed during static analysis: " + aMethod.format("%r %H.%n(%p)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ private StructuredGraph decodeGraph(SimulateClassInitializerClusterMember cluste

var result = new StructuredGraph.Builder(bb.getOptions(), debug)
.method(classInitializer)
.recordInlinedMethods(false)
.trackNodeSourcePosition(analysisParsedGraph.getEncodedGraph().trackNodeSourcePosition())
.recordInlinedMethods(analysisParsedGraph.getEncodedGraph().isRecordingInlinedMethods())
.build();

try (var scope = debug.scope("SimulateClassInitializerGraphDecoder", result)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ public CompilationGraph getCompilationGraph() {

@SuppressWarnings("try")
public StructuredGraph createGraph(DebugContext debug, OptionValues options, CompilationIdentifier compilationId, boolean decode) {
var encodedGraph = getCompilationGraph().getEncodedGraph();
var graph = new StructuredGraph.Builder(options, debug)
.method(method)
.recordInlinedMethods(false)
.trackNodeSourcePosition(getCompilationGraph().getEncodedGraph().trackNodeSourcePosition())
.trackNodeSourcePosition(encodedGraph.trackNodeSourcePosition())
.recordInlinedMethods(encodedGraph.isRecordingInlinedMethods())
.compilationId(compilationId)
.build();

if (decode) {
try (var s = debug.scope("CreateGraph", graph, method)) {
var decoder = new GraphDecoder(AnalysisParsedGraph.HOST_ARCHITECTURE, graph);
decoder.decode(getCompilationGraph().getEncodedGraph());
decoder.decode(encodedGraph);
} catch (Throwable ex) {
throw debug.handle(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import java.util.List;

import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.HostedProviders;
import com.oracle.svm.core.c.BoxedRelocatedPointer;
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
import com.oracle.svm.core.graal.code.SubstrateCompilationIdentifier;
import com.oracle.svm.core.graal.replacements.SubstrateGraphKit;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport;
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;

import jdk.graal.compiler.core.common.type.StampFactory;
import jdk.graal.compiler.core.common.type.StampPair;
Expand Down Expand Up @@ -65,7 +65,7 @@ public class HostedGraphKit extends SubstrateGraphKit {

public HostedGraphKit(DebugContext debug, HostedProviders providers, ResolvedJavaMethod method) {
super(debug, method, providers, providers.getGraphBuilderPlugins(), new SubstrateCompilationIdentifier(),
SubstrateCompilationDirectives.isRuntimeCompiledMethod(method));
((AnalysisMetaAccess) providers.getMetaAccess()).getUniverse().hostVM().recordInlinedMethods((AnalysisMethod) method));
}

@Override
Expand Down

0 comments on commit d34aafd

Please sign in to comment.