< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java

Print this page
rev 56282 : [mq]: graal

*** 75,84 **** --- 75,86 ---- import org.graalvm.compiler.phases.contract.VerifyNodeCosts; import org.graalvm.compiler.phases.tiers.HighTierContext; 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; import org.junit.Test;
*** 96,107 **** --- 98,116 ---- /** * Checks that all classes in *graal*.jar and *jvmci*.jar entries on the boot class path comply with * 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(); if (c.getName().equals("Ljdk/vm/ci/meta/AbstractValue;") || c.getName().equals("jdk/vm/ci/meta/Value")) { return false;
*** 117,126 **** --- 126,138 ---- } 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"); } return false;
*** 129,139 **** protected String getClassPath() { String bootclasspath; 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"); } return bootclasspath; } protected boolean shouldLoadClass(String className) { --- 141,151 ---- protected String getClassPath() { String bootclasspath; if (JavaVersionUtil.JAVA_SPEC <= 8) { bootclasspath = System.getProperty("sun.boot.class.path"); } else { ! bootclasspath = JRT_CLASS_PATH_ENTRY; } return bootclasspath; } protected boolean shouldLoadClass(String className) {
*** 206,225 **** final List<String> classNames = new ArrayList<>(); 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 (isGSON(className)) { /* --- 218,248 ---- final List<String> classNames = new ArrayList<>(); for (String path : bootclasspath.split(File.pathSeparator)) { if (tool.shouldProcess(path)) { try { + if (path.equals(JRT_CLASS_PATH_ENTRY)) { + for (String className : ModuleSupport.getJRTGraalClassNames()) { + if (isGSON(className)) { + /* + * GSON classes are compiled with old JDK + */ + continue; + } + 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)) { /*
*** 228,237 **** --- 251,261 ---- continue; } classNames.add(className); } } + } } catch (IOException ex) { Assert.fail(ex.toString()); } } }
*** 312,323 **** --- 336,351 ---- } }); ResolvedJavaType type = metaAccess.lookupJavaType(c); List<ResolvedJavaMethod> methods = new ArrayList<>(); + 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); }
< prev index next >