author | alanb |
Fri, 07 Apr 2017 08:04:46 +0000 | |
changeset 44520 | 0553e129e0ec |
parent 42307 | cefc81dc1d52 |
permissions | -rw-r--r-- |
36508 | 1 |
/* |
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
42307
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
36508 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* @test |
|
25 |
* @summary test JNI_GetModule() API |
|
26 |
* @run main/native GetModule |
|
27 |
*/ |
|
28 |
||
29 |
import java.lang.management.LockInfo; |
|
30 |
public class GetModule { |
|
31 |
||
32 |
static { |
|
33 |
System.loadLibrary("GetModule"); |
|
34 |
} |
|
35 |
||
36 |
static native Object callGetModule(java.lang.Class clazz); |
|
37 |
||
38 |
public static void main(String[] args) { |
|
39 |
Module module; |
|
38094
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
40 |
Module javaBaseModule; |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
41 |
|
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
42 |
// Module for primitive type, should be "java.base" |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
43 |
java.lang.Integer primitive_int = 1; |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
44 |
try { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
45 |
javaBaseModule = (Module)callGetModule(primitive_int.getClass()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
46 |
if (!javaBaseModule.getName().equals("java.base")) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
47 |
throw new RuntimeException("Unexpected module name for primitive type: " + |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
48 |
javaBaseModule.getName()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
49 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
50 |
} catch(Throwable e) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
51 |
throw new RuntimeException("Unexpected exception for Integer: " + e.toString()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
52 |
} |
36508 | 53 |
|
54 |
// Module for array of primitives, should be "java.base" |
|
55 |
int[] int_array = {1, 2, 3}; |
|
56 |
try { |
|
57 |
javaBaseModule = (Module)callGetModule(int_array.getClass()); |
|
58 |
if (!javaBaseModule.getName().equals("java.base")) { |
|
59 |
throw new RuntimeException("Unexpected module name for array of primitives: " + |
|
60 |
javaBaseModule.getName()); |
|
61 |
} |
|
62 |
} catch(Throwable e) { |
|
63 |
throw new RuntimeException("Unexpected exception for [I: " + e.toString()); |
|
64 |
} |
|
65 |
||
38094
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
66 |
// Module for multi-dimensional array of primitives, should be "java.base" |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
67 |
int[][] multi_int_array = { {1, 2, 3}, {4, 5, 6} }; |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
68 |
try { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
69 |
javaBaseModule = (Module)callGetModule(multi_int_array.getClass()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
70 |
if (!javaBaseModule.getName().equals("java.base")) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
71 |
throw new RuntimeException("Unexpected module name for multi-dimensional array of primitives: " + |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
72 |
javaBaseModule.getName()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
73 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
74 |
} catch(Throwable e) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
75 |
throw new RuntimeException("Unexpected exception for multi-dimensional Integer array: " + e.toString()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
76 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
77 |
|
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
78 |
// Module for java.lang.String, should be "java.base" |
36508 | 79 |
java.lang.String str = "abc"; |
80 |
try { |
|
81 |
module = (Module)callGetModule(str.getClass()); |
|
82 |
if (!module.getName().equals("java.base")) { |
|
83 |
throw new RuntimeException("Unexpected module name for class String: " + |
|
84 |
module.getName()); |
|
85 |
} |
|
86 |
} catch(Throwable e) { |
|
87 |
throw new RuntimeException("Unexpected exception for String: " + e.toString()); |
|
88 |
} |
|
89 |
||
38094
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
90 |
// Module for array of java.lang.Strings, should be "java.base" |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
91 |
java.lang.String[] str_array = {"a", "b", "c"}; |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
92 |
try { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
93 |
javaBaseModule = (Module)callGetModule(str_array.getClass()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
94 |
if (!javaBaseModule.getName().equals("java.base")) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
95 |
throw new RuntimeException("Unexpected module name for array of Strings: " + |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
96 |
javaBaseModule.getName()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
97 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
98 |
} catch(Throwable e) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
99 |
throw new RuntimeException("Unexpected exception for String array: " + e.toString()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
100 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
101 |
|
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
102 |
// Module for multi-dimensional array of java.lang.Strings, should be "java.base" |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
103 |
java.lang.String[][] multi_str_array = { {"a", "b", "c"}, {"d", "e", "f"} }; |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
104 |
try { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
105 |
javaBaseModule = (Module)callGetModule(multi_str_array.getClass()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
106 |
if (!javaBaseModule.getName().equals("java.base")) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
107 |
throw new RuntimeException("Unexpected module name for multi-dimensional array of Strings: " + |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
108 |
javaBaseModule.getName()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
109 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
110 |
} catch(Throwable e) { |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
111 |
throw new RuntimeException("Unexpected exception for multidimensional String array: " + e.toString()); |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
112 |
} |
46977cd73d86
8152844: JVM InstanceKlass Methods For Obtaining Package/Module Should Be Moved to Klass
rprotacio
parents:
36508
diff
changeset
|
113 |
|
36508 | 114 |
// Module for java.lang.management.LockInfo |
115 |
try { |
|
116 |
LockInfo li = new LockInfo("java.lang.Class", 57); |
|
117 |
module = (Module)callGetModule(li.getClass()); |
|
118 |
if (!module.getName().equals("java.management")) { |
|
119 |
throw new RuntimeException("Unexpected module name for class LockInfo: " + |
|
120 |
module.getName()); |
|
121 |
} |
|
122 |
} catch(Throwable e) { |
|
123 |
throw new RuntimeException("Unexpected exception for LockInfo: " + e.toString()); |
|
124 |
} |
|
125 |
||
126 |
// Unnamed module. |
|
127 |
try { |
|
128 |
module = (Module)callGetModule(MyClassLoader.class); |
|
129 |
if (module == null || module.getName() != null) { |
|
130 |
throw new RuntimeException("Bad module for unnamed module"); |
|
131 |
} |
|
132 |
} catch(Throwable e) { |
|
133 |
throw new RuntimeException("Unexpected exception for unnamed module: " + e.toString()); |
|
134 |
} |
|
135 |
||
136 |
try { |
|
137 |
module = (Module)callGetModule(null); |
|
138 |
throw new RuntimeException("Failed to get expected NullPointerException"); |
|
139 |
} catch(NullPointerException e) { |
|
140 |
// Expected |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
static class MyClassLoader extends ClassLoader { } |
|
145 |
} |