From dd28063e11fff8eebc8283f16454bb65759f3864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Mon, 21 Mar 2022 14:17:08 +0100 Subject: [PATCH] Fold ClassInitWithModules into ClassInit --- .../hosted/NativeImageClassLoaderSupport.java | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) 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); - } - } - } }