hotspot/test/runtime/modules/JVMAddModulePackage.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 36508 5f9eee6b383b
child 40631 ed82623d7831
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
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) 2016, 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
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    26
 * @modules java.base/jdk.internal.misc
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /testlibrary /test/lib /compiler/whitebox ..
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @build sun.hotspot.WhiteBox
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @compile/module=java.base java/lang/reflect/ModuleHelper.java
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 JVMAddModulePackage
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 JVMAddModulePackage {
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 cl1 = new MyClassLoader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    41
        MyClassLoader cl3 = new MyClassLoader();
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    42
        Object module1, module2, module3;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    43
        boolean result;
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    44
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        module1 = ModuleHelper.ModuleObject("module1", cl1, new String[] { "mypackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        assertNotNull(module1, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        ModuleHelper.DefineModule(module1, "9.0", "module1/here", new String[] { "mypackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        module2 = ModuleHelper.ModuleObject("module2", cl1, new String[] { "yourpackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        assertNotNull(module2, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        ModuleHelper.DefineModule(module2, "9.0", "module2/here", new String[] { "yourpackage" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    51
        module3 = ModuleHelper.ModuleObject("module3", cl3, new String[] { "package/num3" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        assertNotNull(module3, "Module should not be null");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        ModuleHelper.DefineModule(module3, "9.0", "module3/here", new String[] { "package/num3" });
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    54
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        // Simple call
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        ModuleHelper.AddModulePackage(module1, "new_package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    57
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        // Add a package and export it
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        ModuleHelper.AddModulePackage(module1, "package/num3");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        ModuleHelper.AddModuleExportsToAll(module1, "package/num3");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    61
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        // Null module argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            ModuleHelper.AddModulePackage(null, "new_package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            throw new RuntimeException("Failed to get the expected NPE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    69
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        // Bad module argument, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    72
            ModuleHelper.AddModulePackage(cl1, "new_package");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    73
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    77
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        // Null package argument, expect an NPE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            ModuleHelper.AddModulePackage(module1, null);
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    81
            throw new RuntimeException("Failed to get the expected NPE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        } catch(NullPointerException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            // Expected
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    85
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        // Existing package, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            ModuleHelper.AddModulePackage(module1, "yourpackage");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            throw new RuntimeException("Failed to get the expected IAE");
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        } catch(IllegalArgumentException e) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            // Expected
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
        // Invalid package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            ModuleHelper.AddModulePackage(module1, "your.package");
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
        // Invalid package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            ModuleHelper.AddModulePackage(module1, ";your/package");
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
        // Invalid package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            ModuleHelper.AddModulePackage(module1, "7[743");
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
        // Empty package name, expect an IAE
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        try {
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            ModuleHelper.AddModulePackage(module1, "");
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
    }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   127
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    static class MyClassLoader extends ClassLoader { }
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   129
}
5f9eee6b383b 8142968: Module System implementation
alanb
parents:
diff changeset
   130