--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java Thu Oct 17 20:27:44 2019 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java Thu Oct 17 20:53:35 2019 +0100
@@ -66,6 +66,7 @@
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
+import org.graalvm.compiler.nodes.spi.CoreProviders;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.OptimisticOptimizations;
import org.graalvm.compiler.phases.PhaseSuite;
@@ -73,9 +74,11 @@
import org.graalvm.compiler.phases.VerifyPhase.VerificationError;
import org.graalvm.compiler.phases.contract.VerifyNodeCosts;
import org.graalvm.compiler.phases.tiers.HighTierContext;
-import org.graalvm.compiler.phases.tiers.PhaseContext;
import org.graalvm.compiler.phases.util.Providers;
import org.graalvm.compiler.runtime.RuntimeProvider;
+import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
+import org.graalvm.compiler.test.AddExports;
+import org.graalvm.compiler.test.ModuleSupport;
import jdk.internal.vm.compiler.word.LocationIdentity;
import org.junit.Assert;
import org.junit.Assume;
@@ -97,8 +100,15 @@
* global invariants such as using {@link Object#equals(Object)} to compare certain types instead of
* identity comparisons.
*/
+@AddExports("jdk.internal.vm.ci/*=jdk.aot")
public class CheckGraalInvariants extends GraalCompilerTest {
+ /**
+ * Magic token to denote the classes in the Java runtime image (i.e. in the {@code jrt:/} file
+ * system).
+ */
+ public static final String JRT_CLASS_PATH_ENTRY = "<jrt>";
+
private static boolean shouldVerifyEquals(ResolvedJavaMethod m) {
if (m.getName().equals("identityEquals")) {
ResolvedJavaType c = m.getDeclaringClass();
@@ -118,6 +128,9 @@
public static class InvariantsTool {
protected boolean shouldProcess(String classpathEntry) {
+ if (classpathEntry.equals(JRT_CLASS_PATH_ENTRY)) {
+ return true;
+ }
if (classpathEntry.endsWith(".jar")) {
String name = new File(classpathEntry).getName();
return name.contains("jvmci") || name.contains("graal") || name.contains("jdk.internal.vm.compiler");
@@ -127,10 +140,10 @@
protected String getClassPath() {
String bootclasspath;
- if (Java8OrEarlier) {
+ if (JavaVersionUtil.JAVA_SPEC <= 8) {
bootclasspath = System.getProperty("sun.boot.class.path");
} else {
- bootclasspath = System.getProperty("jdk.module.path") + File.pathSeparatorChar + System.getProperty("jdk.module.upgrade.path");
+ bootclasspath = JRT_CLASS_PATH_ENTRY;
}
return bootclasspath;
}
@@ -139,7 +152,7 @@
if (className.equals("module-info") || className.startsWith("META-INF.versions.")) {
return false;
}
- if (!Java8OrEarlier) {
+ if (JavaVersionUtil.JAVA_SPEC > 8) {
// @formatter:off
/*
* Work around to prevent:
@@ -207,19 +220,8 @@
for (String path : bootclasspath.split(File.pathSeparator)) {
if (tool.shouldProcess(path)) {
try {
- final ZipFile zipFile = new ZipFile(new File(path));
- for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements();) {
- final ZipEntry zipEntry = entry.nextElement();
- String name = zipEntry.getName();
- if (name.endsWith(".class") && !name.startsWith("META-INF/versions/")) {
- String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
- if (isInNativeImage(className)) {
- /*
- * Native Image is an external tool and does not need to follow the
- * Graal invariants.
- */
- continue;
- }
+ if (path.equals(JRT_CLASS_PATH_ENTRY)) {
+ for (String className : ModuleSupport.getJRTGraalClassNames()) {
if (isGSON(className)) {
/*
* GSON classes are compiled with old JDK
@@ -228,6 +230,29 @@
}
classNames.add(className);
}
+ } else {
+ final ZipFile zipFile = new ZipFile(new File(path));
+ for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements();) {
+ final ZipEntry zipEntry = entry.nextElement();
+ String name = zipEntry.getName();
+ if (name.endsWith(".class") && !name.startsWith("META-INF/versions/")) {
+ String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
+ if (isInNativeImage(className)) {
+ /*
+ * Native Image is an external tool and does not need to follow
+ * the Graal invariants.
+ */
+ continue;
+ }
+ if (isGSON(className)) {
+ /*
+ * GSON classes are compiled with old JDK
+ */
+ continue;
+ }
+ classNames.add(className);
+ }
+ }
}
} catch (IOException ex) {
Assert.fail(ex.toString());
@@ -247,7 +272,7 @@
List<String> errors = Collections.synchronizedList(new ArrayList<>());
- List<VerifyPhase<PhaseContext>> verifiers = new ArrayList<>();
+ List<VerifyPhase<CoreProviders>> verifiers = new ArrayList<>();
// If you add a new type to test here, be sure to add appropriate
// methods to the BadUsageWithEquals class below
@@ -270,6 +295,7 @@
verifiers.add(new VerifySystemPropertyUsage());
verifiers.add(new VerifyInstanceOfUsage());
verifiers.add(new VerifyGraphAddUsage());
+ verifiers.add(new VerifyBufferUsage());
verifiers.add(new VerifyGetOptionsUsage());
verifiers.add(new VerifyUnsafeAccess());
@@ -312,8 +338,12 @@
ResolvedJavaType type = metaAccess.lookupJavaType(c);
List<ResolvedJavaMethod> methods = new ArrayList<>();
- methods.addAll(Arrays.asList(type.getDeclaredMethods()));
- methods.addAll(Arrays.asList(type.getDeclaredConstructors()));
+ try {
+ methods.addAll(Arrays.asList(type.getDeclaredMethods()));
+ methods.addAll(Arrays.asList(type.getDeclaredConstructors()));
+ } catch (Throwable e) {
+ errors.add(String.format("Error while checking %s:%n%s", className, printStackTraceToString(e)));
+ }
ResolvedJavaMethod clinit = type.getClassInitializer();
if (clinit != null) {
methods.add(clinit);
@@ -402,6 +432,16 @@
try {
Class<?> c = Class.forName(className, true, CheckGraalInvariants.class.getClassLoader());
classes.add(c);
+ } catch (UnsupportedClassVersionError e) {
+ // graal-test.jar can contain classes compiled for different Java versions
+ } catch (NoClassDefFoundError e) {
+ if (!e.getMessage().contains("Could not initialize class")) {
+ throw e;
+ } else {
+ // A second or later attempt to initialize a class
+ // results in this confusing error where the
+ // original cause of initialization failure is lost
+ }
} catch (Throwable t) {
tool.handleClassLoadingException(t);
}
@@ -413,14 +453,14 @@
* @param metaAccess
* @param verifiers
*/
- private static void checkClass(Class<?> c, MetaAccessProvider metaAccess, List<VerifyPhase<PhaseContext>> verifiers) {
+ private static void checkClass(Class<?> c, MetaAccessProvider metaAccess, List<VerifyPhase<CoreProviders>> verifiers) {
if (Node.class.isAssignableFrom(c)) {
if (c.getAnnotation(NodeInfo.class) == null) {
throw new AssertionError(String.format("Node subclass %s requires %s annotation", c.getName(), NodeClass.class.getSimpleName()));
}
VerifyNodeCosts.verifyNodeClass(c);
}
- for (VerifyPhase<PhaseContext> verifier : verifiers) {
+ for (VerifyPhase<CoreProviders> verifier : verifiers) {
verifier.verifyClass(c, metaAccess);
}
}
@@ -445,8 +485,8 @@
/**
* Checks the invariants for a single graph.
*/
- private static void checkGraph(List<VerifyPhase<PhaseContext>> verifiers, HighTierContext context, StructuredGraph graph) {
- for (VerifyPhase<PhaseContext> verifier : verifiers) {
+ private static void checkGraph(List<VerifyPhase<CoreProviders>> verifiers, HighTierContext context, StructuredGraph graph) {
+ for (VerifyPhase<CoreProviders> verifier : verifiers) {
if (!(verifier instanceof VerifyUsageWithEquals) || shouldVerifyEquals(graph.method())) {
verifier.apply(graph, context);
} else {