Ioi comments

This commit is contained in:
Matias Saavedra Silva 2026-03-27 15:21:57 -04:00
parent b5f04edb52
commit d59e2f1dcb

View File

@ -60,13 +60,34 @@ bool AOTClassInitializer::can_archive_initialized_mirror(InstanceKlass* ik) {
}
#ifdef ASSERT
// If code in ik is executed, then ik must be in the state of being_initialized or
// fully_initialized.
//
// Check that no user code is executed during the assembly phase. Otherwise the user
// code may introduce undesirable environment dependencies into the heap image.
// If any of these two flags are set, we allow user code to be executed
// in the assembly phase. Note that these flags are strictly for the purpose
// of testing HotSpot and are not available in product builds.
if (AOTInitTestClass == nullptr && ArchiveHeapTestClass == nullptr) {
// The above flags (in debug builds only) allow Java code to be executed in assembly phase,
// strictly for testing purposes. If these flags are not set, no Java code should be executed
// in assembly phase.
if (ik->class_loader() != nullptr && !ik->is_hidden()) {
// Interfaces with default methods and <clinit> also execute Java code.
assert(ik->is_interface() && !ik->interface_needs_clinit_execution_as_super(), "cannot execute Java code in assembly phase, %d %d", ik->is_interface(), ik->interface_needs_clinit_execution_as_super());
if (ik->defined_by_boot_loader()) {
// We allow boot classes to be AOT-initialized, except for classes from
// -Xbootclasspath (cp index >= 1) be AOT-initialized, as such classes may be
// provided by the user application.
assert(ik->shared_classpath_index() <= 0,
"only boot classed loaded from the modules image can be AOT-initialized");
} else {
assert(ik->defined_by_platform_loader() || ik->defined_by_app_loader(),
"cannot AOT-initialized classed loaded by other loaders");
// Hidden classes from platform/app loaders need to be AOT-initialized to
// support AOT-linking of lambdas. These hidden classes are generated by the
// VM and do not contain user code.
if (!ik->is_hidden()) {
// OK: ik is an interface used by a lambda. When AOT-linking lambdas, we only
// support interfaces that are not interface_needs_clinit_execution_as_super().
// See AOTConstantPoolResolver::check_lambda_metafactory_signature().
assert(ik->is_interface() && !ik->interface_needs_clinit_execution_as_super(), "cannot execute Java code in assembly phase");
}
}
}
#endif // ASSERT