hotspot/test/runtime/modules/Visibility/XpatchVisibility.java
author lana
Thu, 12 May 2016 15:15:02 +0000
changeset 37915 be4ff50b6cb6
parent 37773 e5b3e9732c3c
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
/*
37773
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36851
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
36508
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 newly introduced java.base package placed within the -Xpatch directory
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 *          is considered part of the boot loader's visibility boundary
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 XpatchVisibility
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 XpatchVisibility {
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 Vis2_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 Vis2_B {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
              "    public void m() {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
              "        System.out.println(\"In B's m()\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
              "    }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
              "}";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
      String Vis2_A_src =
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
              "import p2.*;" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
              "public class Vis2_A {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
              "    public static void main(String args[]) throws Exception {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                      // Try loading a class within a newly introduced java.base
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
                      // package.  Make sure the class can be found via -Xpatch.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
              "        try {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
              "            p2.Vis2_B b = new p2.Vis2_B();" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
              "            if (b.getClass().getClassLoader() != null) {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
              "                throw new RuntimeException(\"XpatchVisibility FAILED - class B " +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                                                           "should be loaded by boot class loader\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
              "            }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
              "            b.m();" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
              "        } catch (Throwable e) {" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
              "            throw new RuntimeException(\"XpatchVisibility FAILED - test " +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                                                       "should not throw an error or exception\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
              "        }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
              "        System.out.println(\"XpatchVisibility PASSED\\n\");" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
              "    }" +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
              "}";
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
      ClassFileInstaller.writeClassToDisk("p2/Vis2_B",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
          InMemoryJavaCompiler.compile("p2.Vis2_B", Vis2_B_src), System.getProperty("test.classes"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
      ClassFileInstaller.writeClassToDisk("p2/Vis2_B", "mods2/java.base");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
      ClassFileInstaller.writeClassToDisk("Vis2_A",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
          InMemoryJavaCompiler.compile("Vis2_A", Vis2_A_src), System.getProperty("test.classes"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
      // Make sure the classes are actually being loaded from mods2
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
      Files.delete(Paths.get(System.getProperty("test.classes") +  File.separator +
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                                                           "p2" + File.separator + "Vis2_B.class"));
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
      new OutputAnalyzer(ProcessTools.createJavaProcessBuilder(
37773
e5b3e9732c3c 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36851
diff changeset
    86
              "-Xpatch:java.base=mods2/java.base",
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
              "-XaddExports:java.base/p2=ALL-UNNAMED",
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
              "Vis2_A")
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
          .start()).shouldHaveExitValue(0);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
}