test/jdk/tools/lib/tests/JImageValidator.java
author ihse
Wed, 28 Feb 2018 21:16:11 +0100
changeset 49070 d7859531621b
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198751: Refactor SetupNativeCompilation to take NAME and TYPE Reviewed-by: tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
package tests;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.io.ByteArrayInputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.io.File;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.io.FileInputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.io.InputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.Properties;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import com.sun.tools.classfile.ClassFile;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import com.sun.tools.classfile.ConstantPoolException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.internal.jimage.BasicImageReader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import jdk.internal.jimage.ImageLocation;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * JDK Modular image validator
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
public class JImageValidator {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    private static final String[] dirs = {"bin", "lib"};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    private final File rootDir;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private final List<String> expectedLocations;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    private final String module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private long moduleExecutionTime;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private long javaExecutionTime;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private final List<String> unexpectedPaths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private final List<String> unexpectedFiles;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private final String[] expectedFiles;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    public JImageValidator(String module, List<String> expectedLocations,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
            File rootDir,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
            List<String> unexpectedPaths,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
            List<String> unexpectedFiles) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        this(module, expectedLocations, rootDir, unexpectedPaths, unexpectedFiles, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    public JImageValidator(String module, List<String> expectedLocations,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
            File rootDir,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            List<String> unexpectedPaths,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            List<String> unexpectedFiles,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            String[] expectedFiles) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        if (!rootDir.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            throw new IOException("Image root dir not found " +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                    rootDir.getAbsolutePath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        this.expectedLocations = expectedLocations;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        this.rootDir = rootDir;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        this.module = module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        this.unexpectedPaths = unexpectedPaths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        this.unexpectedFiles = unexpectedFiles;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        this.expectedFiles = expectedFiles == null ? new String[0] : expectedFiles;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    public void validate() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        for (String d : dirs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            File dir = new File(rootDir, d);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            if (!dir.isDirectory()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                throw new IOException("Invalid directory " + d);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        //check jimage file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        Path path = rootDir.toPath().resolve("lib").resolve("modules");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        if (!Files.isRegularFile(path)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
            throw new IOException(path + " No jimage file generated");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        // Check binary file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        File launcher = new File(rootDir, "bin" + File.separator + module);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        if (launcher.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            ProcessBuilder builder = new ProcessBuilder("sh", launcher.getAbsolutePath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            long t = System.currentTimeMillis();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            Process process = builder.inheritIO().start();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
            int ret = waitFor(process);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            moduleExecutionTime += System.currentTimeMillis() - t;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            if (ret != 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                throw new IOException("Image " + module + " execution failed, check logs.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        for (String f : expectedFiles) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
            File dd = new File(rootDir, f);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            if (!dd.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                throw new IOException("Expected File " + f + " not found");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        //Walk and check that unexpected files are not there
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        try (java.util.stream.Stream<Path> stream = Files.walk(rootDir.toPath())) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            stream.forEach((p) -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                for (String u : unexpectedFiles) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                    if (p.toString().equals(u)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                        throw new RuntimeException("Seen unexpected path " + p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        File javaLauncher = new File(rootDir, "bin" + File.separator +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                (isWindows() ? "java.exe" : "java"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        if (javaLauncher.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
            ProcessBuilder builder = new ProcessBuilder(javaLauncher.getAbsolutePath(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                    "-version");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            long t = System.currentTimeMillis();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            Process process = builder.start();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            int ret = waitFor(process);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            javaExecutionTime += System.currentTimeMillis() - t;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            if (ret != 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                throw new RuntimeException("java launcher execution failed, check logs.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            throw new IOException("java launcher not found.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        // Check release file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        File release = new File(rootDir, "release");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        if (!release.exists()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            throw new IOException("Release file not generated");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            Properties props = new Properties();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            try (FileInputStream fs = new FileInputStream(release)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                props.load(fs);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                String s = props.getProperty("MODULES");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                if (s == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                    throw new IOException("No MODULES property in release");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                if (!s.contains(module)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                    throw new IOException("Module not found in release file " + s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    private int waitFor(Process process) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            return process.waitFor();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        } catch (InterruptedException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            throw new RuntimeException(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
    private static boolean isWindows() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        return System.getProperty("os.name").startsWith("Windows");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    public static void validate(Path jimage, List<String> expectedLocations,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            List<String> unexpectedPaths) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        BasicImageReader reader = BasicImageReader.open(jimage);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        // Validate expected locations
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        List<String> seenLocations = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        for (String loc : expectedLocations) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
            ImageLocation il = reader.findLocation(loc);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            if (il == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                throw new IOException("Location " + loc + " not present in " + jimage);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        seenLocations.addAll(expectedLocations);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        for (String s : reader.getEntryNames()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
            if (s.endsWith(".class") && !s.endsWith("module-info.class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                ImageLocation il = reader.findLocation(s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                    byte[] r = reader.getResource(il);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                    if(r == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                        System.out.println("IL, compressed " +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                                il.getCompressedSize() + " uncompressed " +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                                il.getUncompressedSize());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                        throw new IOException("NULL RESOURCE " + s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                    readClass(r);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                } catch (IOException ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                    System.err.println(s + " ERROR " + ex);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                    throw ex;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            if (seenLocations.contains(s)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                seenLocations.remove(s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
            for(String p : unexpectedPaths) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                if (s.equals(p)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                    throw new IOException("Seen unexpected path " + s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        if (!seenLocations.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
            throw new IOException("ImageReader did not return " + seenLocations);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
    public long getJavaLauncherExecutionTime() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        return javaExecutionTime;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    public long getModuleLauncherExecutionTime() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        return moduleExecutionTime;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
    public static void readClass(byte[] clazz) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        try (InputStream stream = new ByteArrayInputStream(clazz)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            ClassFile.read(stream);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        } catch (ConstantPoolException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            throw new IOException(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
}