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);
123 // that have been specified for a specific module. Currently,
124 // the only way to specify a module/path pair is via the --patch-module
125 // command line option.
126 class ModuleClassPathList : public CHeapObj<mtClass> {
127 private:
128 Symbol* _module_name;
129 // First and last entries of class path entries for a specific module
130 ClassPathEntry* _module_first_entry;
131 ClassPathEntry* _module_last_entry;
132 public:
133 Symbol* module_name() const { return _module_name; }
134 ClassPathEntry* module_first_entry() const { return _module_first_entry; }
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 BOOT_LOADER = 1, /* boot loader */
144 PLATFORM_LOADER = 2, /* PlatformClassLoader */
145 APP_LOADER = 3 /* AppClassLoader */
146 };
147 protected:
148
149 // Performance counters
150 static PerfCounter* _perf_accumulated_time;
151 static PerfCounter* _perf_classes_inited;
152 static PerfCounter* _perf_class_init_time;
153 static PerfCounter* _perf_class_init_selftime;
154 static PerfCounter* _perf_classes_verified;
155 static PerfCounter* _perf_class_verify_time;
156 static PerfCounter* _perf_class_verify_selftime;
157 static PerfCounter* _perf_classes_linked;
158 static PerfCounter* _perf_class_link_time;
159 static PerfCounter* _perf_class_link_selftime;
160 static PerfCounter* _perf_shared_classload_time;
161 static PerfCounter* _perf_sys_classload_time;
162 static PerfCounter* _perf_app_classload_time;
163 static PerfCounter* _perf_app_classload_selftime;
164 static PerfCounter* _perf_app_classload_count;
165 static PerfCounter* _perf_define_appclasses;
166 static PerfCounter* _perf_define_appclass_time;
167 static PerfCounter* _perf_define_appclass_selftime;
168 static PerfCounter* _perf_app_classfile_bytes_read;
169 static PerfCounter* _perf_sys_classfile_bytes_read;
170 static PerfCounter* _perf_ik_link_methods_time;
171 static PerfCounter* _perf_method_adapters_time;
172 static PerfCounter* _perf_ik_link_methods_count;
173 static PerfCounter* _perf_method_adapters_count;
174
175 static PerfCounter* _perf_resolve_indy_time;
176 static PerfCounter* _perf_resolve_invokehandle_time;
177 static PerfCounter* _perf_resolve_mh_time;
178 static PerfCounter* _perf_resolve_mt_time;
179
180 static PerfCounter* _perf_resolve_indy_count;
181 static PerfCounter* _perf_resolve_invokehandle_count;
182 static PerfCounter* _perf_resolve_mh_count;
183 static PerfCounter* _perf_resolve_mt_count;
184
185 static PerfCounter* _unsafe_defineClassCallCounter;
186
187 // Count the time taken to hash the scondary superclass arrays.
188 static PerfCounter* _perf_secondary_hash_time;
189
190 // The boot class path consists of 3 ordered pieces:
191 // 1. the module/path pairs specified to --patch-module
192 // --patch-module=<module>=<file>(<pathsep><file>)*
193 // 2. the base piece
194 // [jimage | build with exploded modules]
195 // 3. boot loader append path
196 // [-Xbootclasspath/a]; [jvmti appended entries]
197 //
198 // The boot loader must obey this order when attempting
283 static PerfCounter* perf_classes_verified() { return _perf_classes_verified; }
284 static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; }
285 static PerfCounter* perf_class_verify_selftime() { return _perf_class_verify_selftime; }
286 static PerfCounter* perf_classes_linked() { return _perf_classes_linked; }
287 static PerfCounter* perf_class_link_time() { return _perf_class_link_time; }
288 static PerfCounter* perf_class_link_selftime() { return _perf_class_link_selftime; }
289 static PerfCounter* perf_shared_classload_time() { return _perf_shared_classload_time; }
290 static PerfCounter* perf_secondary_hash_time() {
291 return _perf_secondary_hash_time;
292 }
293 static PerfCounter* perf_sys_classload_time() { return _perf_sys_classload_time; }
294 static PerfCounter* perf_app_classload_time() { return _perf_app_classload_time; }
295 static PerfCounter* perf_app_classload_selftime() { return _perf_app_classload_selftime; }
296 static PerfCounter* perf_app_classload_count() { return _perf_app_classload_count; }
297 static PerfCounter* perf_define_appclasses() { return _perf_define_appclasses; }
298 static PerfCounter* perf_define_appclass_time() { return _perf_define_appclass_time; }
299 static PerfCounter* perf_define_appclass_selftime() { return _perf_define_appclass_selftime; }
300 static PerfCounter* perf_app_classfile_bytes_read() { return _perf_app_classfile_bytes_read; }
301 static PerfCounter* perf_sys_classfile_bytes_read() { return _perf_sys_classfile_bytes_read; }
302
303 static PerfCounter* perf_ik_link_methods_time() { return _perf_ik_link_methods_time; }
304 static PerfCounter* perf_method_adapters_time() { return _perf_method_adapters_time; }
305 static PerfCounter* perf_ik_link_methods_count() { return _perf_ik_link_methods_count; }
306 static PerfCounter* perf_method_adapters_count() { return _perf_method_adapters_count; }
307
308 static PerfCounter* perf_resolve_invokedynamic_time() { return _perf_resolve_indy_time; }
309 static PerfCounter* perf_resolve_invokehandle_time() { return _perf_resolve_invokehandle_time; }
310 static PerfCounter* perf_resolve_method_handle_time() { return _perf_resolve_mh_time; }
311 static PerfCounter* perf_resolve_method_type_time() { return _perf_resolve_mt_time; }
312
313 static PerfCounter* perf_resolve_invokedynamic_count() { return _perf_resolve_indy_count; }
314 static PerfCounter* perf_resolve_invokehandle_count() { return _perf_resolve_invokehandle_count; }
315 static PerfCounter* perf_resolve_method_handle_count() { return _perf_resolve_mh_count; }
316 static PerfCounter* perf_resolve_method_type_count() { return _perf_resolve_mt_count; }
317
318 static void print_counters(outputStream *st);
319
320 // Record how many calls to Unsafe_DefineClass
321 static PerfCounter* unsafe_defineClassCallCounter() {
322 return _unsafe_defineClassCallCounter;
323 }
324
325 // Modular java runtime image is present vs. a build with exploded modules
326 static bool has_jrt_entry() { return (_jrt_entry != nullptr); }
327 static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
328 static void close_jrt_image();
329
330 // Add a module's exploded directory to the boot loader's exploded module build list
331 static void add_to_exploded_build_list(JavaThread* current, Symbol* module_name);
332
333 // Search the module list for the class file stream based on the file name and java package
334 static ClassFileStream* search_module_entries(JavaThread* current,
335 const GrowableArray<ModuleClassPathList*>* const module_list,
336 PackageEntry* pkg_entry, // Java package entry derived from the class name
337 const char* const file_name);
389
390 static char* lookup_vm_options();
391
392 // Determines if the named module is present in the
393 // modules jimage file or in the exploded modules directory.
394 static bool is_module_observable(const char* module_name);
395
396 static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
397 const char* file_name, jlong &size);
398
399 static void trace_class_path(const char* msg, const char* name = nullptr);
400
401 // VM monitoring and management support
402 static jlong classloader_time_ms();
403 static jlong class_method_total_size();
404 static jlong class_init_count();
405 static jlong class_init_time_ms();
406 static jlong class_verify_time_ms();
407 static jlong class_link_count();
408 static jlong class_link_time_ms();
409
410 // adds a class path to the boot append entries
411 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
412
413 // creates a class path zip entry (returns null if JAR file cannot be opened)
414 static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
415
416 static bool string_ends_with(const char* str, const char* str_to_find);
417
418 // Extract package name from a fully qualified class name
419 // *bad_class_name is set to true if there's a problem with parsing class_name, to
420 // distinguish from a class_name with no package name, as both cases have a null return value
421 static Symbol* package_from_class_name(const Symbol* class_name, bool* bad_class_name = nullptr);
422
423 // Debugging
424 static void verify() PRODUCT_RETURN;
425 };
426
427 // PerfClassTraceTime is used to measure time for class loading related events.
428 // This class tracks cumulative time and exclusive time for specific event types.
429 // During the execution of one event, other event types (e.g. class loading and
430 // resolution) as well as recursive calls of the same event type could happen.
431 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
432 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
433 // instances have been created as multiple events are happening.
434 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);
124 // that have been specified for a specific module. Currently,
125 // the only way to specify a module/path pair is via the --patch-module
126 // command line option.
127 class ModuleClassPathList : public CHeapObj<mtClass> {
128 private:
129 Symbol* _module_name;
130 // First and last entries of class path entries for a specific module
131 ClassPathEntry* _module_first_entry;
132 ClassPathEntry* _module_last_entry;
133 public:
134 Symbol* module_name() const { return _module_name; }
135 ClassPathEntry* module_first_entry() const { return _module_first_entry; }
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);
404
405 static char* lookup_vm_options();
406
407 // Determines if the named module is present in the
408 // modules jimage file or in the exploded modules directory.
409 static bool is_module_observable(const char* module_name);
410
411 static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
412 const char* file_name, jlong &size);
413
414 static void trace_class_path(const char* msg, const char* name = nullptr);
415
416 // VM monitoring and management support
417 static jlong classloader_time_ms();
418 static jlong class_method_total_size();
419 static jlong class_init_count();
420 static jlong class_init_time_ms();
421 static jlong class_verify_time_ms();
422 static jlong class_link_count();
423 static jlong class_link_time_ms();
424 static jlong class_init_bytecodes_count();
425
426 // adds a class path to the boot append entries
427 static void add_to_boot_append_entries(ClassPathEntry* new_entry);
428
429 // creates a class path zip entry (returns null if JAR file cannot be opened)
430 static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
431
432 static bool string_ends_with(const char* str, const char* str_to_find);
433
434 // Extract package name from a fully qualified class name
435 // *bad_class_name is set to true if there's a problem with parsing class_name, to
436 // distinguish from a class_name with no package name, as both cases have a null return value
437 static Symbol* package_from_class_name(const Symbol* class_name, bool* bad_class_name = nullptr);
438
439 // Debugging
440 static void verify() PRODUCT_RETURN;
441 };
442
443 // PerfClassTraceTime is used to measure time for class loading related events.
444 // This class tracks cumulative time and exclusive time for specific event types.
445 // During the execution of one event, other event types (e.g. class loading and
446 // resolution) as well as recursive calls of the same event type could happen.
447 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
448 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
449 // instances have been created as multiple events are happening.
450 class PerfClassTraceTime {
|