test/hotspot/jtreg/runtime/appcds/test-classes/JimageClassPackage.java
author iklam
Tue, 14 Aug 2018 09:59:37 -0700
changeset 51491 187c84a5efe1
parent 48138 78b2ecdd3c4b
permissions -rw-r--r--
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed Summary: Relocate and patch archive regions if necessary Reviewed-by: jiangli, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     1
/*
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     4
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     8
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    13
 * accompanied this code).
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    14
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    18
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    21
 * questions.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    22
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    23
 */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    24
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    25
public class JimageClassPackage {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    26
    public static void main(String args[]) throws Throwable {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    27
        // Test Package for boot/app/ext module classes from the "modules" jimage.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    28
        // The following classes are archived. See runtime/AppCDS/Package.java.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    29
        //     java.util.Dictionary (testcase 0),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    30
        //     sun.tools.javac.Main (testcase 1),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    31
        //     jdk.nio.zipfs.ZipInfo (testcase 2),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    32
        //     java.net.URL (testcase 3),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    33
        //     sun.rmi.rmic.Main (testcase 4),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    34
        //     com.sun.jndi.dns.DnsName (testcase 5)
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    35
        String testcases[][] =
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    36
            {{"Loading shared boot module class first", "java.util",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    37
              "java.util.Dictionary", "java.util.ServiceConfigurationError"},
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    38
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    39
             {"Loading shared app module class first", "sun.tools.javac",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    40
              "sun.tools.javac.Main", "sun.tools.javac.BatchParser"},
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    41
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    42
             {"Loading shared ext module class first", "jdk.nio.zipfs",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    43
              "jdk.nio.zipfs.ZipInfo", "jdk.nio.zipfs.ZipPath"},
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    44
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    45
             {"Loading non-shared boot module class first", "java.net",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    46
              "java.net.HttpCookie", "java.net.URL"},
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    47
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    48
             {"Loading non-shared app module class first", "sun.rmi.rmic",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    49
              "sun.rmi.rmic.RMIGenerator", "sun.rmi.rmic.Main"},
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    50
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    51
             {"Loading non-shared ext module class first", "com.sun.jndi.dns",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    52
              "com.sun.jndi.dns.Resolver", "com.sun.jndi.dns.DnsName"}};
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    53
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    54
        JimageClassPackage test = new JimageClassPackage();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    55
        for (int i = 0; i < testcases.length; i++) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    56
            System.out.println("Testcase " + i + ": " + testcases[i][0]);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    57
            test.testPackage(testcases[i][1], testcases[i][2], testcases[i][3]);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    58
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    59
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    60
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    61
    private void testPackage (String pkg,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    62
                              String shared,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    63
                              String nonShared) throws Throwable {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    64
        Class c1 = Class.forName(shared);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    65
        ClassLoader cl = c1.getClassLoader();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    66
        Package pkg_from_loader;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    67
        if (cl != null) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    68
            pkg_from_loader = cl.getDefinedPackage(pkg);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    69
        } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    70
            pkg_from_loader = Package.getPackage(pkg);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    71
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    72
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    73
        Package pkg_from_shared_class = c1.getPackage();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    74
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    75
        Class c2 = Class.forName(nonShared);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    76
        Package pkg_from_nonshared_class = c2.getPackage();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    77
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    78
        if (pkg_from_loader != null &&
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    79
            pkg_from_shared_class != null &&
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    80
            pkg_from_loader == pkg_from_shared_class &&
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    81
            pkg_from_shared_class == pkg_from_nonshared_class &&
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    82
            pkg_from_shared_class.getName().equals(pkg)) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    83
            System.out.println("Expected package: " + pkg_from_shared_class.toString());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    84
        } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    85
            System.out.println("Unexpected package" + pkg_from_shared_class);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    86
            System.exit(1);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    87
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    88
        if (pkg_from_shared_class.isSealed()) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    89
            System.out.println("Package is sealed");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    90
        } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    91
            System.out.println("Package is not sealed");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    92
            System.exit(1);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    93
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    94
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    95
}