799 tty->print_cr("Shared spaces preloaded: %s", class_name);
800 }
801
802 InstanceKlass* ik = InstanceKlass::cast(klass);
803
804 // Should be class load order as per -XX:+TraceClassLoadingPreorder
805 class_promote_order->append(ik);
806
807 // Link the class to cause the bytecodes to be rewritten and the
808 // cpcache to be created. The linking is done as soon as classes
809 // are loaded in order that the related data structures (klass and
810 // cpCache) are located together.
811 try_link_class(ik, THREAD);
812 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
813
814 class_count++;
815 } else {
816 //tty->print_cr("Preload failed: %s", class_name);
817 }
818 }
819 } else {
820 char errmsg[JVM_MAXPATHLEN];
821 os::lasterror(errmsg, JVM_MAXPATHLEN);
822 tty->print_cr("Loading classlist failed: %s", errmsg);
823 exit(1);
824 }
825
826 return class_count;
827 }
828
829 // Returns true if the class's status has changed
830 bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
831 assert(DumpSharedSpaces, "should only be called during dumping");
832 if (ik->init_state() < InstanceKlass::linked) {
833 bool saved = BytecodeVerificationLocal;
834 if (!SharedClassUtil::is_shared_boot_class(ik)) {
835 // The verification decision is based on BytecodeVerificationRemote
836 // for non-system classes. Since we are using the NULL classloader
837 // to load non-system classes during dumping, we need to temporarily
838 // change BytecodeVerificationLocal to be the same as
1069 } else {
1070 tty->print_cr("archive is valid");
1071 vm_exit(0);
1072 }
1073 }
1074 }
1075
1076 // JVM/TI RedefineClasses() support:
1077 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
1078 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1079
1080 if (UseSharedSpaces) {
1081 // remap the shared readonly space to shared readwrite, private
1082 FileMapInfo* mapinfo = FileMapInfo::current_info();
1083 if (!mapinfo->remap_shared_readonly_as_readwrite()) {
1084 return false;
1085 }
1086 }
1087 return true;
1088 }
|
799 tty->print_cr("Shared spaces preloaded: %s", class_name);
800 }
801
802 InstanceKlass* ik = InstanceKlass::cast(klass);
803
804 // Should be class load order as per -XX:+TraceClassLoadingPreorder
805 class_promote_order->append(ik);
806
807 // Link the class to cause the bytecodes to be rewritten and the
808 // cpcache to be created. The linking is done as soon as classes
809 // are loaded in order that the related data structures (klass and
810 // cpCache) are located together.
811 try_link_class(ik, THREAD);
812 guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
813
814 class_count++;
815 } else {
816 //tty->print_cr("Preload failed: %s", class_name);
817 }
818 }
819 fclose(file);
820 } else {
821 char errmsg[JVM_MAXPATHLEN];
822 os::lasterror(errmsg, JVM_MAXPATHLEN);
823 tty->print_cr("Loading classlist failed: %s", errmsg);
824 exit(1);
825 }
826
827 return class_count;
828 }
829
830 // Returns true if the class's status has changed
831 bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
832 assert(DumpSharedSpaces, "should only be called during dumping");
833 if (ik->init_state() < InstanceKlass::linked) {
834 bool saved = BytecodeVerificationLocal;
835 if (!SharedClassUtil::is_shared_boot_class(ik)) {
836 // The verification decision is based on BytecodeVerificationRemote
837 // for non-system classes. Since we are using the NULL classloader
838 // to load non-system classes during dumping, we need to temporarily
839 // change BytecodeVerificationLocal to be the same as
1070 } else {
1071 tty->print_cr("archive is valid");
1072 vm_exit(0);
1073 }
1074 }
1075 }
1076
1077 // JVM/TI RedefineClasses() support:
1078 bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
1079 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1080
1081 if (UseSharedSpaces) {
1082 // remap the shared readonly space to shared readwrite, private
1083 FileMapInfo* mapinfo = FileMapInfo::current_info();
1084 if (!mapinfo->remap_shared_readonly_as_readwrite()) {
1085 return false;
1086 }
1087 }
1088 return true;
1089 }
1090
1091 int MetaspaceShared::count_class(const char* classlist_file) {
1092 if (classlist_file == NULL) {
1093 return 0;
1094 }
1095 char class_name[256];
1096 int class_count = 0;
1097 FILE* file = fopen(classlist_file, "r");
1098 if (file != NULL) {
1099 while ((fgets(class_name, sizeof class_name, file)) != NULL) {
1100 if (*class_name == '#') { // comment
1101 continue;
1102 }
1103 class_count++;
1104 }
1105 fclose(file);
1106 } else {
1107 char errmsg[JVM_MAXPATHLEN];
1108 os::lasterror(errmsg, JVM_MAXPATHLEN);
1109 tty->print_cr("Loading classlist failed: %s", errmsg);
1110 exit(1);
1111 }
1112
1113 return class_count;
1114 }
1115
1116 // the sizes are good for typical large applications that have a lot of shared
1117 // classes
1118 void MetaspaceShared::estimate_regions_size() {
1119 int class_count = count_class(SharedClassListFile);
1120 class_count += count_class(ExtraSharedClassListFile);
1121
1122 if (class_count > LargeThresholdClassCount) {
1123 if (class_count < HugeThresholdClassCount) {
1124 SET_ESTIMATED_SIZE(Large, ReadOnly);
1125 SET_ESTIMATED_SIZE(Large, ReadWrite);
1126 SET_ESTIMATED_SIZE(Large, MiscData);
1127 SET_ESTIMATED_SIZE(Large, MiscCode);
1128 } else {
1129 SET_ESTIMATED_SIZE(Huge, ReadOnly);
1130 SET_ESTIMATED_SIZE(Huge, ReadWrite);
1131 SET_ESTIMATED_SIZE(Huge, MiscData);
1132 SET_ESTIMATED_SIZE(Huge, MiscCode);
1133 }
1134 }
1135 }
|