1142 int ClassLoader::crc32(int crc, const char* buf, int len) { |
1141 int ClassLoader::crc32(int crc, const char* buf, int len) { |
1143 assert(Crc32 != NULL, "ZIP_CRC32 is not found"); |
1142 assert(Crc32 != NULL, "ZIP_CRC32 is not found"); |
1144 return (*Crc32)(crc, (const jbyte*)buf, len); |
1143 return (*Crc32)(crc, (const jbyte*)buf, len); |
1145 } |
1144 } |
1146 |
1145 |
1147 #if INCLUDE_CDS |
|
1148 void ClassLoader::initialize_module_loader_map(JImageFile* jimage) { |
|
1149 if (!DumpSharedSpaces) { |
|
1150 return; // only needed for CDS dump time |
|
1151 } |
|
1152 |
|
1153 ResourceMark rm; |
|
1154 jlong size; |
|
1155 JImageLocationRef location = (*JImageFindResource)(jimage, JAVA_BASE_NAME, get_jimage_version_string(), MODULE_LOADER_MAP, &size); |
|
1156 if (location == 0) { |
|
1157 vm_exit_during_initialization( |
|
1158 "Cannot find ModuleLoaderMap location from modules jimage.", NULL); |
|
1159 } |
|
1160 char* buffer = NEW_RESOURCE_ARRAY(char, size + 1); |
|
1161 buffer[size] = '\0'; |
|
1162 jlong read = (*JImageGetResource)(jimage, location, buffer, size); |
|
1163 if (read != size) { |
|
1164 vm_exit_during_initialization( |
|
1165 "Cannot find ModuleLoaderMap resource from modules jimage.", NULL); |
|
1166 } |
|
1167 char* char_buf = (char*)buffer; |
|
1168 int buflen = (int)strlen(char_buf); |
|
1169 char* begin_ptr = char_buf; |
|
1170 char* end_ptr = strchr(begin_ptr, '\n'); |
|
1171 bool process_boot_modules = false; |
|
1172 _boot_modules_array = new (ResourceObj::C_HEAP, mtModule) |
|
1173 GrowableArray<char*>(INITIAL_BOOT_MODULES_ARRAY_SIZE, true); |
|
1174 _platform_modules_array = new (ResourceObj::C_HEAP, mtModule) |
|
1175 GrowableArray<char*>(INITIAL_PLATFORM_MODULES_ARRAY_SIZE, true); |
|
1176 while (end_ptr != NULL && (end_ptr - char_buf) < buflen) { |
|
1177 // Allocate a buffer from the C heap to be appended to the _boot_modules_array |
|
1178 // or the _platform_modules_array. |
|
1179 char* temp_name = NEW_C_HEAP_ARRAY(char, (size_t)(end_ptr - begin_ptr + 1), mtInternal); |
|
1180 strncpy(temp_name, begin_ptr, end_ptr - begin_ptr); |
|
1181 temp_name[end_ptr - begin_ptr] = '\0'; |
|
1182 if (strncmp(temp_name, "BOOT", 4) == 0) { |
|
1183 process_boot_modules = true; |
|
1184 FREE_C_HEAP_ARRAY(char, temp_name); |
|
1185 } else if (strncmp(temp_name, "PLATFORM", 8) == 0) { |
|
1186 process_boot_modules = false; |
|
1187 FREE_C_HEAP_ARRAY(char, temp_name); |
|
1188 } else { |
|
1189 // module name |
|
1190 if (process_boot_modules) { |
|
1191 _boot_modules_array->append(temp_name); |
|
1192 } else { |
|
1193 _platform_modules_array->append(temp_name); |
|
1194 } |
|
1195 } |
|
1196 begin_ptr = ++end_ptr; |
|
1197 end_ptr = strchr(begin_ptr, '\n'); |
|
1198 } |
|
1199 } |
|
1200 #endif |
|
1201 |
|
1202 // Function add_package extracts the package from the fully qualified class name |
1146 // Function add_package extracts the package from the fully qualified class name |
1203 // and checks if the package is in the boot loader's package entry table. If so, |
1147 // and checks if the package is in the boot loader's package entry table. If so, |
1204 // then it sets the classpath_index in the package entry record. |
1148 // then it sets the classpath_index in the package entry record. |
1205 // |
1149 // |
1206 // The classpath_index field is used to find the entry on the boot loader class |
1150 // The classpath_index field is used to find the entry on the boot loader class |
1287 Handle str = java_lang_String::create_from_symbol(package_entry->name(), CHECK_NULL); |
1231 Handle str = java_lang_String::create_from_symbol(package_entry->name(), CHECK_NULL); |
1288 result->obj_at_put(x, str()); |
1232 result->obj_at_put(x, str()); |
1289 } |
1233 } |
1290 return result(); |
1234 return result(); |
1291 } |
1235 } |
1292 |
|
1293 #if INCLUDE_CDS |
|
1294 s2 ClassLoader::module_to_classloader(const char* module_name) { |
|
1295 |
|
1296 assert(DumpSharedSpaces, "dump time only"); |
|
1297 assert(_boot_modules_array != NULL, "_boot_modules_array is NULL"); |
|
1298 assert(_platform_modules_array != NULL, "_platform_modules_array is NULL"); |
|
1299 |
|
1300 int array_size = _boot_modules_array->length(); |
|
1301 for (int i = 0; i < array_size; i++) { |
|
1302 if (strcmp(module_name, _boot_modules_array->at(i)) == 0) { |
|
1303 return BOOT_LOADER; |
|
1304 } |
|
1305 } |
|
1306 |
|
1307 array_size = _platform_modules_array->length(); |
|
1308 for (int i = 0; i < array_size; i++) { |
|
1309 if (strcmp(module_name, _platform_modules_array->at(i)) == 0) { |
|
1310 return PLATFORM_LOADER; |
|
1311 } |
|
1312 } |
|
1313 |
|
1314 return APP_LOADER; |
|
1315 } |
|
1316 |
|
1317 s2 ClassLoader::classloader_type(Symbol* class_name, ClassPathEntry* e, int classpath_index, TRAPS) { |
|
1318 assert(DumpSharedSpaces, "Only used for CDS dump time"); |
|
1319 |
|
1320 // obtain the classloader type based on the class name. |
|
1321 // First obtain the package name based on the class name. Then obtain |
|
1322 // the classloader type based on the package name from the jimage using |
|
1323 // a jimage API. If the classloader type cannot be found from the |
|
1324 // jimage, it is determined by the class path entry. |
|
1325 jshort loader_type = ClassLoader::APP_LOADER; |
|
1326 if (e->is_jrt()) { |
|
1327 ResourceMark rm; |
|
1328 TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_0); |
|
1329 if (pkg_name != NULL) { |
|
1330 const char* pkg_name_C_string = (const char*)(pkg_name->as_C_string()); |
|
1331 ClassPathImageEntry* cpie = (ClassPathImageEntry*)e; |
|
1332 JImageFile* jimage = cpie->jimage(); |
|
1333 char* module_name = (char*)(*JImagePackageToModule)(jimage, pkg_name_C_string); |
|
1334 if (module_name != NULL) { |
|
1335 loader_type = ClassLoader::module_to_classloader(module_name); |
|
1336 } |
|
1337 } |
|
1338 } else if (ClassLoaderExt::is_boot_classpath(classpath_index)) { |
|
1339 loader_type = ClassLoader::BOOT_LOADER; |
|
1340 } |
|
1341 return loader_type; |
|
1342 } |
|
1343 #endif |
|
1344 |
1236 |
1345 // caller needs ResourceMark |
1237 // caller needs ResourceMark |
1346 const char* ClassLoader::file_name_for_class_name(const char* class_name, |
1238 const char* ClassLoader::file_name_for_class_name(const char* class_name, |
1347 int class_name_len) { |
1239 int class_name_len) { |
1348 assert(class_name != NULL, "invariant"); |
1240 assert(class_name != NULL, "invariant"); |