Skip to content

Commit 64c55c0

Browse files
committed
[GR-59340] Saturate all reachable methods in open world.
PullRequest: graal/19126
2 parents 2537416 + 513bc1c commit 64c55c0

File tree

10 files changed

+58
-27
lines changed

10 files changed

+58
-27
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/PointsToAnalysis.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,6 @@ public AnalysisMethod forcedAddRootMethod(AnalysisMethod method, boolean invokeS
349349
* optimized away by the analysis.
350350
*/
351351
typeFlow.ensureFlowsGraphCreated(this, null);
352-
/*
353-
* Saturating all the parameters of the method allows to enforce that no optimization is
354-
* performed using the types of the parameters of the methods.
355-
*/
356-
typeFlow.getMethodFlowsGraph().saturateAllParameters(this);
357352
});
358353
return addRootMethod(analysisMethod, invokeSpecial, reason, otherRoots);
359354
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/ReachabilityAnalysis.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public interface ReachabilityAnalysis {
9191

9292
/**
9393
* In addition to register the method as a root, saturate all the parameters. Meant to be used
94-
* under the {@code LayeredBaseImageAnalysis} option to ensure the invocation is replaced by the
95-
* context-insensitive invoke.
94+
* under the {@code UseBaseLayerInclusionPolicy} option to ensure the invocation is replaced by
95+
* the context-insensitive invoke.
9696
*
9797
* @see ReachabilityAnalysis#addRootMethod(AnalysisMethod, boolean, Object,
9898
* MultiMethod.MultiMethodKey...)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public void checkType(ResolvedJavaType type, AnalysisUniverse universe) {
168168
public void onTypeInstantiated(BigBang bb, AnalysisType type) {
169169
}
170170

171+
public boolean isCoreType(@SuppressWarnings("unused") AnalysisType type) {
172+
return false;
173+
}
174+
171175
public boolean useBaseLayer() {
172176
return false;
173177
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraph.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import com.oracle.graal.pointsto.PointsToAnalysis;
3939
import com.oracle.graal.pointsto.meta.AnalysisMethod;
40+
import com.oracle.graal.pointsto.meta.AnalysisType;
4041
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
4142
import com.oracle.graal.pointsto.util.AnalysisError;
4243

@@ -443,11 +444,20 @@ void updateInternalState(GraphKind newGraphKind) {
443444
}
444445

445446
/**
446-
* Saturates all the formal parameters of the graph. This is expected to be used by layered base
447-
* image analysis.
447+
* For open world analysis saturate all the formal parameters and the returns from virtual
448+
* invokes for all methods that can be directly accessible from the open world. This doesn't
449+
* include methods in core VM classes.
448450
*/
449-
public void saturateAllParameters(PointsToAnalysis bb) {
450-
AnalysisError.guarantee(bb.isBaseLayerAnalysisEnabled());
451+
void saturateForOpenTypeWorld(PointsToAnalysis bb) {
452+
/*
453+
* Skip methods declared in core VM types. The core is not extensible from the open world,
454+
* and it should not be invoked directly.
455+
*/
456+
AnalysisType declaringClass = method.getDeclaringClass();
457+
if (bb.getHostVM().isCoreType(declaringClass)) {
458+
return;
459+
}
460+
451461
for (TypeFlow<?> parameter : getParameters()) {
452462
if (parameter != null && parameter.canSaturate(bb)) {
453463
parameter.enableFlow(bb);
@@ -456,19 +466,15 @@ public void saturateAllParameters(PointsToAnalysis bb) {
456466
}
457467

458468
/*
459-
* Even if saturating only parameters already ensures that all code from the base layer is
460-
* reached, it is still necessary to saturate flows from miscEntryFlows, as the extension
461-
* image can introduce new types and methods. For example, an ActualReturnTypeFlow returning
462-
* from an AbstractVirtualInvokeTypeFlow would not be saturated only by saturating
463-
* parameters, as there is no direct use/observer link between the two flows. While all the
464-
* types returned by the implementations from the base image will be in the TypeState, a
465-
* different type might be returned by an implementation introduced by the extension image.
469+
* Saturate the return of virtual invokes that could return new types from the open world.
470+
* Returns from methods that cannot be overwritten, i.e., the receiver type is closed, are
471+
* not saturated.
466472
*/
467-
if (miscEntryFlows != null) {
468-
for (TypeFlow<?> miscEntryFlow : miscEntryFlows) {
469-
if (miscEntryFlow != null && miscEntryFlow.canSaturate(bb)) {
470-
miscEntryFlow.enableFlow(bb);
471-
miscEntryFlow.onSaturated(bb);
473+
for (InvokeTypeFlow invokeTypeFlow : getInvokes()) {
474+
if (!invokeTypeFlow.isDirectInvoke() && !bb.isClosed(invokeTypeFlow.getReceiverType())) {
475+
if (invokeTypeFlow.actualReturn != null) {
476+
invokeTypeFlow.actualReturn.enableFlow(bb);
477+
invokeTypeFlow.actualReturn.onSaturated(bb);
472478
}
473479
}
474480
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ private synchronized void createFlowsGraph(PointsToAnalysis bb, InvokeTypeFlow r
179179
assert flowsGraph != null;
180180

181181
initFlowsGraph(bb, builder.postInitFlows);
182+
183+
if (!bb.getHostVM().isClosedTypeWorld()) {
184+
flowsGraph.saturateForOpenTypeWorld(bb);
185+
}
186+
182187
} catch (Throwable t) {
183188
/* Wrap all errors as parsing errors. */
184189
throw AnalysisError.parsingError(method, t);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ public static boolean includeAll() {
12931293
return IncludeAllFromModule.hasBeenSet() || IncludeAllFromPath.hasBeenSet() || IncludeAllFromClassPath.hasBeenSet();
12941294
}
12951295

1296-
@Option(help = "Run layered image base layer open-world analysis. Includes all public types and methods that can be reached using normal Java access rules.")//
1297-
public static final HostedOptionKey<Boolean> LayeredBaseImageAnalysis = new HostedOptionKey<>(false);
1296+
@Option(help = "Force include include all public types and methods that can be reached using normal Java access rules.")//
1297+
public static final HostedOptionKey<Boolean> UseBaseLayerInclusionPolicy = new HostedOptionKey<>(false);
12981298

12991299
@Option(help = "Support for calls via the Java Foreign Function and Memory API", type = Expert) //
13001300
public static final HostedOptionKey<Boolean> ForeignAPISupport = new HostedOptionKey<>(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ private static Inflation createBigBang(DebugContext debug, OptionValues options,
12991299
ConstantReflectionProvider constantReflectionProvider = aProviders.getConstantReflection();
13001300
WordTypes wordTypes = aProviders.getWordTypes();
13011301
String reason = "Included in the base image";
1302-
ClassInclusionPolicy classInclusionPolicy = SubstrateOptions.LayeredBaseImageAnalysis.getValue(options) ? new ClassInclusionPolicy.LayeredBaseImageInclusionPolicy(reason)
1302+
ClassInclusionPolicy classInclusionPolicy = SubstrateOptions.UseBaseLayerInclusionPolicy.getValue(options) ? new ClassInclusionPolicy.LayeredBaseImageInclusionPolicy(reason)
13031303
: new ClassInclusionPolicy.DefaultAllInclusionPolicy(reason);
13041304
if (PointstoOptions.UseExperimentalReachabilityAnalysis.getValue(options)) {
13051305
ReachabilityMethodProcessingHandler reachabilityMethodProcessingHandler;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ public enum UsageKind {
202202
private final boolean isClosedTypeWorld = SubstrateOptions.useClosedTypeWorld();
203203
private final boolean enableTrackAcrossLayers;
204204

205+
/** Modules containing all {@code svm.core} and {@code svm.hosted} classes. */
206+
private final Set<Module> builderModules;
207+
205208
@SuppressWarnings("this-escape")
206209
public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializationSupport classInitializationSupport, AnnotationSubstitutionProcessor annotationSubstitutions,
207210
MissingRegistrationSupport missingRegistrationSupport) {
@@ -235,6 +238,23 @@ public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializatio
235238
}
236239

237240
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);
248+
}
249+
250+
/**
251+
* Returns true if the type is part of the {@code svm.core} module. Note that builderModules
252+
* also encloses the {@code svm.hosted} classes, but since those classes are not allowed at run
253+
* time then they cannot be an {@link AnalysisType}.
254+
*/
255+
@Override
256+
public boolean isCoreType(AnalysisType type) {
257+
return builderModules.contains(type.getJavaClass().getModule());
238258
}
239259

240260
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static void processLayerOptions(EconomicMap<OptionKey<?>, Object> values)
131131
}
132132
});
133133

134-
SubstrateOptions.LayeredBaseImageAnalysis.update(values, true);
134+
SubstrateOptions.UseBaseLayerInclusionPolicy.update(values, true);
135135
SubstrateOptions.ClosedTypeWorld.update(values, false);
136136
if (imageLayerEnabledHandler != null) {
137137
imageLayerEnabledHandler.onOptionEnabled(values);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
5858
rci.initializeAtBuildTime("java.nio", JDK_CLASS_REASON);
5959
rci.initializeAtBuildTime("java.text", JDK_CLASS_REASON);
6060
rci.initializeAtBuildTime("java.time", JDK_CLASS_REASON);
61+
rci.initializeAtRunTime("java.time.chrono.HijrahChronology", "Reads java.home in class initializer.");
6162
rci.initializeAtBuildTime("java.util", JDK_CLASS_REASON);
6263
rci.initializeAtRunTime("java.util.concurrent.SubmissionPublisher", "Executor service must be recomputed");
6364

0 commit comments

Comments
 (0)