< prev index next >

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

Print this page
rev 48077 : 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
Reviewed-by: smarks

*** 245,261 **** return null; } // -- // special Module to mean "all unnamed modules" ! private static final Module ALL_UNNAMED_MODULE = new Module(null); ! private static final Set<Module> ALL_UNNAMED_MODULE_SET = Set.of(ALL_UNNAMED_MODULE); // special Module to mean "everyone" ! private static final Module EVERYONE_MODULE = new Module(null); ! private static final Set<Module> EVERYONE_SET = Set.of(EVERYONE_MODULE); /** * The holder of data structures to support readability, exports, and * service use added at runtime with the reflective APIs. */ --- 245,264 ---- return null; } // -- + private static class Special { // special Module to mean "all unnamed modules" ! static final Module ALL_UNNAMED_MODULE = new Module(null); ! static final Set<Module> ALL_UNNAMED_MODULE_SET = Set.of(ALL_UNNAMED_MODULE); // special Module to mean "everyone" ! static final Module EVERYONE_MODULE = new Module(null); ! static final Set<Module> EVERYONE_SET = Set.of(EVERYONE_MODULE); ! } ! /** * The holder of data structures to support readability, exports, and * service use added at runtime with the reflective APIs. */
*** 323,333 **** return true; // if other is an unnamed module then check if this module reads // all unnamed modules if (!other.isNamed() ! && ReflectionData.reads.containsKeyPair(this, ALL_UNNAMED_MODULE)) return true; return false; } --- 326,336 ---- return true; // if other is an unnamed module then check if this module reads // all unnamed modules if (!other.isNamed() ! && ReflectionData.reads.containsKeyPair(this, Special.ALL_UNNAMED_MODULE)) return true; return false; }
*** 380,390 **** * Updates this module to read all unnamed modules. * * @apiNote Used by the --add-reads command line option. */ void implAddReadsAllUnnamed() { ! implAddReads(Module.ALL_UNNAMED_MODULE, true); } /** * Updates this module to read another module without notifying the VM. * --- 383,393 ---- * Updates this module to read all unnamed modules. * * @apiNote Used by the --add-reads command line option. */ void implAddReadsAllUnnamed() { ! implAddReads(Special.ALL_UNNAMED_MODULE, true); } /** * Updates this module to read another module without notifying the VM. *
*** 402,412 **** private void implAddReads(Module other, boolean syncVM) { Objects.requireNonNull(other); if (!canRead(other)) { // update VM first, just in case it fails if (syncVM) { ! if (other == ALL_UNNAMED_MODULE) { addReads0(this, null); } else { addReads0(this, other); } } --- 405,415 ---- private void implAddReads(Module other, boolean syncVM) { Objects.requireNonNull(other); if (!canRead(other)) { // update VM first, just in case it fails if (syncVM) { ! if (other == Special.ALL_UNNAMED_MODULE) { addReads0(this, null); } else { addReads0(this, other); } }
*** 505,515 **** * * @see ModuleDescriptor#exports() */ public boolean isExported(String pn) { Objects.requireNonNull(pn); ! return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/false); } /** * Returns {@code true} if this module has <em>opened</em> a package * unconditionally. --- 508,518 ---- * * @see ModuleDescriptor#exports() */ public boolean isExported(String pn) { Objects.requireNonNull(pn); ! return implIsExportedOrOpen(pn, Special.EVERYONE_MODULE, /*open*/false); } /** * Returns {@code true} if this module has <em>opened</em> a package * unconditionally.
*** 529,539 **** * * @see ModuleDescriptor#opens() */ public boolean isOpen(String pn) { Objects.requireNonNull(pn); ! return implIsExportedOrOpen(pn, EVERYONE_MODULE, /*open*/true); } /** * Returns {@code true} if this module exports or opens the given package --- 532,542 ---- * * @see ModuleDescriptor#opens() */ public boolean isOpen(String pn) { Objects.requireNonNull(pn); ! return implIsExportedOrOpen(pn, Special.EVERYONE_MODULE, /*open*/true); } /** * Returns {@code true} if this module exports or opens the given package
*** 592,607 **** * or the given module. Also returns true if the given module is an unnamed * module and targets contains ALL_UNNAMED_MODULE. */ private boolean allows(Set<Module> targets, Module module) { if (targets != null) { ! if (targets.contains(EVERYONE_MODULE)) return true; ! if (module != EVERYONE_MODULE) { if (targets.contains(module)) return true; ! if (!module.isNamed() && targets.contains(ALL_UNNAMED_MODULE)) return true; } } return false; } --- 595,610 ---- * or the given module. Also returns true if the given module is an unnamed * module and targets contains ALL_UNNAMED_MODULE. */ private boolean allows(Set<Module> targets, Module module) { if (targets != null) { ! if (targets.contains(Special.EVERYONE_MODULE)) return true; ! if (module != Special.EVERYONE_MODULE) { if (targets.contains(module)) return true; ! if (!module.isNamed() && targets.contains(Special.ALL_UNNAMED_MODULE)) return true; } } return false; }
*** 610,629 **** * Returns {@code true} if this module reflectively exports or opens the * given package to the given module. */ private boolean isReflectivelyExportedOrOpen(String pn, Module other, boolean open) { // exported or open to all modules ! Map<String, Boolean> exports = ReflectionData.exports.get(this, EVERYONE_MODULE); if (exports != null) { Boolean b = exports.get(pn); if (b != null) { boolean isOpen = b.booleanValue(); if (!open || isOpen) return true; } } ! if (other != EVERYONE_MODULE) { // exported or open to other exports = ReflectionData.exports.get(this, other); if (exports != null) { Boolean b = exports.get(pn); --- 613,632 ---- * Returns {@code true} if this module reflectively exports or opens the * given package to the given module. */ private boolean isReflectivelyExportedOrOpen(String pn, Module other, boolean open) { // exported or open to all modules ! Map<String, Boolean> exports = ReflectionData.exports.get(this, Special.EVERYONE_MODULE); if (exports != null) { Boolean b = exports.get(pn); if (b != null) { boolean isOpen = b.booleanValue(); if (!open || isOpen) return true; } } ! if (other != Special.EVERYONE_MODULE) { // exported or open to other exports = ReflectionData.exports.get(this, other); if (exports != null) { Boolean b = exports.get(pn);
*** 633,643 **** } } // other is an unnamed module && exported or open to all unnamed if (!other.isNamed()) { ! exports = ReflectionData.exports.get(this, ALL_UNNAMED_MODULE); if (exports != null) { Boolean b = exports.get(pn); if (b != null) { boolean isOpen = b.booleanValue(); if (!open || isOpen) return true; --- 636,646 ---- } } // other is an unnamed module && exported or open to all unnamed if (!other.isNamed()) { ! exports = ReflectionData.exports.get(this, Special.ALL_UNNAMED_MODULE); if (exports != null) { Boolean b = exports.get(pn); if (b != null) { boolean isOpen = b.booleanValue(); if (!open || isOpen) return true;
*** 772,782 **** * Updates this module to export a package unconditionally. * * @apiNote This method is for JDK tests only. */ void implAddExports(String pn) { ! implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, false, true); } /** * Updates this module to export a package to another module. * --- 775,785 ---- * Updates this module to export a package unconditionally. * * @apiNote This method is for JDK tests only. */ void implAddExports(String pn) { ! implAddExportsOrOpens(pn, Special.EVERYONE_MODULE, false, true); } /** * Updates this module to export a package to another module. *
*** 790,810 **** * Updates this module to export a package to all unnamed modules. * * @apiNote Used by the --add-exports command line option. */ void implAddExportsToAllUnnamed(String pn) { ! implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, false, true); } /** * Updates this export to export a package unconditionally without * notifying the VM. * * @apiNote This method is for VM white-box testing. */ void implAddExportsNoSync(String pn) { ! implAddExportsOrOpens(pn.replace('/', '.'), Module.EVERYONE_MODULE, false, false); } /** * Updates a module to export a package to another module without * notifying the VM. --- 793,813 ---- * Updates this module to export a package to all unnamed modules. * * @apiNote Used by the --add-exports command line option. */ void implAddExportsToAllUnnamed(String pn) { ! implAddExportsOrOpens(pn, Special.ALL_UNNAMED_MODULE, false, true); } /** * Updates this export to export a package unconditionally without * notifying the VM. * * @apiNote This method is for VM white-box testing. */ void implAddExportsNoSync(String pn) { ! implAddExportsOrOpens(pn.replace('/', '.'), Special.EVERYONE_MODULE, false, false); } /** * Updates a module to export a package to another module without * notifying the VM.
*** 819,829 **** * Updates this module to open a package unconditionally. * * @apiNote This method is for JDK tests only. */ void implAddOpens(String pn) { ! implAddExportsOrOpens(pn, Module.EVERYONE_MODULE, true, true); } /** * Updates this module to open a package to another module. * --- 822,832 ---- * Updates this module to open a package unconditionally. * * @apiNote This method is for JDK tests only. */ void implAddOpens(String pn) { ! implAddExportsOrOpens(pn, Special.EVERYONE_MODULE, true, true); } /** * Updates this module to open a package to another module. *
*** 837,847 **** * Updates this module to open a package to all unnamed modules. * * @apiNote Used by the --add-opens command line option. */ void implAddOpensToAllUnnamed(String pn) { ! implAddExportsOrOpens(pn, Module.ALL_UNNAMED_MODULE, true, true); } /** * Updates a module to export or open a module to another module. * --- 840,850 ---- * Updates this module to open a package to all unnamed modules. * * @apiNote Used by the --add-opens command line option. */ void implAddOpensToAllUnnamed(String pn) { ! implAddExportsOrOpens(pn, Special.ALL_UNNAMED_MODULE, true, true); } /** * Updates a module to export or open a module to another module. *
*** 887,899 **** + " not in contents"); } // update VM first, just in case it fails if (syncVM) { ! if (other == EVERYONE_MODULE) { addExportsToAll0(this, pn); ! } else if (other == ALL_UNNAMED_MODULE) { addExportsToAllUnnamed0(this, pn); } else { addExports0(this, pn, other); } } --- 890,902 ---- + " not in contents"); } // update VM first, just in case it fails if (syncVM) { ! if (other == Special.EVERYONE_MODULE) { addExportsToAll0(this, pn); ! } else if (other == Special.ALL_UNNAMED_MODULE) { addExportsToAllUnnamed0(this, pn); } else { addExports0(this, pn, other); } }
*** 928,940 **** } 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); } --- 931,943 ---- } else { openPackages = new HashMap<>(openPackages); } while (iterator.hasNext()) { String pn = iterator.next(); ! Set<Module> prev = openPackages.putIfAbsent(pn, Special.ALL_UNNAMED_MODULE_SET); if (prev != null) { ! prev.add(Special.ALL_UNNAMED_MODULE); } // update VM to export the package addExportsToAllUnnamed0(this, pn); }
*** 1150,1160 **** } m.reads = reads; // automatic modules read all unnamed modules if (descriptor.isAutomatic()) { ! m.implAddReads(ALL_UNNAMED_MODULE, true); } // exports and opens, skipped for open and automatic if (!descriptor.isOpen() && !descriptor.isAutomatic()) { if (isBootLayer && descriptor.opens().isEmpty()) { --- 1153,1163 ---- } m.reads = reads; // automatic modules read all unnamed modules if (descriptor.isAutomatic()) { ! m.implAddReads(Special.ALL_UNNAMED_MODULE, true); } // exports and opens, skipped for open and automatic if (!descriptor.isOpen() && !descriptor.isAutomatic()) { if (isBootLayer && descriptor.opens().isEmpty()) {
*** 1242,1252 **** exportedPackages.put(source, targets); } } else { // unqualified exports addExportsToAll0(m, source); ! exportedPackages.put(source, EVERYONE_SET); } } if (!exportedPackages.isEmpty()) m.exportedPackages = exportedPackages; --- 1245,1255 ---- exportedPackages.put(source, targets); } } else { // unqualified exports addExportsToAll0(m, source); ! exportedPackages.put(source, Special.EVERYONE_SET); } } if (!exportedPackages.isEmpty()) m.exportedPackages = exportedPackages;
*** 1287,1307 **** openPackages.put(source, targets); } } else { // unqualified opens addExportsToAll0(m, source); ! openPackages.put(source, EVERYONE_SET); } } // next the exports, skipping exports when the package is open for (Exports exports : descriptor.exports()) { String source = exports.source(); // skip export if package is already open to everyone Set<Module> openToTargets = openPackages.get(source); ! if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE)) continue; if (exports.isQualified()) { // qualified exports Set<Module> targets = new HashSet<>(); --- 1290,1310 ---- openPackages.put(source, targets); } } else { // unqualified opens addExportsToAll0(m, source); ! openPackages.put(source, Special.EVERYONE_SET); } } // next the exports, skipping exports when the package is open for (Exports exports : descriptor.exports()) { String source = exports.source(); // skip export if package is already open to everyone Set<Module> openToTargets = openPackages.get(source); ! if (openToTargets != null && openToTargets.contains(Special.EVERYONE_MODULE)) continue; if (exports.isQualified()) { // qualified exports Set<Module> targets = new HashSet<>();
*** 1319,1329 **** exportedPackages.put(source, targets); } } else { // unqualified exports addExportsToAll0(m, source); ! exportedPackages.put(source, EVERYONE_SET); } } if (!openPackages.isEmpty()) m.openPackages = openPackages; --- 1322,1332 ---- exportedPackages.put(source, targets); } } else { // unqualified exports addExportsToAll0(m, source); ! exportedPackages.put(source, Special.EVERYONE_SET); } } if (!openPackages.isEmpty()) m.openPackages = openPackages;
< prev index next >