Skip to content

Commit a101c58

Browse files
committed
Apply PR comments
1 parent aa85a54 commit a101c58

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,19 @@ public void afterAnalysis(AfterAnalysisAccess access) {
221221
* compute the root module set that should be seen at image runtime. It reuses the same methods
222222
* as the original (via reflective invokes).
223223
*/
224-
private Set<String> calculateRootModules(FeatureImpl.AfterAnalysisAccessImpl accessImpl, Collection<String> extraModules) {
224+
private Set<String> calculateRootModules(FeatureImpl.AfterAnalysisAccessImpl accessImpl, Collection<String> addModules) {
225225
String mainModule = moduleLayerFeatureUtils.getMainModuleName();
226226
List<Path> appModulePath = accessImpl.imageClassLoader.applicationModulePath();
227-
String upgradeModulePath = System.getProperty("jdk.module.upgrade.path");
228-
boolean haveUpgradeModulePath = upgradeModulePath != null && !upgradeModulePath.isEmpty();
227+
ModuleFinder upgradeModulePath = NativeImageClassLoaderSupport.finderFor("jdk.module.upgrade.path");
228+
boolean haveUpgradeModulePath = upgradeModulePath != null;
229229
boolean haveSVMLibrarySupportOnAppModulePath = appModulePath.stream().anyMatch(p -> p.endsWith("/lib/svm/library-support.jar"));
230-
boolean haveAppModulePath = (!appModulePath.isEmpty() && !haveSVMLibrarySupportOnAppModulePath) || haveUpgradeModulePath;
230+
boolean haveModulePath = (!appModulePath.isEmpty() && !haveSVMLibrarySupportOnAppModulePath) || haveUpgradeModulePath;
231231
Set<String> limitModules = ModuleLayerFeatureUtils.parseModuleSetModifierProperty(ModuleSupport.PROPERTY_IMAGE_EXPLICITLY_LIMITED_MODULES);
232232

233233
Object systemModules = null;
234234
ModuleFinder systemModuleFinder;
235235

236-
if (!haveAppModulePath && extraModules.isEmpty() && limitModules.isEmpty()) {
236+
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
237237
systemModules = moduleLayerFeatureUtils.invokeSystemModuleFinderSystemModules(mainModule);
238238
}
239239
if (systemModules == null) {
@@ -245,18 +245,23 @@ private Set<String> calculateRootModules(FeatureImpl.AfterAnalysisAccessImpl acc
245245
systemModuleFinder = SystemModuleFinders.ofSystem();
246246
}
247247

248-
systemModuleFinder = ModuleFinder.compose(moduleLayerFeatureUtils.imageClassLoader.classLoaderSupport.modulepathModuleFinder, systemModuleFinder);
248+
ModuleFinder builderModuleFinder = ModuleFinder.compose(moduleLayerFeatureUtils.imageClassLoader.classLoaderSupport.modulepathModuleFinder, systemModuleFinder);
249+
ModuleFinder limitedBuilderModuleFinder = moduleLayerFeatureUtils.invokeModuleBootstrapLimitFinder(builderModuleFinder, Set.of(ModuleLayerFeature.class.getModule().getName()), Set.of());
250+
systemModuleFinder = ModuleFinder.compose(limitedBuilderModuleFinder, systemModuleFinder);
251+
249252
if (haveUpgradeModulePath) {
250-
systemModuleFinder = ModuleFinder.compose(accessImpl.imageClassLoader.classLoaderSupport.upgradeAndSystemModuleFinder, systemModuleFinder);
253+
systemModuleFinder = ModuleFinder.compose(upgradeModulePath, systemModuleFinder);
251254
}
252255

256+
ModuleFinder finder;
253257
ModuleFinder appModulePathFinder = null;
254-
if (haveAppModulePath) {
255-
appModulePathFinder = ModuleFinder.of(accessImpl.imageClassLoader.applicationModulePath().toArray(new Path[0]));
258+
if (haveModulePath) {
259+
appModulePathFinder = ModuleFinder.of(appModulePath.toArray(new Path[0]));
260+
finder = ModuleFinder.compose(systemModuleFinder, appModulePathFinder);
261+
} else {
262+
finder = systemModuleFinder;
256263
}
257264

258-
ModuleFinder finder = haveAppModulePath ? ModuleFinder.compose(systemModuleFinder, appModulePathFinder) : systemModuleFinder;
259-
260265
Set<String> roots = new HashSet<>();
261266

262267
if (mainModule != null) {
@@ -266,7 +271,7 @@ private Set<String> calculateRootModules(FeatureImpl.AfterAnalysisAccessImpl acc
266271
boolean addAllDefaultModules = false;
267272
boolean addAllSystemModules = false;
268273
boolean addAllApplicationModules = false;
269-
for (String mod : extraModules) {
274+
for (String mod : addModules) {
270275
switch (mod) {
271276
case ModuleSupport.MODULE_SET_ALL_DEFAULT:
272277
addAllDefaultModules = true;
@@ -1006,6 +1011,8 @@ ModuleFinder invokeModuleBootstrapLimitFinder(ModuleFinder finder, Set<String> r
10061011
try {
10071012
return (ModuleFinder) moduleBootstrapLimitFinderMethod.invoke(null, finder, roots, otherModules);
10081013
} catch (ReflectiveOperationException e) {
1014+
// TODO remove
1015+
e.printStackTrace();
10091016
throw VMError.shouldNotReachHere("Failed to reflectively invoke ModuleBootstrap.limitFinder().", e);
10101017
}
10111018
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private static ModuleFinder createUpgradeAndSystemModuleFinder() {
290290
/**
291291
* Creates a finder from a module path specified by the {@code prop} system property.
292292
*/
293-
private static ModuleFinder finderFor(String prop) {
293+
static ModuleFinder finderFor(String prop) {
294294
String s = System.getProperty(prop);
295295
if (s == null || s.isEmpty()) {
296296
return null;

0 commit comments

Comments
 (0)