Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,7 @@ public void addBaseLayerMethod(AnalysisMethod analysisMethod) {
}

public void initializeBaseLayerMethod(AnalysisMethod analysisMethod) {
initializeBaseLayerMethod(analysisMethod, getMethodData(analysisMethod));
}

protected void initializeBaseLayerMethod(AnalysisMethod analysisMethod, PersistedAnalysisMethod.Reader md) {
PersistedAnalysisMethod.Reader md = getMethodData(analysisMethod);
registerFlag(md.getIsVirtualRootMethod(), true, () -> analysisMethod.registerAsVirtualRootMethod(PERSISTED));
registerFlag(md.getIsDirectRootMethod(), true, () -> analysisMethod.registerAsDirectRootMethod(PERSISTED));
registerFlag(md.getIsInvoked(), true, () -> analysisMethod.registerAsInvoked(PERSISTED));
Expand All @@ -600,16 +597,28 @@ public boolean hasAnalysisParsedGraph(AnalysisMethod analysisMethod) {

public AnalysisParsedGraph getAnalysisParsedGraph(AnalysisMethod analysisMethod) {
PersistedAnalysisMethod.Reader methodData = getMethodData(analysisMethod);
byte[] encodedAnalyzedGraph = readEncodedGraph(methodData.getAnalysisGraphLocation().toString());
boolean intrinsic = methodData.getAnalysisGraphIsIntrinsic();
EncodedGraph analyzedGraph = (EncodedGraph) ObjectCopier.decode(imageLayerSnapshotUtil.getGraphDecoder(this, analysisMethod, universe.getSnippetReflection()), encodedAnalyzedGraph);
EncodedGraph analyzedGraph = getEncodedGraph(analysisMethod, methodData.getAnalysisGraphLocation());
if (hasStrengthenedGraph(analysisMethod)) {
throw AnalysisError.shouldNotReachHere("Strengthened graphs are not supported until late loading is implemented.");
}
afterGraphDecodeHook(analyzedGraph);
return new AnalysisParsedGraph(analyzedGraph, intrinsic);
}

public boolean hasStrengthenedGraph(AnalysisMethod analysisMethod) {
return getMethodData(analysisMethod).hasStrengthenedGraphLocation();
}

public EncodedGraph getStrengthenedGraph(AnalysisMethod analysisMethod) {
PersistedAnalysisMethod.Reader methodData = getMethodData(analysisMethod);
return getEncodedGraph(analysisMethod, methodData.getStrengthenedGraphLocation());
}

protected EncodedGraph getEncodedGraph(AnalysisMethod analysisMethod, Text.Reader location) {
byte[] encodedAnalyzedGraph = readEncodedGraph(location.toString());
return (EncodedGraph) ObjectCopier.decode(imageLayerSnapshotUtil.getGraphDecoder(this, analysisMethod, universe.getSnippetReflection()), encodedAnalyzedGraph);
}

private byte[] readEncodedGraph(String location) {
int closingBracketAt = location.length() - 1;
AnalysisError.guarantee(location.charAt(0) == '@' && location.charAt(closingBracketAt) == ']', "Location must start with '@' and end with ']': %s", location);
Expand All @@ -632,23 +641,6 @@ private byte[] readEncodedGraph(String location) {
return bb.array();
}

public boolean hasStrengthenedGraph(AnalysisMethod analysisMethod) {
return getMethodData(analysisMethod).hasStrengthenedGraphLocation();
}

public void setStrengthenedGraph(AnalysisMethod analysisMethod) {
PersistedAnalysisMethod.Reader methodData = getMethodData(analysisMethod);
byte[] encodedAnalyzedGraph = readEncodedGraph(methodData.getStrengthenedGraphLocation().toString());
EncodedGraph analyzedGraph = (EncodedGraph) ObjectCopier.decode(imageLayerSnapshotUtil.getGraphDecoder(this, analysisMethod, universe.getSnippetReflection()), encodedAnalyzedGraph);
afterGraphDecodeHook(analyzedGraph);
analysisMethod.setAnalyzedGraph(analyzedGraph);
}

@SuppressWarnings("unused")
protected void afterGraphDecodeHook(EncodedGraph encodedGraph) {

}

protected static int getId(String line) {
return Integer.parseInt(line.split(" = ")[1]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ public final void applyResults(AnalysisMethod method) {
}

if (method.analyzedInPriorLayer()) {
useSharedLayerGraph(method);
/*
* The method was already strengthened in a prior layer, so there is no need to
* strengthen it in this layer.
*/
return;
}

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

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

protected abstract void useSharedLayerGraph(AnalysisMethod method);

protected abstract void persistStrengthenGraph(AnalysisMethod method);

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,14 @@ public boolean useBaseLayer() {

/**
* If we are skipping the analysis of a prior layer method, we must ensure analysis was
* performed in the prior layer and the analysis results have been serialized. Currently this
* performed in the prior layer and the analysis results have been serialized. Currently, this
* approximates to either:
* <ol>
* <li>We have an analyzed graph available. See {@link ImageLayerLoader#hasAnalysisParsedGraph}
* for which analysis graphs are persisted.</li>
* <li>We have a strengthened graph available. See {@link ImageLayerLoader#hasStrengthenedGraph}
* for which strengthened graphs are persisted. Having an analysis parsed graph (see
* {@link ImageLayerLoader#hasAnalysisParsedGraph}) is not enough because methods with only an
* analysis parsed graph are inlined before analysis, but not analyzed. Additionally, having a
* strengthened graph implies also having an analysis parsed graph.</li>
* <li>A compile target exists this layer can call.</li>
* </ol>
*
Expand All @@ -271,7 +274,7 @@ public boolean useBaseLayer() {
@Override
public boolean analyzedInPriorLayer(AnalysisMethod method) {
ImageLayerLoader imageLayerLoader = HostedImageLayerBuildingSupport.singleton().getLoader();
return imageLayerLoader.hasAnalysisParsedGraph(method) || HostedDynamicLayerInfo.singleton().compiledInPriorLayer(method);
return imageLayerLoader.hasStrengthenedGraph(method) || HostedDynamicLayerInfo.singleton().compiledInPriorLayer(method);
}

protected InlineBeforeAnalysisPolicyUtils getInlineBeforeAnalysisPolicyUtils() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.util.function.Supplier;

import com.oracle.graal.pointsto.heap.ImageLayerLoader;
import com.oracle.graal.pointsto.infrastructure.Universe;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
Expand All @@ -44,8 +43,8 @@
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
import com.oracle.svm.hosted.imagelayer.HostedImageLayerBuildingSupport;
import com.oracle.svm.hosted.meta.HostedType;

import com.oracle.svm.hosted.phases.AnalyzeJavaHomeAccessPhase;

import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.nodes.ConstantNode;
import jdk.graal.compiler.nodes.DeoptimizeNode;
Expand Down Expand Up @@ -78,21 +77,9 @@ protected void postStrengthenGraphs(StructuredGraph graph, AnalysisMethod method
}
}

@Override
protected void useSharedLayerGraph(AnalysisMethod method) {
ImageLayerLoader imageLayerLoader = HostedImageLayerBuildingSupport.singleton().getLoader();
/*
* GR-55294: When the analysis elements from the base layer will be able to be materialized
* after the analysis, fewer graphs will have to be loaded here as well.
*/
if (imageLayerLoader.hasStrengthenedGraph(method)) {
imageLayerLoader.setStrengthenedGraph(method);
}
}

@Override
protected void persistStrengthenGraph(AnalysisMethod method) {
if (HostedImageLayerBuildingSupport.buildingSharedLayer() && method.isReachable()) {
if (HostedImageLayerBuildingSupport.buildingSharedLayer() && method.isTrackedAcrossLayers()) {
HostedImageLayerBuildingSupport.singleton().getWriter().persistMethodStrengthenedGraph(method);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.graalvm.collections.UnmodifiableEconomicMap;
import org.graalvm.nativeimage.impl.CEntryPointLiteralCodePointer;

import com.oracle.graal.pointsto.flow.AnalysisParsedGraph;
import com.oracle.graal.pointsto.heap.ImageHeapConstant;
import com.oracle.graal.pointsto.heap.ImageHeapInstance;
import com.oracle.graal.pointsto.heap.ImageLayerLoader;
Expand All @@ -55,7 +54,6 @@
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.ImageSingletonObject;
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.KeyStoreEntry;
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisField;
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisMethod;
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisType;
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedConstant;
import com.oracle.graal.pointsto.meta.AnalysisField;
Expand All @@ -76,7 +74,6 @@
import com.oracle.svm.hosted.SVMHost;
import com.oracle.svm.hosted.c.CGlobalDataFeature;
import com.oracle.svm.hosted.fieldfolding.StaticFinalFieldFoldingFeature;
import com.oracle.svm.hosted.imagelayer.HostedDynamicLayerInfo;
import com.oracle.svm.hosted.meta.HostedUniverse;
import com.oracle.svm.hosted.meta.RelocatableConstant;
import com.oracle.svm.hosted.util.IdentityHashCodeUtil;
Expand Down Expand Up @@ -170,26 +167,14 @@ protected Annotation[] getAnnotations(StructList.Reader<SharedLayerSnapshotCapnP
}

@Override
protected void initializeBaseLayerMethod(AnalysisMethod analysisMethod, PersistedAnalysisMethod.Reader methodData) {
if (!HostedDynamicLayerInfo.singleton().compiledInPriorLayer(analysisMethod) && hasAnalysisParsedGraph(analysisMethod)) {
/*
* GR-55294: When the analysis elements from the base layer will be able to be
* materialized after the analysis, this will not be needed anymore.
*/
analysisMethod.ensureGraphParsed(universe.getBigbang());
analysisMethod.setAnalyzedGraph(((AnalysisParsedGraph) analysisMethod.getGraph()).getEncodedGraph());
}
super.initializeBaseLayerMethod(analysisMethod, methodData);
}

@Override
protected void afterGraphDecodeHook(EncodedGraph encodedGraph) {
super.afterGraphDecodeHook(encodedGraph);
protected EncodedGraph getEncodedGraph(AnalysisMethod analysisMethod, Text.Reader location) {
EncodedGraph encodedGraph = super.getEncodedGraph(analysisMethod, location);
for (int i = 0; i < encodedGraph.getNumObjects(); ++i) {
if (encodedGraph.getObject(i) instanceof CGlobalDataInfo cGlobalDataInfo) {
encodedGraph.setObject(i, CGlobalDataFeature.singleton().registerAsAccessedOrGet(cGlobalDataInfo.getData()));
}
}
return encodedGraph;
}

@Override
Expand Down