445 }
446
447 return NULL;
448 }
449
450 JImageLocationRef ClassLoader::jimage_find_resource(JImageFile* jf,
451 const char* module_name,
452 const char* file_name,
453 jlong &size) {
454 return ((*JImageFindResource)(jf, module_name, get_jimage_version_string(), file_name, &size));
455 }
456
457 bool ClassPathImageEntry::is_modules_image() const {
458 assert(this == _singleton, "VM supports a single jimage");
459 assert(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry(), "must be used for jrt entry");
460 return true;
461 }
462
463 #if INCLUDE_CDS
464 void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
465 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "only called at dump time");
466 tty->print_cr("Hint: enable -Xlog:class+path=info to diagnose the failure");
467 vm_exit_during_initialization(error, message);
468 }
469 #endif
470
471 ModuleClassPathList::ModuleClassPathList(Symbol* module_name) {
472 _module_name = module_name;
473 _module_first_entry = NULL;
474 _module_last_entry = NULL;
475 }
476
477 ModuleClassPathList::~ModuleClassPathList() {
478 // Clean out each ClassPathEntry on list
479 ClassPathEntry* e = _module_first_entry;
480 while (e != NULL) {
481 ClassPathEntry* next_entry = e->next();
482 delete e;
483 e = next_entry;
484 }
485 }
515 }
516 }
517 ls.cr();
518 }
519 }
520
521 void ClassLoader::setup_bootstrap_search_path() {
522 const char* sys_class_path = Arguments::get_sysclasspath();
523 assert(sys_class_path != NULL, "System boot class path must not be NULL");
524 if (PrintSharedArchiveAndExit) {
525 // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
526 // the same as the bootcp of the shared archive.
527 } else {
528 trace_class_path("bootstrap loader class path=", sys_class_path);
529 }
530 setup_boot_search_path(sys_class_path);
531 }
532
533 #if INCLUDE_CDS
534 void ClassLoader::setup_app_search_path(const char *class_path) {
535 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "Sanity");
536
537 ResourceMark rm;
538 ClasspathStream cp_stream(class_path);
539
540 while (cp_stream.has_next()) {
541 const char* path = cp_stream.get_next();
542 update_class_path_entry_list(path, false, false, false);
543 }
544 }
545
546 void ClassLoader::add_to_module_path_entries(const char* path,
547 ClassPathEntry* entry) {
548 assert(entry != NULL, "ClassPathEntry should not be NULL");
549 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
550
551 // The entry does not exist, add to the list
552 if (_module_path_entries == NULL) {
553 assert(_last_module_path_entry == NULL, "Sanity");
554 _module_path_entries = _last_module_path_entry = entry;
555 } else {
556 _last_module_path_entry->set_next(entry);
557 _last_module_path_entry = entry;
558 }
559 }
560
561 // Add a module path to the _module_path_entries list.
562 void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
563 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "dump time only");
564 struct stat st;
565 if (os::stat(path, &st) != 0) {
566 tty->print_cr("os::stat error %d (%s). CDS dump aborted (path was \"%s\").",
567 errno, os::errno_name(errno), path);
568 vm_exit_during_initialization();
569 }
570 // File or directory found
571 ClassPathEntry* new_entry = NULL;
572 new_entry = create_class_path_entry(path, &st, true /* throw_exception */,
573 false /*is_boot_append */, false /* from_class_path_attr */, CHECK);
574 if (new_entry == NULL) {
575 return;
576 }
577
578 add_to_module_path_entries(path, new_entry);
579 return;
580 }
581
582 void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
583 update_module_path_entry_list(path, THREAD);
639 if (_patch_mod_entries != NULL && _patch_mod_entries->is_nonempty()) {
640 int table_len = _patch_mod_entries->length();
641 for (int i = 0; i < table_len; i++) {
642 ModuleClassPathList* patch_mod = _patch_mod_entries->at(i);
643 if (module_name->fast_compare(patch_mod->module_name()) == 0) {
644 return true;
645 }
646 }
647 }
648 return false;
649 }
650
651 // Set up the _jrt_entry if present and boot append path
652 void ClassLoader::setup_boot_search_path(const char *class_path) {
653 EXCEPTION_MARK;
654 ResourceMark rm(THREAD);
655 ClasspathStream cp_stream(class_path);
656 bool set_base_piece = true;
657
658 #if INCLUDE_CDS
659 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
660 if (!Arguments::has_jimage()) {
661 vm_exit_during_initialization("CDS is not supported in exploded JDK build", NULL);
662 }
663 }
664 #endif
665
666 while (cp_stream.has_next()) {
667 const char* path = cp_stream.get_next();
668
669 if (set_base_piece) {
670 // The first time through the bootstrap_search setup, it must be determined
671 // what the base or core piece of the boot loader search is. Either a java runtime
672 // image is present or this is an exploded module build situation.
673 assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME),
674 "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build");
675 struct stat st;
676 if (os::stat(path, &st) == 0) {
677 // Directory found
678 ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, false, CHECK);
679
1343 // file: protocol path could start with file:/ or file:///
1344 // locate the char after all the forward slashes
1345 int offset = 5;
1346 while (*(source + offset) == '/') {
1347 offset++;
1348 }
1349 source += offset;
1350 // for non-windows platforms, move back one char as the path begins with a '/'
1351 #ifndef _WINDOWS
1352 source -= 1;
1353 #endif
1354 } else if (strncmp(source, "jrt:/", 5) == 0) {
1355 source += 5;
1356 }
1357 return source;
1358 }
1359
1360 // Record the shared classpath index and loader type for classes loaded
1361 // by the builtin loaders at dump time.
1362 void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream, TRAPS) {
1363 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "sanity");
1364 assert(stream != NULL, "sanity");
1365
1366 if (ik->is_unsafe_anonymous()) {
1367 // We do not archive unsafe anonymous classes.
1368 return;
1369 }
1370
1371 oop loader = ik->class_loader();
1372 char* src = (char*)stream->source();
1373 if (src == NULL) {
1374 if (loader == NULL) {
1375 // JFR classes
1376 ik->set_shared_classpath_index(0);
1377 ik->set_class_loader_type(ClassLoader::BOOT_LOADER);
1378 }
1379 return;
1380 }
1381
1382 assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build");
1383
1520 "jvmFindLoadedClassNoLockCalls");
1521 NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
1522 "jvmDefineClassNoLockCalls");
1523
1524 NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
1525 "jniDefineClassNoLockCalls");
1526
1527 NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
1528 "unsafeDefineClassCalls");
1529 }
1530
1531 // lookup zip library entry points
1532 load_zip_library();
1533 // lookup jimage library entry points
1534 load_jimage_library();
1535 setup_bootstrap_search_path();
1536 }
1537
1538 #if INCLUDE_CDS
1539 void ClassLoader::initialize_shared_path() {
1540 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1541 ClassLoaderExt::setup_search_paths();
1542 }
1543 }
1544
1545 void ClassLoader::initialize_module_path(TRAPS) {
1546 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
1547 ClassLoaderExt::setup_module_paths(THREAD);
1548 FileMapInfo::allocate_shared_path_table();
1549 }
1550 }
1551 #endif
1552
1553 jlong ClassLoader::classloader_time_ms() {
1554 return UsePerfData ?
1555 Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1556 }
1557
1558 jlong ClassLoader::class_init_count() {
1559 return UsePerfData ? _perf_classes_inited->get_value() : -1;
1560 }
1561
1562 jlong ClassLoader::class_init_time_ms() {
1563 return UsePerfData ?
1564 Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1565 }
1566
|
445 }
446
447 return NULL;
448 }
449
450 JImageLocationRef ClassLoader::jimage_find_resource(JImageFile* jf,
451 const char* module_name,
452 const char* file_name,
453 jlong &size) {
454 return ((*JImageFindResource)(jf, module_name, get_jimage_version_string(), file_name, &size));
455 }
456
457 bool ClassPathImageEntry::is_modules_image() const {
458 assert(this == _singleton, "VM supports a single jimage");
459 assert(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry(), "must be used for jrt entry");
460 return true;
461 }
462
463 #if INCLUDE_CDS
464 void ClassLoader::exit_with_path_failure(const char* error, const char* message) {
465 assert(Arguments::is_dumping_archive(), "only called at dump time");
466 tty->print_cr("Hint: enable -Xlog:class+path=info to diagnose the failure");
467 vm_exit_during_initialization(error, message);
468 }
469 #endif
470
471 ModuleClassPathList::ModuleClassPathList(Symbol* module_name) {
472 _module_name = module_name;
473 _module_first_entry = NULL;
474 _module_last_entry = NULL;
475 }
476
477 ModuleClassPathList::~ModuleClassPathList() {
478 // Clean out each ClassPathEntry on list
479 ClassPathEntry* e = _module_first_entry;
480 while (e != NULL) {
481 ClassPathEntry* next_entry = e->next();
482 delete e;
483 e = next_entry;
484 }
485 }
515 }
516 }
517 ls.cr();
518 }
519 }
520
521 void ClassLoader::setup_bootstrap_search_path() {
522 const char* sys_class_path = Arguments::get_sysclasspath();
523 assert(sys_class_path != NULL, "System boot class path must not be NULL");
524 if (PrintSharedArchiveAndExit) {
525 // Don't print sys_class_path - this is the bootcp of this current VM process, not necessarily
526 // the same as the bootcp of the shared archive.
527 } else {
528 trace_class_path("bootstrap loader class path=", sys_class_path);
529 }
530 setup_boot_search_path(sys_class_path);
531 }
532
533 #if INCLUDE_CDS
534 void ClassLoader::setup_app_search_path(const char *class_path) {
535 assert(Arguments::is_dumping_archive(), "Sanity");
536
537 ResourceMark rm;
538 ClasspathStream cp_stream(class_path);
539
540 while (cp_stream.has_next()) {
541 const char* path = cp_stream.get_next();
542 update_class_path_entry_list(path, false, false, false);
543 }
544 }
545
546 void ClassLoader::add_to_module_path_entries(const char* path,
547 ClassPathEntry* entry) {
548 assert(entry != NULL, "ClassPathEntry should not be NULL");
549 assert(Arguments::is_dumping_archive(), "dump time only");
550
551 // The entry does not exist, add to the list
552 if (_module_path_entries == NULL) {
553 assert(_last_module_path_entry == NULL, "Sanity");
554 _module_path_entries = _last_module_path_entry = entry;
555 } else {
556 _last_module_path_entry->set_next(entry);
557 _last_module_path_entry = entry;
558 }
559 }
560
561 // Add a module path to the _module_path_entries list.
562 void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
563 assert(Arguments::is_dumping_archive(), "dump time only");
564 struct stat st;
565 if (os::stat(path, &st) != 0) {
566 tty->print_cr("os::stat error %d (%s). CDS dump aborted (path was \"%s\").",
567 errno, os::errno_name(errno), path);
568 vm_exit_during_initialization();
569 }
570 // File or directory found
571 ClassPathEntry* new_entry = NULL;
572 new_entry = create_class_path_entry(path, &st, true /* throw_exception */,
573 false /*is_boot_append */, false /* from_class_path_attr */, CHECK);
574 if (new_entry == NULL) {
575 return;
576 }
577
578 add_to_module_path_entries(path, new_entry);
579 return;
580 }
581
582 void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
583 update_module_path_entry_list(path, THREAD);
639 if (_patch_mod_entries != NULL && _patch_mod_entries->is_nonempty()) {
640 int table_len = _patch_mod_entries->length();
641 for (int i = 0; i < table_len; i++) {
642 ModuleClassPathList* patch_mod = _patch_mod_entries->at(i);
643 if (module_name->fast_compare(patch_mod->module_name()) == 0) {
644 return true;
645 }
646 }
647 }
648 return false;
649 }
650
651 // Set up the _jrt_entry if present and boot append path
652 void ClassLoader::setup_boot_search_path(const char *class_path) {
653 EXCEPTION_MARK;
654 ResourceMark rm(THREAD);
655 ClasspathStream cp_stream(class_path);
656 bool set_base_piece = true;
657
658 #if INCLUDE_CDS
659 if (Arguments::is_dumping_archive()) {
660 if (!Arguments::has_jimage()) {
661 vm_exit_during_initialization("CDS is not supported in exploded JDK build", NULL);
662 }
663 }
664 #endif
665
666 while (cp_stream.has_next()) {
667 const char* path = cp_stream.get_next();
668
669 if (set_base_piece) {
670 // The first time through the bootstrap_search setup, it must be determined
671 // what the base or core piece of the boot loader search is. Either a java runtime
672 // image is present or this is an exploded module build situation.
673 assert(string_ends_with(path, MODULES_IMAGE_NAME) || string_ends_with(path, JAVA_BASE_NAME),
674 "Incorrect boot loader search path, no java runtime image or " JAVA_BASE_NAME " exploded build");
675 struct stat st;
676 if (os::stat(path, &st) == 0) {
677 // Directory found
678 ClassPathEntry* new_entry = create_class_path_entry(path, &st, false, false, false, CHECK);
679
1343 // file: protocol path could start with file:/ or file:///
1344 // locate the char after all the forward slashes
1345 int offset = 5;
1346 while (*(source + offset) == '/') {
1347 offset++;
1348 }
1349 source += offset;
1350 // for non-windows platforms, move back one char as the path begins with a '/'
1351 #ifndef _WINDOWS
1352 source -= 1;
1353 #endif
1354 } else if (strncmp(source, "jrt:/", 5) == 0) {
1355 source += 5;
1356 }
1357 return source;
1358 }
1359
1360 // Record the shared classpath index and loader type for classes loaded
1361 // by the builtin loaders at dump time.
1362 void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream, TRAPS) {
1363 assert(Arguments::is_dumping_archive(), "sanity");
1364 assert(stream != NULL, "sanity");
1365
1366 if (ik->is_unsafe_anonymous()) {
1367 // We do not archive unsafe anonymous classes.
1368 return;
1369 }
1370
1371 oop loader = ik->class_loader();
1372 char* src = (char*)stream->source();
1373 if (src == NULL) {
1374 if (loader == NULL) {
1375 // JFR classes
1376 ik->set_shared_classpath_index(0);
1377 ik->set_class_loader_type(ClassLoader::BOOT_LOADER);
1378 }
1379 return;
1380 }
1381
1382 assert(has_jrt_entry(), "CDS dumping does not support exploded JDK build");
1383
1520 "jvmFindLoadedClassNoLockCalls");
1521 NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
1522 "jvmDefineClassNoLockCalls");
1523
1524 NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
1525 "jniDefineClassNoLockCalls");
1526
1527 NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
1528 "unsafeDefineClassCalls");
1529 }
1530
1531 // lookup zip library entry points
1532 load_zip_library();
1533 // lookup jimage library entry points
1534 load_jimage_library();
1535 setup_bootstrap_search_path();
1536 }
1537
1538 #if INCLUDE_CDS
1539 void ClassLoader::initialize_shared_path() {
1540 if (Arguments::is_dumping_archive()) {
1541 ClassLoaderExt::setup_search_paths();
1542 }
1543 }
1544
1545 void ClassLoader::initialize_module_path(TRAPS) {
1546 if (Arguments::is_dumping_archive()) {
1547 ClassLoaderExt::setup_module_paths(THREAD);
1548 FileMapInfo::allocate_shared_path_table();
1549 }
1550 }
1551 #endif
1552
1553 jlong ClassLoader::classloader_time_ms() {
1554 return UsePerfData ?
1555 Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1556 }
1557
1558 jlong ClassLoader::class_init_count() {
1559 return UsePerfData ? _perf_classes_inited->get_value() : -1;
1560 }
1561
1562 jlong ClassLoader::class_init_time_ms() {
1563 return UsePerfData ?
1564 Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1565 }
1566
|