57 #include "oops/symbol.hpp"
58 #include "prims/jvm_misc.hpp"
59 #include "runtime/arguments.hpp"
60 #include "runtime/compilationPolicy.hpp"
61 #include "runtime/handles.hpp"
62 #include "runtime/handles.inline.hpp"
63 #include "runtime/init.hpp"
64 #include "runtime/interfaceSupport.inline.hpp"
65 #include "runtime/java.hpp"
66 #include "runtime/javaCalls.hpp"
67 #include "runtime/os.inline.hpp"
68 #include "runtime/threadCritical.hpp"
69 #include "runtime/timer.hpp"
70 #include "runtime/vm_version.hpp"
71 #include "services/management.hpp"
72 #include "services/threadService.hpp"
73 #include "utilities/events.hpp"
74 #include "utilities/hashtable.inline.hpp"
75 #include "utilities/macros.hpp"
76 #if INCLUDE_CDS
77 #include "classfile/sharedClassUtil.hpp"
78 #include "classfile/sharedPathsMiscInfo.hpp"
79 #endif
80
81 // Entry points in zip.dll for loading zip/jar file entries
82
83 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
84 typedef void (*ZipClose_t)(jzfile *zip);
85 typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
86 typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
87 typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n);
88 typedef jboolean (*ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg);
89 typedef jint (*Crc32_t)(jint crc, const jbyte *buf, jint len);
90
91 static ZipOpen_t ZipOpen = NULL;
92 static ZipClose_t ZipClose = NULL;
93 static FindEntry_t FindEntry = NULL;
94 static ReadEntry_t ReadEntry = NULL;
95 static GetNextEntry_t GetNextEntry = NULL;
96 static canonicalize_fn_t CanonicalizeEntry = NULL;
97 static ZipInflateFully_t ZipInflateFully = NULL;
645 trace_class_path("bootstrap loader class path=", sys_class_path);
646 }
647 #if INCLUDE_CDS
648 if (DumpSharedSpaces) {
649 _shared_paths_misc_info->add_boot_classpath(sys_class_path);
650 }
651 #endif
652 setup_boot_search_path(sys_class_path);
653 }
654
655 #if INCLUDE_CDS
656 int ClassLoader::get_shared_paths_misc_info_size() {
657 return _shared_paths_misc_info->get_used_bytes();
658 }
659
660 void* ClassLoader::get_shared_paths_misc_info() {
661 return _shared_paths_misc_info->buffer();
662 }
663
664 bool ClassLoader::check_shared_paths_misc_info(void *buf, int size) {
665 SharedPathsMiscInfo* checker = SharedClassUtil::allocate_shared_paths_misc_info((char*)buf, size);
666 bool result = checker->check();
667 delete checker;
668 return result;
669 }
670
671 void ClassLoader::setup_app_search_path(const char *class_path) {
672
673 assert(DumpSharedSpaces, "Sanity");
674
675 Thread* THREAD = Thread::current();
676 int len = (int)strlen(class_path);
677 int end = 0;
678
679 // Iterate over class path entries
680 for (int start = 0; start < len; start = end) {
681 while (class_path[end] && class_path[end] != os::path_separator()[0]) {
682 end++;
683 }
684 EXCEPTION_MARK;
685 ResourceMark rm(THREAD);
1391 // There will not be another valid entry for that module.
1392 return NULL;
1393 }
1394
1395 // Called by the boot classloader to load classes
1396 InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
1397 assert(name != NULL, "invariant");
1398 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1399
1400 ResourceMark rm(THREAD);
1401 HandleMark hm(THREAD);
1402
1403 const char* const class_name = name->as_C_string();
1404
1405 EventMark m("loading class %s", class_name);
1406
1407 const char* const file_name = file_name_for_class_name(class_name,
1408 name->utf8_length());
1409 assert(file_name != NULL, "invariant");
1410
1411 ClassLoaderExt::Context context(class_name, file_name, THREAD);
1412
1413 // Lookup stream for parsing .class file
1414 ClassFileStream* stream = NULL;
1415 s2 classpath_index = 0;
1416 ClassPathEntry* e = NULL;
1417
1418 // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
1419 // - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
1420 //
1421 // If search_append_only is true, boot loader visibility boundaries are
1422 // set to be _first_append_entry to the end. This includes:
1423 // [-Xbootclasspath/a]; [jvmti appended entries]
1424 //
1425 // If both DumpSharedSpaces and search_append_only are false, boot loader
1426 // visibility boundaries are set to be the --patch-module entries plus the base piece.
1427 // This would include:
1428 // [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
1429 //
1430
1431 // Load Attempt #1: --patch-module
1432 // Determine the class' defining module. If it appears in the _patch_mod_entries,
1465 // for the appended piece is always 1 to account for either the
1466 // _jrt_entry or the _exploded_entries.
1467 assert(classpath_index == 0, "The classpath_index has been incremented incorrectly");
1468 classpath_index = 1;
1469
1470 e = _first_append_entry;
1471 while (e != NULL) {
1472 stream = e->open_stream(file_name, CHECK_NULL);
1473 if (NULL != stream) {
1474 break;
1475 }
1476 e = e->next();
1477 ++classpath_index;
1478 }
1479 }
1480
1481 if (NULL == stream) {
1482 return NULL;
1483 }
1484
1485 stream->set_verify(context.should_verify(classpath_index));
1486
1487 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
1488 Handle protection_domain;
1489
1490 InstanceKlass* result = KlassFactory::create_from_stream(stream,
1491 name,
1492 loader_data,
1493 protection_domain,
1494 NULL, // host_klass
1495 NULL, // cp_patches
1496 THREAD);
1497 if (HAS_PENDING_EXCEPTION) {
1498 if (DumpSharedSpaces) {
1499 tty->print_cr("Preload Error: Failed to load %s", class_name);
1500 }
1501 return NULL;
1502 }
1503
1504 if (!add_package(file_name, classpath_index, THREAD)) {
1505 return NULL;
1613 // No path entry found for this class. Must be a shared class loaded by the
1614 // user defined classloader.
1615 if (classpath_index < 0) {
1616 assert(ik->shared_classpath_index() < 0, "Sanity");
1617 return;
1618 }
1619 } else {
1620 // The shared path table is set up after module system initialization.
1621 // The path table contains no entry before that. Any classes loaded prior
1622 // to the setup of the shared path table must be from the modules image.
1623 assert(is_modules_image(src), "stream must be from modules image");
1624 assert(FileMapInfo::get_number_of_shared_paths() == 0, "shared path table must not have been setup");
1625 classpath_index = 0;
1626 }
1627
1628 const char* const class_name = ik->name()->as_C_string();
1629 const char* const file_name = file_name_for_class_name(class_name,
1630 ik->name()->utf8_length());
1631 assert(file_name != NULL, "invariant");
1632
1633 ClassLoaderExt::Context context(class_name, file_name, CATCH);
1634 context.record_result(ik->name(), classpath_index, ik, THREAD);
1635 }
1636 #endif // INCLUDE_CDS
1637
1638 // Initialize the class loader's access to methods in libzip. Parse and
1639 // process the boot classpath into a list ClassPathEntry objects. Once
1640 // this list has been created, it must not change order (see class PackageInfo)
1641 // it can be appended to and is by jvmti and the kernel vm.
1642
1643 void ClassLoader::initialize() {
1644 EXCEPTION_MARK;
1645
1646 if (UsePerfData) {
1647 // jvmstat performance counters
1648 NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
1649 NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime");
1650 NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self");
1651 NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime");
1652 NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self");
1653 NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime");
1654 NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self");
1684 NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
1685 "jvmDefineClassNoLockCalls");
1686
1687 NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
1688 "jniDefineClassNoLockCalls");
1689
1690 NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
1691 "unsafeDefineClassCalls");
1692
1693 NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS,
1694 "loadInstanceClassFailRate");
1695 }
1696
1697 // lookup zip library entry points
1698 load_zip_library();
1699 // lookup jimage library entry points
1700 load_jimage_library();
1701 #if INCLUDE_CDS
1702 // initialize search path
1703 if (DumpSharedSpaces) {
1704 _shared_paths_misc_info = SharedClassUtil::allocate_shared_paths_misc_info();
1705 }
1706 #endif
1707 setup_bootstrap_search_path();
1708 }
1709
1710 #if INCLUDE_CDS
1711 void ClassLoader::initialize_shared_path() {
1712 if (DumpSharedSpaces) {
1713 ClassLoaderExt::setup_search_paths();
1714 _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1715 }
1716 }
1717
1718 void ClassLoader::initialize_module_path(TRAPS) {
1719 if (DumpSharedSpaces) {
1720 ClassLoaderExt::setup_module_paths(THREAD);
1721 FileMapInfo::allocate_shared_path_table();
1722 }
1723 }
1724 #endif
|
57 #include "oops/symbol.hpp"
58 #include "prims/jvm_misc.hpp"
59 #include "runtime/arguments.hpp"
60 #include "runtime/compilationPolicy.hpp"
61 #include "runtime/handles.hpp"
62 #include "runtime/handles.inline.hpp"
63 #include "runtime/init.hpp"
64 #include "runtime/interfaceSupport.inline.hpp"
65 #include "runtime/java.hpp"
66 #include "runtime/javaCalls.hpp"
67 #include "runtime/os.inline.hpp"
68 #include "runtime/threadCritical.hpp"
69 #include "runtime/timer.hpp"
70 #include "runtime/vm_version.hpp"
71 #include "services/management.hpp"
72 #include "services/threadService.hpp"
73 #include "utilities/events.hpp"
74 #include "utilities/hashtable.inline.hpp"
75 #include "utilities/macros.hpp"
76 #if INCLUDE_CDS
77 #include "classfile/sharedPathsMiscInfo.hpp"
78 #endif
79
80 // Entry points in zip.dll for loading zip/jar file entries
81
82 typedef void * * (*ZipOpen_t)(const char *name, char **pmsg);
83 typedef void (*ZipClose_t)(jzfile *zip);
84 typedef jzentry* (*FindEntry_t)(jzfile *zip, const char *name, jint *sizeP, jint *nameLen);
85 typedef jboolean (*ReadEntry_t)(jzfile *zip, jzentry *entry, unsigned char *buf, char *namebuf);
86 typedef jzentry* (*GetNextEntry_t)(jzfile *zip, jint n);
87 typedef jboolean (*ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg);
88 typedef jint (*Crc32_t)(jint crc, const jbyte *buf, jint len);
89
90 static ZipOpen_t ZipOpen = NULL;
91 static ZipClose_t ZipClose = NULL;
92 static FindEntry_t FindEntry = NULL;
93 static ReadEntry_t ReadEntry = NULL;
94 static GetNextEntry_t GetNextEntry = NULL;
95 static canonicalize_fn_t CanonicalizeEntry = NULL;
96 static ZipInflateFully_t ZipInflateFully = NULL;
644 trace_class_path("bootstrap loader class path=", sys_class_path);
645 }
646 #if INCLUDE_CDS
647 if (DumpSharedSpaces) {
648 _shared_paths_misc_info->add_boot_classpath(sys_class_path);
649 }
650 #endif
651 setup_boot_search_path(sys_class_path);
652 }
653
654 #if INCLUDE_CDS
655 int ClassLoader::get_shared_paths_misc_info_size() {
656 return _shared_paths_misc_info->get_used_bytes();
657 }
658
659 void* ClassLoader::get_shared_paths_misc_info() {
660 return _shared_paths_misc_info->buffer();
661 }
662
663 bool ClassLoader::check_shared_paths_misc_info(void *buf, int size) {
664 SharedPathsMiscInfo* checker = new SharedPathsMiscInfo((char*)buf, size);
665 bool result = checker->check();
666 delete checker;
667 return result;
668 }
669
670 void ClassLoader::setup_app_search_path(const char *class_path) {
671
672 assert(DumpSharedSpaces, "Sanity");
673
674 Thread* THREAD = Thread::current();
675 int len = (int)strlen(class_path);
676 int end = 0;
677
678 // Iterate over class path entries
679 for (int start = 0; start < len; start = end) {
680 while (class_path[end] && class_path[end] != os::path_separator()[0]) {
681 end++;
682 }
683 EXCEPTION_MARK;
684 ResourceMark rm(THREAD);
1390 // There will not be another valid entry for that module.
1391 return NULL;
1392 }
1393
1394 // Called by the boot classloader to load classes
1395 InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TRAPS) {
1396 assert(name != NULL, "invariant");
1397 assert(THREAD->is_Java_thread(), "must be a JavaThread");
1398
1399 ResourceMark rm(THREAD);
1400 HandleMark hm(THREAD);
1401
1402 const char* const class_name = name->as_C_string();
1403
1404 EventMark m("loading class %s", class_name);
1405
1406 const char* const file_name = file_name_for_class_name(class_name,
1407 name->utf8_length());
1408 assert(file_name != NULL, "invariant");
1409
1410 // Lookup stream for parsing .class file
1411 ClassFileStream* stream = NULL;
1412 s2 classpath_index = 0;
1413 ClassPathEntry* e = NULL;
1414
1415 // If DumpSharedSpaces is true boot loader visibility boundaries are set to:
1416 // - [jimage] + [_first_append_entry to _last_append_entry] (all path entries).
1417 //
1418 // If search_append_only is true, boot loader visibility boundaries are
1419 // set to be _first_append_entry to the end. This includes:
1420 // [-Xbootclasspath/a]; [jvmti appended entries]
1421 //
1422 // If both DumpSharedSpaces and search_append_only are false, boot loader
1423 // visibility boundaries are set to be the --patch-module entries plus the base piece.
1424 // This would include:
1425 // [--patch-module=<module>=<file>(<pathsep><file>)*]; [jimage | exploded module build]
1426 //
1427
1428 // Load Attempt #1: --patch-module
1429 // Determine the class' defining module. If it appears in the _patch_mod_entries,
1462 // for the appended piece is always 1 to account for either the
1463 // _jrt_entry or the _exploded_entries.
1464 assert(classpath_index == 0, "The classpath_index has been incremented incorrectly");
1465 classpath_index = 1;
1466
1467 e = _first_append_entry;
1468 while (e != NULL) {
1469 stream = e->open_stream(file_name, CHECK_NULL);
1470 if (NULL != stream) {
1471 break;
1472 }
1473 e = e->next();
1474 ++classpath_index;
1475 }
1476 }
1477
1478 if (NULL == stream) {
1479 return NULL;
1480 }
1481
1482 stream->set_verify(ClassLoaderExt::should_verify(classpath_index));
1483
1484 ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
1485 Handle protection_domain;
1486
1487 InstanceKlass* result = KlassFactory::create_from_stream(stream,
1488 name,
1489 loader_data,
1490 protection_domain,
1491 NULL, // host_klass
1492 NULL, // cp_patches
1493 THREAD);
1494 if (HAS_PENDING_EXCEPTION) {
1495 if (DumpSharedSpaces) {
1496 tty->print_cr("Preload Error: Failed to load %s", class_name);
1497 }
1498 return NULL;
1499 }
1500
1501 if (!add_package(file_name, classpath_index, THREAD)) {
1502 return NULL;
1610 // No path entry found for this class. Must be a shared class loaded by the
1611 // user defined classloader.
1612 if (classpath_index < 0) {
1613 assert(ik->shared_classpath_index() < 0, "Sanity");
1614 return;
1615 }
1616 } else {
1617 // The shared path table is set up after module system initialization.
1618 // The path table contains no entry before that. Any classes loaded prior
1619 // to the setup of the shared path table must be from the modules image.
1620 assert(is_modules_image(src), "stream must be from modules image");
1621 assert(FileMapInfo::get_number_of_shared_paths() == 0, "shared path table must not have been setup");
1622 classpath_index = 0;
1623 }
1624
1625 const char* const class_name = ik->name()->as_C_string();
1626 const char* const file_name = file_name_for_class_name(class_name,
1627 ik->name()->utf8_length());
1628 assert(file_name != NULL, "invariant");
1629
1630 ClassLoaderExt::record_result(classpath_index, ik, THREAD);
1631 }
1632 #endif // INCLUDE_CDS
1633
1634 // Initialize the class loader's access to methods in libzip. Parse and
1635 // process the boot classpath into a list ClassPathEntry objects. Once
1636 // this list has been created, it must not change order (see class PackageInfo)
1637 // it can be appended to and is by jvmti and the kernel vm.
1638
1639 void ClassLoader::initialize() {
1640 EXCEPTION_MARK;
1641
1642 if (UsePerfData) {
1643 // jvmstat performance counters
1644 NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
1645 NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime");
1646 NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self");
1647 NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime");
1648 NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self");
1649 NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime");
1650 NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self");
1680 NEWPERFEVENTCOUNTER(_sync_JVMDefineClassLockFreeCounter, SUN_CLS,
1681 "jvmDefineClassNoLockCalls");
1682
1683 NEWPERFEVENTCOUNTER(_sync_JNIDefineClassLockFreeCounter, SUN_CLS,
1684 "jniDefineClassNoLockCalls");
1685
1686 NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS,
1687 "unsafeDefineClassCalls");
1688
1689 NEWPERFEVENTCOUNTER(_load_instance_class_failCounter, SUN_CLS,
1690 "loadInstanceClassFailRate");
1691 }
1692
1693 // lookup zip library entry points
1694 load_zip_library();
1695 // lookup jimage library entry points
1696 load_jimage_library();
1697 #if INCLUDE_CDS
1698 // initialize search path
1699 if (DumpSharedSpaces) {
1700 _shared_paths_misc_info = new SharedPathsMiscInfo();
1701 }
1702 #endif
1703 setup_bootstrap_search_path();
1704 }
1705
1706 #if INCLUDE_CDS
1707 void ClassLoader::initialize_shared_path() {
1708 if (DumpSharedSpaces) {
1709 ClassLoaderExt::setup_search_paths();
1710 _shared_paths_misc_info->write_jint(0); // see comments in SharedPathsMiscInfo::check()
1711 }
1712 }
1713
1714 void ClassLoader::initialize_module_path(TRAPS) {
1715 if (DumpSharedSpaces) {
1716 ClassLoaderExt::setup_module_paths(THREAD);
1717 FileMapInfo::allocate_shared_path_table();
1718 }
1719 }
1720 #endif
|