Skip to content

Commit

Permalink
Fold ClassInitWithModules into ClassInit
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed Mar 21, 2022
1 parent b848c33 commit dd28063
Showing 1 changed file with 31 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -540,9 +540,39 @@ protected ClassInit(ForkJoinPool executor, ImageClassLoader imageClassLoader) {
}

protected void init() {
List<String> 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<Module> 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 {
Expand Down Expand Up @@ -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<String> 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<Module> 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);
}
}
}
}

0 comments on commit dd28063

Please sign in to comment.