14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotArtifactFinder.hpp"
26 #include "cds/aotClassLinker.hpp"
27 #include "cds/aotClassLocation.hpp"
28 #include "cds/archiveBuilder.hpp"
29 #include "cds/archiveHeapWriter.hpp"
30 #include "cds/archiveUtils.inline.hpp"
31 #include "cds/cds_globals.hpp"
32 #include "cds/cdsConfig.hpp"
33 #include "cds/dynamicArchive.hpp"
34 #include "cds/regeneratedClasses.hpp"
35 #include "classfile/classLoader.hpp"
36 #include "classfile/classLoaderData.inline.hpp"
37 #include "classfile/symbolTable.hpp"
38 #include "classfile/systemDictionaryShared.hpp"
39 #include "classfile/vmSymbols.hpp"
40 #include "gc/shared/collectedHeap.hpp"
41 #include "gc/shared/gcVMOperations.hpp"
42 #include "gc/shared/gc_globals.hpp"
43 #include "jvm.h"
44 #include "logging/log.hpp"
45 #include "memory/metaspaceClosure.hpp"
46 #include "memory/resourceArea.hpp"
47 #include "oops/klass.inline.hpp"
48 #include "runtime/arguments.hpp"
49 #include "runtime/os.hpp"
50 #include "runtime/sharedRuntime.hpp"
51 #include "runtime/vmOperations.hpp"
52 #include "runtime/vmThread.hpp"
53 #include "utilities/align.hpp"
476 if (CDSConfig::is_dumping_dynamic_archive() && !CDSConfig::is_using_archive()) {
477 // This could happen if SharedArchiveFile has failed to load:
478 // - -Xshare:off was specified
479 // - SharedArchiveFile points to an non-existent file.
480 // - SharedArchiveFile points to an archive that has failed CRC check
481 // - SharedArchiveFile is not specified and the VM doesn't have a compatible default archive
482
483 #define __THEMSG " is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info."
484 if (RecordDynamicDumpInfo) {
485 log_error(cds)("-XX:+RecordDynamicDumpInfo%s", __THEMSG);
486 MetaspaceShared::unrecoverable_loading_error();
487 } else {
488 assert(ArchiveClassesAtExit != nullptr, "sanity");
489 log_warning(cds)("-XX:ArchiveClassesAtExit" __THEMSG);
490 }
491 #undef __THEMSG
492 CDSConfig::disable_dumping_dynamic_archive();
493 }
494 }
495
496 void DynamicArchive::dump_at_exit(JavaThread* current, const char* archive_name) {
497 ExceptionMark em(current);
498 ResourceMark rm(current);
499 CDSConfig::DumperThreadMark dumper_thread_mark(current);
500
501 if (!CDSConfig::is_dumping_dynamic_archive() || archive_name == nullptr) {
502 return;
503 }
504
505 log_info(cds, dynamic)("Preparing for dynamic dump at exit in thread %s", current->name());
506
507 JavaThread* THREAD = current; // For TRAPS processing related to link_shared_classes
508 MetaspaceShared::link_shared_classes(false/*not from jcmd*/, THREAD);
509 if (!HAS_PENDING_EXCEPTION) {
510 VM_PopulateDynamicDumpSharedSpace op(archive_name);
511 VMThread::execute(&op);
512 return;
513 }
514
515 // One of the prepatory steps failed
516 oop ex = current->pending_exception();
517 log_error(cds)("Dynamic dump has failed");
518 log_error(cds)("%s: %s", ex->klass()->external_name(),
519 java_lang_String::as_utf8_string(java_lang_Throwable::message(ex)));
520 CLEAR_PENDING_EXCEPTION;
521 CDSConfig::disable_dumping_dynamic_archive(); // Just for good measure
522 }
523
524 // This is called by "jcmd VM.cds dynamic_dump"
525 void DynamicArchive::dump_for_jcmd(const char* archive_name, TRAPS) {
526 CDSConfig::DumperThreadMark dumper_thread_mark(THREAD);
527 assert(CDSConfig::is_using_archive() && RecordDynamicDumpInfo, "already checked in arguments.cpp");
528 assert(ArchiveClassesAtExit == nullptr, "already checked in arguments.cpp");
529 assert(CDSConfig::is_dumping_dynamic_archive(), "already checked by check_for_dynamic_dump() during VM startup");
530 MetaspaceShared::link_shared_classes(true/*from jcmd*/, CHECK);
531 // copy shared path table to saved.
532 VM_PopulateDynamicDumpSharedSpace op(archive_name);
533 VMThread::execute(&op);
534 }
535
536 bool DynamicArchive::validate(FileMapInfo* dynamic_info) {
537 assert(!dynamic_info->is_static(), "must be");
538 // Check if the recorded base archive matches with the current one
539 FileMapInfo* base_info = FileMapInfo::current_info();
540 DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header();
541
542 // Check the header crc
543 if (dynamic_header->base_header_crc() != base_info->crc()) {
544 log_warning(cds)("Dynamic archive cannot be used: static archive header checksum verification failed.");
545 return false;
546 }
547
548 // Check each space's crc
549 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
550 if (dynamic_header->base_region_crc(i) != base_info->region_crc(i)) {
551 log_warning(cds)("Dynamic archive cannot be used: static archive region #%d checksum verification failed.", i);
552 return false;
553 }
|
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotArtifactFinder.hpp"
26 #include "cds/aotClassLinker.hpp"
27 #include "cds/aotClassLocation.hpp"
28 #include "cds/archiveBuilder.hpp"
29 #include "cds/archiveHeapWriter.hpp"
30 #include "cds/archiveUtils.inline.hpp"
31 #include "cds/cds_globals.hpp"
32 #include "cds/cdsConfig.hpp"
33 #include "cds/dynamicArchive.hpp"
34 #include "cds/lambdaFormInvokers.hpp"
35 #include "cds/metaspaceShared.hpp"
36 #include "cds/regeneratedClasses.hpp"
37 #include "classfile/classLoader.hpp"
38 #include "classfile/classLoaderData.inline.hpp"
39 #include "classfile/symbolTable.hpp"
40 #include "classfile/systemDictionaryShared.hpp"
41 #include "classfile/vmSymbols.hpp"
42 #include "gc/shared/collectedHeap.hpp"
43 #include "gc/shared/gcVMOperations.hpp"
44 #include "gc/shared/gc_globals.hpp"
45 #include "jvm.h"
46 #include "logging/log.hpp"
47 #include "memory/metaspaceClosure.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "oops/klass.inline.hpp"
50 #include "runtime/arguments.hpp"
51 #include "runtime/os.hpp"
52 #include "runtime/sharedRuntime.hpp"
53 #include "runtime/vmOperations.hpp"
54 #include "runtime/vmThread.hpp"
55 #include "utilities/align.hpp"
478 if (CDSConfig::is_dumping_dynamic_archive() && !CDSConfig::is_using_archive()) {
479 // This could happen if SharedArchiveFile has failed to load:
480 // - -Xshare:off was specified
481 // - SharedArchiveFile points to an non-existent file.
482 // - SharedArchiveFile points to an archive that has failed CRC check
483 // - SharedArchiveFile is not specified and the VM doesn't have a compatible default archive
484
485 #define __THEMSG " is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info."
486 if (RecordDynamicDumpInfo) {
487 log_error(cds)("-XX:+RecordDynamicDumpInfo%s", __THEMSG);
488 MetaspaceShared::unrecoverable_loading_error();
489 } else {
490 assert(ArchiveClassesAtExit != nullptr, "sanity");
491 log_warning(cds)("-XX:ArchiveClassesAtExit" __THEMSG);
492 }
493 #undef __THEMSG
494 CDSConfig::disable_dumping_dynamic_archive();
495 }
496 }
497
498 void DynamicArchive::dump_impl(bool jcmd_request, const char* archive_name, TRAPS) {
499 MetaspaceShared::link_shared_classes(CHECK);
500 if (!jcmd_request && CDSConfig::is_dumping_regenerated_lambdaform_invokers()) {
501 LambdaFormInvokers::regenerate_holder_classes(CHECK);
502 } else {
503 // Make sure we have at least one class in the dynamic archive
504 TempNewSymbol class_name = SymbolTable::new_symbol("jdk/internal/misc/CDS$DummyForDynamicArchive");
505 SystemDictionary::resolve_or_null(class_name, Handle(), CHECK);
506 }
507
508 VM_PopulateDynamicDumpSharedSpace op(archive_name);
509 VMThread::execute(&op);
510 }
511
512 void DynamicArchive::dump_at_exit(JavaThread* current, const char* archive_name) {
513 ExceptionMark em(current);
514 ResourceMark rm(current);
515 CDSConfig::DumperThreadMark dumper_thread_mark(current);
516
517 if (!CDSConfig::is_dumping_dynamic_archive() || archive_name == nullptr) {
518 return;
519 }
520
521 log_info(cds, dynamic)("Preparing for dynamic dump at exit in thread %s", current->name());
522
523 JavaThread* THREAD = current; // For TRAPS processing related to link_shared_classes
524 dump_impl(/*jcmd_request=*/false, archive_name, THREAD);
525 if (HAS_PENDING_EXCEPTION) {
526 // One of the prepatory steps failed
527 oop ex = current->pending_exception();
528 log_error(cds)("Dynamic dump has failed");
529 log_error(cds)("%s: %s", ex->klass()->external_name(),
530 java_lang_String::as_utf8_string(java_lang_Throwable::message(ex)));
531 CLEAR_PENDING_EXCEPTION;
532 CDSConfig::disable_dumping_dynamic_archive(); // Just for good measure
533 }
534 }
535
536 // This is called by "jcmd VM.cds dynamic_dump"
537 void DynamicArchive::dump_for_jcmd(const char* archive_name, TRAPS) {
538 CDSConfig::DumperThreadMark dumper_thread_mark(THREAD);
539 assert(CDSConfig::is_using_archive() && RecordDynamicDumpInfo, "already checked in arguments.cpp");
540 assert(ArchiveClassesAtExit == nullptr, "already checked in arguments.cpp");
541 assert(CDSConfig::is_dumping_dynamic_archive(), "already checked by check_for_dynamic_dump() during VM startup");
542 dump_impl(/*jcmd_request=*/true, archive_name, CHECK);
543 }
544
545 bool DynamicArchive::validate(FileMapInfo* dynamic_info) {
546 assert(!dynamic_info->is_static(), "must be");
547 // Check if the recorded base archive matches with the current one
548 FileMapInfo* base_info = FileMapInfo::current_info();
549 DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header();
550
551 // Check the header crc
552 if (dynamic_header->base_header_crc() != base_info->crc()) {
553 log_warning(cds)("Dynamic archive cannot be used: static archive header checksum verification failed.");
554 return false;
555 }
556
557 // Check each space's crc
558 for (int i = 0; i < MetaspaceShared::n_regions; i++) {
559 if (dynamic_header->base_region_crc(i) != base_info->region_crc(i)) {
560 log_warning(cds)("Dynamic archive cannot be used: static archive region #%d checksum verification failed.", i);
561 return false;
562 }
|