hotspot/test/runtime/modules/Visibility/XbootcpVisibility.java
author lana
Thu, 12 May 2016 15:15:02 +0000
changeset 37915 be4ff50b6cb6
parent 36851 03e2f4d0a421
child 40631 ed82623d7831
permissions -rw-r--r--
Added tag jdk-9+118 for changeset cc643de7cb06
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) 2015, 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 Ensure that a package whose module has not been defined to the boot loader
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 *          is correctly located with -Xbootclasspath/a
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @requires !(os.family == "windows")
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @library /testlibrary
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 36508
diff changeset
    30
 * @modules java.base/jdk.internal.misc
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *          java.management
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main/othervm XbootcpVisibility
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    34
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.io.File;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Files;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Paths;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import jdk.test.lib.*;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
public class XbootcpVisibility {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
    public static void main(String[] args) throws Throwable {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        String Vis1_B_src =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
                "package p2;" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
                "public class Vis1_B { public void m() { System.out.println(\"In B's m()\"); } }";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        ClassFileInstaller.writeClassToDisk("p2/Vis1_B",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
            InMemoryJavaCompiler.compile("p2.Vis1_B", Vis1_B_src), System.getProperty("test.classes"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        ClassFileInstaller.writeClassToDisk("p2/Vis1_B", "mods1");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        String Vis1_C_src =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
                "package p2;" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                "public class Vis1_C { public void m() { System.out.println(\"In C's m()\"); } }";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        ClassFileInstaller.writeClassToDisk("p2/Vis1_C",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
            InMemoryJavaCompiler.compile("p2.Vis1_C", Vis1_C_src), System.getProperty("test.classes"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        ClassFileInstaller.writeClassToDisk("p2/Vis1_C", "mods1");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        String Vis1_A_src =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
            "public class Vis1_A {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
            "    public static void main(String args[]) throws Exception {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            // Try loading a class within a named package
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            // in the unnamed module.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
            // Ensure the class can still be loaded successfully by the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            // boot loader since it is located on -Xbootclasspath/a.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            "        try {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            "            p2.Vis1_B b = new p2.Vis1_B();" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            "            if (b.getClass().getClassLoader() != null) {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            "              throw new RuntimeException(\"XbootcpVisibility FAILED - class B " +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                                                      "should be loaded by boot class loader\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
            "            }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
            "            b.m();" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            // Now that the package p2 has been recorded in the
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
            // unnamed module within the boot loader's PackageEntryTable,
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            // ensure that a different class within the same package
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            // can be located on -Xbootclasspath/a as well.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            "            p2.Vis1_C c = new p2.Vis1_C();" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            "            if (c.getClass().getClassLoader() != null) {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
            "              throw new RuntimeException(\"XbootcpVisibility FAILED - class C " +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                                                       "should be loaded by boot class loader\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            "            }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            "            c.m();" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            "        } catch (Exception e) {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            "            System.out.println(e);" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            "            throw new RuntimeException(\"XbootcpVisibility FAILED - " +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                                                     "test should not throw exception\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            "        }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
            "        System.out.println(\"XbootcpVisibility PASSED\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            "    }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            "}";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        ClassFileInstaller.writeClassToDisk("Vis1_A",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                InMemoryJavaCompiler.compile("Vis1_A", Vis1_A_src), System.getProperty("test.classes"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        // Make sure the classes are actually being loaded from mods1
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        Files.delete(Paths.get(System.getProperty("test.classes") +  File.separator +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                                                               "p2" + File.separator + "Vis1_B.class"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        Files.delete(Paths.get(System.getProperty("test.classes") +  File.separator +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                                                               "p2" + File.separator + "Vis1_C.class"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                "-Xbootclasspath/a:nonexistent.jar",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                "-Xbootclasspath/a:mods1",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                "Vis1_A")
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
            .start()).shouldHaveExitValue(0);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
}