< prev index next >

src/hotspot/share/classfile/classLoader.cpp

Print this page

  51 #include "logging/logTag.hpp"
  52 #include "memory/allocation.inline.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/instanceKlass.hpp"
  57 #include "oops/instanceRefKlass.hpp"
  58 #include "oops/klass.inline.hpp"
  59 #include "oops/method.inline.hpp"
  60 #include "oops/objArrayOop.inline.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "oops/symbol.hpp"
  63 #include "prims/jvm_misc.hpp"
  64 #include "runtime/arguments.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/init.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/os.hpp"
  71 #include "runtime/perfData.hpp"
  72 #include "runtime/threadCritical.hpp"
  73 #include "runtime/timer.hpp"
  74 #include "runtime/vm_version.hpp"
  75 #include "services/management.hpp"
  76 #include "services/threadService.hpp"
  77 #include "utilities/checkedCast.hpp"
  78 #include "utilities/classpathStream.hpp"
  79 #include "utilities/events.hpp"
  80 #include "utilities/macros.hpp"
  81 #include "utilities/ostream.hpp"
  82 #include "utilities/utf8.hpp"
  83 
  84 #include <stdlib.h>
  85 #include <ctype.h>
  86 
  87 // Entry point in java.dll for path canonicalization
  88 
  89 typedef int (*canonicalize_fn_t)(const char *orig, char *out, int len);
  90 
  91 static canonicalize_fn_t CanonicalizeEntry  = nullptr;
  92 
  93 // Entry points for jimage.dll for loading jimage file entries
  94 
  95 static JImageOpen_t                    JImageOpen             = nullptr;
  96 static JImageClose_t                   JImageClose            = nullptr;
  97 static JImageFindResource_t            JImageFindResource     = nullptr;
  98 static JImageGetResource_t             JImageGetResource      = nullptr;
  99 
 100 // JimageFile pointer, or null if exploded JDK build.
 101 static JImageFile*                     JImage_file            = nullptr;
 102 
 103 // Globals
 104 
 105 PerfCounter*    ClassLoader::_perf_accumulated_time = nullptr;
 106 PerfCounter*    ClassLoader::_perf_classes_inited = nullptr;
 107 PerfCounter*    ClassLoader::_perf_class_init_time = nullptr;
 108 PerfCounter*    ClassLoader::_perf_class_init_selftime = nullptr;

 109 PerfCounter*    ClassLoader::_perf_classes_verified = nullptr;
 110 PerfCounter*    ClassLoader::_perf_class_verify_time = nullptr;
 111 PerfCounter*    ClassLoader::_perf_class_verify_selftime = nullptr;
 112 PerfCounter*    ClassLoader::_perf_classes_linked = nullptr;
 113 PerfCounter*    ClassLoader::_perf_class_link_time = nullptr;
 114 PerfCounter*    ClassLoader::_perf_class_link_selftime = nullptr;
 115 PerfCounter*    ClassLoader::_perf_shared_classload_time = nullptr;
 116 PerfCounter*    ClassLoader::_perf_sys_classload_time = nullptr;
 117 PerfCounter*    ClassLoader::_perf_app_classload_time = nullptr;
 118 PerfCounter*    ClassLoader::_perf_app_classload_selftime = nullptr;
 119 PerfCounter*    ClassLoader::_perf_app_classload_count = nullptr;
 120 PerfCounter*    ClassLoader::_perf_define_appclasses = nullptr;
 121 PerfCounter*    ClassLoader::_perf_define_appclass_time = nullptr;
 122 PerfCounter*    ClassLoader::_perf_define_appclass_selftime = nullptr;
 123 PerfCounter*    ClassLoader::_perf_app_classfile_bytes_read = nullptr;
 124 PerfCounter*    ClassLoader::_perf_sys_classfile_bytes_read = nullptr;





 125 PerfCounter*    ClassLoader::_perf_ik_link_methods_time = nullptr;
 126 PerfCounter*    ClassLoader::_perf_method_adapters_time = nullptr;
 127 PerfCounter*    ClassLoader::_perf_ik_link_methods_count = nullptr;
 128 PerfCounter*    ClassLoader::_perf_method_adapters_count = nullptr;
 129 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = nullptr;
 130 PerfCounter*    ClassLoader::_perf_secondary_hash_time = nullptr;
 131 
 132 PerfCounter*    ClassLoader::_perf_resolve_indy_time = nullptr;
 133 PerfCounter*    ClassLoader::_perf_resolve_invokehandle_time = nullptr;
 134 PerfCounter*    ClassLoader::_perf_resolve_mh_time = nullptr;
 135 PerfCounter*    ClassLoader::_perf_resolve_mt_time = nullptr;
 136 
 137 PerfCounter*    ClassLoader::_perf_resolve_indy_count = nullptr;
 138 PerfCounter*    ClassLoader::_perf_resolve_invokehandle_count = nullptr;
 139 PerfCounter*    ClassLoader::_perf_resolve_mh_count = nullptr;
 140 PerfCounter*    ClassLoader::_perf_resolve_mt_count = nullptr;
 141 
 142 void ClassLoader::print_counters(outputStream *st) {
 143   st->print_cr("ClassLoader:");
 144   st->print_cr("  clinit:               " JLONG_FORMAT "ms / " JLONG_FORMAT " events", ClassLoader::class_init_time_ms(), ClassLoader::class_init_count());
 145   st->print_cr("  link methods:         " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_ik_link_methods_time->get_value())   , _perf_ik_link_methods_count->get_value());
 146   st->print_cr("  method adapters:      " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_method_adapters_time->get_value())   , _perf_method_adapters_count->get_value());






 147   st->print_cr("  resolve...");
 148   st->print_cr("    invokedynamic:   " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_indy_time->get_value())         , _perf_resolve_indy_count->get_value());
 149   st->print_cr("    invokehandle:    " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_invokehandle_time->get_value()) , _perf_resolve_invokehandle_count->get_value());
 150   st->print_cr("    CP_MethodHandle: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mh_time->get_value())           , _perf_resolve_mh_count->get_value());
 151   st->print_cr("    CP_MethodType:   " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mt_time->get_value())           , _perf_resolve_mt_count->get_value());
 152   st->cr();











 153 }
 154 
 155 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = nullptr;
 156 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = nullptr;
 157 ClassPathEntry* ClassLoader::_jrt_entry = nullptr;
 158 
 159 ClassPathEntry* volatile ClassLoader::_first_append_entry_list = nullptr;
 160 ClassPathEntry* volatile ClassLoader::_last_append_entry  = nullptr;
 161 
 162 // helper routines
 163 #if INCLUDE_CDS
 164 static bool string_starts_with(const char* str, const char* str_to_find) {
 165   size_t str_len = strlen(str);
 166   size_t str_to_find_len = strlen(str_to_find);
 167   if (str_to_find_len > str_len) {
 168     return false;
 169   }
 170   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 171 }
 172 #endif

 326   jint name_len;
 327   jzentry* entry = ZipLibrary::find_entry(_zip, name, filesize, &name_len);
 328   if (entry == nullptr) return nullptr;
 329   u1* buffer;
 330   char name_buf[128];
 331   char* filename;
 332   if (name_len < 128) {
 333     filename = name_buf;
 334   } else {
 335     filename = NEW_RESOURCE_ARRAY(char, name_len + 1);
 336   }
 337 
 338   // read contents into resource array
 339   size_t size = (uint32_t)(*filesize);
 340   if (nul_terminate) {
 341     if (sizeof(size) == sizeof(uint32_t) && size == UINT_MAX) {
 342       return nullptr; // 32-bit integer overflow will occur.
 343     }
 344     size++;
 345   }


 346   buffer = NEW_RESOURCE_ARRAY(u1, size);
 347   if (!ZipLibrary::read_entry(_zip, entry, buffer, filename)) {
 348     return nullptr;
 349   }
 350 
 351   // return result
 352   if (nul_terminate) {
 353     buffer[size - 1] = 0;
 354   }
 355   return buffer;
 356 }
 357 
 358 ClassFileStream* ClassPathZipEntry::open_stream(JavaThread* current, const char* name) {
 359   jint filesize;
 360   u1* buffer = open_entry(current, name, &filesize, false);
 361   if (buffer == nullptr) {
 362     return nullptr;
 363   }
 364   if (UsePerfData) {
 365     ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize);

1330 #endif // INCLUDE_CDS
1331 
1332 // Initialize the class loader's access to methods in libzip.  Parse and
1333 // process the boot classpath into a list ClassPathEntry objects.  Once
1334 // this list has been created, it must not change order (see class PackageInfo)
1335 // it can be appended to and is by jvmti.
1336 
1337 void ClassLoader::initialize(TRAPS) {
1338   if (UsePerfData) {
1339     // jvmstat performance counters
1340     NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
1341     NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime");
1342     NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self");
1343     NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime");
1344     NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self");
1345     NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime");
1346     NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self");
1347     NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses");
1348     NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses");
1349     NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses");

1350 
1351     NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime");
1352     NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime");
1353     NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime");
1354     NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self");
1355     NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount");
1356     NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses");
1357     NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime");
1358     NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self");
1359     NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes");
1360     NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes");
1361     NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS, "unsafeDefineClassCalls");
1362     NEWPERFTICKCOUNTER(_perf_secondary_hash_time, SUN_CLS, "secondarySuperHashTime");
1363 
1364     if (log_is_enabled(Info, perf, class, link)) {






1365       NEWPERFTICKCOUNTER(_perf_ik_link_methods_time, SUN_CLS, "linkMethodsTime");
1366       NEWPERFTICKCOUNTER(_perf_method_adapters_time, SUN_CLS, "makeAdaptersTime");
1367       NEWPERFEVENTCOUNTER(_perf_ik_link_methods_count, SUN_CLS, "linkMethodsCount");
1368       NEWPERFEVENTCOUNTER(_perf_method_adapters_count, SUN_CLS, "makeAdaptersCount");
1369 
1370       NEWPERFTICKCOUNTER(_perf_resolve_indy_time, SUN_CLS, "resolve_invokedynamic_time");
1371       NEWPERFTICKCOUNTER(_perf_resolve_invokehandle_time, SUN_CLS, "resolve_invokehandle_time");
1372       NEWPERFTICKCOUNTER(_perf_resolve_mh_time, SUN_CLS, "resolve_MethodHandle_time");
1373       NEWPERFTICKCOUNTER(_perf_resolve_mt_time, SUN_CLS, "resolve_MethodType_time");
1374 
1375       NEWPERFEVENTCOUNTER(_perf_resolve_indy_count, SUN_CLS, "resolve_invokedynamic_count");
1376       NEWPERFEVENTCOUNTER(_perf_resolve_invokehandle_count, SUN_CLS, "resolve_invokehandle_count");
1377       NEWPERFEVENTCOUNTER(_perf_resolve_mh_count, SUN_CLS, "resolve_MethodHandle_count");
1378       NEWPERFEVENTCOUNTER(_perf_resolve_mt_count, SUN_CLS, "resolve_MethodType_count");
1379     }
1380   }
1381 
1382   // lookup java library entry points
1383   load_java_library();
1384   // jimage library entry points are loaded below, in lookup_vm_options
1385   setup_bootstrap_search_path(THREAD);
1386 }
1387 
1388 static char* lookup_vm_resource(JImageFile *jimage, const char *jimage_version, const char *path) {
1389   jlong size;
1390   JImageLocationRef location = (*JImageFindResource)(jimage, "java.base", jimage_version, path, &size);
1391   if (location == 0)
1392     return nullptr;
1393   char *val = NEW_C_HEAP_ARRAY(char, size+1, mtClass);

1418 
1419 bool ClassLoader::is_module_observable(const char* module_name) {
1420   assert(JImageOpen != nullptr, "jimage library should have been opened");
1421   if (JImage_file == nullptr) {
1422     struct stat st;
1423     const char *path = get_exploded_module_path(module_name, true);
1424     bool res = os::stat(path, &st) == 0;
1425     FREE_C_HEAP_ARRAY(char, path);
1426     return res;
1427   }
1428   jlong size;
1429   const char *jimage_version = get_jimage_version_string();
1430   return (*JImageFindResource)(JImage_file, module_name, jimage_version, "module-info.class", &size) != 0;
1431 }
1432 
1433 jlong ClassLoader::classloader_time_ms() {
1434   return UsePerfData ?
1435     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1436 }
1437 




1438 jlong ClassLoader::class_init_count() {
1439   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1440 }
1441 
1442 jlong ClassLoader::class_init_time_ms() {
1443   return UsePerfData ?
1444     Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1445 }
1446 
1447 jlong ClassLoader::class_verify_time_ms() {
1448   return UsePerfData ?
1449     Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1;
1450 }
1451 
1452 jlong ClassLoader::class_link_count() {
1453   return UsePerfData ? _perf_classes_linked->get_value() : -1;
1454 }
1455 
1456 jlong ClassLoader::class_link_time_ms() {
1457   return UsePerfData ?

  51 #include "logging/logTag.hpp"
  52 #include "memory/allocation.inline.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/instanceKlass.hpp"
  57 #include "oops/instanceRefKlass.hpp"
  58 #include "oops/klass.inline.hpp"
  59 #include "oops/method.inline.hpp"
  60 #include "oops/objArrayOop.inline.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "oops/symbol.hpp"
  63 #include "prims/jvm_misc.hpp"
  64 #include "runtime/arguments.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/init.hpp"
  67 #include "runtime/interfaceSupport.inline.hpp"
  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/os.hpp"
  71 #include "runtime/perfData.inline.hpp"
  72 #include "runtime/threadCritical.hpp"
  73 #include "runtime/timer.hpp"
  74 #include "runtime/vm_version.hpp"
  75 #include "services/management.hpp"
  76 #include "services/threadService.hpp"
  77 #include "utilities/checkedCast.hpp"
  78 #include "utilities/classpathStream.hpp"
  79 #include "utilities/events.hpp"
  80 #include "utilities/macros.hpp"
  81 #include "utilities/ostream.hpp"
  82 #include "utilities/utf8.hpp"
  83 
  84 #include <stdlib.h>
  85 #include <ctype.h>
  86 
  87 // Entry point in java.dll for path canonicalization
  88 
  89 typedef int (*canonicalize_fn_t)(const char *orig, char *out, int len);
  90 
  91 static canonicalize_fn_t CanonicalizeEntry  = nullptr;
  92 
  93 // Entry points for jimage.dll for loading jimage file entries
  94 
  95 static JImageOpen_t                    JImageOpen             = nullptr;
  96 static JImageClose_t                   JImageClose            = nullptr;
  97 static JImageFindResource_t            JImageFindResource     = nullptr;
  98 static JImageGetResource_t             JImageGetResource      = nullptr;
  99 
 100 // JimageFile pointer, or null if exploded JDK build.
 101 static JImageFile*                     JImage_file            = nullptr;
 102 
 103 // Globals
 104 
 105 PerfCounter*    ClassLoader::_perf_accumulated_time = nullptr;
 106 PerfCounter*    ClassLoader::_perf_classes_inited = nullptr;
 107 PerfCounter*    ClassLoader::_perf_class_init_time = nullptr;
 108 PerfCounter*    ClassLoader::_perf_class_init_selftime = nullptr;
 109 PerfCounter*    ClassLoader::_perf_class_init_bytecodes_count = nullptr;
 110 PerfCounter*    ClassLoader::_perf_classes_verified = nullptr;
 111 PerfCounter*    ClassLoader::_perf_class_verify_time = nullptr;
 112 PerfCounter*    ClassLoader::_perf_class_verify_selftime = nullptr;
 113 PerfCounter*    ClassLoader::_perf_classes_linked = nullptr;
 114 PerfCounter*    ClassLoader::_perf_class_link_time = nullptr;
 115 PerfCounter*    ClassLoader::_perf_class_link_selftime = nullptr;
 116 PerfCounter*    ClassLoader::_perf_shared_classload_time = nullptr;
 117 PerfCounter*    ClassLoader::_perf_sys_classload_time = nullptr;
 118 PerfCounter*    ClassLoader::_perf_app_classload_time = nullptr;
 119 PerfCounter*    ClassLoader::_perf_app_classload_selftime = nullptr;
 120 PerfCounter*    ClassLoader::_perf_app_classload_count = nullptr;
 121 PerfCounter*    ClassLoader::_perf_define_appclasses = nullptr;
 122 PerfCounter*    ClassLoader::_perf_define_appclass_time = nullptr;
 123 PerfCounter*    ClassLoader::_perf_define_appclass_selftime = nullptr;
 124 PerfCounter*    ClassLoader::_perf_app_classfile_bytes_read = nullptr;
 125 PerfCounter*    ClassLoader::_perf_sys_classfile_bytes_read = nullptr;
 126 PerfCounter*    ClassLoader::_perf_preload_total_time = nullptr;
 127 PerfCounter*    ClassLoader::_perf_preload_time = nullptr;
 128 PerfCounter*    ClassLoader::_perf_prelink_time = nullptr;
 129 PerfCounter*    ClassLoader::_perf_preinit_time = nullptr;
 130 PerfCounter*    ClassLoader::_perf_preresolve_time = nullptr;
 131 PerfCounter*    ClassLoader::_perf_ik_link_methods_time = nullptr;
 132 PerfCounter*    ClassLoader::_perf_method_adapters_time = nullptr;
 133 PerfCounter*    ClassLoader::_perf_ik_link_methods_count = nullptr;
 134 PerfCounter*    ClassLoader::_perf_method_adapters_count = nullptr;
 135 PerfCounter*    ClassLoader::_unsafe_defineClassCallCounter = nullptr;
 136 PerfCounter*    ClassLoader::_perf_secondary_hash_time = nullptr;
 137 
 138 PerfTickCounters*    ClassLoader::_perf_resolve_indy_time = nullptr;
 139 PerfTickCounters*    ClassLoader::_perf_resolve_invokehandle_time = nullptr;
 140 PerfTickCounters*    ClassLoader::_perf_resolve_mh_time = nullptr;
 141 PerfTickCounters*    ClassLoader::_perf_resolve_mt_time = nullptr;
 142 
 143 PerfCounter*    ClassLoader::_perf_resolve_indy_count = nullptr;
 144 PerfCounter*    ClassLoader::_perf_resolve_invokehandle_count = nullptr;
 145 PerfCounter*    ClassLoader::_perf_resolve_mh_count = nullptr;
 146 PerfCounter*    ClassLoader::_perf_resolve_mt_count = nullptr;
 147 
 148 void ClassLoader::print_counters(outputStream *st) {
 149   st->print_cr("ClassLoader:");
 150   st->print_cr(   "  clinit:               " JLONG_FORMAT_W(6) "us / " JLONG_FORMAT " events",
 151                ClassLoader::class_init_time_ms(), ClassLoader::class_init_count());
 152   st->print_cr("  link methods:         " JLONG_FORMAT_W(6) "us / " JLONG_FORMAT " events",
 153                Management::ticks_to_us(_perf_ik_link_methods_time->get_value())   , _perf_ik_link_methods_count->get_value());
 154   st->print_cr("  method adapters:      " JLONG_FORMAT_W(6) "us / " JLONG_FORMAT " events",
 155                Management::ticks_to_us(_perf_method_adapters_time->get_value())   , _perf_method_adapters_count->get_value());
 156   if (CountBytecodes || CountBytecodesPerThread) {
 157     st->print_cr("; executed " JLONG_FORMAT " bytecodes", ClassLoader::class_init_bytecodes_count());
 158   }
 159   st->print_cr("  resolve...");
 160   st->print_cr("    invokedynamic:   " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) / " JLONG_FORMAT_W(5) " events",
 161                _perf_resolve_indy_time->elapsed_counter_value_us(),
 162                _perf_resolve_indy_time->thread_counter_value_us(),
 163                _perf_resolve_indy_count->get_value());
 164   st->print_cr("    invokehandle:    " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) / " JLONG_FORMAT_W(5) " events",
 165                _perf_resolve_invokehandle_time->elapsed_counter_value_us(),
 166                _perf_resolve_invokehandle_time->thread_counter_value_us(),
 167                _perf_resolve_invokehandle_count->get_value());
 168   st->print_cr("    CP_MethodHandle: " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) / " JLONG_FORMAT_W(5) " events",
 169                _perf_resolve_mh_time->elapsed_counter_value_us(),
 170                _perf_resolve_mh_time->thread_counter_value_us(),
 171                _perf_resolve_mh_count->get_value());
 172   st->print_cr("    CP_MethodType:   " JLONG_FORMAT_W(6) "us (elapsed) " JLONG_FORMAT_W(6) "us (thread) / " JLONG_FORMAT_W(5) " events",
 173                _perf_resolve_mt_time->elapsed_counter_value_us(),
 174                _perf_resolve_mt_time->thread_counter_value_us(),
 175                _perf_resolve_mt_count->get_value());
 176 }
 177 
 178 GrowableArray<ModuleClassPathList*>* ClassLoader::_patch_mod_entries = nullptr;
 179 GrowableArray<ModuleClassPathList*>* ClassLoader::_exploded_entries = nullptr;
 180 ClassPathEntry* ClassLoader::_jrt_entry = nullptr;
 181 
 182 ClassPathEntry* volatile ClassLoader::_first_append_entry_list = nullptr;
 183 ClassPathEntry* volatile ClassLoader::_last_append_entry  = nullptr;
 184 
 185 // helper routines
 186 #if INCLUDE_CDS
 187 static bool string_starts_with(const char* str, const char* str_to_find) {
 188   size_t str_len = strlen(str);
 189   size_t str_to_find_len = strlen(str_to_find);
 190   if (str_to_find_len > str_len) {
 191     return false;
 192   }
 193   return (strncmp(str, str_to_find, str_to_find_len) == 0);
 194 }
 195 #endif

 349   jint name_len;
 350   jzentry* entry = ZipLibrary::find_entry(_zip, name, filesize, &name_len);
 351   if (entry == nullptr) return nullptr;
 352   u1* buffer;
 353   char name_buf[128];
 354   char* filename;
 355   if (name_len < 128) {
 356     filename = name_buf;
 357   } else {
 358     filename = NEW_RESOURCE_ARRAY(char, name_len + 1);
 359   }
 360 
 361   // read contents into resource array
 362   size_t size = (uint32_t)(*filesize);
 363   if (nul_terminate) {
 364     if (sizeof(size) == sizeof(uint32_t) && size == UINT_MAX) {
 365       return nullptr; // 32-bit integer overflow will occur.
 366     }
 367     size++;
 368   }
 369 
 370   // ZIP_ReadEntry also frees zentry
 371   buffer = NEW_RESOURCE_ARRAY(u1, size);
 372   if (!ZipLibrary::read_entry(_zip, entry, buffer, filename)) {
 373     return nullptr;
 374   }
 375 
 376   // return result
 377   if (nul_terminate) {
 378     buffer[size - 1] = 0;
 379   }
 380   return buffer;
 381 }
 382 
 383 ClassFileStream* ClassPathZipEntry::open_stream(JavaThread* current, const char* name) {
 384   jint filesize;
 385   u1* buffer = open_entry(current, name, &filesize, false);
 386   if (buffer == nullptr) {
 387     return nullptr;
 388   }
 389   if (UsePerfData) {
 390     ClassLoader::perf_sys_classfile_bytes_read()->inc(filesize);

1355 #endif // INCLUDE_CDS
1356 
1357 // Initialize the class loader's access to methods in libzip.  Parse and
1358 // process the boot classpath into a list ClassPathEntry objects.  Once
1359 // this list has been created, it must not change order (see class PackageInfo)
1360 // it can be appended to and is by jvmti.
1361 
1362 void ClassLoader::initialize(TRAPS) {
1363   if (UsePerfData) {
1364     // jvmstat performance counters
1365     NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
1366     NEWPERFTICKCOUNTER(_perf_class_init_time, SUN_CLS, "classInitTime");
1367     NEWPERFTICKCOUNTER(_perf_class_init_selftime, SUN_CLS, "classInitTime.self");
1368     NEWPERFTICKCOUNTER(_perf_class_verify_time, SUN_CLS, "classVerifyTime");
1369     NEWPERFTICKCOUNTER(_perf_class_verify_selftime, SUN_CLS, "classVerifyTime.self");
1370     NEWPERFTICKCOUNTER(_perf_class_link_time, SUN_CLS, "classLinkedTime");
1371     NEWPERFTICKCOUNTER(_perf_class_link_selftime, SUN_CLS, "classLinkedTime.self");
1372     NEWPERFEVENTCOUNTER(_perf_classes_inited, SUN_CLS, "initializedClasses");
1373     NEWPERFEVENTCOUNTER(_perf_classes_linked, SUN_CLS, "linkedClasses");
1374     NEWPERFEVENTCOUNTER(_perf_classes_verified, SUN_CLS, "verifiedClasses");
1375     NEWPERFEVENTCOUNTER(_perf_class_init_bytecodes_count, SUN_CLS, "clinitBytecodesCount");
1376 
1377     NEWPERFTICKCOUNTER(_perf_shared_classload_time, SUN_CLS, "sharedClassLoadTime");
1378     NEWPERFTICKCOUNTER(_perf_sys_classload_time, SUN_CLS, "sysClassLoadTime");
1379     NEWPERFTICKCOUNTER(_perf_app_classload_time, SUN_CLS, "appClassLoadTime");
1380     NEWPERFTICKCOUNTER(_perf_app_classload_selftime, SUN_CLS, "appClassLoadTime.self");
1381     NEWPERFEVENTCOUNTER(_perf_app_classload_count, SUN_CLS, "appClassLoadCount");
1382     NEWPERFTICKCOUNTER(_perf_define_appclasses, SUN_CLS, "defineAppClasses");
1383     NEWPERFTICKCOUNTER(_perf_define_appclass_time, SUN_CLS, "defineAppClassTime");
1384     NEWPERFTICKCOUNTER(_perf_define_appclass_selftime, SUN_CLS, "defineAppClassTime.self");
1385     NEWPERFBYTECOUNTER(_perf_app_classfile_bytes_read, SUN_CLS, "appClassBytes");
1386     NEWPERFBYTECOUNTER(_perf_sys_classfile_bytes_read, SUN_CLS, "sysClassBytes");
1387     NEWPERFEVENTCOUNTER(_unsafe_defineClassCallCounter, SUN_CLS, "unsafeDefineClassCalls");
1388     NEWPERFTICKCOUNTER(_perf_secondary_hash_time, SUN_CLS, "secondarySuperHashTime");
1389 
1390     if (log_is_enabled(Info, perf, class, link) || log_is_enabled(Info, init)) {
1391       NEWPERFTICKCOUNTER(_perf_preload_total_time, SUN_CLS, "preloadTotalTime");
1392       NEWPERFTICKCOUNTER(_perf_preload_time, SUN_CLS, "preloadTime");
1393       NEWPERFTICKCOUNTER(_perf_prelink_time, SUN_CLS, "prelinkTime");
1394       NEWPERFTICKCOUNTER(_perf_preinit_time, SUN_CLS, "preinitTime");
1395       NEWPERFTICKCOUNTER(_perf_preresolve_time, SUN_CLS, "preresolveTime");
1396 
1397       NEWPERFTICKCOUNTER(_perf_ik_link_methods_time, SUN_CLS, "linkMethodsTime");
1398       NEWPERFTICKCOUNTER(_perf_method_adapters_time, SUN_CLS, "makeAdaptersTime");
1399       NEWPERFEVENTCOUNTER(_perf_ik_link_methods_count, SUN_CLS, "linkMethodsCount");
1400       NEWPERFEVENTCOUNTER(_perf_method_adapters_count, SUN_CLS, "makeAdaptersCount");
1401 
1402       NEWPERFTICKCOUNTERS(_perf_resolve_indy_time, SUN_CLS, "resolve_invokedynamic_time");
1403       NEWPERFTICKCOUNTERS(_perf_resolve_invokehandle_time, SUN_CLS, "resolve_invokehandle_time");
1404       NEWPERFTICKCOUNTERS(_perf_resolve_mh_time, SUN_CLS, "resolve_MethodHandle_time");
1405       NEWPERFTICKCOUNTERS(_perf_resolve_mt_time, SUN_CLS, "resolve_MethodType_time");
1406 
1407       NEWPERFEVENTCOUNTER(_perf_resolve_indy_count, SUN_CLS, "resolve_invokedynamic_count");
1408       NEWPERFEVENTCOUNTER(_perf_resolve_invokehandle_count, SUN_CLS, "resolve_invokehandle_count");
1409       NEWPERFEVENTCOUNTER(_perf_resolve_mh_count, SUN_CLS, "resolve_MethodHandle_count");
1410       NEWPERFEVENTCOUNTER(_perf_resolve_mt_count, SUN_CLS, "resolve_MethodType_count");
1411     }
1412   }
1413 
1414   // lookup java library entry points
1415   load_java_library();
1416   // jimage library entry points are loaded below, in lookup_vm_options
1417   setup_bootstrap_search_path(THREAD);
1418 }
1419 
1420 static char* lookup_vm_resource(JImageFile *jimage, const char *jimage_version, const char *path) {
1421   jlong size;
1422   JImageLocationRef location = (*JImageFindResource)(jimage, "java.base", jimage_version, path, &size);
1423   if (location == 0)
1424     return nullptr;
1425   char *val = NEW_C_HEAP_ARRAY(char, size+1, mtClass);

1450 
1451 bool ClassLoader::is_module_observable(const char* module_name) {
1452   assert(JImageOpen != nullptr, "jimage library should have been opened");
1453   if (JImage_file == nullptr) {
1454     struct stat st;
1455     const char *path = get_exploded_module_path(module_name, true);
1456     bool res = os::stat(path, &st) == 0;
1457     FREE_C_HEAP_ARRAY(char, path);
1458     return res;
1459   }
1460   jlong size;
1461   const char *jimage_version = get_jimage_version_string();
1462   return (*JImageFindResource)(JImage_file, module_name, jimage_version, "module-info.class", &size) != 0;
1463 }
1464 
1465 jlong ClassLoader::classloader_time_ms() {
1466   return UsePerfData ?
1467     Management::ticks_to_ms(_perf_accumulated_time->get_value()) : -1;
1468 }
1469 
1470 jlong ClassLoader::class_init_bytecodes_count() {
1471   return UsePerfData ? _perf_class_init_bytecodes_count->get_value() : -1;
1472 }
1473 
1474 jlong ClassLoader::class_init_count() {
1475   return UsePerfData ? _perf_classes_inited->get_value() : -1;
1476 }
1477 
1478 jlong ClassLoader::class_init_time_ms() {
1479   return UsePerfData ?
1480     Management::ticks_to_ms(_perf_class_init_time->get_value()) : -1;
1481 }
1482 
1483 jlong ClassLoader::class_verify_time_ms() {
1484   return UsePerfData ?
1485     Management::ticks_to_ms(_perf_class_verify_time->get_value()) : -1;
1486 }
1487 
1488 jlong ClassLoader::class_link_count() {
1489   return UsePerfData ? _perf_classes_linked->get_value() : -1;
1490 }
1491 
1492 jlong ClassLoader::class_link_time_ms() {
1493   return UsePerfData ?
< prev index next >