hotspot/test/runtime/modules/getModuleJNI/GetModule.java
changeset 38094 46977cd73d86
parent 36508 5f9eee6b383b
child 42307 cefc81dc1d52
equal deleted inserted replaced
38090:34d0dd634032 38094:46977cd73d86
    40     static native boolean callCanReadModule(java.lang.reflect.Module asking_module,
    40     static native boolean callCanReadModule(java.lang.reflect.Module asking_module,
    41                                             java.lang.reflect.Module source_module);
    41                                             java.lang.reflect.Module source_module);
    42 
    42 
    43     public static void main(String[] args) {
    43     public static void main(String[] args) {
    44         Module module;
    44         Module module;
       
    45         Module javaBaseModule;
       
    46 
       
    47         // Module for primitive type, should be "java.base"
       
    48         java.lang.Integer primitive_int = 1;
       
    49         try {
       
    50             javaBaseModule = (Module)callGetModule(primitive_int.getClass());
       
    51             if (!javaBaseModule.getName().equals("java.base")) {
       
    52                 throw new RuntimeException("Unexpected module name for primitive type: " +
       
    53                                            javaBaseModule.getName());
       
    54             }
       
    55         } catch(Throwable e) {
       
    56             throw new RuntimeException("Unexpected exception for Integer: " + e.toString());
       
    57         }
    45 
    58 
    46         // Module for array of primitives, should be "java.base"
    59         // Module for array of primitives, should be "java.base"
    47         int[] int_array = {1, 2, 3};
    60         int[] int_array = {1, 2, 3};
    48         Module javaBaseModule;
       
    49         try {
    61         try {
    50             javaBaseModule = (Module)callGetModule(int_array.getClass());
    62             javaBaseModule = (Module)callGetModule(int_array.getClass());
    51             if (!javaBaseModule.getName().equals("java.base")) {
    63             if (!javaBaseModule.getName().equals("java.base")) {
    52                 throw new RuntimeException("Unexpected module name for array of primitives: " +
    64                 throw new RuntimeException("Unexpected module name for array of primitives: " +
    53                                            javaBaseModule.getName());
    65                                            javaBaseModule.getName());
    54             }
    66             }
    55         } catch(Throwable e) {
    67         } catch(Throwable e) {
    56             throw new RuntimeException("Unexpected exception for [I: " + e.toString());
    68             throw new RuntimeException("Unexpected exception for [I: " + e.toString());
    57         }
    69         }
    58 
    70 
    59         // Module for java.lang.String
    71         // Module for multi-dimensional array of primitives, should be "java.base"
       
    72         int[][] multi_int_array = { {1, 2, 3}, {4, 5, 6} };
       
    73         try {
       
    74             javaBaseModule = (Module)callGetModule(multi_int_array.getClass());
       
    75             if (!javaBaseModule.getName().equals("java.base")) {
       
    76                 throw new RuntimeException("Unexpected module name for multi-dimensional array of primitives: " +
       
    77                                            javaBaseModule.getName());
       
    78             }
       
    79         } catch(Throwable e) {
       
    80             throw new RuntimeException("Unexpected exception for multi-dimensional Integer array: " + e.toString());
       
    81         }
       
    82 
       
    83         // Module for java.lang.String, should be "java.base"
    60         java.lang.String str = "abc";
    84         java.lang.String str = "abc";
    61         try {
    85         try {
    62             module = (Module)callGetModule(str.getClass());
    86             module = (Module)callGetModule(str.getClass());
    63             if (!module.getName().equals("java.base")) {
    87             if (!module.getName().equals("java.base")) {
    64                 throw new RuntimeException("Unexpected module name for class String: " +
    88                 throw new RuntimeException("Unexpected module name for class String: " +
    65                                            module.getName());
    89                                            module.getName());
    66             }
    90             }
    67         } catch(Throwable e) {
    91         } catch(Throwable e) {
    68             throw new RuntimeException("Unexpected exception for String: " + e.toString());
    92             throw new RuntimeException("Unexpected exception for String: " + e.toString());
       
    93         }
       
    94 
       
    95         // Module for array of java.lang.Strings, should be "java.base"
       
    96         java.lang.String[] str_array = {"a", "b", "c"};
       
    97         try {
       
    98             javaBaseModule = (Module)callGetModule(str_array.getClass());
       
    99             if (!javaBaseModule.getName().equals("java.base")) {
       
   100                 throw new RuntimeException("Unexpected module name for array of Strings: " +
       
   101                                            javaBaseModule.getName());
       
   102             }
       
   103         } catch(Throwable e) {
       
   104             throw new RuntimeException("Unexpected exception for String array: " + e.toString());
       
   105         }
       
   106 
       
   107         // Module for multi-dimensional array of java.lang.Strings, should be "java.base"
       
   108         java.lang.String[][] multi_str_array = { {"a", "b", "c"}, {"d", "e", "f"} };
       
   109         try {
       
   110             javaBaseModule = (Module)callGetModule(multi_str_array.getClass());
       
   111             if (!javaBaseModule.getName().equals("java.base")) {
       
   112                 throw new RuntimeException("Unexpected module name for multi-dimensional array of Strings: " +
       
   113                                            javaBaseModule.getName());
       
   114             }
       
   115         } catch(Throwable e) {
       
   116             throw new RuntimeException("Unexpected exception for multidimensional String array: " + e.toString());
    69         }
   117         }
    70 
   118 
    71         // Module for java.lang.management.LockInfo
   119         // Module for java.lang.management.LockInfo
    72         try {
   120         try {
    73             LockInfo li = new LockInfo("java.lang.Class", 57);
   121             LockInfo li = new LockInfo("java.lang.Class", 57);