8267281: Call prepare_for_dynamic_dumping for jcmd dynamic_dump

Reviewed-by: iklam, ccheung
This commit is contained in:
Yumin Qi 2021-07-12 19:03:38 +00:00
parent 353e9c8607
commit a4e5f08fef
7 changed files with 15 additions and 12 deletions

View File

@ -346,12 +346,12 @@ public:
}
};
void DynamicArchive::prepare_for_dynamic_dumping_at_exit() {
void DynamicArchive::prepare_for_dynamic_dumping() {
EXCEPTION_MARK;
ResourceMark rm(THREAD);
MetaspaceShared::link_and_cleanup_shared_classes(THREAD);
MetaspaceShared::link_shared_classes(THREAD);
if (HAS_PENDING_EXCEPTION) {
log_error(cds)("ArchiveClassesAtExit has failed");
log_error(cds)("Dynamic dump has failed");
log_error(cds)("%s: %s", PENDING_EXCEPTION->klass()->external_name(),
java_lang_String::as_utf8_string(java_lang_Throwable::message(PENDING_EXCEPTION)));
// We cannot continue to dump the archive anymore.
@ -365,7 +365,10 @@ void DynamicArchive::dump(const char* archive_name, TRAPS) {
assert(ArchiveClassesAtExit == nullptr, "already checked in arguments.cpp?");
ArchiveClassesAtExit = archive_name;
if (Arguments::init_shared_archive_paths()) {
dump(CHECK);
prepare_for_dynamic_dumping();
if (DynamicDumpSharedSpaces) {
dump(CHECK);
}
} else {
ArchiveClassesAtExit = nullptr;
THROW_MSG(vmSymbols::java_lang_RuntimeException(),

View File

@ -59,7 +59,7 @@ public:
class DynamicArchive : AllStatic {
public:
static void prepare_for_dynamic_dumping_at_exit();
static void prepare_for_dynamic_dumping();
static void dump(const char* archive_name, TRAPS);
static void dump(TRAPS);
static bool is_mapped() { return FileMapInfo::dynamic_info() != NULL; }

View File

@ -592,7 +592,7 @@ bool MetaspaceShared::link_class_for_cds(InstanceKlass* ik, TRAPS) {
return res;
}
void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
void MetaspaceShared::link_shared_classes(TRAPS) {
// Collect all loaded ClassLoaderData.
ResourceMark rm;
@ -726,7 +726,7 @@ void MetaspaceShared::preload_and_dump_impl(TRAPS) {
// were not explicitly specified in the classlist. E.g., if an interface implemented by class K
// fails verification, all other interfaces that were not specified in the classlist but
// are implemented by K are not verified.
link_and_cleanup_shared_classes(CHECK);
link_shared_classes(CHECK);
log_info(cds)("Rewriting and linking classes: done");
#if INCLUDE_CDS_JAVA_HEAP

View File

@ -129,7 +129,7 @@ public:
}
static bool try_link_class(JavaThread* current, InstanceKlass* ik);
static void link_and_cleanup_shared_classes(TRAPS) NOT_CDS_RETURN;
static void link_shared_classes(TRAPS) NOT_CDS_RETURN;
static bool link_class_for_cds(InstanceKlass* ik, TRAPS) NOT_CDS_RETURN_(false);
static bool linking_required(InstanceKlass* ik) NOT_CDS_RETURN_(false);

View File

@ -424,7 +424,7 @@ JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
#if INCLUDE_CDS
// Link all classes for dynamic CDS dumping before vm exit.
if (DynamicDumpSharedSpaces) {
DynamicArchive::prepare_for_dynamic_dumping_at_exit();
DynamicArchive::prepare_for_dynamic_dumping();
}
#endif
EventShutdown event;

View File

@ -3258,7 +3258,7 @@ void JavaThread::invoke_shutdown_hooks() {
HandleMark hm(this);
// We could get here with a pending exception, if so clear it now or
// it will cause MetaspaceShared::link_and_cleanup_shared_classes to
// it will cause MetaspaceShared::link_shared_classes to
// fail for dynamic dump.
if (this->has_pending_exception()) {
this->clear_pending_exception();
@ -3269,7 +3269,7 @@ void JavaThread::invoke_shutdown_hooks() {
// Same operation is being done in JVM_BeforeHalt for handling the
// case where the application calls System.exit().
if (DynamicDumpSharedSpaces) {
DynamicArchive::prepare_for_dynamic_dumping_at_exit();
DynamicArchive::prepare_for_dynamic_dumping();
}
#endif

View File

@ -53,7 +53,7 @@ public class TestDynamicDumpAtOom extends DynamicArchiveTestBase {
jarFile,
mainClass,
"1024").assertAbnormalExit(output -> {
output.shouldContain("ArchiveClassesAtExit has failed")
output.shouldContain("Dynamic dump has failed")
.shouldContain("java.lang.OutOfMemoryError: Java heap space");
});
}