hotspot/test/runtime/modules/JVMAddModuleExports.java
author alanb
Fri, 07 Apr 2017 08:04:46 +0000
changeset 44520 0553e129e0ec
parent 40631 ed82623d7831
child 44993 f61bcd80ec1f
child 46404 ae62ba99a1a7
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: lfoltan, sspitsyn Contributed-by: alan.bateman@oracle.com, harold.seigel@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 40631
diff changeset
     2
 * Copyright (c) 2016, 2017, 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
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    26
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    27
 * @library /test/lib ..
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @build sun.hotspot.WhiteBox
44520
0553e129e0ec 8177530: Module system implementation refresh (4/2017)
alanb
parents: 40631
diff changeset
    29
 * @compile/module=java.base java/lang/ModuleHelper.java
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMAddModuleExports
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 static jdk.test.lib.Asserts.*;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    36
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    37
public class JVMAddModuleExports {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    38
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    39
    public static void main(String args[]) throws Throwable {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    40
        MyClassLoader from_cl = new MyClassLoader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
        MyClassLoader to_cl = new MyClassLoader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
        Module from_module, to_module;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
        from_module = ModuleHelper.ModuleObject("from_module", from_cl, new String[] { "mypackage", "this/package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        assertNotNull(from_module, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        ModuleHelper.DefineModule(from_module, "9.0", "from_module/here", new String[] { "mypackage", "this/package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        to_module = ModuleHelper.ModuleObject("to_module", to_cl, new String[] { "yourpackage", "that/package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        assertNotNull(to_module, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        ModuleHelper.DefineModule(to_module, "9.0", "to_module/here", new String[] { "yourpackage", "that/package" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        // Null from_module argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
            ModuleHelper.AddModuleExports((Module)null, "mypackage", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
            throw new RuntimeException("Failed to get the expected NPE for null from_module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        // Null to_module argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
            ModuleHelper.AddModuleExports(from_module, "mypackage", (Module)null);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
            throw new RuntimeException("Failed to get the expected NPE for null to_module");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        // Bad from_module argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            ModuleHelper.AddModuleExports(to_cl, "mypackage", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        // Null package argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            ModuleHelper.AddModuleExports(from_module, null, to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            throw new RuntimeException("Failed to get the expected NPE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        // Bad to_module argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            ModuleHelper.AddModuleExports(from_module, "mypackage", from_cl);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        // Exporting a package to the same module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        ModuleHelper.AddModuleExports(from_module, "mypackage", from_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    93
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        // Export a package that does not exist to to_module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            ModuleHelper.AddModuleExports(from_module, "notmypackage", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    97
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    99
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   101
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        // Export a package, that is not in from_module, to to_module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            ModuleHelper.AddModuleExports(from_module, "yourpackage", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   105
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   107
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   109
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        // Export a package, that does not exist, to from_module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            ModuleHelper.AddModuleExports(from_module, "notmypackage", from_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   113
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   117
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        // Export a package, that is not in from_module, to from_module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            ModuleHelper.AddModuleExports(from_module, "that/package", from_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   125
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        // Export the same package twice to the same module
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        ModuleHelper.AddModuleExports(from_module, "this/package", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        ModuleHelper.AddModuleExports(from_module, "this/package", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        // Export a package, using '.' instead of '/'
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            ModuleHelper.AddModuleExports(from_module, "this.package", to_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   137
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        // Export a package to the unnamed module and then to a specific module.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        // The qualified export should be ignored.
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        ModuleHelper.AddModuleExportsToAll(to_module, "that/package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        ModuleHelper.AddModuleExports(to_module, "that/package", from_module);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   142
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   143
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    static class MyClassLoader extends ClassLoader { }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   145
}