< prev index next >

test/tools/jimage/VerifyJimage.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2014, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 47,57 **** /* * @test * @summary Verify jimage * @modules java.base/jdk.internal.jimage ! * @run main/othervm --add-modules=ALL-SYSTEM,jdk.incubator.httpclient VerifyJimage */ /** * This test runs in two modes: * (1) No argument: it verifies the jimage by loading all classes in the runtime --- 47,57 ---- /* * @test * @summary Verify jimage * @modules java.base/jdk.internal.jimage ! * @run main/othervm --add-modules ALL-SYSTEM VerifyJimage */ /** * This test runs in two modes: * (1) No argument: it verifies the jimage by loading all classes in the runtime
*** 74,85 **** return; } long start = System.nanoTime(); int numThreads = Integer.getInteger("jdk.test.threads", 1); ! List<JImageReader> readers = newJImageReaders(); ! VerifyJimage verify = new VerifyJimage(readers, numThreads); if (args.length == 0) { // load classes from jimage verify.loadClasses(); } else { Path dir = Paths.get(args[0]); --- 74,85 ---- return; } long start = System.nanoTime(); int numThreads = Integer.getInteger("jdk.test.threads", 1); ! JImageReader reader = newJImageReader(); ! VerifyJimage verify = new VerifyJimage(reader, numThreads); if (args.length == 0) { // load classes from jimage verify.loadClasses(); } else { Path dir = Paths.get(args[0]);
*** 88,100 **** } verify.compareExplodedModules(dir); } verify.waitForCompletion(); long end = System.nanoTime(); ! int entries = readers.stream() ! .mapToInt(JImageReader::entries) ! .sum(); System.out.format("%d entries %d files verified: %d ms %d errors%n", entries, verify.count.get(), TimeUnit.NANOSECONDS.toMillis(end - start), failed.size()); for (String f : failed) { System.err.println(f); --- 88,98 ---- } verify.compareExplodedModules(dir); } verify.waitForCompletion(); long end = System.nanoTime(); ! 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()); for (String f : failed) { System.err.println(f);
*** 103,117 **** throw new AssertionError("Test failed"); } } private final AtomicInteger count = new AtomicInteger(0); ! private final List<JImageReader> readers; private final ExecutorService pool; ! VerifyJimage(List<JImageReader> readers, int numThreads) { ! this.readers = readers; this.pool = Executors.newFixedThreadPool(numThreads); } private void waitForCompletion() throws InterruptedException { pool.shutdown(); --- 101,115 ---- throw new AssertionError("Test failed"); } } private final AtomicInteger count = new AtomicInteger(0); ! private final JImageReader reader; private final ExecutorService pool; ! VerifyJimage(JImageReader reader, int numThreads) { ! this.reader = reader; this.pool = Executors.newFixedThreadPool(numThreads); } private void waitForCompletion() throws InterruptedException { pool.shutdown();
*** 130,140 **** try { Files.find(mdir, Integer.MAX_VALUE, (Path p, BasicFileAttributes attr) -> !Files.isDirectory(p) && !mdir.relativize(p).toString().startsWith("_") && !p.getFileName().toString().equals("MANIFEST.MF")) ! .forEach(p -> compare(mdir, p, readers)); } catch (IOException e) { throw new UncheckedIOException(e); } } }); --- 128,138 ---- try { Files.find(mdir, Integer.MAX_VALUE, (Path p, BasicFileAttributes attr) -> !Files.isDirectory(p) && !mdir.relativize(p).toString().startsWith("_") && !p.getFileName().toString().equals("MANIFEST.MF")) ! .forEach(p -> compare(mdir, p, reader)); } catch (IOException e) { throw new UncheckedIOException(e); } } });
*** 152,162 **** private final List<String> APP_RESOURCES = Arrays.asList( "jdk.hotspot.agent/META-INF/services/com.sun.jdi.connect.Connector", "jdk.jdi/META-INF/services/com.sun.jdi.connect.Connector" ); ! private void compare(Path mdir, Path p, List<JImageReader> readers) { String entry = p.getFileName().toString().equals(MODULE_INFO) ? mdir.getFileName().toString() + "/" + MODULE_INFO : mdir.relativize(p).toString().replace(File.separatorChar, '/'); count.incrementAndGet(); --- 150,160 ---- private final List<String> APP_RESOURCES = Arrays.asList( "jdk.hotspot.agent/META-INF/services/com.sun.jdi.connect.Connector", "jdk.jdi/META-INF/services/com.sun.jdi.connect.Connector" ); ! 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, '/'); count.incrementAndGet();
*** 165,193 **** // skip until the service config file is merged System.out.println("Skipped " + file); 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 { 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) { --- 163,183 ---- // skip until the service config file is merged System.out.println("Skipped " + file); return; } ! if (reader.findLocation(entry) != null) { reader.compare(entry, p); } } private void loadClasses() { ClassLoader loader = ClassLoader.getSystemClassLoader(); ! 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) {
*** 196,220 **** } catch (ClassNotFoundException e) { failed.add(reader.imageName() + ": " + cn + " not found"); } }); } } ! private String removeModule(String path) { ! int index = path.indexOf('/', 1); ! return path.substring(index + 1, path.length()); } ! private static List<JImageReader> newJImageReaders() 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; } static class JImageReader extends BasicImageReader { final Path jimage; JImageReader(Path p) throws IOException { --- 186,218 ---- } 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 boolean accept(String entry) { ! int index = entry.indexOf('/', 1); ! String mn = index > 1 ? entry.substring(1, index) : ""; ! // filter deployment modules ! if (mn.isEmpty() || mn.contains("deploy") || ! mn.contains("javaws") || mn.contains("plugin")) { ! return false; ! } ! return entry.endsWith(".class") && !entry.endsWith(MODULE_INFO); } ! private static JImageReader newJImageReader() throws IOException { String home = System.getProperty("java.home"); Path jimage = Paths.get(home, "lib", "modules"); System.out.println("opened " + jimage); ! return new JImageReader(jimage); } static class JImageReader extends BasicImageReader { final Path jimage; JImageReader(Path p) throws IOException {
< prev index next >