Skip to content

Commit 2965e65

Browse files
committed
[GR-58518] Register base layer virtual calls as roots.
PullRequest: graal/19029
2 parents a4af309 + 7edffaa commit 2965e65

File tree

10 files changed

+177
-42
lines changed

10 files changed

+177
-42
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ protected void persistHook() {
321321

322322
}
323323

324+
public boolean isTypePersisted(AnalysisType type) {
325+
return persistedTypeIds.contains(type.getId());
326+
}
327+
324328
protected void persistType(AnalysisType type) {
325329
if (!persistedTypeIds.add(type.getId())) {
326330
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ private void handleInvoke(Invoke invoke, SimplifierTool tool) {
675675
/* Last resort, try to inject profiles optimistically. */
676676
TypeState receiverTypeState = null;
677677
if (invokeFlow.getTargetMethod().hasReceiver()) {
678-
if (invokeFlow.isSaturated()) {
678+
if (methodFlow.isSaturated((PointsToAnalysis) bb, invokeFlow)) {
679679
/*
680680
* For saturated invokes use all seen instantiated subtypes of target method
681681
* declaring class. In an open world this is incomplete as new types may be

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/layeredimagesingleton/ImageSingletonLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.util.List;
2828

2929
public interface ImageSingletonLoader {
30+
31+
List<Boolean> readBoolList(String keyName);
32+
3033
int readInt(String keyName);
3134

3235
List<Integer> readIntList(String keyName);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/layeredimagesingleton/ImageSingletonWriter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.util.List;
2828

2929
public interface ImageSingletonWriter {
30+
31+
void writeBoolList(String keyName, List<Boolean> value);
32+
3033
void writeInt(String keyName, int value);
3134

3235
void writeIntList(String keyName, List<Integer> value);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public void beforeUniverseBuilding(BeforeUniverseBuildingAccess access) {
6969
}
7070
}
7171

72+
public Set<Module> getBuilderModules() {
73+
Module m0 = ImageSingletons.lookup(VMFeature.class).getClass().getModule();
74+
Module m1 = SVMHost.class.getModule();
75+
return m0.equals(m1) ? Set.of(m0) : Set.of(m0, m1);
76+
}
77+
7278
private final Set<AnalysisType> triggeredTypes = new HashSet<>();
7379
private final Set<AnalysisMethod> triggeredMethods = new HashSet<>();
7480

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,7 @@ public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializatio
238238
}
239239

240240
enableTrackAcrossLayers = ImageLayerBuildingSupport.buildingSharedLayer();
241-
builderModules = getBuilderModules();
242-
}
243-
244-
private static Set<Module> getBuilderModules() {
245-
Module m0 = ImageSingletons.lookup(VMFeature.class).getClass().getModule();
246-
Module m1 = SVMHost.class.getModule();
247-
return m0.equals(m1) ? Set.of(m0) : Set.of(m0, m1);
241+
builderModules = ImageSingletons.contains(OpenTypeWorldFeature.class) ? ImageSingletons.lookup(OpenTypeWorldFeature.class).getBuilderModules() : null;
248242
}
249243

250244
/**

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import com.oracle.svm.core.graal.phases.OptimizeExceptionPathsPhase;
6161
import com.oracle.svm.core.heap.RestrictHeapAccess;
6262
import com.oracle.svm.core.heap.RestrictHeapAccessCallees;
63+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
6364
import com.oracle.svm.core.meta.MethodPointer;
6465
import com.oracle.svm.core.meta.SubstrateMethodPointerConstant;
6566
import com.oracle.svm.core.util.InterruptImageBuilding;
@@ -69,6 +70,7 @@
6970
import com.oracle.svm.hosted.NativeImageOptions;
7071
import com.oracle.svm.hosted.ProgressReporter;
7172
import com.oracle.svm.hosted.diagnostic.HostedHeapDumpFeature;
73+
import com.oracle.svm.hosted.imagelayer.LayeredDispatchTableSupport;
7274
import com.oracle.svm.hosted.meta.HostedMethod;
7375
import com.oracle.svm.hosted.meta.HostedUniverse;
7476
import com.oracle.svm.hosted.phases.ImageBuildStatisticsCounterPhase;
@@ -184,6 +186,8 @@ public record UnpublishedTrivialMethods(CompilationGraph unpublishedGraph, boole
184186

185187
private final ConcurrentMap<HostedMethod, UnpublishedTrivialMethods> unpublishedTrivialMethods = new ConcurrentHashMap<>();
186188

189+
private final LayeredDispatchTableSupport layeredDispatchTableSupport = ImageLayerBuildingSupport.buildingSharedLayer() ? LayeredDispatchTableSupport.singleton() : null;
190+
187191
public abstract static class CompileReason {
188192
/**
189193
* For debugging only: chaining of the compile reason, so that you can track the compilation
@@ -392,7 +396,7 @@ public void finish(DebugContext debug) {
392396
parseAll();
393397
}
394398

395-
if (!PointstoOptions.UseExperimentalReachabilityAnalysis.getValue(universe.hostVM().options())) {
399+
if (!ImageLayerBuildingSupport.buildingImageLayer() && !PointstoOptions.UseExperimentalReachabilityAnalysis.getValue(universe.hostVM().options())) {
396400
/*
397401
* Reachability Analysis creates call graphs with more edges compared to the
398402
* Points-to Analysis, therefore the annotations would have to be added to a lot
@@ -950,14 +954,9 @@ public void scheduleEntryPoints() {
950954
}
951955
}
952956

953-
private static boolean layeredForceCompilation(HostedMethod hMethod) {
954-
/*
955-
* If a method from a base layer interface is not compiled in a prior layer but is in the
956-
* vtable of a type from a new layer, the method needs to be compiled as there would be a
957-
* missing symbol otherwise.
958-
*/
959-
return hMethod.wrapped.isInBaseLayer() && !hMethod.isCompiledInPriorLayer() && hMethod.getDeclaringClass().isInterface() &&
960-
Arrays.stream(hMethod.getDeclaringClass().getSubTypes()).anyMatch(t -> !t.getWrapped().isInBaseLayer() && hMethod.isInVirtualMethodTable(t));
957+
private static boolean layeredForceCompilation(@SuppressWarnings("unused") HostedMethod hMethod) {
958+
// GR-57021 force some methods to be compiled in initial layer
959+
return false;
961960
}
962961

963962
public void scheduleDeoptTargets() {
@@ -1345,6 +1344,9 @@ protected void ensureCalleesCompiled(HostedMethod method, CompileReason reason,
13451344
if (call.direct || isDynamicallyResolvedCall(result, call)) {
13461345
ensureCompiled(callTarget, new DirectCallReason(method, reason));
13471346
} else if (callTarget != null && callTarget.getImplementations() != null) {
1347+
if (layeredDispatchTableSupport != null) {
1348+
layeredDispatchTableSupport.recordVirtualCallTarget(method, callTarget);
1349+
}
13481350
for (HostedMethod impl : callTarget.getImplementations()) {
13491351
ensureCompiled(impl, new VirtualCallReason(method, callTarget, reason));
13501352
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,15 @@ private static <T> T cast(Object object) {
391391
return (T) object;
392392
}
393393

394+
@Override
395+
public List<Boolean> readBoolList(String keyName) {
396+
List<Object> value = cast(keyStore.get(keyName));
397+
String type = cast(value.get(0));
398+
assert type.equals("B(") : type;
399+
List<Integer> internalValue = cast(value.get(1));
400+
return internalValue.stream().map(e -> e == 1).toList();
401+
}
402+
394403
@Override
395404
public int readInt(String keyName) {
396405
List<Object> value = cast(keyStore.get(keyName));

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ EconomicMap<String, Object> getKeyValueStore() {
317317
return keyValueStore;
318318
}
319319

320+
@Override
321+
public void writeBoolList(String keyName, List<Boolean> value) {
322+
var internalValue = value.stream().map(e -> e ? 1 : 0).toList();
323+
var previous = keyValueStore.put(keyName, List.of("B(", internalValue));
324+
assert previous == null : previous;
325+
}
326+
320327
@Override
321328
public void writeInt(String keyName, int value) {
322329
var previous = keyValueStore.put(keyName, List.of("I", value));

0 commit comments

Comments
 (0)