Skip to content

Commit b40c22c

Browse files
committed
Document code
1 parent b00e02f commit b40c22c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

substratevm/src/com.oracle.svm.hosted.jdk11/src/com/oracle/svm/hosted/ModuleLayerFeature.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ private static Stream<String> extractRequiredModuleNames(Module m) {
210210
}
211211

212212
private ModuleLayer synthesizeRuntimeBootLayer(ImageClassLoader cl, Set<String> reachableModules, Set<Module> syntheticModules) {
213+
/**
214+
* For consistent module lookup we reuse the {@link ModuleFinder}s defined and used in
215+
* {@link NativeImageClassLoaderSupportJDK11OrLater}.
216+
*/
213217
NativeImageClassLoaderSupportJDK11OrLater classLoaderSupport = (NativeImageClassLoaderSupportJDK11OrLater) cl.classLoaderSupport;
214218
ModuleFinder beforeFinder = classLoaderSupport.modulepathModuleFinder;
215219
ModuleFinder afterFinder = classLoaderSupport.upgradeAndSystemModuleFinder;

substratevm/src/com.oracle.svm.hosted.jdk11/src/com/oracle/svm/hosted/jdk/NativeImageClassLoaderSupportJDK11OrLater.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.ArrayDeque;
3838
import java.util.ArrayList;
3939
import java.util.Arrays;
40+
import java.util.Collection;
4041
import java.util.Collections;
4142
import java.util.Deque;
4243
import java.util.HashSet;
@@ -97,6 +98,13 @@ private ModuleLayer createModuleLayer(Path[] modulePaths, ClassLoader parent) {
9798
ModuleFinder modulePathsFinder = ModuleFinder.of(modulePaths);
9899
Set<String> moduleNames = modulePathsFinder.findAll().stream().map(moduleReference -> moduleReference.descriptor().name()).collect(Collectors.toSet());
99100

101+
/**
102+
* When building a moduleLayer for the module-path passed to native-image we need to be able
103+
* to resolve against system modules that are not used by the moduleLayer in which the
104+
* image-builder got loaded into. To do so we use {@link upgradeAndSystemModuleFinder} as
105+
* {@code ModuleFinder after} in
106+
* {@link Configuration#resolve(ModuleFinder, ModuleFinder, Collection)}.
107+
*/
100108
Configuration configuration = ModuleLayer.boot().configuration().resolve(modulePathsFinder, upgradeAndSystemModuleFinder, moduleNames);
101109
/**
102110
* For the modules we want to build an image for, a ModuleLayer is needed that can be
@@ -106,7 +114,8 @@ private ModuleLayer createModuleLayer(Path[] modulePaths, ClassLoader parent) {
106114
}
107115

108116
/**
109-
* Gets a finder that locates the upgrade modules and the system modules, in that order.
117+
* Gets a finder that locates the upgrade modules and the system modules, in that order. Upgrade
118+
* modules are used when mx environment variable {@code MX_BUILD_EXPLODED=true} is used.
110119
*/
111120
private static ModuleFinder createUpgradeAndSystemModuleFinder() {
112121
ModuleFinder finder = ModuleFinder.ofSystem();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,15 @@ void trackMethod(AnalysisMetaAccess metaAccess) {
125125
void apply(BytecodePosition invokeLocation) {
126126
Class<?> javaClass = ((AnalysisMethod) invokeLocation.getMethod()).getDeclaringClass().getJavaClass();
127127
if (systemModuleDescriptors.contains(ModuleSupport.getModuleDescriptor(javaClass))) {
128+
/* Ensure all JDK system modules are excluded from reporting reflection use. */
128129
return;
129130
}
130131
ClassLoader classLoader = javaClass.getClassLoader();
131132
if (!NativeImageSystemClassLoader.singleton().isNativeImageClassLoader(classLoader)) {
133+
/* Classes not loaded by NativeImageClassLoader are also excluded. */
132134
return;
133135
}
136+
/* Collect reflection use in application classes. */
134137
checker.check(this, invokeLocation);
135138
}
136139

0 commit comments

Comments
 (0)