@@ -48,12 +48,37 @@ public abstract class LayeredModuleSingleton {
4848 public static final String ALL_UNNAMED_MODULE_NAME = "native-image-all-unnamed" ;
4949 public static final String EVERYONE_MODULE_NAME = "native-image-everyone" ;
5050
51+ /**
52+ * Map containing all the {@code Module#openPackages} values for each module. The key is the
53+ * module name and the value is the corresponding {@code Module#openPackages}. The name of the
54+ * module is used instead of the Module object because the hashcode of the Module object is not
55+ * consistent across layers. This is ensured by
56+ * {@link LayeredModuleSingleton#setPackages(ResolvedJavaModule, EconomicMap, Map, String)}}.
57+ */
5158 protected final EconomicMap <String , Map <String , Set <String >>> moduleOpenPackages ;
59+
60+ /**
61+ * See {@link LayeredModuleSingleton#moduleOpenPackages}.
62+ */
5263 protected final EconomicMap <String , Map <String , Set <String >>> moduleExportedPackages ;
5364
65+ /**
66+ * Keeps track of all the modules whose {@code Module#openPackages} and
67+ * {@code Module#exportedPackages} are set by
68+ * {@link LayeredModuleSingleton#setExportedPackages(ResolvedJavaModule, Map)} and
69+ * {@link LayeredModuleSingleton#setOpenPackages(ResolvedJavaModule, Map)}. This also allows to
70+ * ensure each module has a different name.
71+ */
5472 private final EconomicMap <String , ResolvedJavaModule > nameToModule = EconomicMap .create ();
5573
74+ /**
75+ * The value of {@code Module.EVERYONE_MODULE}.
76+ */
5677 private ResolvedJavaModule everyoneModule ;
78+
79+ /**
80+ * The value of {@code Module.ALL_UNNAMED_MODULE}.
81+ */
5782 private ResolvedJavaModule allUnnamedModule ;
5883
5984 public LayeredModuleSingleton () {
@@ -82,6 +107,10 @@ public Map<String, Set<String>> getExportedPackages(ResolvedJavaModule module) {
82107 return moduleExportedPackages .get (module .getName ());
83108 }
84109
110+ /**
111+ * Returns all the modules whose {@code Module#openPackages} and {@code Module#exportedPackages}
112+ * are set.
113+ */
85114 public Iterable <ResolvedJavaModule > getModules () {
86115 return nameToModule .getValues ();
87116 }
@@ -114,6 +143,10 @@ private void setPackages(ResolvedJavaModule module, EconomicMap<String, Map<Stri
114143 Set <String > modules = namesMap .computeIfAbsent (entry .getKey (), _ -> new HashSet <>());
115144 modules .addAll (entry .getValue ().stream ().map (GraalAccess ::lookupModule ).map (ResolvedJavaModule ::getName ).toList ());
116145 modules .remove (null );
146+ /*
147+ * ALL_UNNAMED_MODULE and EVERYONE_MODULE don't have a name, so they need a special
148+ * marker to track them.
149+ */
117150 if (entry .getValue ().contains (OriginalModuleProvider .getJavaModule (allUnnamedModule ))) {
118151 modules .add (ALL_UNNAMED_MODULE_NAME );
119152 }
0 commit comments