8179025: Exclude deployment modules from FieldSetAccessibleTest.java and VerifyJimage.java
Reviewed-by: alanb
This commit is contained in:
parent
c122be4029
commit
b52f472fcf
@ -124,7 +124,6 @@ java/beans/Introspector/8132566/OverrideUserDefPropertyInfoTest.java 8132565 gen
|
||||
# jdk_lang
|
||||
|
||||
java/lang/StringCoding/CheckEncodings.sh 7008363 generic-all
|
||||
java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java 8178776 generic-all
|
||||
|
||||
jdk/internal/misc/JavaLangAccess/NewUnsafeString.java 8176188 generic-all
|
||||
|
||||
@ -256,8 +255,6 @@ tools/jimage/JImageExtractTest.java 8170120 generic-
|
||||
tools/jimage/JImageListTest.java 8170120 generic-all
|
||||
tools/jimage/JImageVerifyTest.java 8170120 generic-all
|
||||
|
||||
tools/jimage/VerifyJimage.java 8178776 generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_jdi
|
||||
|
@ -24,6 +24,7 @@
|
||||
import java.io.FilePermission;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.module.ModuleFinder;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@ -46,9 +47,11 @@ import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.PropertyPermission;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.internal.module.Modules;
|
||||
@ -257,9 +260,11 @@ public class FieldSetAccessibleTest {
|
||||
|
||||
final FileSystem jrt;
|
||||
final Path root;
|
||||
final Set<String> modules;
|
||||
ClassNameJrtStreamBuilder() {
|
||||
jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
root = jrt.getPath("/modules");
|
||||
jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
root = jrt.getPath("/modules");
|
||||
modules = systemModules();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -267,7 +272,7 @@ public class FieldSetAccessibleTest {
|
||||
try {
|
||||
return Files.walk(root)
|
||||
.filter(p -> p.getNameCount() > 2)
|
||||
.filter(p -> ModuleLayer.boot().findModule(p.getName(1).toString()).isPresent())
|
||||
.filter(p -> modules.contains(p.getName(1).toString()))
|
||||
.map(p -> p.subpath(2, p.getNameCount()))
|
||||
.map(p -> p.toString())
|
||||
.filter(s -> s.endsWith(".class") && !s.endsWith("module-info.class"))
|
||||
@ -276,6 +281,17 @@ public class FieldSetAccessibleTest {
|
||||
throw new UncheckedIOException("Unable to walk \"/modules\"", x);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Filter deployment modules
|
||||
*/
|
||||
static Set<String> systemModules() {
|
||||
Set<String> mods = Set.of("javafx.deploy", "jdk.deploy", "jdk.plugin", "jdk.javaws");
|
||||
return ModuleFinder.ofSystem().findAll().stream()
|
||||
.map(mref -> mref.descriptor().name())
|
||||
.filter(mn -> !mods.contains(mn))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
// Test with or without a security manager
|
||||
|
@ -35,6 +35,7 @@ import jdk.internal.module.ModuleInfo;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.module.Configuration;
|
||||
import java.lang.module.ModuleDescriptor;
|
||||
import java.lang.module.ModuleDescriptor.Exports;
|
||||
import java.lang.module.ModuleDescriptor.Opens;
|
||||
@ -69,9 +70,8 @@ public class JdkQualifiedExportTest {
|
||||
|
||||
static Set<String> KNOWN_EXCEPTIONS =
|
||||
Set.of("java.xml/com.sun.xml.internal.stream.writers",
|
||||
"jdk.internal.vm.ci/jdk.vm.ci.services",
|
||||
"jdk.jsobject/jdk.internal.netscape.javascript.spi");
|
||||
static Set<String> DEPLOY_MODULES =
|
||||
Set.of("jdk.deploy", "jdk.plugin", "jdk.javaws");
|
||||
|
||||
static void checkExports(ModuleDescriptor md) {
|
||||
// build a map of upgradeable module to Exports that are qualified to it
|
||||
@ -80,8 +80,7 @@ public class JdkQualifiedExportTest {
|
||||
md.exports().stream()
|
||||
.filter(Exports::isQualified)
|
||||
.forEach(e -> e.targets().stream()
|
||||
.filter(mn -> !HashedModules.contains(mn) &&
|
||||
ModuleFinder.ofSystem().find(mn).isPresent())
|
||||
.filter(mn -> accept(md, mn))
|
||||
.forEach(t -> targetToExports.computeIfAbsent(t, _k -> new HashSet<>())
|
||||
.add(e)));
|
||||
|
||||
@ -97,10 +96,9 @@ public class JdkQualifiedExportTest {
|
||||
exp.source(), e.getKey()));
|
||||
});
|
||||
|
||||
// workaround until all qualified exports to upgradeable modules
|
||||
// are eliminated
|
||||
// no qualified exports to upgradeable modules are expected
|
||||
// except the known exception cases
|
||||
if (targetToExports.entrySet().stream()
|
||||
.filter(e -> !DEPLOY_MODULES.contains(e.getKey()))
|
||||
.flatMap(e -> e.getValue().stream())
|
||||
.anyMatch(e -> !KNOWN_EXCEPTIONS.contains(mn + "/" + e.source()))) {
|
||||
throw new RuntimeException(mn + " can't export package to upgradeable modules");
|
||||
@ -115,8 +113,7 @@ public class JdkQualifiedExportTest {
|
||||
md.opens().stream()
|
||||
.filter(Opens::isQualified)
|
||||
.forEach(e -> e.targets().stream()
|
||||
.filter(mn -> !HashedModules.contains(mn) &&
|
||||
ModuleFinder.ofSystem().find(mn).isPresent())
|
||||
.filter(mn -> accept(md, mn))
|
||||
.forEach(t -> targetToOpens.computeIfAbsent(t, _k -> new HashSet<>())
|
||||
.add(e)));
|
||||
|
||||
@ -136,6 +133,23 @@ public class JdkQualifiedExportTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if target is an upgradeable module but not required
|
||||
* by the source module directly and indirectly.
|
||||
*/
|
||||
private static boolean accept(ModuleDescriptor source, String target) {
|
||||
if (HashedModules.contains(target))
|
||||
return false;
|
||||
|
||||
if (!ModuleFinder.ofSystem().find(target).isPresent())
|
||||
return false;
|
||||
|
||||
Configuration cf = Configuration.empty().resolve(ModuleFinder.of(),
|
||||
ModuleFinder.ofSystem(),
|
||||
Set.of(source.name()));
|
||||
return !cf.findModule(target).isPresent();
|
||||
}
|
||||
|
||||
private static class HashedModules {
|
||||
static Set<String> HASHED_MODULES = hashedModules();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -49,7 +49,7 @@ import jdk.internal.jimage.ImageLocation;
|
||||
* @test
|
||||
* @summary Verify jimage
|
||||
* @modules java.base/jdk.internal.jimage
|
||||
* @run main/othervm --add-modules=ALL-SYSTEM,jdk.incubator.httpclient VerifyJimage
|
||||
* @run main/othervm --add-modules ALL-SYSTEM VerifyJimage
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -76,8 +76,8 @@ public class VerifyJimage {
|
||||
|
||||
long start = System.nanoTime();
|
||||
int numThreads = Integer.getInteger("jdk.test.threads", 1);
|
||||
List<JImageReader> readers = newJImageReaders();
|
||||
VerifyJimage verify = new VerifyJimage(readers, numThreads);
|
||||
JImageReader reader = newJImageReader();
|
||||
VerifyJimage verify = new VerifyJimage(reader, numThreads);
|
||||
if (args.length == 0) {
|
||||
// load classes from jimage
|
||||
verify.loadClasses();
|
||||
@ -90,9 +90,7 @@ public class VerifyJimage {
|
||||
}
|
||||
verify.waitForCompletion();
|
||||
long end = System.nanoTime();
|
||||
int entries = readers.stream()
|
||||
.mapToInt(JImageReader::entries)
|
||||
.sum();
|
||||
int entries = reader.entries();
|
||||
System.out.format("%d entries %d files verified: %d ms %d errors%n",
|
||||
entries, verify.count.get(),
|
||||
TimeUnit.NANOSECONDS.toMillis(end - start), failed.size());
|
||||
@ -105,11 +103,11 @@ public class VerifyJimage {
|
||||
}
|
||||
|
||||
private final AtomicInteger count = new AtomicInteger(0);
|
||||
private final List<JImageReader> readers;
|
||||
private final JImageReader reader;
|
||||
private final ExecutorService pool;
|
||||
|
||||
VerifyJimage(List<JImageReader> readers, int numThreads) {
|
||||
this.readers = readers;
|
||||
VerifyJimage(JImageReader reader, int numThreads) {
|
||||
this.reader = reader;
|
||||
this.pool = Executors.newFixedThreadPool(numThreads);
|
||||
}
|
||||
|
||||
@ -132,7 +130,7 @@ public class VerifyJimage {
|
||||
-> !Files.isDirectory(p) &&
|
||||
!mdir.relativize(p).toString().startsWith("_") &&
|
||||
!p.getFileName().toString().equals("MANIFEST.MF"))
|
||||
.forEach(p -> compare(mdir, p, readers));
|
||||
.forEach(p -> compare(mdir, p, reader));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
@ -154,7 +152,7 @@ public class VerifyJimage {
|
||||
"jdk.jdi/META-INF/services/com.sun.jdi.connect.Connector"
|
||||
);
|
||||
|
||||
private void compare(Path mdir, Path p, List<JImageReader> readers) {
|
||||
private void compare(Path mdir, Path p, JImageReader reader) {
|
||||
String entry = p.getFileName().toString().equals(MODULE_INFO)
|
||||
? mdir.getFileName().toString() + "/" + MODULE_INFO
|
||||
: mdir.relativize(p).toString().replace(File.separatorChar, '/');
|
||||
@ -167,52 +165,55 @@ public class VerifyJimage {
|
||||
return;
|
||||
}
|
||||
|
||||
String jimage = "modules";
|
||||
JImageReader reader = readers.stream()
|
||||
.filter(r -> r.findLocation(entry) != null)
|
||||
.filter(r -> jimage.isEmpty() || r.imageName().equals(jimage))
|
||||
.findFirst().orElse(null);
|
||||
if (reader == null) {
|
||||
failed.add(entry + " not found: " + p.getFileName().toString());
|
||||
} else {
|
||||
if (reader.findLocation(entry) != null) {
|
||||
reader.compare(entry, p);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadClasses() {
|
||||
ClassLoader loader = ClassLoader.getSystemClassLoader();
|
||||
for (JImageReader reader : readers) {
|
||||
Arrays.stream(reader.getEntryNames())
|
||||
.filter(n -> n.endsWith(".class") && !n.endsWith(MODULE_INFO))
|
||||
.forEach(n -> {
|
||||
String cn = removeModule(n).replaceAll("\\.class$", "").replace('/', '.');
|
||||
count.incrementAndGet();
|
||||
try {
|
||||
System.out.println("Loading " + cn);
|
||||
Class.forName(cn, false, loader);
|
||||
} catch (VerifyError ve) {
|
||||
System.err.println("VerifyError for " + cn);
|
||||
failed.add(reader.imageName() + ": " + cn + " not verified: " + ve.getMessage());
|
||||
} catch (ClassNotFoundException e) {
|
||||
failed.add(reader.imageName() + ": " + cn + " not found");
|
||||
}
|
||||
});
|
||||
Stream.of(reader.getEntryNames())
|
||||
.filter(this::accept)
|
||||
.map(this::toClassName)
|
||||
.forEach(cn -> {
|
||||
count.incrementAndGet();
|
||||
try {
|
||||
System.out.println("Loading " + cn);
|
||||
Class.forName(cn, false, loader);
|
||||
} catch (VerifyError ve) {
|
||||
System.err.println("VerifyError for " + cn);
|
||||
failed.add(reader.imageName() + ": " + cn + " not verified: " + ve.getMessage());
|
||||
} catch (ClassNotFoundException e) {
|
||||
failed.add(reader.imageName() + ": " + cn + " not found");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String toClassName(String entry) {
|
||||
int index = entry.indexOf('/', 1);
|
||||
return entry.substring(index + 1, entry.length())
|
||||
.replaceAll("\\.class$", "").replace('/', '.');
|
||||
}
|
||||
|
||||
private static Set<String> DEPLOY_MODULES =
|
||||
Set.of("javafx.deploy", "jdk.deploy", "jdk.plugin", "jdk.javaws");
|
||||
|
||||
private boolean accept(String entry) {
|
||||
int index = entry.indexOf('/', 1);
|
||||
String mn = index > 1 ? entry.substring(1, index) : "";
|
||||
// filter deployment modules
|
||||
|
||||
if (mn.isEmpty() || DEPLOY_MODULES.contains(mn)) {
|
||||
return false;
|
||||
}
|
||||
return entry.endsWith(".class") && !entry.endsWith(MODULE_INFO);
|
||||
}
|
||||
|
||||
private String removeModule(String path) {
|
||||
int index = path.indexOf('/', 1);
|
||||
return path.substring(index + 1, path.length());
|
||||
}
|
||||
|
||||
private static List<JImageReader> newJImageReaders() throws IOException {
|
||||
private static JImageReader newJImageReader() throws IOException {
|
||||
String home = System.getProperty("java.home");
|
||||
Path jimage = Paths.get(home, "lib", "modules");
|
||||
JImageReader reader = new JImageReader(jimage);
|
||||
List<JImageReader> result = new ArrayList<>();
|
||||
System.out.println("opened " + jimage);
|
||||
result.add(reader);
|
||||
return result;
|
||||
return new JImageReader(jimage);
|
||||
}
|
||||
|
||||
static class JImageReader extends BasicImageReader {
|
||||
|
Loading…
x
Reference in New Issue
Block a user