27 #include "classfile/loaderConstraints.hpp"
28 #include "classfile/placeholders.hpp"
29 #include "classfile/sharedClassUtil.hpp"
30 #include "classfile/symbolTable.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "code/codeCache.hpp"
33 #include "gc/shared/gcLocker.hpp"
34 #include "interpreter/bytecodeStream.hpp"
35 #include "interpreter/bytecodes.hpp"
36 #include "memory/filemap.hpp"
37 #include "memory/metaspace.hpp"
38 #include "memory/metaspaceShared.hpp"
39 #include "oops/objArrayOop.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/os.hpp"
42 #include "runtime/signature.hpp"
43 #include "runtime/vmThread.hpp"
44 #include "runtime/vm_operations.hpp"
45 #include "utilities/hashtable.inline.hpp"
46
47 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
48
49 int MetaspaceShared::_max_alignment = 0;
50
51 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
52
53 MetaspaceSharedStats MetaspaceShared::_stats;
54
55 bool MetaspaceShared::_link_classes_made_progress;
56 bool MetaspaceShared::_check_classes_made_progress;
57 bool MetaspaceShared::_has_error_classes;
58 bool MetaspaceShared::_archive_loading_failed = false;
59 // Read/write a data stream for restoring/preserving metadata pointers and
60 // miscellaneous data from/to the shared archive file.
61
62 void MetaspaceShared::serialize(SerializeClosure* soc) {
63 int tag = 0;
64 soc->do_tag(--tag);
65
66 // Verify the sizes of various metadata in the system.
67 soc->do_tag(sizeof(Method));
68 soc->do_tag(sizeof(ConstMethod));
561
562 SystemDictionary::reverse();
563 SystemDictionary::copy_buckets(&md_top, md_end);
564
565 ClassLoader::verify();
566 ClassLoader::copy_package_info_buckets(&md_top, md_end);
567 ClassLoader::verify();
568
569 SystemDictionary::copy_table(&md_top, md_end);
570 ClassLoader::verify();
571 ClassLoader::copy_package_info_table(&md_top, md_end);
572 ClassLoader::verify();
573
574 // Write the other data to the output array.
575 WriteClosure wc(md_top, md_end);
576 MetaspaceShared::serialize(&wc);
577 md_top = wc.get_top();
578
579 // Print shared spaces all the time
580 // To make fmt_space be a syntactic constant (for format warnings), use #define.
581 #define fmt_space "%s space: %9d [ %4.1f%% of total] out of %9d bytes [%4.1f%% used] at " INTPTR_FORMAT
582 Metaspace* ro_space = _loader_data->ro_metaspace();
583 Metaspace* rw_space = _loader_data->rw_metaspace();
584
585 // Allocated size of each space (may not be all occupied)
586 const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
587 const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
588 const size_t md_alloced = md_end-md_low;
589 const size_t mc_alloced = mc_end-mc_low;
590 const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced
591 + ss_bytes;
592
593 // Occupied size of each space.
594 const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
595 const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
596 const size_t md_bytes = size_t(md_top - md_low);
597 const size_t mc_bytes = size_t(mc_top - mc_low);
598
599 // Percent of total size
600 const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes + ss_bytes;
601 const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
602 const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
603 const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
604 const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
605 const double ss_t_perc = ss_bytes / double(total_bytes) * 100.0;
606
607 // Percent of fullness of each space
608 const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
609 const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
610 const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
611 const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
612 const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
613
614 tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, ro_space->bottom());
615 tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, rw_space->bottom());
616 tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, md_low);
617 tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, mc_low);
618 tty->print_cr(fmt_space, "st", ss_bytes, ss_t_perc, ss_bytes, 100.0, ss_low);
619 tty->print_cr("total : %9d [100.0%% of total] out of %9d bytes [%4.1f%% used]",
620 total_bytes, total_alloced, total_u_perc);
621
622 // Update the vtable pointers in all of the Klass objects in the
623 // heap. They should point to newly generated vtable.
624 patch_klass_vtables(vtbl_list, vtable);
625
626 // dunno what this is for.
627 char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass);
628 memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
629 memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
630
631 // Create and write the archive file that maps the shared spaces.
632
633 FileMapInfo* mapinfo = new FileMapInfo();
634 mapinfo->populate_header(MetaspaceShared::max_alignment());
635
636 // Pass 1 - update file offsets in header.
637 mapinfo->write_header();
638 mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
639 mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
721 // enable this when running real apps.
722 SystemDictionary::remove_classes_in_error_state();
723 } else {
724 tty->print_cr("Please remove the unverifiable classes from your class list and try again");
725 exit(1);
726 }
727 }
728 }
729
730 void MetaspaceShared::prepare_for_dumping() {
731 ClassLoader::initialize_shared_path();
732 FileMapInfo::allocate_classpath_entry_table();
733 }
734
735 // Preload classes from a list, populate the shared spaces and dump to a
736 // file.
737 void MetaspaceShared::preload_and_dump(TRAPS) {
738 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
739 ResourceMark rm;
740
741 tty->print_cr("Allocated shared space: %d bytes at " PTR_FORMAT,
742 MetaspaceShared::shared_rs()->size(),
743 MetaspaceShared::shared_rs()->base());
744
745 // Preload classes to be shared.
746 // Should use some os:: method rather than fopen() here. aB.
747 const char* class_list_path;
748 if (SharedClassListFile == NULL) {
749 // Construct the path to the class list (in jre/lib)
750 // Walk up two directories from the location of the VM and
751 // optionally tack on "lib" (depending on platform)
752 char class_list_path_str[JVM_MAXPATHLEN];
753 os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
754 for (int i = 0; i < 3; i++) {
755 char *end = strrchr(class_list_path_str, *os::file_separator());
756 if (end != NULL) *end = '\0';
757 }
758 int class_list_path_len = (int)strlen(class_list_path_str);
759 if (class_list_path_len >= 3) {
760 if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
761 if (class_list_path_len < JVM_MAXPATHLEN - 4) {
762 jio_snprintf(class_list_path_str + class_list_path_len,
763 sizeof(class_list_path_str) - class_list_path_len,
|
27 #include "classfile/loaderConstraints.hpp"
28 #include "classfile/placeholders.hpp"
29 #include "classfile/sharedClassUtil.hpp"
30 #include "classfile/symbolTable.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "code/codeCache.hpp"
33 #include "gc/shared/gcLocker.hpp"
34 #include "interpreter/bytecodeStream.hpp"
35 #include "interpreter/bytecodes.hpp"
36 #include "memory/filemap.hpp"
37 #include "memory/metaspace.hpp"
38 #include "memory/metaspaceShared.hpp"
39 #include "oops/objArrayOop.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/os.hpp"
42 #include "runtime/signature.hpp"
43 #include "runtime/vmThread.hpp"
44 #include "runtime/vm_operations.hpp"
45 #include "utilities/hashtable.inline.hpp"
46
47 int MetaspaceShared::_max_alignment = 0;
48
49 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
50
51 MetaspaceSharedStats MetaspaceShared::_stats;
52
53 bool MetaspaceShared::_link_classes_made_progress;
54 bool MetaspaceShared::_check_classes_made_progress;
55 bool MetaspaceShared::_has_error_classes;
56 bool MetaspaceShared::_archive_loading_failed = false;
57 // Read/write a data stream for restoring/preserving metadata pointers and
58 // miscellaneous data from/to the shared archive file.
59
60 void MetaspaceShared::serialize(SerializeClosure* soc) {
61 int tag = 0;
62 soc->do_tag(--tag);
63
64 // Verify the sizes of various metadata in the system.
65 soc->do_tag(sizeof(Method));
66 soc->do_tag(sizeof(ConstMethod));
559
560 SystemDictionary::reverse();
561 SystemDictionary::copy_buckets(&md_top, md_end);
562
563 ClassLoader::verify();
564 ClassLoader::copy_package_info_buckets(&md_top, md_end);
565 ClassLoader::verify();
566
567 SystemDictionary::copy_table(&md_top, md_end);
568 ClassLoader::verify();
569 ClassLoader::copy_package_info_table(&md_top, md_end);
570 ClassLoader::verify();
571
572 // Write the other data to the output array.
573 WriteClosure wc(md_top, md_end);
574 MetaspaceShared::serialize(&wc);
575 md_top = wc.get_top();
576
577 // Print shared spaces all the time
578 // To make fmt_space be a syntactic constant (for format warnings), use #define.
579 #define fmt_space "%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%4.1f%% used] at " INTPTR_FORMAT
580 Metaspace* ro_space = _loader_data->ro_metaspace();
581 Metaspace* rw_space = _loader_data->rw_metaspace();
582
583 // Allocated size of each space (may not be all occupied)
584 const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
585 const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
586 const size_t md_alloced = md_end-md_low;
587 const size_t mc_alloced = mc_end-mc_low;
588 const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced
589 + ss_bytes;
590
591 // Occupied size of each space.
592 const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
593 const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
594 const size_t md_bytes = size_t(md_top - md_low);
595 const size_t mc_bytes = size_t(mc_top - mc_low);
596
597 // Percent of total size
598 const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes + ss_bytes;
599 const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
600 const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
601 const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
602 const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
603 const double ss_t_perc = ss_bytes / double(total_bytes) * 100.0;
604
605 // Percent of fullness of each space
606 const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
607 const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
608 const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
609 const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
610 const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
611
612 tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, p2i(ro_space->bottom()));
613 tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, p2i(rw_space->bottom()));
614 tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, p2i(md_low));
615 tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, p2i(mc_low));
616 tty->print_cr(fmt_space, "st", ss_bytes, ss_t_perc, ss_bytes, 100.0, p2i(ss_low));
617 tty->print_cr("total : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%4.1f%% used]",
618 total_bytes, total_alloced, total_u_perc);
619
620 // Update the vtable pointers in all of the Klass objects in the
621 // heap. They should point to newly generated vtable.
622 patch_klass_vtables(vtbl_list, vtable);
623
624 // dunno what this is for.
625 char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass);
626 memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
627 memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
628
629 // Create and write the archive file that maps the shared spaces.
630
631 FileMapInfo* mapinfo = new FileMapInfo();
632 mapinfo->populate_header(MetaspaceShared::max_alignment());
633
634 // Pass 1 - update file offsets in header.
635 mapinfo->write_header();
636 mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
637 mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
719 // enable this when running real apps.
720 SystemDictionary::remove_classes_in_error_state();
721 } else {
722 tty->print_cr("Please remove the unverifiable classes from your class list and try again");
723 exit(1);
724 }
725 }
726 }
727
728 void MetaspaceShared::prepare_for_dumping() {
729 ClassLoader::initialize_shared_path();
730 FileMapInfo::allocate_classpath_entry_table();
731 }
732
733 // Preload classes from a list, populate the shared spaces and dump to a
734 // file.
735 void MetaspaceShared::preload_and_dump(TRAPS) {
736 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
737 ResourceMark rm;
738
739 tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
740 MetaspaceShared::shared_rs()->size(),
741 p2i(MetaspaceShared::shared_rs()->base()));
742
743 // Preload classes to be shared.
744 // Should use some os:: method rather than fopen() here. aB.
745 const char* class_list_path;
746 if (SharedClassListFile == NULL) {
747 // Construct the path to the class list (in jre/lib)
748 // Walk up two directories from the location of the VM and
749 // optionally tack on "lib" (depending on platform)
750 char class_list_path_str[JVM_MAXPATHLEN];
751 os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
752 for (int i = 0; i < 3; i++) {
753 char *end = strrchr(class_list_path_str, *os::file_separator());
754 if (end != NULL) *end = '\0';
755 }
756 int class_list_path_len = (int)strlen(class_list_path_str);
757 if (class_list_path_len >= 3) {
758 if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
759 if (class_list_path_len < JVM_MAXPATHLEN - 4) {
760 jio_snprintf(class_list_path_str + class_list_path_len,
761 sizeof(class_list_path_str) - class_list_path_len,
|