From d59e2f1dcb1c2dc52df341aa371eda1806368545 Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Fri, 27 Mar 2026 15:21:57 -0400 Subject: [PATCH] Ioi comments --- src/hotspot/share/cds/aotClassInitializer.cpp | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/cds/aotClassInitializer.cpp b/src/hotspot/share/cds/aotClassInitializer.cpp index a7250dcdc7f..c66a73fb24c 100644 --- a/src/hotspot/share/cds/aotClassInitializer.cpp +++ b/src/hotspot/share/cds/aotClassInitializer.cpp @@ -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 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