comparison src/share/vm/memory/metaspaceShared.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents eaf39a954227 0558eb13dcf3
children
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "classfile/dictionary.hpp" 26 #include "classfile/dictionary.hpp"
27 #include "classfile/classLoaderExt.hpp"
27 #include "classfile/loaderConstraints.hpp" 28 #include "classfile/loaderConstraints.hpp"
28 #include "classfile/placeholders.hpp" 29 #include "classfile/placeholders.hpp"
30 #include "classfile/sharedClassUtil.hpp"
29 #include "classfile/symbolTable.hpp" 31 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp" 32 #include "classfile/systemDictionary.hpp"
31 #include "code/codeCache.hpp" 33 #include "code/codeCache.hpp"
32 #include "memory/filemap.hpp" 34 #include "memory/filemap.hpp"
33 #include "memory/gcLocker.hpp" 35 #include "memory/gcLocker.hpp"
36 #include "oops/objArrayOop.hpp" 38 #include "oops/objArrayOop.hpp"
37 #include "oops/oop.inline.hpp" 39 #include "oops/oop.inline.hpp"
38 #include "runtime/signature.hpp" 40 #include "runtime/signature.hpp"
39 #include "runtime/vm_operations.hpp" 41 #include "runtime/vm_operations.hpp"
40 #include "runtime/vmThread.hpp" 42 #include "runtime/vmThread.hpp"
43 #include "utilities/hashtable.hpp"
41 #include "utilities/hashtable.inline.hpp" 44 #include "utilities/hashtable.inline.hpp"
42 45
43 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
44 47
45 int MetaspaceShared::_max_alignment = 0; 48 int MetaspaceShared::_max_alignment = 0;
46 49
47 ReservedSpace* MetaspaceShared::_shared_rs = NULL; 50 ReservedSpace* MetaspaceShared::_shared_rs = NULL;
48 51
52 bool MetaspaceShared::_link_classes_made_progress;
53 bool MetaspaceShared::_check_classes_made_progress;
54 bool MetaspaceShared::_has_error_classes;
55 bool MetaspaceShared::_archive_loading_failed = false;
49 // Read/write a data stream for restoring/preserving metadata pointers and 56 // Read/write a data stream for restoring/preserving metadata pointers and
50 // miscellaneous data from/to the shared archive file. 57 // miscellaneous data from/to the shared archive file.
51 58
52 void MetaspaceShared::serialize(SerializeClosure* soc) { 59 void MetaspaceShared::serialize(SerializeClosure* soc) {
53 int tag = 0; 60 int tag = 0;
443 _global_klass_objects = new GrowableArray<Klass*>(1000); 450 _global_klass_objects = new GrowableArray<Klass*>(1000);
444 Universe::basic_type_classes_do(collect_classes); 451 Universe::basic_type_classes_do(collect_classes);
445 SystemDictionary::classes_do(collect_classes); 452 SystemDictionary::classes_do(collect_classes);
446 453
447 tty->print_cr("Number of classes %d", _global_klass_objects->length()); 454 tty->print_cr("Number of classes %d", _global_klass_objects->length());
455 {
456 int num_type_array = 0, num_obj_array = 0, num_inst = 0;
457 for (int i = 0; i < _global_klass_objects->length(); i++) {
458 Klass* k = _global_klass_objects->at(i);
459 if (k->oop_is_instance()) {
460 num_inst ++;
461 } else if (k->oop_is_objArray()) {
462 num_obj_array ++;
463 } else {
464 assert(k->oop_is_typeArray(), "sanity");
465 num_type_array ++;
466 }
467 }
468 tty->print_cr(" instance classes = %5d", num_inst);
469 tty->print_cr(" obj array classes = %5d", num_obj_array);
470 tty->print_cr(" type array classes = %5d", num_type_array);
471 }
448 472
449 // Update all the fingerprints in the shared methods. 473 // Update all the fingerprints in the shared methods.
450 tty->print("Calculating fingerprints ... "); 474 tty->print("Calculating fingerprints ... ");
451 calculate_fingerprints(); 475 calculate_fingerprints();
452 tty->print_cr("done. "); 476 tty->print_cr("done. ");
508 SymbolTable::copy_table(&md_top, md_end); 532 SymbolTable::copy_table(&md_top, md_end);
509 SystemDictionary::copy_table(&md_top, md_end); 533 SystemDictionary::copy_table(&md_top, md_end);
510 ClassLoader::verify(); 534 ClassLoader::verify();
511 ClassLoader::copy_package_info_table(&md_top, md_end); 535 ClassLoader::copy_package_info_table(&md_top, md_end);
512 ClassLoader::verify(); 536 ClassLoader::verify();
537
538 ClassLoaderExt::copy_lookup_cache_to_archive(&md_top, md_end);
513 539
514 // Write the other data to the output array. 540 // Write the other data to the output array.
515 WriteClosure wc(md_top, md_end); 541 WriteClosure wc(md_top, md_end);
516 MetaspaceShared::serialize(&wc); 542 MetaspaceShared::serialize(&wc);
517 md_top = wc.get_top(); 543 md_top = wc.get_top();
609 dac.dump_stats(int(ro_bytes), int(rw_bytes), int(md_bytes), int(mc_bytes)); 635 dac.dump_stats(int(ro_bytes), int(rw_bytes), int(md_bytes), int(mc_bytes));
610 } 636 }
611 #undef fmt_space 637 #undef fmt_space
612 } 638 }
613 639
614 static void link_shared_classes(Klass* obj, TRAPS) { 640
641 void MetaspaceShared::link_one_shared_class(Klass* obj, TRAPS) {
615 Klass* k = obj; 642 Klass* k = obj;
616 if (k->oop_is_instance()) { 643 if (k->oop_is_instance()) {
617 InstanceKlass* ik = (InstanceKlass*) k; 644 InstanceKlass* ik = (InstanceKlass*) k;
618 // Link the class to cause the bytecodes to be rewritten and the 645 // Link the class to cause the bytecodes to be rewritten and the
619 // cpcache to be created. 646 // cpcache to be created. Class verification is done according
620 if (ik->init_state() < InstanceKlass::linked) { 647 // to -Xverify setting.
621 ik->link_class(THREAD); 648 _link_classes_made_progress |= try_link_class(ik, THREAD);
622 guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting"); 649 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
623 } 650 }
624 } 651 }
625 } 652
626 653 void MetaspaceShared::check_one_shared_class(Klass* k) {
627 654 if (k->oop_is_instance() && InstanceKlass::cast(k)->check_sharing_error_state()) {
628 // Support for a simple checksum of the contents of the class list 655 _check_classes_made_progress = true;
629 // file to prevent trivial tampering. The algorithm matches that in 656 }
630 // the MakeClassList program used by the J2SE build process. 657 }
631 #define JSUM_SEED ((jlong)CONST64(0xcafebabebabecafe)) 658
632 static jlong 659 void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
633 jsum(jlong start, const char *buf, const int len) 660 // We need to iterate because verification may cause additional classes
634 { 661 // to be loaded.
635 jlong h = start; 662 do {
636 char *p = (char *)buf, *e = p + len; 663 _link_classes_made_progress = false;
637 while (p < e) { 664 SystemDictionary::classes_do(link_one_shared_class, THREAD);
638 char c = *p++; 665 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
639 if (c <= ' ') { 666 } while (_link_classes_made_progress);
640 /* Skip spaces and control characters */ 667
641 continue; 668 if (_has_error_classes) {
642 } 669 // Mark all classes whose super class or interfaces failed verification.
643 h = 31 * h + c; 670 do {
644 } 671 // Not completely sure if we need to do this iteratively. Anyway,
645 return h; 672 // we should come here only if there are unverifiable classes, which
673 // shouldn't happen in normal cases. So better safe than sorry.
674 _check_classes_made_progress = false;
675 SystemDictionary::classes_do(check_one_shared_class);
676 } while (_check_classes_made_progress);
677
678 if (IgnoreUnverifiableClassesDuringDump) {
679 // This is useful when running JCK or SQE tests. You should not
680 // enable this when running real apps.
681 SystemDictionary::remove_classes_in_error_state();
682 } else {
683 tty->print_cr("Please remove the unverifiable classes from your class list and try again");
684 exit(1);
685 }
686 }
687 }
688
689 void MetaspaceShared::prepare_for_dumping() {
690 ClassLoader::initialize_shared_path();
691 FileMapInfo::allocate_classpath_entry_table();
646 } 692 }
647 693
648 // Preload classes from a list, populate the shared spaces and dump to a 694 // Preload classes from a list, populate the shared spaces and dump to a
649 // file. 695 // file.
650 void MetaspaceShared::preload_and_dump(TRAPS) { 696 void MetaspaceShared::preload_and_dump(TRAPS) {
651 TraceTime timer("Dump Shared Spaces", TraceStartupTime); 697 TraceTime timer("Dump Shared Spaces", TraceStartupTime);
652 ResourceMark rm; 698 ResourceMark rm;
653 699
700 tty->print_cr("Allocated shared space: %d bytes at " PTR_FORMAT,
701 MetaspaceShared::shared_rs()->size(),
702 MetaspaceShared::shared_rs()->base());
703
654 // Preload classes to be shared. 704 // Preload classes to be shared.
655 // Should use some os:: method rather than fopen() here. aB. 705 // Should use some os:: method rather than fopen() here. aB.
656 // Construct the path to the class list (in jre/lib) 706 const char* class_list_path;
657 // Walk up two directories from the location of the VM and 707 if (SharedClassListFile == NULL) {
658 // optionally tack on "lib" (depending on platform) 708 // Construct the path to the class list (in jre/lib)
659 char class_list_path[JVM_MAXPATHLEN]; 709 // Walk up two directories from the location of the VM and
660 os::jvm_path(class_list_path, sizeof(class_list_path)); 710 // optionally tack on "lib" (depending on platform)
661 for (int i = 0; i < 3; i++) { 711 char class_list_path_str[JVM_MAXPATHLEN];
662 char *end = strrchr(class_list_path, *os::file_separator()); 712 os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
663 if (end != NULL) *end = '\0'; 713 for (int i = 0; i < 3; i++) {
664 } 714 char *end = strrchr(class_list_path_str, *os::file_separator());
665 int class_list_path_len = (int)strlen(class_list_path); 715 if (end != NULL) *end = '\0';
666 if (class_list_path_len >= 3) { 716 }
667 if (strcmp(class_list_path + class_list_path_len - 3, "lib") != 0) { 717 int class_list_path_len = (int)strlen(class_list_path_str);
668 strcat(class_list_path, os::file_separator()); 718 if (class_list_path_len >= 3) {
669 strcat(class_list_path, "lib"); 719 if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
670 } 720 strcat(class_list_path_str, os::file_separator());
671 } 721 strcat(class_list_path_str, "lib");
672 strcat(class_list_path, os::file_separator()); 722 }
673 strcat(class_list_path, "classlist"); 723 }
674 724 strcat(class_list_path_str, os::file_separator());
725 strcat(class_list_path_str, "classlist");
726 class_list_path = class_list_path_str;
727 } else {
728 class_list_path = SharedClassListFile;
729 }
730
731 int class_count = 0;
732 GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
733
734 // sun.io.Converters
735 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
736 SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
737
738 // java.util.HashMap
739 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
740 SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
741
742 tty->print_cr("Loading classes to share ...");
743 _has_error_classes = false;
744 class_count += preload_and_dump(class_list_path, class_promote_order,
745 THREAD);
746 if (ExtraSharedClassListFile) {
747 class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
748 THREAD);
749 }
750 tty->print_cr("Loading classes to share: done.");
751
752 ClassLoaderExt::init_lookup_cache(THREAD);
753
754 if (PrintSharedSpaces) {
755 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
756 }
757
758 // Rewrite and link classes
759 tty->print_cr("Rewriting and linking classes ...");
760
761 // Link any classes which got missed. This would happen if we have loaded classes that
762 // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
763 // fails verification, all other interfaces that were not specified in the classlist but
764 // are implemented by K are not verified.
765 link_and_cleanup_shared_classes(CATCH);
766 tty->print_cr("Rewriting and linking classes: done");
767
768 // Create and dump the shared spaces. Everything so far is loaded
769 // with the null class loader.
770 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
771 VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
772 VMThread::execute(&op);
773
774 // Since various initialization steps have been undone by this process,
775 // it is not reasonable to continue running a java process.
776 exit(0);
777 }
778
779 int MetaspaceShared::preload_and_dump(const char * class_list_path,
780 GrowableArray<Klass*>* class_promote_order,
781 TRAPS) {
675 FILE* file = fopen(class_list_path, "r"); 782 FILE* file = fopen(class_list_path, "r");
783 char class_name[256];
784 int class_count = 0;
785
676 if (file != NULL) { 786 if (file != NULL) {
677 jlong computed_jsum = JSUM_SEED;
678 jlong file_jsum = 0;
679
680 char class_name[256];
681 int class_count = 0;
682 GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
683
684 // sun.io.Converters
685 static const char obj_array_sig[] = "[[Ljava/lang/Object;";
686 SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
687
688 // java.util.HashMap
689 static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
690 SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
691
692 tty->print("Loading classes to share ... ");
693 while ((fgets(class_name, sizeof class_name, file)) != NULL) { 787 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
694 if (*class_name == '#') { 788 if (*class_name == '#') { // comment
695 jint fsh, fsl;
696 if (sscanf(class_name, "# %8x%8x\n", &fsh, &fsl) == 2) {
697 file_jsum = ((jlong)(fsh) << 32) | (fsl & 0xffffffff);
698 }
699
700 continue; 789 continue;
701 } 790 }
702 // Remove trailing newline 791 // Remove trailing newline
703 size_t name_len = strlen(class_name); 792 size_t name_len = strlen(class_name);
704 class_name[name_len-1] = '\0'; 793 if (class_name[name_len-1] == '\n') {
705 794 class_name[name_len-1] = '\0';
706 computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1); 795 }
707 796
708 // Got a class name - load it. 797 // Got a class name - load it.
709 TempNewSymbol class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD); 798 TempNewSymbol class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD);
710 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol."); 799 guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol.");
711 Klass* klass = SystemDictionary::resolve_or_null(class_name_symbol, 800 Klass* klass = SystemDictionary::resolve_or_null(class_name_symbol,
712 THREAD); 801 THREAD);
713 guarantee(!HAS_PENDING_EXCEPTION, "Exception resolving a class."); 802 CLEAR_PENDING_EXCEPTION;
714 if (klass != NULL) { 803 if (klass != NULL) {
715 if (PrintSharedSpaces && Verbose && WizardMode) { 804 if (PrintSharedSpaces && Verbose && WizardMode) {
716 tty->print_cr("Shared spaces preloaded: %s", class_name); 805 tty->print_cr("Shared spaces preloaded: %s", class_name);
717 } 806 }
718 807
719
720 InstanceKlass* ik = InstanceKlass::cast(klass); 808 InstanceKlass* ik = InstanceKlass::cast(klass);
721 809
722 // Should be class load order as per -XX:+TraceClassLoadingPreorder 810 // Should be class load order as per -XX:+TraceClassLoadingPreorder
723 class_promote_order->append(ik); 811 class_promote_order->append(ik);
724 812
725 // Link the class to cause the bytecodes to be rewritten and the 813 // Link the class to cause the bytecodes to be rewritten and the
726 // cpcache to be created. The linking is done as soon as classes 814 // cpcache to be created. The linking is done as soon as classes
727 // are loaded in order that the related data structures (klass and 815 // are loaded in order that the related data structures (klass and
728 // cpCache) are located together. 816 // cpCache) are located together.
729 817 try_link_class(ik, THREAD);
730 if (ik->init_state() < InstanceKlass::linked) { 818 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
731 ik->link_class(THREAD);
732 guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting");
733 }
734
735 // TODO: Resolve klasses in constant pool
736 ik->constants()->resolve_class_constants(THREAD);
737 819
738 class_count++; 820 class_count++;
739 } else { 821 } else {
740 if (PrintSharedSpaces && Verbose && WizardMode) { 822 //tty->print_cr("Preload failed: %s", class_name);
741 tty->cr();
742 tty->print_cr(" Preload failed: %s", class_name);
743 }
744 } 823 }
745 file_jsum = 0; // Checksum must be on last line of file 824 }
746 } 825 fclose(file);
747 if (computed_jsum != file_jsum) {
748 tty->cr();
749 tty->print_cr("Preload failed: checksum of class list was incorrect.");
750 exit(1);
751 }
752
753 tty->print_cr("done. ");
754
755 if (PrintSharedSpaces) {
756 tty->print_cr("Shared spaces: preloaded %d classes", class_count);
757 }
758
759 // Rewrite and unlink classes.
760 tty->print("Rewriting and linking classes ... ");
761
762 // Link any classes which got missed. (It's not quite clear why
763 // they got missed.) This iteration would be unsafe if we weren't
764 // single-threaded at this point; however we can't do it on the VM
765 // thread because it requires object allocation.
766 SystemDictionary::classes_do(link_shared_classes, CATCH);
767 tty->print_cr("done. ");
768
769 // Create and dump the shared spaces. Everything so far is loaded
770 // with the null class loader.
771 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
772 VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
773 VMThread::execute(&op);
774
775 } else { 826 } else {
776 char errmsg[JVM_MAXPATHLEN]; 827 char errmsg[JVM_MAXPATHLEN];
777 os::lasterror(errmsg, JVM_MAXPATHLEN); 828 os::lasterror(errmsg, JVM_MAXPATHLEN);
778 tty->print_cr("Loading classlist failed: %s", errmsg); 829 tty->print_cr("Loading classlist failed: %s", errmsg);
779 exit(1); 830 exit(1);
780 } 831 }
781 832
782 // Since various initialization steps have been undone by this process, 833 return class_count;
783 // it is not reasonable to continue running a java process. 834 }
784 exit(0); 835
785 } 836 // Returns true if the class's status has changed
786 837 bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
838 assert(DumpSharedSpaces, "should only be called during dumping");
839 if (ik->init_state() < InstanceKlass::linked) {
840 bool saved = BytecodeVerificationLocal;
841 if (!SharedClassUtil::is_shared_boot_class(ik)) {
842 // The verification decision is based on BytecodeVerificationRemote
843 // for non-system classes. Since we are using the NULL classloader
844 // to load non-system classes during dumping, we need to temporarily
845 // change BytecodeVerificationLocal to be the same as
846 // BytecodeVerificationRemote. Note this can cause the parent system
847 // classes also being verified. The extra overhead is acceptable during
848 // dumping.
849 BytecodeVerificationLocal = BytecodeVerificationRemote;
850 }
851 ik->link_class(THREAD);
852 if (HAS_PENDING_EXCEPTION) {
853 ResourceMark rm;
854 tty->print_cr("Preload Warning: Verification failed for %s",
855 ik->external_name());
856 CLEAR_PENDING_EXCEPTION;
857 ik->set_in_error_state();
858 _has_error_classes = true;
859 }
860 BytecodeVerificationLocal = saved;
861 return true;
862 } else {
863 return false;
864 }
865 }
787 866
788 // Closure for serializing initialization data in from a data area 867 // Closure for serializing initialization data in from a data area
789 // (ptr_array) read from the shared file. 868 // (ptr_array) read from the shared file.
790 869
791 class ReadClosure : public SerializeClosure { 870 class ReadClosure : public SerializeClosure {
869 mapinfo->verify_region_checksum(rw) && 948 mapinfo->verify_region_checksum(rw) &&
870 (_md_base = mapinfo->map_region(md)) != NULL && 949 (_md_base = mapinfo->map_region(md)) != NULL &&
871 mapinfo->verify_region_checksum(md) && 950 mapinfo->verify_region_checksum(md) &&
872 (_mc_base = mapinfo->map_region(mc)) != NULL && 951 (_mc_base = mapinfo->map_region(mc)) != NULL &&
873 mapinfo->verify_region_checksum(mc) && 952 mapinfo->verify_region_checksum(mc) &&
874 (image_alignment == (size_t)max_alignment())) { 953 (image_alignment == (size_t)max_alignment()) &&
954 mapinfo->validate_classpath_entry_table()) {
875 // Success (no need to do anything) 955 // Success (no need to do anything)
876 return true; 956 return true;
877 } else { 957 } else {
878 // If there was a failure in mapping any of the spaces, unmap the ones 958 // If there was a failure in mapping any of the spaces, unmap the ones
879 // that succeeded 959 // that succeeded
885 // Release the entire mapped region 965 // Release the entire mapped region
886 shared_rs.release(); 966 shared_rs.release();
887 #endif 967 #endif
888 // If -Xshare:on is specified, print out the error message and exit VM, 968 // If -Xshare:on is specified, print out the error message and exit VM,
889 // otherwise, set UseSharedSpaces to false and continue. 969 // otherwise, set UseSharedSpaces to false and continue.
890 if (RequireSharedSpaces) { 970 if (RequireSharedSpaces || PrintSharedArchiveAndExit) {
891 vm_exit_during_initialization("Unable to use shared archive.", NULL); 971 vm_exit_during_initialization("Unable to use shared archive.", "Failed map_region for using -Xshare:on.");
892 } else { 972 } else {
893 FLAG_SET_DEFAULT(UseSharedSpaces, false); 973 FLAG_SET_DEFAULT(UseSharedSpaces, false);
894 } 974 }
895 return false; 975 return false;
896 } 976 }
980 1060
981 len = *(intptr_t*)buffer; // skip over package info table char[] arrays. 1061 len = *(intptr_t*)buffer; // skip over package info table char[] arrays.
982 buffer += sizeof(intptr_t); 1062 buffer += sizeof(intptr_t);
983 buffer += len; 1063 buffer += len;
984 1064
1065 buffer = ClassLoaderExt::restore_lookup_cache_from_archive(buffer);
1066
985 intptr_t* array = (intptr_t*)buffer; 1067 intptr_t* array = (intptr_t*)buffer;
986 ReadClosure rc(&array); 1068 ReadClosure rc(&array);
987 serialize(&rc); 1069 serialize(&rc);
988 1070
989 // Close the mapinfo file 1071 // Close the mapinfo file
990 mapinfo->close(); 1072 mapinfo->close();
1073
1074 if (PrintSharedArchiveAndExit) {
1075 if (PrintSharedDictionary) {
1076 tty->print_cr("\nShared classes:\n");
1077 SystemDictionary::print_shared(false);
1078 }
1079 if (_archive_loading_failed) {
1080 tty->print_cr("archive is invalid");
1081 vm_exit(1);
1082 } else {
1083 tty->print_cr("archive is valid");
1084 vm_exit(0);
1085 }
1086 }
991 } 1087 }
992 1088
993 // JVM/TI RedefineClasses() support: 1089 // JVM/TI RedefineClasses() support:
994 bool MetaspaceShared::remap_shared_readonly_as_readwrite() { 1090 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
995 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1091 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1001 return false; 1097 return false;
1002 } 1098 }
1003 } 1099 }
1004 return true; 1100 return true;
1005 } 1101 }
1102
1103 int MetaspaceShared::count_class(const char* classlist_file) {
1104 if (classlist_file == NULL) {
1105 return 0;
1106 }
1107 char class_name[256];
1108 int class_count = 0;
1109 FILE* file = fopen(classlist_file, "r");
1110 if (file != NULL) {
1111 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
1112 if (*class_name == '#') { // comment
1113 continue;
1114 }
1115 class_count++;
1116 }
1117 fclose(file);
1118 } else {
1119 char errmsg[JVM_MAXPATHLEN];
1120 os::lasterror(errmsg, JVM_MAXPATHLEN);
1121 tty->print_cr("Loading classlist failed: %s", errmsg);
1122 exit(1);
1123 }
1124
1125 return class_count;
1126 }
1127
1128 // the sizes are good for typical large applications that have a lot of shared
1129 // classes
1130 void MetaspaceShared::estimate_regions_size() {
1131 int class_count = count_class(SharedClassListFile);
1132 class_count += count_class(ExtraSharedClassListFile);
1133
1134 if (class_count > LargeThresholdClassCount) {
1135 if (class_count < HugeThresholdClassCount) {
1136 SET_ESTIMATED_SIZE(Large, ReadOnly);
1137 SET_ESTIMATED_SIZE(Large, ReadWrite);
1138 SET_ESTIMATED_SIZE(Large, MiscData);
1139 SET_ESTIMATED_SIZE(Large, MiscCode);
1140 } else {
1141 SET_ESTIMATED_SIZE(Huge, ReadOnly);
1142 SET_ESTIMATED_SIZE(Huge, ReadWrite);
1143 SET_ESTIMATED_SIZE(Huge, MiscData);
1144 SET_ESTIMATED_SIZE(Huge, MiscCode);
1145 }
1146 }
1147 }