test/hotspot/jtreg/runtime/SharedArchiveFile/NonBootLoaderClasses.java
author iklam
Mon, 04 Feb 2019 19:42:36 -0800
changeset 53636 962ed57b29c9
parent 52218 111ba072921b
permissions -rw-r--r--
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests Reviewed-by: ccheung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     1
/*
53636
962ed57b29c9 8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents: 52218
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     4
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     8
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    13
 * accompanied this code).
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    14
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    18
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    21
 * questions.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    22
 */
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    23
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    24
/*
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    25
 * @test NonBootLoaderClasses
49931
840e26123940 8193213: Make the UseAppCDS option obsolete.
jiangli
parents: 48469
diff changeset
    26
 * @summary Test to ensure platform and app classes are archived when specified in classlist
48469
7312ae4465d6 8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents: 47216
diff changeset
    27
 * @requires vm.cds
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    28
 * @library /test/lib
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    30
 *          java.management
51990
6003e034cdd8 8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents: 51411
diff changeset
    31
 * @run driver NonBootLoaderClasses
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    32
 */
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    33
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    34
import jdk.test.lib.cds.CDSOptions;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    35
import jdk.test.lib.cds.CDSTestUtils;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    37
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    38
public class NonBootLoaderClasses {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    40
        final String PLATFORM_CLASS = "jdk/dynalink/DynamicLinker";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    41
        final String APP_CLASS = "com/sun/tools/javac/Main";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    42
        String[] classes = {PLATFORM_CLASS, APP_CLASS};
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    43
        String classList =
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    44
            CDSTestUtils.makeClassList(classes).getPath();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    45
        String archiveName = "NonBootLoaderClasses.jsa";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    46
        CDSOptions opts = (new CDSOptions())
53636
962ed57b29c9 8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents: 52218
diff changeset
    47
            .addPrefix("-XX:ExtraSharedClassListFile=" + classList, "-Djava.class.path=")
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    48
            .setArchiveName(archiveName);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    49
        CDSTestUtils.createArchiveAndCheck(opts);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    50
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    51
        // Print the shared dictionary and inspect the output
52218
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    52
        opts = (new CDSOptions())
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    53
            .setUseVersion(false)
53636
962ed57b29c9 8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents: 52218
diff changeset
    54
            .addSuffix("-Djava.class.path=",
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    55
                "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + archiveName,
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    56
                "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary");
52218
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    57
        CDSTestUtils.run(opts)
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    58
            .assertNormalExit(output -> {
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    59
                output.shouldContain("archive is valid");
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    60
                output.shouldContain(PLATFORM_CLASS.replace('/', '.'));
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    61
                output.shouldContain(APP_CLASS.replace('/', '.'));
111ba072921b 8210990: [TESTBUG] Some CDS tests don't respect JVM variant being tested
ccheung
parents: 51990
diff changeset
    62
            });
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    63
   }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    64
}