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