test/hotspot/jtreg/runtime/cds/appcds/ProhibitedPackage.java
author coleenp
Mon, 29 Jul 2019 10:34:20 -0400
changeset 57567 b000362a89a0
parent 54927 test/hotspot/jtreg/runtime/appcds/ProhibitedPackage.java@1512d88b24c6
permissions -rw-r--r--
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds Summary: add top level cds directory and adjust test groups Reviewed-by: mseledtsov, ccheung
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
/*
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
48138
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
/*
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    26
 * @test
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    27
 * @summary AppCDS handling of prohibited package.
48469
7312ae4465d6 8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents: 48156
diff changeset
    28
 * @requires vm.cds
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    29
 * @library /test/lib
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    30
 * @modules jdk.jartool/sun.tools.jar
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    31
 * @compile test-classes/ProhibitedHelper.java test-classes/Prohibited.jasm
51990
6003e034cdd8 8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents: 51507
diff changeset
    32
 * @run driver ProhibitedPackage
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    33
 */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    34
49162
c200b4700aeb 8195065: runtime/appcds/ProhibitedPackage.java intermittent failure
iklam
parents: 49008
diff changeset
    35
import jdk.test.lib.cds.CDSOptions;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    36
import jdk.test.lib.Platform;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    37
import jdk.test.lib.process.OutputAnalyzer;
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
public class ProhibitedPackage {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    40
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    42
        JarBuilder.build("prohibited_pkg", "java/lang/Prohibited", "ProhibitedHelper");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    43
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    44
        String appJar = TestCommon.getTestJar("prohibited_pkg.jar");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    45
48155
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 48138
diff changeset
    46
        // Test support for customer loaders
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    47
        if (Platform.areCustomLoadersSupportedForCDS() &&
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    48
            !TestCommon.isDynamicArchive()) {
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    49
            String classlist[] = new String[] {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    50
                "java/lang/Object id: 1",
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    51
                "java/lang/Prohibited id: 2 super: 1 source: " + appJar
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    52
            };
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
            // Make sure a class in a prohibited package for a custom loader
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    55
            // will be ignored during dumping.
48156
a8f9aac3c2e5 8191747: [TESTBUG] runtime/appcds/DumpClassList.java and ProhibitedPackage.java fail on product bits
iklam
parents: 48155
diff changeset
    56
            TestCommon.dump(appJar,  classlist, "-Xlog:cds")
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    57
                .shouldContain("Dumping")
48156
a8f9aac3c2e5 8191747: [TESTBUG] runtime/appcds/DumpClassList.java and ProhibitedPackage.java fail on product bits
iklam
parents: 48155
diff changeset
    58
                .shouldContain("[cds] Prohibited package for non-bootstrap classes: java/lang/Prohibited.class")
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    59
                .shouldHaveExitValue(0);
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
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    62
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    63
        // Make sure a class in a prohibited package for a non-custom loader
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    64
        // will be ignored during dumping.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    65
        TestCommon.dump(appJar,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    66
                        TestCommon.list("java/lang/Prohibited", "ProhibitedHelper"),
48156
a8f9aac3c2e5 8191747: [TESTBUG] runtime/appcds/DumpClassList.java and ProhibitedPackage.java fail on product bits
iklam
parents: 48155
diff changeset
    67
                        "-Xlog:class+load")
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    68
            .shouldContain("Dumping")
48156
a8f9aac3c2e5 8191747: [TESTBUG] runtime/appcds/DumpClassList.java and ProhibitedPackage.java fail on product bits
iklam
parents: 48155
diff changeset
    69
            .shouldNotContain("[info][class,load] java.lang.Prohibited source: ")
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    70
            .shouldHaveExitValue(0);
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
        // Try loading the class in a prohibited package with various -Xshare
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    73
        // modes. The class shouldn't be loaded and appropriate exceptions
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    74
        // are expected.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    75
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    76
        OutputAnalyzer output;
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
        // -Xshare:on
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
    79
        TestCommon.run(
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    80
            "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
51507
3e3764f8fe36 8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents: 49162
diff changeset
    81
            "-cp", appJar, "ProhibitedHelper")
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
    82
          .assertNormalExit("Prohibited package name: java.lang");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    83
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    84
        // -Xshare:auto
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    85
        output = TestCommon.execAuto(
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    86
            "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
51507
3e3764f8fe36 8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents: 49162
diff changeset
    87
            "-cp", appJar, "ProhibitedHelper");
49162
c200b4700aeb 8195065: runtime/appcds/ProhibitedPackage.java intermittent failure
iklam
parents: 49008
diff changeset
    88
        CDSOptions opts = (new CDSOptions()).setXShareMode("auto");
c200b4700aeb 8195065: runtime/appcds/ProhibitedPackage.java intermittent failure
iklam
parents: 49008
diff changeset
    89
        TestCommon.checkExec(output, opts, "Prohibited package name: java.lang");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    90
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    91
        // -Xshare:off
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    92
        output = TestCommon.execOff(
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    93
            "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
51507
3e3764f8fe36 8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents: 49162
diff changeset
    94
            "-cp", appJar, "ProhibitedHelper");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    95
        output.shouldContain("Prohibited package name: java.lang");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    96
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    97
}