hotspot/test/runtime/SharedArchiveFile/BootAppendTests.java
author iklam
Tue, 05 Apr 2016 14:52:12 -0700
changeset 37263 08dec586ed5c
parent 36508 5f9eee6b383b
child 38151 fffedc5e5cf8
permissions -rw-r--r--
8153300: [TESTBUG] Enhance test/testlibrary/ClassFileInstaller.java to support JAR files Reviewed-by: lfoltan, mseledtsov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    23
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary Testing -Xbootclasspath/a support for CDS
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /testlibrary
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *          java.management
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *          jdk.jvmstat/sun.jvmstat.monitor
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @ignore 8150683
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @compile javax/sound/sampled/MyClass.jasm
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @compile org/omg/CORBA/Context.jasm
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @compile nonjdk/myPackage/MyClass.java
37263
08dec586ed5c 8153300: [TESTBUG] Enhance test/testlibrary/ClassFileInstaller.java to support JAR files
iklam
parents: 36508
diff changeset
    35
 * @build jdk.test.lib.* LoadClass ClassFileInstaller
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 * @run main/othervm BootAppendTests
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 */
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.io.File;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.io.FileOutputStream;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.io.IOException;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.io.PrintStream;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.nio.file.Path;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.nio.file.Paths;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import jdk.test.lib.ProcessTools;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import jdk.test.lib.OutputAnalyzer;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
public class BootAppendTests {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    private static final String APP_CLASS = "LoadClass";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private static final String BOOT_APPEND_MODULE_CLASS = "javax/sound/sampled/MyClass";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS = "org/omg/CORBA/Context";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private static final String BOOT_APPEND_CLASS = "nonjdk/myPackage/MyClass";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private static final String BOOT_APPEND_MODULE_CLASS_NAME =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        BOOT_APPEND_MODULE_CLASS.replace('/', '.');
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private static final String BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        BOOT_APPEND_DUPLICATE_MODULE_CLASS.replace('/', '.');
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final String BOOT_APPEND_CLASS_NAME =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        BOOT_APPEND_CLASS.replace('/', '.');
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private static final String[] ARCHIVE_CLASSES =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        {BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS, BOOT_APPEND_CLASS};
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    private static final String modes[] = {"on", "off"};
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    private static String appJar;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    private static String bootAppendJar;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    public static void main(String... args) throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        dumpArchive();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        testBootAppendModuleClass();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        testBootAppendDuplicateModuleClass();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        testBootAppendExcludedModuleClass();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        testBootAppendDuplicateExcludedModuleClass();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        testBootAppendClass();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    static void dumpArchive() throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        // create the classlist
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        File classlist = new File(new File(System.getProperty("test.classes", ".")),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                                  "BootAppendTest.classlist");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        FileOutputStream fos = new FileOutputStream(classlist);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        PrintStream ps = new PrintStream(fos);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        for (String s : ARCHIVE_CLASSES) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            ps.println(s);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        ps.close();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        fos.close();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        // build jar files
37263
08dec586ed5c 8153300: [TESTBUG] Enhance test/testlibrary/ClassFileInstaller.java to support JAR files
iklam
parents: 36508
diff changeset
    91
        appJar = ClassFileInstaller.writeJar("app.jar", APP_CLASS);
08dec586ed5c 8153300: [TESTBUG] Enhance test/testlibrary/ClassFileInstaller.java to support JAR files
iklam
parents: 36508
diff changeset
    92
        bootAppendJar = ClassFileInstaller.writeJar("bootAppend.jar",
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
            BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_DUPLICATE_MODULE_CLASS, BOOT_APPEND_CLASS);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        // dump
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
            "-XX:+UnlockDiagnosticVMOptions",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
            "-XX:SharedArchiveFile=./BootAppendTests.jsa",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            "-XX:SharedClassListFile=" + classlist.getPath(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
            "-XX:+PrintSharedSpaces",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            "-Xbootclasspath/a:" + bootAppendJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
            "-Xshare:dump");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        output.shouldContain("Loading classes to share")
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
              .shouldHaveExitValue(0);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        // Make sure all the classes were successfully archived.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        for (String archiveClass : ARCHIVE_CLASSES) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
            output.shouldNotContain("Preload Warning: Cannot find " + archiveClass);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    // Test #1: If a class on -Xbootclasspath/a is from a package defined in
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    //          bootmodules, the class is not loaded at runtime.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    //          Verify the behavior is the same when the class is archived
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
    //          with CDS enabled at runtime.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
    //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
    //          The javax.sound.sampled package is defined in the java.desktop module.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    //          The archived javax.sound.sampled.MyClass from the -Xbootclasspath/a
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
    //          should not be loaded at runtime.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    public static void testBootAppendModuleClass() throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        for (String mode : modes) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                "-XX:+UnlockDiagnosticVMOptions",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                "-cp", appJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                "-Xbootclasspath/a:" + bootAppendJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                "-Xshare:" + mode,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                APP_CLASS,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                BOOT_APPEND_MODULE_CLASS_NAME);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   131
            OutputAnalyzer output = new OutputAnalyzer(pb.start());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            output.shouldContain("java.lang.ClassNotFoundException: javax.sound.sampled.MyClass");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    // Test #2: If a class on -Xbootclasspath/a has the same fully qualified
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    //          name as a class defined in boot modules, the class is not loaded
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   138
    //          from -Xbootclasspath/a. Verify the behavior is the same at runtime
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    //          when CDS is enabled.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    //          The org.omg.CORBA.Context is a boot module class. The class on
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   142
    //          the -Xbootclasspath/a path that has the same fully-qualified name
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    //          should not be loaded at runtime when CDS is enabled.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    //          The one from the boot modules should be loaded instead.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    public static void testBootAppendDuplicateModuleClass() throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        for (String mode : modes) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                "-XX:+UnlockDiagnosticVMOptions",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                "-XX:+TraceClassLoading",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                "-cp", appJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                "-Xbootclasspath/a:" + bootAppendJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                "-Xshare:" + mode,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                APP_CLASS,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   156
            OutputAnalyzer output = new OutputAnalyzer(pb.start());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            output.shouldContain("[classload] org.omg.CORBA.Context source: jrt:/java.corba");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   160
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    // Test #3: If a class on -Xbootclasspath/a is from a package defined in boot modules,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    //          the class can be loaded from -Xbootclasspath/a when the module is excluded
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    //          using -limitmods. Verify the behavior is the same at runtime when CDS is
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    //          enabled.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    //          The java.desktop module is excluded using -limitmods at runtime,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    //          javax.sound.sampled.MyClass is archived from -Xbootclasspath/a. It can be
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    //          loaded from the archive at runtime.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   169
    public static void testBootAppendExcludedModuleClass() throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        for (String mode : modes) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                "-XX:+UnlockDiagnosticVMOptions",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                "-XX:+TraceClassLoading",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                "-cp", appJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                "-Xbootclasspath/a:" + bootAppendJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                "-limitmods", "java.base",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                "-Xshare:" + mode,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                APP_CLASS,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                BOOT_APPEND_MODULE_CLASS_NAME);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   181
            OutputAnalyzer output = new OutputAnalyzer(pb.start());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            output.shouldContain("[classload] javax.sound.sampled.MyClass");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   183
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            // When CDS is enabled, the shared class should be loaded from the archive.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            if (mode.equals("on")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                output.shouldContain("[classload] javax.sound.sampled.MyClass source: shared objects file");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   190
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    // Test #4: If a class on -Xbootclasspath/a has the same fully qualified
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    //          name as a class defined in boot modules, the class is loaded
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   193
    //          from -Xbootclasspath/a when the boot module is excluded using
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   194
    //          -limitmods. Verify the behavior is the same at runtime when CDS is
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   195
    //          enabled.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   196
    //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    //          The org.omg.CORBA.Context is a boot module class. The class
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    //          on -Xbootclasspath/a that has the same fully-qualified name
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    //          as org.omg.CORBA.Context can be loaded at runtime when
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    //          java.corba is excluded.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    public static void testBootAppendDuplicateExcludedModuleClass() throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        for (String mode : modes) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                "-XX:+UnlockDiagnosticVMOptions",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                "-XX:+TraceClassLoading",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                "-cp", appJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                "-Xbootclasspath/a:" + bootAppendJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                "-limitmods", "java.base",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                "-Xshare:" + mode,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                APP_CLASS,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                BOOT_APPEND_DUPLICATE_MODULE_CLASS_NAME);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            OutputAnalyzer output = new OutputAnalyzer(pb.start());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   214
            output.shouldContain("[classload] org.omg.CORBA.Context");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   215
            output.shouldMatch(".*\\[classload\\] org.omg.CORBA.Context source:.*bootAppend.jar");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   217
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   218
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   219
    // Test #5: If a class on -Xbootclasspath/a is not from named modules,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   220
    //          the class can be loaded at runtime. Verify the behavior is
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   221
    //          the same at runtime when CDS is enabled.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   222
    //
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    //          The nonjdk.myPackage is not defined in named modules. The
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    //          archived nonjdk.myPackage.MyClass from -Xbootclasspath/a
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    //          can be loaded at runtime when CDS is enabled.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    public static void testBootAppendClass() throws Exception {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        for (String mode : modes) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   228
            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                "-XX:+UnlockDiagnosticVMOptions",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                "-XX:SharedArchiveFile=./BootAppendTests.jsa",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                "-XX:+TraceClassLoading",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                "-cp", appJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                "-Xbootclasspath/a:" + bootAppendJar,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                "-Xshare:" + mode,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                APP_CLASS,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                BOOT_APPEND_CLASS_NAME);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            OutputAnalyzer output = new OutputAnalyzer(pb.start());
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            output.shouldContain("[classload] nonjdk.myPackage.MyClass");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   239
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   240
            // If CDS is enabled, the nonjdk.myPackage.MyClass should be loaded
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   241
            // from the shared archive.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   242
            if (mode.equals("on")) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                output.shouldContain(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                    "[classload] nonjdk.myPackage.MyClass source: shared objects file");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   245
            }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   247
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   248
}