Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/hotspot/share/cds/aotClassInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@ bool AOTClassInitializer::can_archive_initialized_mirror(InstanceKlass* ik) {
return false;
}

#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) {
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

// About "static field that may hold a different value" errors:
//
// Automatic selection for aot-inited classes
Expand Down
2 changes: 1 addition & 1 deletion test/lib/jdk/test/lib/cds/CDSTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public static OutputAnalyzer createArchiveAndCheck(String... cliPrefix)
public static void checkCommonExecExceptions(OutputAnalyzer output, Exception e)
throws Exception {
if (output.getStdout().contains("https://bugreport.java.com/bugreport/crash.jsp")) {
throw new RuntimeException("Hotspot crashed");
throw new RuntimeException(getCrashMessage(output.getStdout()));
}
if (output.getStdout().contains("TEST FAILED")) {
throw new RuntimeException("Test Failed");
Expand Down