< prev index next >

src/hotspot/share/classfile/classLoader.hpp

Print this page

 77  private:
 78   const char* _dir;           // Name of directory
 79  public:
 80   const char* name() const { return _dir; }
 81   ClassPathDirEntry(const char* dir) {
 82     _dir = copy_path(dir);
 83   }
 84   virtual ~ClassPathDirEntry();
 85   ClassFileStream* open_stream(JavaThread* current, const char* name);
 86 };
 87 
 88 class ClassPathZipEntry: public ClassPathEntry {
 89  private:
 90   jzfile* _zip;              // The zip archive
 91   const char*   _zip_name;   // Name of zip archive
 92   bool _from_class_path_attr; // From the "Class-path" attribute of a jar file
 93  public:
 94   bool is_jar_file() const { return true;  }
 95   bool from_class_path_attr() const { return _from_class_path_attr; }
 96   const char* name() const { return _zip_name; }
 97   ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append, bool from_class_path_attr);
 98   virtual ~ClassPathZipEntry();

 99   u1* open_entry(JavaThread* current, const char* name, jint* filesize, bool nul_terminate);
100   ClassFileStream* open_stream(JavaThread* current, const char* name);
101 };
102 
103 
104 // For java image files
105 class ClassPathImageEntry: public ClassPathEntry {
106 private:
107   const char* _name;
108   DEBUG_ONLY(static ClassPathImageEntry* _singleton;)
109 public:
110   bool is_modules_image() const;
111   const char* name() const { return _name == nullptr ? "" : _name; }
112   JImageFile* jimage() const;
113   JImageFile* jimage_non_null() const;
114   void close_jimage();
115   ClassPathImageEntry(JImageFile* jimage, const char* name);
116   virtual ~ClassPathImageEntry() { ShouldNotReachHere(); }
117   ClassFileStream* open_stream(JavaThread* current, const char* name);
118   ClassFileStream* open_stream_for_loader(JavaThread* current, const char* name, ClassLoaderData* loader_data);

122 // that have been specified for a specific module.  Currently,
123 // the only way to specify a module/path pair is via the --patch-module
124 // command line option.
125 class ModuleClassPathList : public CHeapObj<mtClass> {
126 private:
127   Symbol* _module_name;
128   // First and last entries of class path entries for a specific module
129   ClassPathEntry* _module_first_entry;
130   ClassPathEntry* _module_last_entry;
131 public:
132   Symbol* module_name() const { return _module_name; }
133   ClassPathEntry* module_first_entry() const { return _module_first_entry; }
134   ModuleClassPathList(Symbol* module_name);
135   ~ModuleClassPathList();
136   void add_to_list(ClassPathEntry* new_entry);
137 };
138 
139 class ClassLoader: AllStatic {
140  public:
141   enum ClassLoaderType {

142     BOOT_LOADER = 1,      /* boot loader */
143     PLATFORM_LOADER  = 2, /* PlatformClassLoader */
144     APP_LOADER  = 3       /* AppClassLoader */
145   };
146  protected:
147 
148   // Performance counters
149   static PerfCounter* _perf_accumulated_time;
150   static PerfCounter* _perf_classes_inited;
151   static PerfCounter* _perf_class_init_time;
152   static PerfCounter* _perf_class_init_selftime;

153   static PerfCounter* _perf_classes_verified;
154   static PerfCounter* _perf_class_verify_time;
155   static PerfCounter* _perf_class_verify_selftime;
156   static PerfCounter* _perf_classes_linked;
157   static PerfCounter* _perf_class_link_time;
158   static PerfCounter* _perf_class_link_selftime;
159   static PerfCounter* _perf_shared_classload_time;
160   static PerfCounter* _perf_sys_classload_time;
161   static PerfCounter* _perf_app_classload_time;
162   static PerfCounter* _perf_app_classload_selftime;
163   static PerfCounter* _perf_app_classload_count;
164   static PerfCounter* _perf_define_appclasses;
165   static PerfCounter* _perf_define_appclass_time;
166   static PerfCounter* _perf_define_appclass_selftime;
167   static PerfCounter* _perf_app_classfile_bytes_read;
168   static PerfCounter* _perf_sys_classfile_bytes_read;



















169 
170   static PerfCounter* _unsafe_defineClassCallCounter;
171 
172   // The boot class path consists of 3 ordered pieces:
173   //  1. the module/path pairs specified to --patch-module
174   //    --patch-module=<module>=<file>(<pathsep><file>)*
175   //  2. the base piece
176   //    [jimage | build with exploded modules]
177   //  3. boot loader append path
178   //    [-Xbootclasspath/a]; [jvmti appended entries]
179   //
180   // The boot loader must obey this order when attempting
181   // to load a class.
182 
183   // 1. Contains the module/path pairs specified to --patch-module
184   static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
185 
186   // 2. the base piece
187   //    Contains the ClassPathEntry of the modular java runtime image.
188   //    If no java runtime image is present, this indicates a

262   static PerfCounter* perf_classes_inited()           { return _perf_classes_inited; }
263   static PerfCounter* perf_class_init_time()          { return _perf_class_init_time; }
264   static PerfCounter* perf_class_init_selftime()      { return _perf_class_init_selftime; }
265   static PerfCounter* perf_classes_verified()         { return _perf_classes_verified; }
266   static PerfCounter* perf_class_verify_time()        { return _perf_class_verify_time; }
267   static PerfCounter* perf_class_verify_selftime()    { return _perf_class_verify_selftime; }
268   static PerfCounter* perf_classes_linked()           { return _perf_classes_linked; }
269   static PerfCounter* perf_class_link_time()          { return _perf_class_link_time; }
270   static PerfCounter* perf_class_link_selftime()      { return _perf_class_link_selftime; }
271   static PerfCounter* perf_shared_classload_time()    { return _perf_shared_classload_time; }
272   static PerfCounter* perf_sys_classload_time()       { return _perf_sys_classload_time; }
273   static PerfCounter* perf_app_classload_time()       { return _perf_app_classload_time; }
274   static PerfCounter* perf_app_classload_selftime()   { return _perf_app_classload_selftime; }
275   static PerfCounter* perf_app_classload_count()      { return _perf_app_classload_count; }
276   static PerfCounter* perf_define_appclasses()        { return _perf_define_appclasses; }
277   static PerfCounter* perf_define_appclass_time()     { return _perf_define_appclass_time; }
278   static PerfCounter* perf_define_appclass_selftime() { return _perf_define_appclass_selftime; }
279   static PerfCounter* perf_app_classfile_bytes_read() { return _perf_app_classfile_bytes_read; }
280   static PerfCounter* perf_sys_classfile_bytes_read() { return _perf_sys_classfile_bytes_read; }
281 
























282   // Record how many calls to Unsafe_DefineClass
283   static PerfCounter* unsafe_defineClassCallCounter() {
284     return _unsafe_defineClassCallCounter;
285   }
286 
287   // Modular java runtime image is present vs. a build with exploded modules
288   static bool has_jrt_entry() { return (_jrt_entry != nullptr); }
289   static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
290   static void close_jrt_image();
291 
292   // Add a module's exploded directory to the boot loader's exploded module build list
293   static void add_to_exploded_build_list(JavaThread* current, Symbol* module_name);
294 
295   // Search the module list for the class file stream based on the file name and java package
296   static ClassFileStream* search_module_entries(JavaThread* current,
297                                                 const GrowableArray<ModuleClassPathList*>* const module_list,
298                                                 PackageEntry* pkg_entry, // Java package entry derived from the class name
299                                                 const char* const file_name);
300 
301   // Load individual .class file

351 
352   static char* lookup_vm_options();
353 
354   // Determines if the named module is present in the
355   // modules jimage file or in the exploded modules directory.
356   static bool is_module_observable(const char* module_name);
357 
358   static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
359                                                 const char* file_name, jlong &size);
360 
361   static void  trace_class_path(const char* msg, const char* name = nullptr);
362 
363   // VM monitoring and management support
364   static jlong classloader_time_ms();
365   static jlong class_method_total_size();
366   static jlong class_init_count();
367   static jlong class_init_time_ms();
368   static jlong class_verify_time_ms();
369   static jlong class_link_count();
370   static jlong class_link_time_ms();

371 
372   // adds a class path to the boot append entries
373   static void add_to_boot_append_entries(ClassPathEntry* new_entry);
374 
375   // creates a class path zip entry (returns null if JAR file cannot be opened)
376   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath, bool is_boot_append);
377 
378   static bool string_ends_with(const char* str, const char* str_to_find);
379 
380   // Extract package name from a fully qualified class name
381   // *bad_class_name is set to true if there's a problem with parsing class_name, to
382   // distinguish from a class_name with no package name, as both cases have a null return value
383   static Symbol* package_from_class_name(const Symbol* class_name, bool* bad_class_name = nullptr);
384 
385   // Debugging
386   static void verify()              PRODUCT_RETURN;
387 };
388 
389 // PerfClassTraceTime is used to measure time for class loading related events.
390 // This class tracks cumulative time and exclusive time for specific event types.
391 // During the execution of one event, other event types (e.g. class loading and
392 // resolution) as well as recursive calls of the same event type could happen.
393 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
394 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
395 // instances have been created as multiple events are happening.
396 class PerfClassTraceTime {

 77  private:
 78   const char* _dir;           // Name of directory
 79  public:
 80   const char* name() const { return _dir; }
 81   ClassPathDirEntry(const char* dir) {
 82     _dir = copy_path(dir);
 83   }
 84   virtual ~ClassPathDirEntry();
 85   ClassFileStream* open_stream(JavaThread* current, const char* name);
 86 };
 87 
 88 class ClassPathZipEntry: public ClassPathEntry {
 89  private:
 90   jzfile* _zip;              // The zip archive
 91   const char*   _zip_name;   // Name of zip archive
 92   bool _from_class_path_attr; // From the "Class-path" attribute of a jar file
 93  public:
 94   bool is_jar_file() const { return true;  }
 95   bool from_class_path_attr() const { return _from_class_path_attr; }
 96   const char* name() const { return _zip_name; }
 97   ClassPathZipEntry(jzfile* zip, const char* zip_name, bool from_class_path_attr);
 98   virtual ~ClassPathZipEntry();
 99   bool has_entry(JavaThread* current, const char* name);
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     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_class_init_bytecodes_count;
156   static PerfCounter* _perf_classes_verified;
157   static PerfCounter* _perf_class_verify_time;
158   static PerfCounter* _perf_class_verify_selftime;
159   static PerfCounter* _perf_classes_linked;
160   static PerfCounter* _perf_class_link_time;
161   static PerfCounter* _perf_class_link_selftime;
162   static PerfCounter* _perf_shared_classload_time;
163   static PerfCounter* _perf_sys_classload_time;
164   static PerfCounter* _perf_app_classload_time;
165   static PerfCounter* _perf_app_classload_selftime;
166   static PerfCounter* _perf_app_classload_count;
167   static PerfCounter* _perf_define_appclasses;
168   static PerfCounter* _perf_define_appclass_time;
169   static PerfCounter* _perf_define_appclass_selftime;
170   static PerfCounter* _perf_app_classfile_bytes_read;
171   static PerfCounter* _perf_sys_classfile_bytes_read;
172   static PerfCounter* _perf_preload_total_time;
173   static PerfCounter* _perf_preload_time;
174   static PerfCounter* _perf_prelink_time;
175   static PerfCounter* _perf_preinit_time;
176   static PerfCounter* _perf_preresolve_time;
177   static PerfCounter* _perf_ik_link_methods_time;
178   static PerfCounter* _perf_method_adapters_time;
179   static PerfCounter* _perf_ik_link_methods_count;
180   static PerfCounter* _perf_method_adapters_count;
181 
182   static PerfTickCounters* _perf_resolve_indy_time;
183   static PerfTickCounters* _perf_resolve_invokehandle_time;
184   static PerfTickCounters* _perf_resolve_mh_time;
185   static PerfTickCounters* _perf_resolve_mt_time;
186 
187   static PerfCounter* _perf_resolve_indy_count;
188   static PerfCounter* _perf_resolve_invokehandle_count;
189   static PerfCounter* _perf_resolve_mh_count;
190   static PerfCounter* _perf_resolve_mt_count;
191 
192   static PerfCounter* _unsafe_defineClassCallCounter;
193 
194   // The boot class path consists of 3 ordered pieces:
195   //  1. the module/path pairs specified to --patch-module
196   //    --patch-module=<module>=<file>(<pathsep><file>)*
197   //  2. the base piece
198   //    [jimage | build with exploded modules]
199   //  3. boot loader append path
200   //    [-Xbootclasspath/a]; [jvmti appended entries]
201   //
202   // The boot loader must obey this order when attempting
203   // to load a class.
204 
205   // 1. Contains the module/path pairs specified to --patch-module
206   static GrowableArray<ModuleClassPathList*>* _patch_mod_entries;
207 
208   // 2. the base piece
209   //    Contains the ClassPathEntry of the modular java runtime image.
210   //    If no java runtime image is present, this indicates a

284   static PerfCounter* perf_classes_inited()           { return _perf_classes_inited; }
285   static PerfCounter* perf_class_init_time()          { return _perf_class_init_time; }
286   static PerfCounter* perf_class_init_selftime()      { return _perf_class_init_selftime; }
287   static PerfCounter* perf_classes_verified()         { return _perf_classes_verified; }
288   static PerfCounter* perf_class_verify_time()        { return _perf_class_verify_time; }
289   static PerfCounter* perf_class_verify_selftime()    { return _perf_class_verify_selftime; }
290   static PerfCounter* perf_classes_linked()           { return _perf_classes_linked; }
291   static PerfCounter* perf_class_link_time()          { return _perf_class_link_time; }
292   static PerfCounter* perf_class_link_selftime()      { return _perf_class_link_selftime; }
293   static PerfCounter* perf_shared_classload_time()    { return _perf_shared_classload_time; }
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_preload_total_time() { return _perf_preload_total_time; }
305   static PerfCounter* perf_preload_time() { return _perf_preload_time; }
306   static PerfCounter* perf_prelink_time() { return _perf_prelink_time; }
307   static PerfCounter* perf_preinit_time() { return _perf_preinit_time; }
308   static PerfCounter* perf_preresolve_time() { return _perf_preresolve_time; }
309   static PerfCounter* perf_ik_link_methods_time() { return _perf_ik_link_methods_time; }
310   static PerfCounter* perf_method_adapters_time() { return _perf_method_adapters_time; }
311   static PerfCounter* perf_ik_link_methods_count() { return _perf_ik_link_methods_count; }
312   static PerfCounter* perf_method_adapters_count() { return _perf_method_adapters_count; }
313 
314   static PerfTickCounters* perf_resolve_invokedynamic_time() { return _perf_resolve_indy_time; }
315   static PerfTickCounters* perf_resolve_invokehandle_time() { return _perf_resolve_invokehandle_time; }
316   static PerfTickCounters* perf_resolve_method_handle_time() { return _perf_resolve_mh_time; }
317   static PerfTickCounters* perf_resolve_method_type_time() { return _perf_resolve_mt_time; }
318 
319   static PerfCounter* perf_resolve_invokedynamic_count() { return _perf_resolve_indy_count; }
320   static PerfCounter* perf_resolve_invokehandle_count() { return _perf_resolve_invokehandle_count; }
321   static PerfCounter* perf_resolve_method_handle_count() { return _perf_resolve_mh_count; }
322   static PerfCounter* perf_resolve_method_type_count() { return _perf_resolve_mt_count; }
323 
324   static PerfCounter* perf_class_init_bytecodes_count() { return _perf_class_init_bytecodes_count; }
325 
326   static void print_counters();
327 
328   // Record how many calls to Unsafe_DefineClass
329   static PerfCounter* unsafe_defineClassCallCounter() {
330     return _unsafe_defineClassCallCounter;
331   }
332 
333   // Modular java runtime image is present vs. a build with exploded modules
334   static bool has_jrt_entry() { return (_jrt_entry != nullptr); }
335   static ClassPathEntry* get_jrt_entry() { return _jrt_entry; }
336   static void close_jrt_image();
337 
338   // Add a module's exploded directory to the boot loader's exploded module build list
339   static void add_to_exploded_build_list(JavaThread* current, Symbol* module_name);
340 
341   // Search the module list for the class file stream based on the file name and java package
342   static ClassFileStream* search_module_entries(JavaThread* current,
343                                                 const GrowableArray<ModuleClassPathList*>* const module_list,
344                                                 PackageEntry* pkg_entry, // Java package entry derived from the class name
345                                                 const char* const file_name);
346 
347   // Load individual .class file

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   static jlong class_init_bytecodes_count();
418 
419   // adds a class path to the boot append entries
420   static void add_to_boot_append_entries(ClassPathEntry* new_entry);
421 
422   // creates a class path zip entry (returns null if JAR file cannot be opened)
423   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
424 
425   static bool string_ends_with(const char* str, const char* str_to_find);
426 
427   // Extract package name from a fully qualified class name
428   // *bad_class_name is set to true if there's a problem with parsing class_name, to
429   // distinguish from a class_name with no package name, as both cases have a null return value
430   static Symbol* package_from_class_name(const Symbol* class_name, bool* bad_class_name = nullptr);
431 
432   // Debugging
433   static void verify()              PRODUCT_RETURN;
434 };
435 
436 // PerfClassTraceTime is used to measure time for class loading related events.
437 // This class tracks cumulative time and exclusive time for specific event types.
438 // During the execution of one event, other event types (e.g. class loading and
439 // resolution) as well as recursive calls of the same event type could happen.
440 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
441 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
442 // instances have been created as multiple events are happening.
443 class PerfClassTraceTime {
< prev index next >