27 import java.util.regex.Matcher; |
27 import java.util.regex.Matcher; |
28 import java.util.regex.Pattern; |
28 import java.util.regex.Pattern; |
29 |
29 |
30 import org.graalvm.compiler.nodes.StructuredGraph; |
30 import org.graalvm.compiler.nodes.StructuredGraph; |
31 import org.graalvm.compiler.nodes.java.MethodCallTargetNode; |
31 import org.graalvm.compiler.nodes.java.MethodCallTargetNode; |
|
32 import org.graalvm.compiler.nodes.spi.CoreProviders; |
32 import org.graalvm.compiler.phases.VerifyPhase; |
33 import org.graalvm.compiler.phases.VerifyPhase; |
33 import org.graalvm.compiler.phases.tiers.PhaseContext; |
|
34 |
34 |
35 import jdk.vm.ci.meta.MetaAccessProvider; |
35 import jdk.vm.ci.meta.MetaAccessProvider; |
36 import jdk.vm.ci.meta.ResolvedJavaMethod; |
36 import jdk.vm.ci.meta.ResolvedJavaMethod; |
37 import jdk.vm.ci.meta.ResolvedJavaType; |
37 import jdk.vm.ci.meta.ResolvedJavaType; |
38 import jdk.vm.ci.services.Services; |
38 import jdk.vm.ci.services.Services; |
41 * Checks against calls to {@link System#getProperty(String)}, |
41 * Checks against calls to {@link System#getProperty(String)}, |
42 * {@link System#getProperty(String, String)} and {@link System#getProperties()}. System properties |
42 * {@link System#getProperty(String, String)} and {@link System#getProperties()}. System properties |
43 * can be modified by application code so {@link Services#getSavedProperties()} should be used |
43 * can be modified by application code so {@link Services#getSavedProperties()} should be used |
44 * instead. |
44 * instead. |
45 */ |
45 */ |
46 public class VerifySystemPropertyUsage extends VerifyPhase<PhaseContext> { |
46 public class VerifySystemPropertyUsage extends VerifyPhase<CoreProviders> { |
47 |
47 |
48 static final Class<?>[] BOXES = {Integer.class, Long.class, Boolean.class, Float.class, Double.class}; |
48 static final Class<?>[] BOXES = {Integer.class, Long.class, Boolean.class, Float.class, Double.class}; |
49 static final int JVMCI_VERSION_MAJOR; |
49 static final int JVMCI_VERSION_MAJOR; |
50 static final int JVMCI_VERSION_MINOR; |
50 static final int JVMCI_VERSION_MINOR; |
51 static { |
51 static { |
63 JVMCI_VERSION_MAJOR = major; |
63 JVMCI_VERSION_MAJOR = major; |
64 JVMCI_VERSION_MINOR = minor; |
64 JVMCI_VERSION_MINOR = minor; |
65 } |
65 } |
66 |
66 |
67 @Override |
67 @Override |
68 protected void verify(StructuredGraph graph, PhaseContext context) { |
68 protected void verify(StructuredGraph graph, CoreProviders context) { |
69 MetaAccessProvider metaAccess = context.getMetaAccess(); |
69 MetaAccessProvider metaAccess = context.getMetaAccess(); |
70 final ResolvedJavaType systemType = metaAccess.lookupJavaType(System.class); |
70 final ResolvedJavaType systemType = metaAccess.lookupJavaType(System.class); |
71 final ResolvedJavaType[] boxTypes = new ResolvedJavaType[BOXES.length]; |
71 final ResolvedJavaType[] boxTypes = new ResolvedJavaType[BOXES.length]; |
72 for (int i = 0; i < boxTypes.length; i++) { |
72 for (int i = 0; i < boxTypes.length; i++) { |
73 boxTypes[i] = metaAccess.lookupJavaType(BOXES[i]); |
73 boxTypes[i] = metaAccess.lookupJavaType(BOXES[i]); |
85 return; |
85 return; |
86 } |
86 } |
87 } else if (holderQualified.equals("org.graalvm.compiler.hotspot.JVMCIVersionCheck") && caller.getName().equals("main")) { |
87 } else if (holderQualified.equals("org.graalvm.compiler.hotspot.JVMCIVersionCheck") && caller.getName().equals("main")) { |
88 // The main method in JVMCIVersionCheck is only called from the shell |
88 // The main method in JVMCIVersionCheck is only called from the shell |
89 return; |
89 return; |
90 } else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("org.graalvm.polyglot")) { |
90 } else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("org.graalvm.polyglot") || packageName.startsWith("org.graalvm.home")) { |
91 // Truffle and Polyglot do not depend on JVMCI so cannot use |
91 // Truffle and SDK do not depend on JVMCI so they cannot use |
92 // Services.getSavedProperties() |
92 // Services.getSavedProperties() |
93 return; |
93 return; |
94 } else if (packageName.startsWith("com.oracle.svm")) { |
94 } else if (packageName.startsWith("com.oracle.svm")) { |
95 // SVM must read system properties in: |
95 // SVM must read system properties in: |
96 // * its JDK substitutions to mimic required JDK semantics |
96 // * its JDK substitutions to mimic required JDK semantics |
97 // * native-image for config info |
97 // * native-image for config info |
|
98 return; |
|
99 } else if (packageName.startsWith("jdk.tools.jaotc")) { |
|
100 // Workaround since jdk.internal.vm.ci/jdk.vm.ci.services is not exported to jdk.aot. |
|
101 // The jaotc launcher dynamically adds these exports. |
98 return; |
102 return; |
99 } |
103 } |
100 for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) { |
104 for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) { |
101 ResolvedJavaMethod callee = t.targetMethod(); |
105 ResolvedJavaMethod callee = t.targetMethod(); |
102 if (callee.getDeclaringClass().equals(systemType)) { |
106 if (callee.getDeclaringClass().equals(systemType)) { |