Skip to content

Commit d729cb9

Browse files
committed
[GR-59912] Persist all strengthened graphs from tracked methods
PullRequest: graal/19347
2 parents 7ea0e9c + 8416d9b commit d729cb9

File tree

5 files changed

+32
-64
lines changed

5 files changed

+32
-64
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageLayerLoader.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,7 @@ public void addBaseLayerMethod(AnalysisMethod analysisMethod) {
578578
}
579579

580580
public void initializeBaseLayerMethod(AnalysisMethod analysisMethod) {
581-
initializeBaseLayerMethod(analysisMethod, getMethodData(analysisMethod));
582-
}
583-
584-
protected void initializeBaseLayerMethod(AnalysisMethod analysisMethod, PersistedAnalysisMethod.Reader md) {
581+
PersistedAnalysisMethod.Reader md = getMethodData(analysisMethod);
585582
registerFlag(md.getIsVirtualRootMethod(), true, () -> analysisMethod.registerAsVirtualRootMethod(PERSISTED));
586583
registerFlag(md.getIsDirectRootMethod(), true, () -> analysisMethod.registerAsDirectRootMethod(PERSISTED));
587584
registerFlag(md.getIsInvoked(), true, () -> analysisMethod.registerAsInvoked(PERSISTED));
@@ -600,16 +597,28 @@ public boolean hasAnalysisParsedGraph(AnalysisMethod analysisMethod) {
600597

601598
public AnalysisParsedGraph getAnalysisParsedGraph(AnalysisMethod analysisMethod) {
602599
PersistedAnalysisMethod.Reader methodData = getMethodData(analysisMethod);
603-
byte[] encodedAnalyzedGraph = readEncodedGraph(methodData.getAnalysisGraphLocation().toString());
604600
boolean intrinsic = methodData.getAnalysisGraphIsIntrinsic();
605-
EncodedGraph analyzedGraph = (EncodedGraph) ObjectCopier.decode(imageLayerSnapshotUtil.getGraphDecoder(this, analysisMethod, universe.getSnippetReflection()), encodedAnalyzedGraph);
601+
EncodedGraph analyzedGraph = getEncodedGraph(analysisMethod, methodData.getAnalysisGraphLocation());
606602
if (hasStrengthenedGraph(analysisMethod)) {
607603
throw AnalysisError.shouldNotReachHere("Strengthened graphs are not supported until late loading is implemented.");
608604
}
609-
afterGraphDecodeHook(analyzedGraph);
610605
return new AnalysisParsedGraph(analyzedGraph, intrinsic);
611606
}
612607

608+
public boolean hasStrengthenedGraph(AnalysisMethod analysisMethod) {
609+
return getMethodData(analysisMethod).hasStrengthenedGraphLocation();
610+
}
611+
612+
public EncodedGraph getStrengthenedGraph(AnalysisMethod analysisMethod) {
613+
PersistedAnalysisMethod.Reader methodData = getMethodData(analysisMethod);
614+
return getEncodedGraph(analysisMethod, methodData.getStrengthenedGraphLocation());
615+
}
616+
617+
protected EncodedGraph getEncodedGraph(AnalysisMethod analysisMethod, Text.Reader location) {
618+
byte[] encodedAnalyzedGraph = readEncodedGraph(location.toString());
619+
return (EncodedGraph) ObjectCopier.decode(imageLayerSnapshotUtil.getGraphDecoder(this, analysisMethod, universe.getSnippetReflection()), encodedAnalyzedGraph);
620+
}
621+
613622
private byte[] readEncodedGraph(String location) {
614623
int closingBracketAt = location.length() - 1;
615624
AnalysisError.guarantee(location.charAt(0) == '@' && location.charAt(closingBracketAt) == ']', "Location must start with '@' and end with ']': %s", location);
@@ -632,23 +641,6 @@ private byte[] readEncodedGraph(String location) {
632641
return bb.array();
633642
}
634643

635-
public boolean hasStrengthenedGraph(AnalysisMethod analysisMethod) {
636-
return getMethodData(analysisMethod).hasStrengthenedGraphLocation();
637-
}
638-
639-
public void setStrengthenedGraph(AnalysisMethod analysisMethod) {
640-
PersistedAnalysisMethod.Reader methodData = getMethodData(analysisMethod);
641-
byte[] encodedAnalyzedGraph = readEncodedGraph(methodData.getStrengthenedGraphLocation().toString());
642-
EncodedGraph analyzedGraph = (EncodedGraph) ObjectCopier.decode(imageLayerSnapshotUtil.getGraphDecoder(this, analysisMethod, universe.getSnippetReflection()), encodedAnalyzedGraph);
643-
afterGraphDecodeHook(analyzedGraph);
644-
analysisMethod.setAnalyzedGraph(analyzedGraph);
645-
}
646-
647-
@SuppressWarnings("unused")
648-
protected void afterGraphDecodeHook(EncodedGraph encodedGraph) {
649-
650-
}
651-
652644
protected static int getId(String line) {
653645
return Integer.parseInt(line.split(" = ")[1]);
654646
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ public final void applyResults(AnalysisMethod method) {
240240
}
241241

242242
if (method.analyzedInPriorLayer()) {
243-
useSharedLayerGraph(method);
243+
/*
244+
* The method was already strengthened in a prior layer, so there is no need to
245+
* strengthen it in this layer.
246+
*/
244247
return;
245248
}
246249

@@ -273,8 +276,6 @@ public final void applyResults(AnalysisMethod method) {
273276

274277
protected abstract void postStrengthenGraphs(StructuredGraph graph, AnalysisMethod method);
275278

276-
protected abstract void useSharedLayerGraph(AnalysisMethod method);
277-
278279
protected abstract void persistStrengthenGraph(AnalysisMethod method);
279280

280281
/*

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@ public boolean useBaseLayer() {
256256

257257
/**
258258
* If we are skipping the analysis of a prior layer method, we must ensure analysis was
259-
* performed in the prior layer and the analysis results have been serialized. Currently this
259+
* performed in the prior layer and the analysis results have been serialized. Currently, this
260260
* approximates to either:
261261
* <ol>
262-
* <li>We have an analyzed graph available. See {@link ImageLayerLoader#hasAnalysisParsedGraph}
263-
* for which analysis graphs are persisted.</li>
262+
* <li>We have a strengthened graph available. See {@link ImageLayerLoader#hasStrengthenedGraph}
263+
* for which strengthened graphs are persisted. Having an analysis parsed graph (see
264+
* {@link ImageLayerLoader#hasAnalysisParsedGraph}) is not enough because methods with only an
265+
* analysis parsed graph are inlined before analysis, but not analyzed. Additionally, having a
266+
* strengthened graph implies also having an analysis parsed graph.</li>
264267
* <li>A compile target exists this layer can call.</li>
265268
* </ol>
266269
*
@@ -269,7 +272,7 @@ public boolean useBaseLayer() {
269272
@Override
270273
public boolean analyzedInPriorLayer(AnalysisMethod method) {
271274
ImageLayerLoader imageLayerLoader = HostedImageLayerBuildingSupport.singleton().getLoader();
272-
return imageLayerLoader.hasAnalysisParsedGraph(method) || HostedDynamicLayerInfo.singleton().compiledInPriorLayer(method);
275+
return imageLayerLoader.hasStrengthenedGraph(method) || HostedDynamicLayerInfo.singleton().compiledInPriorLayer(method);
273276
}
274277

275278
protected InlineBeforeAnalysisPolicyUtils getInlineBeforeAnalysisPolicyUtils() {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstrateStrengthenGraphs.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.function.Supplier;
2828

29-
import com.oracle.graal.pointsto.heap.ImageLayerLoader;
3029
import com.oracle.graal.pointsto.infrastructure.Universe;
3130
import com.oracle.graal.pointsto.meta.AnalysisMethod;
3231
import com.oracle.graal.pointsto.meta.AnalysisType;
@@ -44,8 +43,8 @@
4443
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
4544
import com.oracle.svm.hosted.imagelayer.HostedImageLayerBuildingSupport;
4645
import com.oracle.svm.hosted.meta.HostedType;
47-
4846
import com.oracle.svm.hosted.phases.AnalyzeJavaHomeAccessPhase;
47+
4948
import jdk.graal.compiler.graph.Node;
5049
import jdk.graal.compiler.nodes.ConstantNode;
5150
import jdk.graal.compiler.nodes.DeoptimizeNode;
@@ -78,21 +77,9 @@ protected void postStrengthenGraphs(StructuredGraph graph, AnalysisMethod method
7877
}
7978
}
8079

81-
@Override
82-
protected void useSharedLayerGraph(AnalysisMethod method) {
83-
ImageLayerLoader imageLayerLoader = HostedImageLayerBuildingSupport.singleton().getLoader();
84-
/*
85-
* GR-55294: When the analysis elements from the base layer will be able to be materialized
86-
* after the analysis, fewer graphs will have to be loaded here as well.
87-
*/
88-
if (imageLayerLoader.hasStrengthenedGraph(method)) {
89-
imageLayerLoader.setStrengthenedGraph(method);
90-
}
91-
}
92-
9380
@Override
9481
protected void persistStrengthenGraph(AnalysisMethod method) {
95-
if (HostedImageLayerBuildingSupport.buildingSharedLayer() && method.isReachable()) {
82+
if (HostedImageLayerBuildingSupport.buildingSharedLayer() && method.isTrackedAcrossLayers()) {
9683
HostedImageLayerBuildingSupport.singleton().getWriter().persistMethodStrengthenedGraph(method);
9784
}
9885
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageLayerLoader.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.graalvm.collections.UnmodifiableEconomicMap;
4545
import org.graalvm.nativeimage.impl.CEntryPointLiteralCodePointer;
4646

47-
import com.oracle.graal.pointsto.flow.AnalysisParsedGraph;
4847
import com.oracle.graal.pointsto.heap.ImageHeapConstant;
4948
import com.oracle.graal.pointsto.heap.ImageHeapInstance;
5049
import com.oracle.graal.pointsto.heap.ImageLayerLoader;
@@ -55,7 +54,6 @@
5554
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.ImageSingletonObject;
5655
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.KeyStoreEntry;
5756
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisField;
58-
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisMethod;
5957
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisType;
6058
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedConstant;
6159
import com.oracle.graal.pointsto.meta.AnalysisField;
@@ -76,7 +74,6 @@
7674
import com.oracle.svm.hosted.SVMHost;
7775
import com.oracle.svm.hosted.c.CGlobalDataFeature;
7876
import com.oracle.svm.hosted.fieldfolding.StaticFinalFieldFoldingFeature;
79-
import com.oracle.svm.hosted.imagelayer.HostedDynamicLayerInfo;
8077
import com.oracle.svm.hosted.meta.HostedUniverse;
8178
import com.oracle.svm.hosted.meta.RelocatableConstant;
8279
import com.oracle.svm.hosted.util.IdentityHashCodeUtil;
@@ -170,26 +167,14 @@ protected Annotation[] getAnnotations(StructList.Reader<SharedLayerSnapshotCapnP
170167
}
171168

172169
@Override
173-
protected void initializeBaseLayerMethod(AnalysisMethod analysisMethod, PersistedAnalysisMethod.Reader methodData) {
174-
if (!HostedDynamicLayerInfo.singleton().compiledInPriorLayer(analysisMethod) && hasAnalysisParsedGraph(analysisMethod)) {
175-
/*
176-
* GR-55294: When the analysis elements from the base layer will be able to be
177-
* materialized after the analysis, this will not be needed anymore.
178-
*/
179-
analysisMethod.ensureGraphParsed(universe.getBigbang());
180-
analysisMethod.setAnalyzedGraph(((AnalysisParsedGraph) analysisMethod.getGraph()).getEncodedGraph());
181-
}
182-
super.initializeBaseLayerMethod(analysisMethod, methodData);
183-
}
184-
185-
@Override
186-
protected void afterGraphDecodeHook(EncodedGraph encodedGraph) {
187-
super.afterGraphDecodeHook(encodedGraph);
170+
protected EncodedGraph getEncodedGraph(AnalysisMethod analysisMethod, Text.Reader location) {
171+
EncodedGraph encodedGraph = super.getEncodedGraph(analysisMethod, location);
188172
for (int i = 0; i < encodedGraph.getNumObjects(); ++i) {
189173
if (encodedGraph.getObject(i) instanceof CGlobalDataInfo cGlobalDataInfo) {
190174
encodedGraph.setObject(i, CGlobalDataFeature.singleton().registerAsAccessedOrGet(cGlobalDataInfo.getData()));
191175
}
192176
}
177+
return encodedGraph;
193178
}
194179

195180
@Override

0 commit comments

Comments
 (0)