< prev index next >

src/java.base/share/classes/java/lang/Module.java

Print this page
rev 57943 : 8238599: Refactor and simplify implAddOpensToAllUnnamed
Reviewed-by: alanb

*** 907,948 **** map.putIfAbsent(pn, Boolean.FALSE); } } /** ! * Updates a module to open all packages returned by the given iterator to ! * all unnamed modules. * * @apiNote Used during startup to open packages for illegal access. */ ! void implAddOpensToAllUnnamed(Iterator<String> iterator) { if (jdk.internal.misc.VM.isModuleSystemInited()) { throw new IllegalStateException("Module system already initialized"); } // replace this module's openPackages map with a new map that opens // the packages to all unnamed modules. Map<String, Set<Module>> openPackages = this.openPackages; if (openPackages == null) { ! openPackages = new HashMap<>(); } else { openPackages = new HashMap<>(openPackages); } ! while (iterator.hasNext()) { ! String pn = iterator.next(); Set<Module> prev = openPackages.putIfAbsent(pn, ALL_UNNAMED_MODULE_SET); if (prev != null) { prev.add(ALL_UNNAMED_MODULE); } // update VM to export the package addExportsToAllUnnamed0(this, pn); } - this.openPackages = openPackages; } - // -- services -- /** * If the caller's module is this module then update this module to add a * service dependence on the given service type. This method is intended --- 907,951 ---- map.putIfAbsent(pn, Boolean.FALSE); } } /** ! * Updates a module to open all packages in the given sets to all unnamed ! * modules. * * @apiNote Used during startup to open packages for illegal access. */ ! void implAddOpensToAllUnnamed(Set<String> concealedPkgs, Set<String> exportedPkgs) { if (jdk.internal.misc.VM.isModuleSystemInited()) { throw new IllegalStateException("Module system already initialized"); } // replace this module's openPackages map with a new map that opens // the packages to all unnamed modules. Map<String, Set<Module>> openPackages = this.openPackages; if (openPackages == null) { ! openPackages = new HashMap<>((4 * (concealedPkgs.size() + exportedPkgs.size()) / 3) + 1); } else { openPackages = new HashMap<>(openPackages); } ! implAddOpensToAllUnnamed(concealedPkgs, openPackages); ! implAddOpensToAllUnnamed(exportedPkgs, openPackages); ! this.openPackages = openPackages; ! } ! ! private void implAddOpensToAllUnnamed(Set<String> pkgs, Map<String, Set<Module>> openPackages) { ! for (String pn : pkgs) { Set<Module> prev = openPackages.putIfAbsent(pn, ALL_UNNAMED_MODULE_SET); if (prev != null) { prev.add(ALL_UNNAMED_MODULE); } // update VM to export the package addExportsToAllUnnamed0(this, pn); } } // -- services -- /** * If the caller's module is this module then update this module to add a * service dependence on the given service type. This method is intended
< prev index next >