78 private:
79 const char* _dir; // Name of directory
80 public:
81 const char* name() const { return _dir; }
82 ClassPathDirEntry(const char* dir) {
83 _dir = copy_path(dir);
84 }
85 virtual ~ClassPathDirEntry();
86 ClassFileStream* open_stream(JavaThread* current, const char* name);
87 };
88
89 class ClassPathZipEntry: public ClassPathEntry {
90 private:
91 jzfile* _zip; // The zip archive
92 const char* _zip_name; // Name of zip archive
93 bool _from_class_path_attr; // From the "Class-path" attribute of a jar file
94 public:
95 bool is_jar_file() const { return true; }
96 bool from_class_path_attr() const { return _from_class_path_attr; }
97 const char* name() const { return _zip_name; }
98 ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append, bool from_class_path_attr);
99 virtual ~ClassPathZipEntry();
100 u1* open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate);
101 ClassFileStream* open_stream(JavaThread* current, const char* name);
102 };
103
104
105 // For java image files
106 class ClassPathImageEntry: public ClassPathEntry {
107 private:
108 const char* _name;
109 DEBUG_ONLY(static ClassPathImageEntry* _singleton;)
110 public:
111 bool is_modules_image() const;
112 const char* name() const { return _name == nullptr ? "" : _name; }
113 JImageFile* jimage() const;
114 JImageFile* jimage_non_null() const;
115 void close_jimage();
116 ClassPathImageEntry(JImageFile* jimage, const char* name);
117 virtual ~ClassPathImageEntry() { ShouldNotReachHere(); }
118 ClassFileStream* open_stream(JavaThread* current, const char* name);
119 ClassFileStream* open_stream_for_loader(JavaThread* current, const char* name, ClassLoaderData* loader_data);
135 ModuleClassPathList(Symbol* module_name);
136 ~ModuleClassPathList();
137 void add_to_list(ClassPathEntry* new_entry);
138 };
139
140 class ClassLoader: AllStatic {
141 public:
142 enum ClassLoaderType {
143 OTHER = 0,
144 BOOT_LOADER = 1, /* boot loader */
145 PLATFORM_LOADER = 2, /* PlatformClassLoader */
146 APP_LOADER = 3 /* AppClassLoader */
147 };
148 protected:
149
150 // Performance counters
151 static PerfCounter* _perf_accumulated_time;
152 static PerfCounter* _perf_classes_inited;
153 static PerfCounter* _perf_class_init_time;
154 static PerfCounter* _perf_class_init_selftime;
155 static PerfCounter* _perf_classes_verified;
156 static PerfCounter* _perf_class_verify_time;
157 static PerfCounter* _perf_class_verify_selftime;
158 static PerfCounter* _perf_classes_linked;
159 static PerfCounter* _perf_class_link_time;
160 static PerfCounter* _perf_class_link_selftime;
161 static PerfCounter* _perf_shared_classload_time;
162 static PerfCounter* _perf_sys_classload_time;
163 static PerfCounter* _perf_app_classload_time;
164 static PerfCounter* _perf_app_classload_selftime;
165 static PerfCounter* _perf_app_classload_count;
166 static PerfCounter* _perf_define_appclasses;
167 static PerfCounter* _perf_define_appclass_time;
168 static PerfCounter* _perf_define_appclass_selftime;
169 static PerfCounter* _perf_app_classfile_bytes_read;
170 static PerfCounter* _perf_sys_classfile_bytes_read;
171 static PerfCounter* _perf_ik_link_methods_time;
172 static PerfCounter* _perf_method_adapters_time;
173 static PerfCounter* _perf_ik_link_methods_count;
174 static PerfCounter* _perf_method_adapters_count;
175
176 static PerfCounter* _perf_resolve_indy_time;
177 static PerfCounter* _perf_resolve_invokehandle_time;
178 static PerfCounter* _perf_resolve_mh_time;
179 static PerfCounter* _perf_resolve_mt_time;
180
181 static PerfCounter* _perf_resolve_indy_count;
182 static PerfCounter* _perf_resolve_invokehandle_count;
183 static PerfCounter* _perf_resolve_mh_count;
184 static PerfCounter* _perf_resolve_mt_count;
185
186 static PerfCounter* _unsafe_defineClassCallCounter;
187
188 // Count the time taken to hash the scondary superclass arrays.
189 static PerfCounter* _perf_secondary_hash_time;
190
191 // The boot class path consists of 3 ordered pieces:
192 // 1. the module/path pairs specified to --patch-module
193 // --patch-module=<module>=<file>(<pathsep><file>)*
194 // 2. the base piece
195 // [jimage | build with exploded modules]
196 // 3. boot loader append path
197 // [-Xbootclasspath/a]; [jvmti appended entries]
198 //
199 // The boot loader must obey this order when attempting
284 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
285 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
286 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
287 static PerfCounter* perf_classes_linked() { return _perf_classes_linked; }
288 static PerfCounter* perf_class_link_time() { return _perf_class_link_time; }
289 static PerfCounter* perf_class_link_selftime() { return _perf_class_link_selftime; }
290 static PerfCounter* perf_shared_classload_time() { return _perf_shared_classload_time; }
291 static PerfCounter* perf_secondary_hash_time() {
292 return _perf_secondary_hash_time;
293 }
294 static PerfCounter* perf_sys_classload_time() { return _perf_sys_classload_time; }
295 static PerfCounter* perf_app_classload_time() { return _perf_app_classload_time; }
296 static PerfCounter* perf_app_classload_selftime() { return _perf_app_classload_selftime; }
297 static PerfCounter* perf_app_classload_count() { return _perf_app_classload_count; }
298 static PerfCounter* perf_define_appclasses() { return _perf_define_appclasses; }
299 static PerfCounter* perf_define_appclass_time() { return _perf_define_appclass_time; }
300 static PerfCounter* perf_define_appclass_selftime() { return _perf_define_appclass_selftime; }
301 static PerfCounter* perf_app_classfile_bytes_read() { return _perf_app_classfile_bytes_read; }
302 static PerfCounter* perf_sys_classfile_bytes_read() { return _perf_sys_classfile_bytes_read; }
303
304 static PerfCounter* perf_ik_link_methods_time() { return _perf_ik_link_methods_time; }
305 static PerfCounter* perf_method_adapters_time() { return _perf_method_adapters_time; }
306 static PerfCounter* perf_ik_link_methods_count() { return _perf_ik_link_methods_count; }
307 static PerfCounter* perf_method_adapters_count() { return _perf_method_adapters_count; }
308
309 static PerfCounter* perf_resolve_invokedynamic_time() { return _perf_resolve_indy_time; }
310 static PerfCounter* perf_resolve_invokehandle_time() { return _perf_resolve_invokehandle_time; }
311 static PerfCounter* perf_resolve_method_handle_time() { return _perf_resolve_mh_time; }
312 static PerfCounter* perf_resolve_method_type_time() { return _perf_resolve_mt_time; }
313
314 static PerfCounter* perf_resolve_invokedynamic_count() { return _perf_resolve_indy_count; }
315 static PerfCounter* perf_resolve_invokehandle_count() { return _perf_resolve_invokehandle_count; }
316 static PerfCounter* perf_resolve_method_handle_count() { return _perf_resolve_mh_count; }
317 static PerfCounter* perf_resolve_method_type_count() { return _perf_resolve_mt_count; }
318
319 static void print_counters(outputStream *st);
320
321 // Record how many calls to Unsafe_DefineClass
322 static PerfCounter* unsafe_defineClassCallCounter() {
323 return _unsafe_defineClassCallCounter;
324 }
325
326 // Modular java runtime image is present vs. a build with exploded modules
327 static bool has_jrt_entry() { return (_jrt_entry != nullptr); }
328 static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
329 static void close_jrt_image();
330
331 // Add a module's exploded directory to the boot loader's exploded module build list
332 static void add_to_exploded_build_list(JavaThread* current, Symbol* module_name);
333
334 // Search the module list for the class file stream based on the file name and java package
335 static ClassFileStream* search_module_entries(JavaThread* current,
336 const GrowableArray<ModuleClassPathList*>* const module_list,
337 PackageEntry* pkg_entry, // Java package entry derived from the class name
338 const char* const file_name);
391
392 static char* lookup_vm_options();
393
394 // Determines if the named module is present in the
395 // modules jimage file or in the exploded modules directory.
396 static bool is_module_observable(const char* module_name);
397
398 static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
399 const char* file_name, jlong &size);
400
401 static void trace_class_path(const char* msg, const char* name = nullptr);
402
403 // VM monitoring and management support
404 static jlong classloader_time_ms();
405 static jlong class_method_total_size();
406 static jlong class_init_count();
407 static jlong class_init_time_ms();
408 static jlong class_verify_time_ms();
409 static jlong class_link_count();
410 static jlong class_link_time_ms();
411
412 // adds a class path to the boot append entries
413 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
414
415 // creates a class path zip entry (returns null if JAR file cannot be opened)
416 static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
417
418 static bool string_ends_with(const char* str, const char* str_to_find);
419
420 // Extract package name from a fully qualified class name
421 // *bad_class_name is set to true if there's a problem with parsing class_name, to
422 // distinguish from a class_name with no package name, as both cases have a null return value
423 static Symbol* package_from_class_name(const Symbol* class_name, bool* bad_class_name = nullptr);
424
425 // Debugging
426 static void verify() PRODUCT_RETURN;
427 };
428
429 // PerfClassTraceTime is used to measure time for class loading related events.
430 // This class tracks cumulative time and exclusive time for specific event types.
431 // During the execution of one event, other event types (e.g. class loading and
432 // resolution) as well as recursive calls of the same event type could happen.
433 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
434 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
435 // instances have been created as multiple events are happening.
436 class PerfClassTraceTime {
|
78 private:
79 const char* _dir; // Name of directory
80 public:
81 const char* name() const { return _dir; }
82 ClassPathDirEntry(const char* dir) {
83 _dir = copy_path(dir);
84 }
85 virtual ~ClassPathDirEntry();
86 ClassFileStream* open_stream(JavaThread* current, const char* name);
87 };
88
89 class ClassPathZipEntry: public ClassPathEntry {
90 private:
91 jzfile* _zip; // The zip archive
92 const char* _zip_name; // Name of zip archive
93 bool _from_class_path_attr; // From the "Class-path" attribute of a jar file
94 public:
95 bool is_jar_file() const { return true; }
96 bool from_class_path_attr() const { return _from_class_path_attr; }
97 const char* name() const { return _zip_name; }
98 ClassPathZipEntry(jzfile* zip, const char* zip_name, bool from_class_path_attr);
99 virtual ~ClassPathZipEntry();
100 bool has_entry(JavaThread* current, const char* name);
101 u1* open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate);
102 ClassFileStream* open_stream(JavaThread* current, const char* name);
103 };
104
105
106 // For java image files
107 class ClassPathImageEntry: public ClassPathEntry {
108 private:
109 const char* _name;
110 DEBUG_ONLY(static ClassPathImageEntry* _singleton;)
111 public:
112 bool is_modules_image() const;
113 const char* name() const { return _name == nullptr ? "" : _name; }
114 JImageFile* jimage() const;
115 JImageFile* jimage_non_null() const;
116 void close_jimage();
117 ClassPathImageEntry(JImageFile* jimage, const char* name);
118 virtual ~ClassPathImageEntry() { ShouldNotReachHere(); }
119 ClassFileStream* open_stream(JavaThread* current, const char* name);
120 ClassFileStream* open_stream_for_loader(JavaThread* current, const char* name, ClassLoaderData* loader_data);
136 ModuleClassPathList(Symbol* module_name);
137 ~ModuleClassPathList();
138 void add_to_list(ClassPathEntry* new_entry);
139 };
140
141 class ClassLoader: AllStatic {
142 public:
143 enum ClassLoaderType {
144 OTHER = 0,
145 BOOT_LOADER = 1, /* boot loader */
146 PLATFORM_LOADER = 2, /* PlatformClassLoader */
147 APP_LOADER = 3 /* AppClassLoader */
148 };
149 protected:
150
151 // Performance counters
152 static PerfCounter* _perf_accumulated_time;
153 static PerfCounter* _perf_classes_inited;
154 static PerfCounter* _perf_class_init_time;
155 static PerfCounter* _perf_class_init_selftime;
156 static PerfCounter* _perf_class_init_bytecodes_count;
157 static PerfCounter* _perf_classes_verified;
158 static PerfCounter* _perf_class_verify_time;
159 static PerfCounter* _perf_class_verify_selftime;
160 static PerfCounter* _perf_classes_linked;
161 static PerfCounter* _perf_class_link_time;
162 static PerfCounter* _perf_class_link_selftime;
163 static PerfCounter* _perf_shared_classload_time;
164 static PerfCounter* _perf_sys_classload_time;
165 static PerfCounter* _perf_app_classload_time;
166 static PerfCounter* _perf_app_classload_selftime;
167 static PerfCounter* _perf_app_classload_count;
168 static PerfCounter* _perf_define_appclasses;
169 static PerfCounter* _perf_define_appclass_time;
170 static PerfCounter* _perf_define_appclass_selftime;
171 static PerfCounter* _perf_app_classfile_bytes_read;
172 static PerfCounter* _perf_sys_classfile_bytes_read;
173 static PerfCounter* _perf_preload_total_time;
174 static PerfCounter* _perf_preload_time;
175 static PerfCounter* _perf_prelink_time;
176 static PerfCounter* _perf_preinit_time;
177 static PerfCounter* _perf_preresolve_time;
178 static PerfCounter* _perf_ik_link_methods_time;
179 static PerfCounter* _perf_method_adapters_time;
180 static PerfCounter* _perf_ik_link_methods_count;
181 static PerfCounter* _perf_method_adapters_count;
182
183 static PerfTickCounters* _perf_resolve_indy_time;
184 static PerfTickCounters* _perf_resolve_invokehandle_time;
185 static PerfTickCounters* _perf_resolve_mh_time;
186 static PerfTickCounters* _perf_resolve_mt_time;
187
188 static PerfCounter* _perf_resolve_indy_count;
189 static PerfCounter* _perf_resolve_invokehandle_count;
190 static PerfCounter* _perf_resolve_mh_count;
191 static PerfCounter* _perf_resolve_mt_count;
192
193 static PerfCounter* _unsafe_defineClassCallCounter;
194
195 // Count the time taken to hash the scondary superclass arrays.
196 static PerfCounter* _perf_secondary_hash_time;
197
198 // The boot class path consists of 3 ordered pieces:
199 // 1. the module/path pairs specified to --patch-module
200 // --patch-module=<module>=<file>(<pathsep><file>)*
201 // 2. the base piece
202 // [jimage | build with exploded modules]
203 // 3. boot loader append path
204 // [-Xbootclasspath/a]; [jvmti appended entries]
205 //
206 // The boot loader must obey this order when attempting
291 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
292 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
293 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
294 static PerfCounter* perf_classes_linked() { return _perf_classes_linked; }
295 static PerfCounter* perf_class_link_time() { return _perf_class_link_time; }
296 static PerfCounter* perf_class_link_selftime() { return _perf_class_link_selftime; }
297 static PerfCounter* perf_shared_classload_time() { return _perf_shared_classload_time; }
298 static PerfCounter* perf_secondary_hash_time() {
299 return _perf_secondary_hash_time;
300 }
301 static PerfCounter* perf_sys_classload_time() { return _perf_sys_classload_time; }
302 static PerfCounter* perf_app_classload_time() { return _perf_app_classload_time; }
303 static PerfCounter* perf_app_classload_selftime() { return _perf_app_classload_selftime; }
304 static PerfCounter* perf_app_classload_count() { return _perf_app_classload_count; }
305 static PerfCounter* perf_define_appclasses() { return _perf_define_appclasses; }
306 static PerfCounter* perf_define_appclass_time() { return _perf_define_appclass_time; }
307 static PerfCounter* perf_define_appclass_selftime() { return _perf_define_appclass_selftime; }
308 static PerfCounter* perf_app_classfile_bytes_read() { return _perf_app_classfile_bytes_read; }
309 static PerfCounter* perf_sys_classfile_bytes_read() { return _perf_sys_classfile_bytes_read; }
310
311 static PerfCounter* perf_preload_total_time() { return _perf_preload_total_time; }
312 static PerfCounter* perf_preload_time() { return _perf_preload_time; }
313 static PerfCounter* perf_prelink_time() { return _perf_prelink_time; }
314 static PerfCounter* perf_preinit_time() { return _perf_preinit_time; }
315 static PerfCounter* perf_preresolve_time() { return _perf_preresolve_time; }
316 static PerfCounter* perf_ik_link_methods_time() { return _perf_ik_link_methods_time; }
317 static PerfCounter* perf_method_adapters_time() { return _perf_method_adapters_time; }
318 static PerfCounter* perf_ik_link_methods_count() { return _perf_ik_link_methods_count; }
319 static PerfCounter* perf_method_adapters_count() { return _perf_method_adapters_count; }
320
321 static PerfTickCounters* perf_resolve_invokedynamic_time() { return _perf_resolve_indy_time; }
322 static PerfTickCounters* perf_resolve_invokehandle_time() { return _perf_resolve_invokehandle_time; }
323 static PerfTickCounters* perf_resolve_method_handle_time() { return _perf_resolve_mh_time; }
324 static PerfTickCounters* perf_resolve_method_type_time() { return _perf_resolve_mt_time; }
325
326 static PerfCounter* perf_resolve_invokedynamic_count() { return _perf_resolve_indy_count; }
327 static PerfCounter* perf_resolve_invokehandle_count() { return _perf_resolve_invokehandle_count; }
328 static PerfCounter* perf_resolve_method_handle_count() { return _perf_resolve_mh_count; }
329 static PerfCounter* perf_resolve_method_type_count() { return _perf_resolve_mt_count; }
330
331 static PerfCounter* perf_class_init_bytecodes_count() { return _perf_class_init_bytecodes_count; }
332
333 static void print_counters(outputStream *st);
334
335 // Record how many calls to Unsafe_DefineClass
336 static PerfCounter* unsafe_defineClassCallCounter() {
337 return _unsafe_defineClassCallCounter;
338 }
339
340 // Modular java runtime image is present vs. a build with exploded modules
341 static bool has_jrt_entry() { return (_jrt_entry != nullptr); }
342 static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
343 static void close_jrt_image();
344
345 // Add a module's exploded directory to the boot loader's exploded module build list
346 static void add_to_exploded_build_list(JavaThread* current, Symbol* module_name);
347
348 // Search the module list for the class file stream based on the file name and java package
349 static ClassFileStream* search_module_entries(JavaThread* current,
350 const GrowableArray<ModuleClassPathList*>* const module_list,
351 PackageEntry* pkg_entry, // Java package entry derived from the class name
352 const char* const file_name);
405
406 static char* lookup_vm_options();
407
408 // Determines if the named module is present in the
409 // modules jimage file or in the exploded modules directory.
410 static bool is_module_observable(const char* module_name);
411
412 static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
413 const char* file_name, jlong &size);
414
415 static void trace_class_path(const char* msg, const char* name = nullptr);
416
417 // VM monitoring and management support
418 static jlong classloader_time_ms();
419 static jlong class_method_total_size();
420 static jlong class_init_count();
421 static jlong class_init_time_ms();
422 static jlong class_verify_time_ms();
423 static jlong class_link_count();
424 static jlong class_link_time_ms();
425 static jlong class_init_bytecodes_count();
426
427 // adds a class path to the boot append entries
428 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
429
430 // creates a class path zip entry (returns null if JAR file cannot be opened)
431 static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
432
433 static bool string_ends_with(const char* str, const char* str_to_find);
434
435 // Extract package name from a fully qualified class name
436 // *bad_class_name is set to true if there's a problem with parsing class_name, to
437 // distinguish from a class_name with no package name, as both cases have a null return value
438 static Symbol* package_from_class_name(const Symbol* class_name, bool* bad_class_name = nullptr);
439
440 // Debugging
441 static void verify() PRODUCT_RETURN;
442 };
443
444 // PerfClassTraceTime is used to measure time for class loading related events.
445 // This class tracks cumulative time and exclusive time for specific event types.
446 // During the execution of one event, other event types (e.g. class loading and
447 // resolution) as well as recursive calls of the same event type could happen.
448 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
449 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
450 // instances have been created as multiple events are happening.
451 class PerfClassTraceTime {
|