892 addExportsToAll0(this, pn);
893 } else if (other == ALL_UNNAMED_MODULE) {
894 addExportsToAllUnnamed0(this, pn);
895 } else {
896 addExports0(this, pn, other);
897 }
898 }
899
900 // add package name to exports if absent
901 Map<String, Boolean> map = ReflectionData.exports
902 .computeIfAbsent(this, other,
903 (m1, m2) -> new ConcurrentHashMap<>());
904 if (open) {
905 map.put(pn, Boolean.TRUE); // may need to promote from FALSE to TRUE
906 } else {
907 map.putIfAbsent(pn, Boolean.FALSE);
908 }
909 }
910
911 /**
912 * Updates a module to open all packages returned by the given iterator to
913 * all unnamed modules.
914 *
915 * @apiNote Used during startup to open packages for illegal access.
916 */
917 void implAddOpensToAllUnnamed(Iterator<String> iterator) {
918 if (jdk.internal.misc.VM.isModuleSystemInited()) {
919 throw new IllegalStateException("Module system already initialized");
920 }
921
922 // replace this module's openPackages map with a new map that opens
923 // the packages to all unnamed modules.
924 Map<String, Set<Module>> openPackages = this.openPackages;
925 if (openPackages == null) {
926 openPackages = new HashMap<>();
927 } else {
928 openPackages = new HashMap<>(openPackages);
929 }
930 while (iterator.hasNext()) {
931 String pn = iterator.next();
932 Set<Module> prev = openPackages.putIfAbsent(pn, ALL_UNNAMED_MODULE_SET);
933 if (prev != null) {
934 prev.add(ALL_UNNAMED_MODULE);
935 }
936
937 // update VM to export the package
938 addExportsToAllUnnamed0(this, pn);
939 }
940 this.openPackages = openPackages;
941 }
942
943
944 // -- services --
945
946 /**
947 * If the caller's module is this module then update this module to add a
948 * service dependence on the given service type. This method is intended
949 * for use by frameworks that invoke {@link java.util.ServiceLoader
950 * ServiceLoader} on behalf of other modules or where the framework is
951 * passed a reference to the service type by other code. This method is
952 * a no-op when invoked on an unnamed module or an automatic module.
953 *
954 * <p> This method does not cause {@link Configuration#resolveAndBind
955 * resolveAndBind} to be re-run. </p>
956 *
957 * @param service
958 * The service type
959 *
960 * @return this module
961 *
962 * @throws IllegalCallerException
|
892 addExportsToAll0(this, pn);
893 } else if (other == ALL_UNNAMED_MODULE) {
894 addExportsToAllUnnamed0(this, pn);
895 } else {
896 addExports0(this, pn, other);
897 }
898 }
899
900 // add package name to exports if absent
901 Map<String, Boolean> map = ReflectionData.exports
902 .computeIfAbsent(this, other,
903 (m1, m2) -> new ConcurrentHashMap<>());
904 if (open) {
905 map.put(pn, Boolean.TRUE); // may need to promote from FALSE to TRUE
906 } else {
907 map.putIfAbsent(pn, Boolean.FALSE);
908 }
909 }
910
911 /**
912 * Updates a module to open all packages in the given sets to all unnamed
913 * modules.
914 *
915 * @apiNote Used during startup to open packages for illegal access.
916 */
917 void implAddOpensToAllUnnamed(Set<String> concealedPkgs, Set<String> exportedPkgs) {
918 if (jdk.internal.misc.VM.isModuleSystemInited()) {
919 throw new IllegalStateException("Module system already initialized");
920 }
921
922 // replace this module's openPackages map with a new map that opens
923 // the packages to all unnamed modules.
924 Map<String, Set<Module>> openPackages = this.openPackages;
925 if (openPackages == null) {
926 openPackages = new HashMap<>((4 * (concealedPkgs.size() + exportedPkgs.size()) / 3) + 1);
927 } else {
928 openPackages = new HashMap<>(openPackages);
929 }
930 implAddOpensToAllUnnamed(concealedPkgs, openPackages);
931 implAddOpensToAllUnnamed(exportedPkgs, openPackages);
932 this.openPackages = openPackages;
933 }
934
935 private void implAddOpensToAllUnnamed(Set<String> pkgs, Map<String, Set<Module>> openPackages) {
936 for (String pn : pkgs) {
937 Set<Module> prev = openPackages.putIfAbsent(pn, ALL_UNNAMED_MODULE_SET);
938 if (prev != null) {
939 prev.add(ALL_UNNAMED_MODULE);
940 }
941
942 // update VM to export the package
943 addExportsToAllUnnamed0(this, pn);
944 }
945 }
946
947 // -- services --
948
949 /**
950 * If the caller's module is this module then update this module to add a
951 * service dependence on the given service type. This method is intended
952 * for use by frameworks that invoke {@link java.util.ServiceLoader
953 * ServiceLoader} on behalf of other modules or where the framework is
954 * passed a reference to the service type by other code. This method is
955 * a no-op when invoked on an unnamed module or an automatic module.
956 *
957 * <p> This method does not cause {@link Configuration#resolveAndBind
958 * resolveAndBind} to be re-run. </p>
959 *
960 * @param service
961 * The service type
962 *
963 * @return this module
964 *
965 * @throws IllegalCallerException
|