hotspot/test/runtime/modules/ModuleHelper.java
changeset 44520 0553e129e0ec
parent 43665 4bb003cad9b9
child 45628 ea212c4584d7
child 46388 d7a164ad6b7f
equal deleted inserted replaced
44471:7e8e5ceecf99 44520:0553e129e0ec
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.net.URI;
    24 import java.net.URI;
    25 import java.lang.module.ModuleDescriptor;
    25 import java.lang.module.ModuleDescriptor;
    26 import java.lang.reflect.Module;
       
    27 import java.util.Collections;
    26 import java.util.Collections;
    28 import java.util.HashSet;
    27 import java.util.HashSet;
    29 import java.util.Set;
    28 import java.util.Set;
    30 
    29 
    31 import sun.hotspot.WhiteBox;
    30 import sun.hotspot.WhiteBox;
    39     }
    38     }
    40 
    39 
    41     public static void AddModuleExports(Object from, String pkg, Object to) throws Throwable {
    40     public static void AddModuleExports(Object from, String pkg, Object to) throws Throwable {
    42         WhiteBox wb = WhiteBox.getWhiteBox();
    41         WhiteBox wb = WhiteBox.getWhiteBox();
    43         wb.AddModuleExports(from, pkg, to);
    42         wb.AddModuleExports(from, pkg, to);
    44         java.lang.reflect.ModuleHelper.addExportsNoSync((Module)from, pkg, (Module)to);
    43         java.lang.ModuleHelper.addExportsNoSync((Module)from, pkg, (Module)to);
    45     }
    44     }
    46 
    45 
    47     public static void AddReadsModule(Object from, Object to) throws Throwable {
    46     public static void AddReadsModule(Object from, Object to) throws Throwable {
    48         WhiteBox wb = WhiteBox.getWhiteBox();
    47         WhiteBox wb = WhiteBox.getWhiteBox();
    49         wb.AddReadsModule(from, to);
    48         wb.AddReadsModule(from, to);
    50         java.lang.reflect.ModuleHelper.addReadsNoSync((Module)from, (Module)to);
    49         java.lang.ModuleHelper.addReadsNoSync((Module)from, (Module)to);
    51     }
    50     }
    52 
    51 
    53     public static void AddModulePackage(Object m, String pkg) throws Throwable {
    52     public static void AddModulePackage(Object m, String pkg) throws Throwable {
    54         WhiteBox wb = WhiteBox.getWhiteBox();
    53         WhiteBox wb = WhiteBox.getWhiteBox();
    55         wb.AddModulePackage(m, pkg);
    54         wb.AddModulePackage(m, pkg);
    56         java.lang.reflect.ModuleHelper.addPackageNoSync((Module)m, pkg);
    55         java.lang.ModuleHelper.addPackageNoSync((Module)m, pkg);
    57     }
    56     }
    58 
    57 
    59     public static Module GetModuleByPackageName(Object ldr, String pkg) throws Throwable {
    58     public static Module GetModuleByPackageName(Object ldr, String pkg) throws Throwable {
    60         WhiteBox wb = WhiteBox.getWhiteBox();
    59         WhiteBox wb = WhiteBox.getWhiteBox();
    61         return (Module)wb.GetModuleByPackageName(ldr, pkg);
    60         return (Module)wb.GetModuleByPackageName(ldr, pkg);
    62     }
    61     }
    63 
    62 
    64     public static void AddModuleExportsToAllUnnamed(Object m, String pkg) throws Throwable {
    63     public static void AddModuleExportsToAllUnnamed(Object m, String pkg) throws Throwable {
    65         WhiteBox wb = WhiteBox.getWhiteBox();
    64         WhiteBox wb = WhiteBox.getWhiteBox();
    66         wb.AddModuleExportsToAllUnnamed(m, pkg);
    65         wb.AddModuleExportsToAllUnnamed(m, pkg);
    67         //java.lang.reflect.ModuleHelper.addExportsToAllUnnamedNoSync((Module)m, pkg);
    66         //java.lang.ModuleHelper.addExportsToAllUnnamedNoSync((Module)m, pkg);
    68     }
    67     }
    69 
    68 
    70     public static void AddModuleExportsToAll(Object m, String pkg) throws Throwable {
    69     public static void AddModuleExportsToAll(Object m, String pkg) throws Throwable {
    71         WhiteBox wb = WhiteBox.getWhiteBox();
    70         WhiteBox wb = WhiteBox.getWhiteBox();
    72         wb.AddModuleExportsToAll(m, pkg);
    71         wb.AddModuleExportsToAll(m, pkg);
    73         java.lang.reflect.ModuleHelper.addExportsNoSync((Module)m, pkg, (Module)null);
    72         java.lang.ModuleHelper.addExportsNoSync((Module)m, pkg, (Module)null);
    74     }
    73     }
    75 
    74 
    76     public static Module ModuleObject(String name, ClassLoader loader, String[] pkgs) throws Throwable {
    75     public static Module ModuleObject(String name, ClassLoader loader, String[] pkgs) throws Throwable {
    77         Set<String> pkg_set = new HashSet<>();
    76         Set<String> pkg_set = new HashSet<>();
    78         if (pkgs != null) {
    77         if (pkgs != null) {
    85 
    84 
    86         ModuleDescriptor descriptor =
    85         ModuleDescriptor descriptor =
    87             ModuleDescriptor.newModule(name).packages(pkg_set).build();
    86             ModuleDescriptor.newModule(name).packages(pkg_set).build();
    88         URI uri = URI.create("module:/" + name);
    87         URI uri = URI.create("module:/" + name);
    89 
    88 
    90         return java.lang.reflect.ModuleHelper.newModule(loader, descriptor);
    89         return java.lang.ModuleHelper.newModule(loader, descriptor);
    91     }
    90     }
    92 
    91 
    93 }
    92 }