Skip to content

Commit

Permalink
[GR-47186] Unified native-image classloader for module- and class-path.
Browse files Browse the repository at this point in the history
PullRequest: graal/15140
  • Loading branch information
olpaw committed Aug 30, 2023
2 parents 8d0ad47 + 2d3ffcc commit 7659203
Show file tree
Hide file tree
Showing 5 changed files with 875 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import java.io.File;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Set;
import java.util.Vector;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

Expand Down Expand Up @@ -361,3 +364,11 @@ final class ClassLoaderUtil {

public static final LazyFinalReference<Target_java_lang_Module> unnamedModuleReference = new LazyFinalReference<>(Target_java_lang_Module::new);
}

@TargetClass(className = "java.lang.ClassLoader", innerClass = "ParallelLoaders")
final class Target_java_lang_ClassLoader_ParallelLoaders {

@Alias //
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias) //
private static Set<Class<? extends ClassLoader>> loaderTypes = Collections.newSetFromMap(new WeakHashMap<>());
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -67,21 +66,13 @@ public class ClassLoaderSupportImpl extends ClassLoaderSupport {

private final NativeImageClassLoaderSupport classLoaderSupport;

private final ClassLoader imageClassLoader;
private final URLClassLoader classPathClassLoader;
private final NativeImageClassLoader imageClassLoader;

private final Map<String, Set<Module>> packageToModules;

public ClassLoaderSupportImpl(NativeImageClassLoaderSupport classLoaderSupport) {
this.classLoaderSupport = classLoaderSupport;
imageClassLoader = classLoaderSupport.getClassLoader();
/*
* Only if imageClassLoader is not the URLClassLoader we need to also remember its parent as
* classPathClassLoader (for use in isNativeImageClassLoaderImpl). Otherwise, there is only
* the URLClassLoader (already stored in imageClassLoader, extra classPathClassLoader field
* can be set to null).
*/
classPathClassLoader = imageClassLoader instanceof URLClassLoader ? null : (URLClassLoader) imageClassLoader.getParent();
packageToModules = new HashMap<>();
buildPackageToModulesMap(classLoaderSupport);
}
Expand All @@ -91,9 +82,6 @@ protected boolean isNativeImageClassLoaderImpl(ClassLoader loader) {
if (loader == imageClassLoader) {
return true;
}
if (classPathClassLoader != null && loader == classPathClassLoader) {
return true;
}
if (loader instanceof NativeImageSystemClassLoader) {
return true;
}
Expand Down
Loading

0 comments on commit 7659203

Please sign in to comment.