8381710: Avoid using lambdas in ModuleBootstrap in AOT training mode

Co-authored-by: Alan Bateman <alanb@openjdk.org>
Reviewed-by: kvn, liach
This commit is contained in:
Ioi Lam 2026-05-19 19:20:02 +00:00
parent ff34610ead
commit a37b02baa2
2 changed files with 36 additions and 17 deletions

View File

@ -115,10 +115,18 @@ void AOTArtifactFinder::find_artifacts() {
// Add all the InstanceKlasses (and their array classes) that are always included.
SystemDictionaryShared::dumptime_table()->iterate_all_live_classes([&] (InstanceKlass* ik, DumpTimeClassInfo& info) {
// Skip "AOT tooling classes" in this block. They will be included in the AOT cache only if
// - One of their subtypes is included
// - One of their instances is found by HeapShared.
if (!info.is_excluded() && !info.is_aot_tooling_class()) {
bool skip = info.is_excluded();
if (!(ik->is_initialized() && ik->has_aot_safe_initializer())) {
if (info.is_aot_tooling_class()) {
// This class is loading only by AOT tooling (not as part of the app's training run).
// Skip this class for now, but it might be added later if
// - One of its subtypes is included
// - One of its instances is found by HeapShared.
skip = true;
}
}
if (!skip) {
bool add = false;
if (!ik->is_hidden()) {
// All non-hidden classes are always included into the AOT cache

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -517,10 +517,13 @@ public final class ModuleBootstrap {
* modular JAR files.
*/
private static boolean allJrtOrModularJar(Configuration cf) {
return !cf.modules().stream()
.map(m -> m.reference().location().orElseThrow())
.anyMatch(uri -> !uri.getScheme().equalsIgnoreCase("jrt")
&& !isJarFile(uri));
for (ResolvedModule module : cf.modules()) {
URI uri = module.reference().location().orElseThrow();
if (!uri.getScheme().equalsIgnoreCase("jrt") && !isJarFile(uri)) {
return false;
}
}
return true;
}
/**
@ -539,11 +542,16 @@ public final class ModuleBootstrap {
* Returns true if the configuration contains modules with overlapping packages.
*/
private static boolean containsSplitPackages(Configuration cf) {
boolean found = cf.modules().stream()
.map(m -> m.reference().descriptor().packages())
.flatMap(Set::stream)
.allMatch(new HashSet<>()::add);
return !found;
var allPackages = new HashSet<String>();
for (ResolvedModule module: cf.modules()) {
Set<String> packages = module.reference().descriptor().packages();
int expectedCount = allPackages.size() + packages.size();
allPackages.addAll(packages);
if (expectedCount > allPackages.size()) {
return true; // overlapping packages.
}
}
return false;
}
/**
@ -1058,9 +1066,12 @@ public final class ModuleBootstrap {
* Returns true if the configuration contains an incubator module.
*/
private static boolean containsIncubatorModule(Configuration cf) {
return cf.modules().stream()
.map(ResolvedModule::reference)
.anyMatch(ModuleResolution::hasIncubatingWarning);
for (ResolvedModule module : cf.modules()) {
if (ModuleResolution.hasIncubatingWarning(module.reference())) {
return true;
}
}
return false;
}
/**