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