Skip to content

Commit 45880ce

Browse files
committed
Use HostedSubstrateUtil for runtime classloader resolving
1 parent 21a6dca commit 45880ce

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package com.oracle.svm.hosted;
2626

27-
import static com.oracle.svm.core.util.VMError.shouldNotReachHereAtRuntime;
28-
2927
import java.lang.module.Configuration;
3028
import java.lang.module.FindException;
3129
import java.lang.module.ModuleDescriptor;
@@ -56,7 +54,6 @@
5654
import java.util.stream.Collectors;
5755
import java.util.stream.Stream;
5856

59-
import jdk.internal.loader.ClassLoaders;
6057
import org.graalvm.nativeimage.ImageSingletons;
6158
import org.graalvm.nativeimage.Platform;
6259
import org.graalvm.nativeimage.Platforms;
@@ -73,6 +70,7 @@
7370
import com.oracle.svm.core.jdk.Resources;
7471
import com.oracle.svm.core.jdk.RuntimeClassLoaderValueSupport;
7572
import com.oracle.svm.core.jdk.RuntimeModuleSupport;
73+
import com.oracle.svm.core.util.HostedSubstrateUtil;
7674
import com.oracle.svm.core.util.VMError;
7775
import com.oracle.svm.hosted.FeatureImpl.AfterAnalysisAccessImpl;
7876
import com.oracle.svm.hosted.FeatureImpl.AnalysisAccessBase;
@@ -87,6 +85,8 @@
8785
import jdk.internal.module.ServicesCatalog;
8886
import jdk.internal.module.SystemModuleFinders;
8987

88+
import static com.oracle.svm.core.util.VMError.shouldNotReachHereAtRuntime;
89+
9090
/**
9191
* This feature:
9292
* <ul>
@@ -808,24 +808,12 @@ public ModuleFinder getAppModuleFinder() {
808808
}
809809
}
810810

811-
private ClassLoader getRuntimeLoaderFor(ClassLoader hostedLoader) {
812-
/*
813-
* Make sure to replace builder class loader with the application class loader. This is
814-
* the case, for example, for library support modules.
815-
*/
816-
if (hostedLoader == imageClassLoader.getClassLoader()) {
817-
return ClassLoaders.appClassLoader();
818-
} else {
819-
return hostedLoader;
820-
}
821-
}
822-
823811
public Module getRuntimeModuleForHostedModule(Module hostedModule, boolean optional) {
824812
return getRuntimeModuleForHostedModule(hostedModule.getClassLoader(), hostedModule.getName(), optional);
825813
}
826814

827815
public Module getRuntimeModuleForHostedModule(ClassLoader hostedLoader, String hostedModuleName, boolean optional) {
828-
ClassLoader loader = getRuntimeLoaderFor(hostedLoader);
816+
ClassLoader loader = HostedSubstrateUtil.getRuntimeClassLoader(hostedLoader);
829817
Map<String, Module> loaderRuntimeModules = runtimeModules.get(loader);
830818
if (loaderRuntimeModules == null) {
831819
if (optional) {
@@ -863,7 +851,7 @@ public Module getOrCreateRuntimeModuleForHostedModule(Module hostedModule, Analy
863851

864852
public Module getOrCreateRuntimeModuleForHostedModule(ClassLoader hostedLoader, String hostedModuleName, ModuleDescriptor runtimeModuleDescriptor, AnalysisAccessBase access,
865853
boolean enableNativeAccess) {
866-
ClassLoader loader = getRuntimeLoaderFor(hostedLoader);
854+
ClassLoader loader = HostedSubstrateUtil.getRuntimeClassLoader(hostedLoader);
867855
synchronized (runtimeModules) {
868856
Module runtimeModule = getRuntimeModuleForHostedModule(loader, hostedModuleName, true);
869857
if (runtimeModule != null) {

0 commit comments

Comments
 (0)