diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java index ddf325915bfe..1c264368b80c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java @@ -158,7 +158,7 @@ public ClassLoader getClassLoader() { } public void initAllClasses(ForkJoinPool executor, ImageClassLoader imageClassLoader) { - new ClassInitWithModules(executor, imageClassLoader).init(); + new ClassInit(executor, imageClassLoader).init(); } private HostedOptionParser hostedOptionParser; @@ -540,9 +540,39 @@ protected ClassInit(ForkJoinPool executor, ImageClassLoader imageClassLoader) { } protected void init() { + List requiresInit = Arrays.asList( + "jdk.internal.vm.ci", "jdk.internal.vm.compiler", "com.oracle.graal.graal_enterprise", + "org.graalvm.sdk", "org.graalvm.truffle"); + + for (ModuleReference moduleReference : upgradeAndSystemModuleFinder.findAll()) { + if (requiresInit.contains(moduleReference.descriptor().name())) { + initModule(moduleReference); + } + } + for (ModuleReference moduleReference : modulepathModuleFinder.findAll()) { + initModule(moduleReference); + } + classpath().parallelStream().forEach(this::loadClassesFromPath); } + private void initModule(ModuleReference moduleReference) { + Optional optionalModule = findModule(moduleReference.descriptor().name()); + if (optionalModule.isEmpty()) { + return; + } + try (ModuleReader moduleReader = moduleReference.open()) { + Module module = optionalModule.get(); + moduleReader.list().forEach(moduleResource -> { + if (moduleResource.endsWith(CLASS_EXTENSION)) { + executor.execute(() -> handleClassFileName(moduleReference.location().orElseThrow(), module, moduleResource, '/')); + } + }); + } catch (IOException e) { + throw new RuntimeException("Unable get list of resources in module" + moduleReference.descriptor().name(), e); + } + } + private void loadClassesFromPath(Path path) { if (ClasspathUtils.isJar(path)) { try { @@ -678,46 +708,4 @@ protected void handleClassFileName(URI container, Object module, String fileName } } } - - private class ClassInitWithModules extends ClassInit { - - ClassInitWithModules(ForkJoinPool executor, ImageClassLoader imageClassLoader) { - super(executor, imageClassLoader); - } - - @Override - protected void init() { - List requiresInit = Arrays.asList( - "jdk.internal.vm.ci", "jdk.internal.vm.compiler", "com.oracle.graal.graal_enterprise", - "org.graalvm.sdk", "org.graalvm.truffle"); - - for (ModuleReference moduleReference : upgradeAndSystemModuleFinder.findAll()) { - if (requiresInit.contains(moduleReference.descriptor().name())) { - initModule(moduleReference); - } - } - for (ModuleReference moduleReference : modulepathModuleFinder.findAll()) { - initModule(moduleReference); - } - - super.init(); - } - - private void initModule(ModuleReference moduleReference) { - Optional optionalModule = findModule(moduleReference.descriptor().name()); - if (optionalModule.isEmpty()) { - return; - } - try (ModuleReader moduleReader = moduleReference.open()) { - Module module = optionalModule.get(); - moduleReader.list().forEach(moduleResource -> { - if (moduleResource.endsWith(CLASS_EXTENSION)) { - executor.execute(() -> handleClassFileName(moduleReference.location().orElseThrow(), module, moduleResource, '/')); - } - }); - } catch (IOException e) { - throw new RuntimeException("Unable get list of resources in module" + moduleReference.descriptor().name(), e); - } - } - } }