From 2873f726e3d54d0ee48aca1c8aaa677bd445f6fd Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Fri, 13 Mar 2026 11:22:48 -0400 Subject: [PATCH] 8366020: Assert that user code is not executed during the AOT assembly phase. --- src/hotspot/share/cds/aotClassInitializer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/hotspot/share/cds/aotClassInitializer.cpp b/src/hotspot/share/cds/aotClassInitializer.cpp index 06fc3af6f30..b59c153f4ab 100644 --- a/src/hotspot/share/cds/aotClassInitializer.cpp +++ b/src/hotspot/share/cds/aotClassInitializer.cpp @@ -59,6 +59,21 @@ bool AOTClassInitializer::can_archive_initialized_mirror(InstanceKlass* ik) { return false; } +#ifndef PRODUCT + if (AOTInitTestClass == nullptr && ArchiveHeapTestClass == nullptr) { + // The above flags (in debug builds only) allow user code to be executed in assembly phase, + // strictly for testing purposes. If these flags are not set, no user code will be executed + // in assembly phase. + if (ik->class_loader() != nullptr && !ik->is_hidden()) { + if (ik->is_interface() && !ik->interface_needs_clinit_execution_as_super()) { + // TODO: why are these interfaces marked as initialized?? + } else { + assert(false, "cannot execute user code"); + } + } + } +#endif // PRODUCT + // About "static field that may hold a different value" errors: // // Automatic selection for aot-inited classes