Skip to content

Commit 11b8cc0

Browse files
teshullZeavee
authored andcommitted
remove parsedCallback field
1 parent 88ab9c1 commit 11b8cc0

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/ImageLayerWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.graal.pointsto.api;
2626

27+
import com.oracle.graal.pointsto.flow.AnalysisParsedGraph;
2728
import com.oracle.graal.pointsto.meta.AnalysisMethod;
2829
import com.oracle.graal.pointsto.util.AnalysisError;
2930

@@ -35,7 +36,7 @@ public void onTrackedAcrossLayer(AnalysisMethod method, Object reason) {
3536
}
3637

3738
@SuppressWarnings("unused")
38-
public void persistAnalysisParsedGraph(AnalysisMethod method) {
39+
public void persistAnalysisParsedGraph(AnalysisMethod method, AnalysisParsedGraph analysisParsedGraph) {
3940
throw AnalysisError.shouldNotReachHere("This method should not be called");
4041
}
4142
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Map;
4040
import java.util.Set;
4141
import java.util.concurrent.ConcurrentHashMap;
42+
import java.util.concurrent.atomic.AtomicBoolean;
4243
import java.util.concurrent.atomic.AtomicReference;
4344
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
4445
import java.util.concurrent.locks.ReentrantLock;
@@ -61,7 +62,6 @@
6162
import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod;
6263
import com.oracle.graal.pointsto.reports.ReportUtils;
6364
import com.oracle.graal.pointsto.util.AnalysisError;
64-
import com.oracle.graal.pointsto.util.AnalysisFuture;
6565
import com.oracle.graal.pointsto.util.AtomicUtils;
6666
import com.oracle.graal.pointsto.util.ConcurrentLightHashSet;
6767
import com.oracle.svm.common.meta.MultiMethod;
@@ -143,8 +143,6 @@ public record Signature(String name, AnalysisType[] parameterTypes) {
143143

144144
private final MultiMethodKey multiMethodKey;
145145

146-
private AnalysisFuture<Void> parsedCallBack;
147-
148146
/**
149147
* Map from a key to the corresponding implementation. All multi-method implementations for a
150148
* given Java method share the same map. This allows one to easily switch between different
@@ -178,6 +176,7 @@ public record Signature(String name, AnalysisType[] parameterTypes) {
178176
private final boolean enableReachableInCurrentLayer;
179177

180178
private final AtomicReference<GraphCacheEntry> parsedGraphCacheState = new AtomicReference<>(GraphCacheEntry.UNPARSED);
179+
private final AtomicBoolean trackedGraphPersisted = new AtomicBoolean(false);
181180

182181
private EncodedGraph analyzedGraph;
183182

@@ -551,17 +550,10 @@ protected void notifyImplementationInvokedCallbacks() {
551550
ConcurrentLightHashSet.removeElementIf(this, implementationInvokedNotificationsUpdater, ElementNotification::isNotified);
552551
}
553552

554-
public void registerParsedGraphCallback(AnalysisFuture<Void> parsingCallBack) {
555-
this.parsedCallBack = parsingCallBack;
556-
if (getParsedGraphCacheStateObject() instanceof AnalysisParsedGraph) {
557-
notifyParsedCallback();
558-
}
559-
}
560-
561-
private void notifyParsedCallback() {
562-
if (parsedCallBack != null) {
563-
parsedCallBack.ensureDone();
564-
parsedCallBack = null;
553+
private void persistTrackedGraph(AnalysisParsedGraph graph) {
554+
if (isTrackedAcrossLayers() && trackedGraphPersisted.compareAndSet(false, true)) {
555+
ImageLayerWriter imageLayerWriter = getUniverse().getImageLayerWriter();
556+
imageLayerWriter.persistAnalysisParsedGraph(this, graph);
565557
}
566558
}
567559

@@ -696,15 +688,16 @@ public void onReachable(Object reason) {
696688
@Override
697689
protected void onTrackedAcrossLayers(Object reason) {
698690
AnalysisError.guarantee(!getUniverse().sealed(), "Method %s was marked as tracked after the universe was sealed", this);
699-
ImageLayerWriter imageLayerWriter = getUniverse().getImageLayerWriter();
700-
imageLayerWriter.onTrackedAcrossLayer(this, reason);
691+
getUniverse().getImageLayerWriter().onTrackedAcrossLayer(this, reason);
701692
declaringClass.registerAsTrackedAcrossLayers(reason);
702693
for (AnalysisType parameter : toParameterList()) {
703694
parameter.registerAsTrackedAcrossLayers(reason);
704695
}
705696
signature.getReturnType().registerAsTrackedAcrossLayers(reason);
706697

707-
registerParsedGraphCallback(new AnalysisFuture<>(() -> imageLayerWriter.persistAnalysisParsedGraph(this)));
698+
if (getParsedGraphCacheStateObject() instanceof AnalysisParsedGraph analysisParsedGraph) {
699+
persistTrackedGraph(analysisParsedGraph);
700+
}
708701
}
709702

710703
public void registerOverrideReachabilityNotification(MethodOverrideReachableNotification notification) {
@@ -1254,9 +1247,13 @@ private AnalysisParsedGraph setGraph(BigBang bb, Stage stage, GraphCacheEntry ex
12541247
boolean result = parsedGraphCacheState.compareAndSet(lockState, newEntry);
12551248
AnalysisError.guarantee(result, "State transition failed");
12561249

1257-
notifyParsedCallback();
1250+
AnalysisParsedGraph analysisParsedGraph = (AnalysisParsedGraph) newEntry.get(stage);
1251+
1252+
if (stage == Stage.finalStage()) {
1253+
persistTrackedGraph(analysisParsedGraph);
1254+
}
12581255

1259-
return (AnalysisParsedGraph) newEntry.get(stage);
1256+
return analysisParsedGraph;
12601257

12611258
} catch (Throwable ex) {
12621259
parsedGraphCacheState.set(GraphCacheEntry.createParsingError(stage, expectedValue, ex));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,9 @@ private PersistedAnalysisMethod.Reader getMethodData(AnalysisMethod analysisMeth
823823
}
824824

825825
/**
826-
* See {@link SVMImageLayerWriter#persistAnalysisParsedGraph(AnalysisMethod)} for
827-
* implementation.
826+
* See
827+
* {@link SVMImageLayerWriter#persistAnalysisParsedGraph(AnalysisMethod, AnalysisParsedGraph)}
828+
* for implementation.
828829
*/
829830
@Override
830831
public boolean hasAnalysisParsedGraph(AnalysisMethod analysisMethod) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,7 @@ private static AnalysisMethod getRelocatableConstantMethod(MethodPointer methodP
904904
}
905905

906906
@Override
907-
public void persistAnalysisParsedGraph(AnalysisMethod method) {
908-
AnalysisParsedGraph analysisParsedGraph = (AnalysisParsedGraph) method.getParsedGraphCacheStateObject();
907+
public void persistAnalysisParsedGraph(AnalysisMethod method, AnalysisParsedGraph analysisParsedGraph) {
909908
String name = imageLayerSnapshotUtil.getMethodDescriptor(method);
910909
MethodGraphsInfo graphsInfo = methodsMap.get(name);
911910
if (graphsInfo == null || graphsInfo.analysisGraphLocation == null) {

0 commit comments

Comments
 (0)