Skip to content

Commit f6c7115

Browse files
committed
Improve documentation of Layered Module code
1 parent ff74ca5 commit f6c7115

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/LayeredModuleSingleton.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SharedLayerBootLayerModulesSingleton.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
import com.oracle.svm.hosted.imagelayer.SVMImageLayerSingletonLoader;
5050
import com.oracle.svm.hosted.imagelayer.SVMImageLayerWriter;
5151

52+
/**
53+
* This singleton persists all the modules from the {@code bootLayer} of the shared layers and
54+
* allows to loads them in the extension layers. This is needed for the {@code RuntimeModuleSupport}
55+
* that contains the runtime bootLayer and is only installed in the application layer.
56+
*/
5257
@Platforms(Platform.HOSTED_ONLY.class)
5358
@AutomaticallyRegisteredImageSingleton(onlyWith = BuildingInitialLayerPredicate.class)
5459
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = SharedLayerBootLayerModulesSingleton.LayeredCallbacks.class, layeredInstallationKind = Independent.class)

0 commit comments

Comments
 (0)