Skip to content

Commit 11477c2

Browse files
committed
[GR-33117] Move platform from AnalysisUniverse to SVMHost
PullRequest: graal/9537
2 parents ad43ef9 + 41ee545 commit 11477c2

File tree

8 files changed

+50
-49
lines changed

8 files changed

+50
-49
lines changed

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

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

27+
import java.lang.reflect.AnnotatedElement;
2728
import java.util.Optional;
2829
import java.util.concurrent.ForkJoinPool;
2930

@@ -121,4 +122,9 @@ default InlineBeforeAnalysisPolicy<?> inlineBeforeAnalysisPolicy() {
121122
default boolean skipInterface(AnalysisUniverse universe, ResolvedJavaType interfaceType, ResolvedJavaType implementingType) {
122123
return false;
123124
}
125+
126+
@SuppressWarnings("unused")
127+
default boolean platformSupported(AnalysisUniverse universe, AnnotatedElement element) {
128+
return true;
129+
}
124130
}

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

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package com.oracle.graal.pointsto.meta;
2626

27-
import java.lang.reflect.AnnotatedElement;
2827
import java.util.ArrayList;
2928
import java.util.Arrays;
3029
import java.util.Collection;
@@ -42,17 +41,13 @@
4241

4342
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
4443
import org.graalvm.compiler.core.common.SuppressFBWarnings;
45-
import org.graalvm.nativeimage.Platform;
46-
import org.graalvm.nativeimage.Platforms;
47-
import org.graalvm.util.GuardedAnnotationAccess;
4844
import org.graalvm.word.WordBase;
4945

5046
import com.oracle.graal.pointsto.AnalysisPolicy;
5147
import com.oracle.graal.pointsto.BigBang;
5248
import com.oracle.graal.pointsto.api.HostVM;
5349
import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
5450
import com.oracle.graal.pointsto.infrastructure.AnalysisConstantPool;
55-
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
5651
import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor;
5752
import com.oracle.graal.pointsto.infrastructure.Universe;
5853
import com.oracle.graal.pointsto.infrastructure.WrappedConstantPool;
@@ -118,20 +113,18 @@ public class AnalysisUniverse implements Universe {
118113

119114
private AnalysisType objectClass;
120115
private final JavaKind wordKind;
121-
private final Platform platform;
122116
private AnalysisPolicy analysisPolicy;
123117

124118
public JavaKind getWordKind() {
125119
return wordKind;
126120
}
127121

128122
@SuppressWarnings("unchecked")
129-
public AnalysisUniverse(HostVM hostVM, JavaKind wordKind, Platform platform, AnalysisPolicy analysisPolicy, SubstitutionProcessor substitutions, MetaAccessProvider originalMetaAccess,
123+
public AnalysisUniverse(HostVM hostVM, JavaKind wordKind, AnalysisPolicy analysisPolicy, SubstitutionProcessor substitutions, MetaAccessProvider originalMetaAccess,
130124
SnippetReflectionProvider originalSnippetReflection,
131125
SnippetReflectionProvider snippetReflection) {
132126
this.hostVM = hostVM;
133127
this.wordKind = wordKind;
134-
this.platform = platform;
135128
this.analysisPolicy = analysisPolicy;
136129
this.substitutions = substitutions;
137130
this.originalMetaAccess = originalMetaAccess;
@@ -215,7 +208,7 @@ public JavaType lookupAllowUnresolved(JavaType rawType) {
215208

216209
@SuppressFBWarnings(value = {"ES_COMPARING_STRINGS_WITH_EQ"}, justification = "Bug in findbugs")
217210
private AnalysisType createType(ResolvedJavaType type) {
218-
if (!platformSupported(type)) {
211+
if (!hostVM.platformSupported(this, type)) {
219212
throw new UnsupportedFeatureException("type is not available in this platform: " + type.toJavaName(true));
220213
}
221214
if (sealed && !type.isArray()) {
@@ -380,7 +373,7 @@ public JavaField lookupAllowUnresolved(JavaField rawField) {
380373
}
381374

382375
private AnalysisField createField(ResolvedJavaField field) {
383-
if (!platformSupported(field)) {
376+
if (!hostVM.platformSupported(this, field)) {
384377
throw new UnsupportedFeatureException("field is not available in this platform: " + field.format("%H.%n"));
385378
}
386379
if (sealed) {
@@ -422,7 +415,7 @@ public JavaMethod lookupAllowUnresolved(JavaMethod rawMethod) {
422415
}
423416

424417
private AnalysisMethod createMethod(ResolvedJavaMethod method) {
425-
if (!platformSupported(method)) {
418+
if (!hostVM.platformSupported(this, method)) {
426419
throw new UnsupportedFeatureException("Method " + method.format("%H.%n(%p)" + " is not available in this platform."));
427420
}
428421
if (sealed) {
@@ -436,7 +429,7 @@ private AnalysisMethod createMethod(ResolvedJavaMethod method) {
436429
public AnalysisMethod[] lookup(JavaMethod[] inputs) {
437430
List<AnalysisMethod> result = new ArrayList<>(inputs.length);
438431
for (JavaMethod method : inputs) {
439-
if (platformSupported((ResolvedJavaMethod) method)) {
432+
if (hostVM.platformSupported(this, (ResolvedJavaMethod) method)) {
440433
AnalysisMethod aMethod = lookup(method);
441434
if (aMethod != null) {
442435
result.add(aMethod);
@@ -699,31 +692,7 @@ public AnalysisPolicy analysisPolicy() {
699692
return analysisPolicy;
700693
}
701694

702-
public boolean platformSupported(AnnotatedElement element) {
703-
if (element instanceof ResolvedJavaType) {
704-
Package p = OriginalClassProvider.getJavaClass(getOriginalSnippetReflection(), (ResolvedJavaType) element).getPackage();
705-
if (p != null && !platformSupported(p)) {
706-
return false;
707-
}
708-
}
709-
710-
Platforms platformsAnnotation = GuardedAnnotationAccess.getAnnotation(element, Platforms.class);
711-
if (platform == null || platformsAnnotation == null) {
712-
return true;
713-
}
714-
for (Class<? extends Platform> platformGroup : platformsAnnotation.value()) {
715-
if (platformGroup.isInstance(platform)) {
716-
return true;
717-
}
718-
}
719-
return false;
720-
}
721-
722695
public MetaAccessProvider getOriginalMetaAccess() {
723696
return originalMetaAccess;
724697
}
725-
726-
public Platform getPlatform() {
727-
return platform;
728-
}
729698
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor;
6565

6666
import jdk.vm.ci.meta.JavaKind;
67+
import org.graalvm.nativeimage.Platform;
6768

6869
public class HostedConfiguration {
6970

@@ -129,8 +130,8 @@ public static ObjectLayout createObjectLayout(JavaKind referenceKind) {
129130
}
130131

131132
public SVMHost createHostVM(OptionValues options, ForkJoinPool buildExecutor, ClassLoader classLoader, ClassInitializationSupport classInitializationSupport,
132-
UnsafeAutomaticSubstitutionProcessor automaticSubstitutions) {
133-
return new SVMHost(options, buildExecutor, classLoader, classInitializationSupport, automaticSubstitutions);
133+
UnsafeAutomaticSubstitutionProcessor automaticSubstitutions, Platform platform) {
134+
return new SVMHost(options, buildExecutor, classLoader, classInitializationSupport, automaticSubstitutions, platform);
134135
}
135136

136137
public CompileQueue createCompileQueue(DebugContext debug, FeatureHandler featureHandler, HostedUniverse hostedUniverse,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,12 @@ public static AnalysisUniverse createAnalysisUniverse(OptionValues options, Targ
926926
SubstitutionProcessor aSubstitutions = createAnalysisSubstitutionProcessor(originalMetaAccess, originalSnippetReflection, cEnumProcessor, automaticSubstitutions,
927927
annotationSubstitutions, additionalSubstitutions);
928928

929-
SVMHost hostVM = HostedConfiguration.instance().createHostVM(options, buildExecutor, loader.getClassLoader(), classInitializationSupport, automaticSubstitutions);
929+
SVMHost hostVM = HostedConfiguration.instance().createHostVM(options, buildExecutor, loader.getClassLoader(), classInitializationSupport, automaticSubstitutions, loader.platform);
930930

931931
automaticSubstitutions.init(loader, originalMetaAccess);
932932
AnalysisPolicy analysisPolicy = PointstoOptions.AllocationSiteSensitiveHeap.getValue(options) ? new BytecodeSensitiveAnalysisPolicy(options)
933933
: new DefaultAnalysisPolicy(options);
934-
return new AnalysisUniverse(hostVM, target.wordJavaKind, loader.platform, analysisPolicy, aSubstitutions, originalMetaAccess, originalSnippetReflection,
934+
return new AnalysisUniverse(hostVM, target.wordJavaKind, analysisPolicy, aSubstitutions, originalMetaAccess, originalSnippetReflection,
935935
new SubstrateSnippetReflectionProvider(new SubstrateWordTypes(originalMetaAccess, FrameAccess.getWordKind())));
936936
}
937937

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.lang.ref.Reference;
2929
import java.lang.ref.SoftReference;
3030
import java.lang.ref.WeakReference;
31+
import java.lang.reflect.AnnotatedElement;
3132
import java.lang.reflect.Method;
3233
import java.lang.reflect.Modifier;
3334
import java.util.ArrayList;
@@ -61,6 +62,8 @@
6162
import org.graalvm.compiler.options.OptionValues;
6263
import org.graalvm.compiler.phases.OptimisticOptimizations;
6364
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
65+
import org.graalvm.nativeimage.Platform;
66+
import org.graalvm.nativeimage.Platforms;
6467
import org.graalvm.nativeimage.c.function.RelocatedPointer;
6568
import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess;
6669
import org.graalvm.util.GuardedAnnotationAccess;
@@ -119,7 +122,7 @@ public class SVMHost implements HostVM {
119122
private final ConcurrentHashMap<DynamicHub, AnalysisType> hubToType = new ConcurrentHashMap<>();
120123

121124
private final Map<String, EnumSet<AnalysisType.UsageKind>> forbiddenTypes;
122-
125+
private final Platform platform;
123126
private final OptionValues options;
124127
private final ForkJoinPool executor;
125128
private final ClassLoader classLoader;
@@ -146,7 +149,7 @@ public class SVMHost implements HostVM {
146149
private static final Method getNestHostMethod = JavaVersionUtil.JAVA_SPEC >= 11 ? ReflectionUtil.lookupMethod(Class.class, "getNestHost") : null;
147150

148151
public SVMHost(OptionValues options, ForkJoinPool executor, ClassLoader classLoader, ClassInitializationSupport classInitializationSupport,
149-
UnsafeAutomaticSubstitutionProcessor automaticSubstitutions) {
152+
UnsafeAutomaticSubstitutionProcessor automaticSubstitutions, Platform platform) {
150153
this.options = options;
151154
this.executor = executor;
152155
this.classLoader = classLoader;
@@ -155,6 +158,7 @@ public SVMHost(OptionValues options, ForkJoinPool executor, ClassLoader classLoa
155158
this.classReachabilityListeners = new ArrayList<>();
156159
this.forbiddenTypes = setupForbiddenTypes(options);
157160
this.automaticSubstitutions = automaticSubstitutions;
161+
this.platform = platform;
158162
}
159163

160164
private static Map<String, EnumSet<AnalysisType.UsageKind>> setupForbiddenTypes(OptionValues options) {
@@ -720,7 +724,7 @@ public static class Options {
720724

721725
@Override
722726
public boolean skipInterface(AnalysisUniverse universe, ResolvedJavaType interfaceType, ResolvedJavaType implementingType) {
723-
if (!universe.platformSupported(interfaceType)) {
727+
if (!platformSupported(universe, interfaceType)) {
724728
String message = "The interface " + interfaceType.toJavaName(true) + " is not available in the current platform, but used by " + implementingType.toJavaName(true) + ". " +
725729
"GraalVM before version 21.2 ignored such interfaces, but this was an oversight.";
726730

@@ -736,4 +740,25 @@ public boolean skipInterface(AnalysisUniverse universe, ResolvedJavaType interfa
736740
}
737741
return false;
738742
}
743+
744+
@Override
745+
public boolean platformSupported(AnalysisUniverse universe, AnnotatedElement element) {
746+
if (element instanceof ResolvedJavaType) {
747+
Package p = OriginalClassProvider.getJavaClass(universe.getOriginalSnippetReflection(), (ResolvedJavaType) element).getPackage();
748+
if (p != null && !platformSupported(universe, p)) {
749+
return false;
750+
}
751+
}
752+
753+
Platforms platformsAnnotation = GuardedAnnotationAccess.getAnnotation(element, Platforms.class);
754+
if (platform == null || platformsAnnotation == null) {
755+
return true;
756+
}
757+
for (Class<? extends Platform> platformGroup : platformsAnnotation.value()) {
758+
if (platformGroup.isInstance(platform)) {
759+
return true;
760+
}
761+
}
762+
return false;
763+
}
739764
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/Inflation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private void fillAnnotatedSuperInfo(AnalysisType type, DynamicHub hub) {
414414
private boolean isTypeAllowed(Type t) {
415415
if (t instanceof Class) {
416416
Optional<? extends ResolvedJavaType> resolved = metaAccess.optionalLookupJavaType((Class<?>) t);
417-
return resolved.isPresent() && universe.platformSupported(resolved.get());
417+
return resolved.isPresent() && hostVM.platformSupported(universe, resolved.get());
418418
}
419419
return true;
420420
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionReflectivityFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class SubstitutionReflectivityFilter {
4646
public static boolean shouldExclude(Class<?> classObj, AnalysisMetaAccess metaAccess, AnalysisUniverse universe) {
4747
try {
4848
ResolvedJavaType analysisClass = metaAccess.lookupJavaType(classObj);
49-
if (!universe.platformSupported(analysisClass)) {
49+
if (!universe.hostVM().platformSupported(universe, analysisClass)) {
5050
return true;
5151
} else if (analysisClass.isAnnotationPresent(Delete.class)) {
5252
return true; // accesses would fail at runtime
@@ -60,7 +60,7 @@ public static boolean shouldExclude(Class<?> classObj, AnalysisMetaAccess metaAc
6060
public static boolean shouldExclude(Executable method, AnalysisMetaAccess metaAccess, AnalysisUniverse universe) {
6161
try {
6262
AnalysisMethod aMethod = metaAccess.lookupJavaMethod(method);
63-
if (!universe.platformSupported(aMethod)) {
63+
if (!universe.hostVM().platformSupported(universe, aMethod)) {
6464
return true;
6565
} else if (aMethod.isAnnotationPresent(Delete.class)) {
6666
return true; // accesses would fail at runtime
@@ -83,7 +83,7 @@ public static boolean shouldExclude(Executable method, AnalysisMetaAccess metaAc
8383
public static boolean shouldExclude(Field field, AnalysisMetaAccess metaAccess, AnalysisUniverse universe) {
8484
try {
8585
AnalysisField aField = metaAccess.lookupJavaField(field);
86-
if (!universe.platformSupported(aField)) {
86+
if (!universe.hostVM().platformSupported(universe, aField)) {
8787
return true;
8888
}
8989
if (aField.isAnnotationPresent(Delete.class)) {

substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/WhiteListParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ private AnalysisType resolve(String type) throws UnsupportedPlatformException {
207207
private void verifySupportedOnActivePlatform(Class<?> clz) throws UnsupportedPlatformException {
208208
AnalysisUniverse universe = bigBang.getUniverse();
209209
Package pkg = clz.getPackage();
210-
if (pkg != null && !universe.platformSupported(pkg)) {
210+
if (pkg != null && !universe.hostVM().platformSupported(universe, pkg)) {
211211
throw new UnsupportedPlatformException(clz.getPackage());
212212
}
213213
Class<?> current = clz;
214214
do {
215-
if (!universe.platformSupported(current)) {
215+
if (!universe.hostVM().platformSupported(universe, current)) {
216216
throw new UnsupportedPlatformException(current);
217217
}
218218
current = current.getEnclosingClass();

0 commit comments

Comments
 (0)