src/share/vm/classfile/classLoader.hpp

Print this page
rev 6853 : 8046070: Class Data Sharing clean up and refactoring
Summary: Cleaned up CDS to be more configurable, maintainable and extensible
Reviewed-by: dholmes, coleenp, acorn, mchung


  90   char *name;                   /* entry name */
  91   jlong time;                   /* modification time */
  92   jlong size;                   /* size of uncompressed data */
  93   jlong csize;                  /* size of compressed data (zero if uncompressed) */
  94   jint crc;                     /* crc of uncompressed data */
  95   char *comment;                /* optional zip file comment */
  96   jbyte *extra;                 /* optional extra data */
  97   jlong pos;                    /* position of LOC header (if negative) or data */
  98 } jzentry;
  99 
 100 
 101 class ClassPathZipEntry: public ClassPathEntry {
 102  private:
 103   jzfile* _zip;        // The zip archive
 104   char*   _zip_name;   // Name of zip archive
 105  public:
 106   bool is_jar_file()  { return true;  }
 107   const char* name()  { return _zip_name; }
 108   ClassPathZipEntry(jzfile* zip, const char* zip_name);
 109   ~ClassPathZipEntry();

 110   ClassFileStream* open_stream(const char* name, TRAPS);
 111   void contents_do(void f(const char* name, void* context), void* context);
 112   // Debugging
 113   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 114   NOT_PRODUCT(bool is_rt_jar();)
 115 };
 116 
 117 
 118 // For lazier loading of boot class path entries
 119 class LazyClassPathEntry: public ClassPathEntry {
 120  private:
 121   char* _path; // dir or file
 122   struct stat _st;
 123   MetaIndex* _meta_index;
 124   bool _has_error;

 125   volatile ClassPathEntry* _resolved_entry;
 126   ClassPathEntry* resolve_entry(TRAPS);
 127  public:
 128   bool is_jar_file();
 129   const char* name()  { return _path; }
 130   LazyClassPathEntry(char* path, const struct stat* st);
 131   virtual ~LazyClassPathEntry();

 132 
 133   ClassFileStream* open_stream(const char* name, TRAPS);
 134   void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; }
 135   virtual bool is_lazy();
 136   // Debugging
 137   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 138   NOT_PRODUCT(bool is_rt_jar();)
 139 };
 140 
 141 class PackageHashtable;
 142 class PackageInfo;

 143 template <MEMFLAGS F> class HashtableBucket;
 144 
 145 class ClassLoader: AllStatic {
 146  public:
 147   enum SomeConstants {
 148     package_hash_table_size = 31  // Number of buckets
 149   };
 150  private:
 151   friend class LazyClassPathEntry;
 152 
 153   // Performance counters
 154   static PerfCounter* _perf_accumulated_time;
 155   static PerfCounter* _perf_classes_inited;
 156   static PerfCounter* _perf_class_init_time;
 157   static PerfCounter* _perf_class_init_selftime;
 158   static PerfCounter* _perf_classes_verified;
 159   static PerfCounter* _perf_class_verify_time;
 160   static PerfCounter* _perf_class_verify_selftime;
 161   static PerfCounter* _perf_classes_linked;
 162   static PerfCounter* _perf_class_link_time;
 163   static PerfCounter* _perf_class_link_selftime;
 164   static PerfCounter* _perf_class_parse_time;
 165   static PerfCounter* _perf_class_parse_selftime;
 166   static PerfCounter* _perf_sys_class_lookup_time;
 167   static PerfCounter* _perf_shared_classload_time;
 168   static PerfCounter* _perf_sys_classload_time;
 169   static PerfCounter* _perf_app_classload_time;
 170   static PerfCounter* _perf_app_classload_selftime;


 172   static PerfCounter* _perf_define_appclasses;
 173   static PerfCounter* _perf_define_appclass_time;
 174   static PerfCounter* _perf_define_appclass_selftime;
 175   static PerfCounter* _perf_app_classfile_bytes_read;
 176   static PerfCounter* _perf_sys_classfile_bytes_read;
 177 
 178   static PerfCounter* _sync_systemLoaderLockContentionRate;
 179   static PerfCounter* _sync_nonSystemLoaderLockContentionRate;
 180   static PerfCounter* _sync_JVMFindLoadedClassLockFreeCounter;
 181   static PerfCounter* _sync_JVMDefineClassLockFreeCounter;
 182   static PerfCounter* _sync_JNIDefineClassLockFreeCounter;
 183 
 184   static PerfCounter* _unsafe_defineClassCallCounter;
 185   static PerfCounter* _isUnsyncloadClass;
 186   static PerfCounter* _load_instance_class_failCounter;
 187 
 188   // First entry in linked list of ClassPathEntry instances
 189   static ClassPathEntry* _first_entry;
 190   // Last entry in linked list of ClassPathEntry instances
 191   static ClassPathEntry* _last_entry;


 192   // Hash table used to keep track of loaded packages
 193   static PackageHashtable* _package_hash_table;
 194   static const char* _shared_archive;
 195 



 196   // Hash function
 197   static unsigned int hash(const char *s, int n);
 198   // Returns the package file name corresponding to the specified package
 199   // or class name, or null if not found.
 200   static PackageInfo* lookup_package(const char *pkgname);
 201   // Adds a new package entry for the specified class or package name and
 202   // corresponding directory or jar file name.
 203   static bool add_package(const char *pkgname, int classpath_index, TRAPS);
 204 
 205   // Initialization
 206   static void setup_meta_index();


 207   static void setup_bootstrap_search_path();


 208   static void load_zip_library();
 209   static ClassPathEntry* create_class_path_entry(char *path, const struct stat* st,
 210                                                  bool lazy, TRAPS);
 211 
 212   // Canonicalizes path names, so strcmp will work properly. This is mainly
 213   // to avoid confusing the zip library
 214   static bool get_canonical_path(char* orig, char* out, int len);
 215  public:
 216   // Used by the kernel jvm.
 217   static void update_class_path_entry_list(char *path,
 218                                            bool check_for_duplicates);
 219   static void print_bootclasspath();
 220 
 221   // Timing
 222   static PerfCounter* perf_accumulated_time()         { return _perf_accumulated_time; }
 223   static PerfCounter* perf_classes_inited()           { return _perf_classes_inited; }
 224   static PerfCounter* perf_class_init_time()          { return _perf_class_init_time; }
 225   static PerfCounter* perf_class_init_selftime()      { return _perf_class_init_selftime; }
 226   static PerfCounter* perf_classes_verified()         { return _perf_classes_verified; }
 227   static PerfCounter* perf_class_verify_time()        { return _perf_class_verify_time; }
 228   static PerfCounter* perf_class_verify_selftime()    { return _perf_class_verify_selftime; }
 229   static PerfCounter* perf_classes_linked()           { return _perf_classes_linked; }
 230   static PerfCounter* perf_class_link_time()          { return _perf_class_link_time; }
 231   static PerfCounter* perf_class_link_selftime()      { return _perf_class_link_selftime; }
 232   static PerfCounter* perf_class_parse_time()         { return _perf_class_parse_time; }
 233   static PerfCounter* perf_class_parse_selftime()     { return _perf_class_parse_selftime; }
 234   static PerfCounter* perf_sys_class_lookup_time()    { return _perf_sys_class_lookup_time; }
 235   static PerfCounter* perf_shared_classload_time()    { return _perf_shared_classload_time; }
 236   static PerfCounter* perf_sys_classload_time()       { return _perf_sys_classload_time; }
 237   static PerfCounter* perf_app_classload_time()       { return _perf_app_classload_time; }
 238   static PerfCounter* perf_app_classload_selftime()   { return _perf_app_classload_selftime; }


 281 
 282   // Load individual .class file
 283   static instanceKlassHandle load_classfile(Symbol* h_name, TRAPS);
 284 
 285   // If the specified package has been loaded by the system, then returns
 286   // the name of the directory or ZIP file that the package was loaded from.
 287   // Returns null if the package was not loaded.
 288   // Note: The specified name can either be the name of a class or package.
 289   // If a package name is specified, then it must be "/"-separator and also
 290   // end with a trailing "/".
 291   static oop get_system_package(const char* name, TRAPS);
 292 
 293   // Returns an array of Java strings representing all of the currently
 294   // loaded system packages.
 295   // Note: The package names returned are "/"-separated and end with a
 296   // trailing "/".
 297   static objArrayOop get_system_packages(TRAPS);
 298 
 299   // Initialization
 300   static void initialize();

 301   static void create_package_info_table();
 302   static void create_package_info_table(HashtableBucket<mtClass> *t, int length,
 303                                         int number_of_entries);
 304   static int compute_Object_vtable();
 305 
 306   static ClassPathEntry* classpath_entry(int n) {
 307     ClassPathEntry* e = ClassLoader::_first_entry;
 308     while (--n >= 0) {
 309       assert(e != NULL, "Not that many classpath entries.");
 310       e = e->next();
 311     }
 312     return e;
 313   }
 314 

 315   // Sharing dump and restore
 316   static void copy_package_info_buckets(char** top, char* end);
 317   static void copy_package_info_table(char** top, char* end);
 318 










 319   // VM monitoring and management support
 320   static jlong classloader_time_ms();
 321   static jlong class_method_total_size();
 322   static jlong class_init_count();
 323   static jlong class_init_time_ms();
 324   static jlong class_verify_time_ms();
 325   static jlong class_link_count();
 326   static jlong class_link_time_ms();
 327 
 328   // indicates if class path already contains a entry (exact match by name)
 329   static bool contains_entry(ClassPathEntry* entry);
 330 
 331   // adds a class path list
 332   static void add_to_list(ClassPathEntry* new_entry);
 333 
 334   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
 335   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
 336 
 337   // Debugging
 338   static void verify()              PRODUCT_RETURN;
 339 
 340   // Force compilation of all methods in all classes in bootstrap class path (stress test)
 341 #ifndef PRODUCT
 342  private:
 343   static int _compile_the_world_class_counter;
 344   static int _compile_the_world_method_counter;
 345  public:
 346   static void compile_the_world();
 347   static void compile_the_world_in(char* name, Handle loader, TRAPS);
 348   static int  compile_the_world_counter() { return _compile_the_world_class_counter; }
 349 #endif //PRODUCT
 350 };
 351 
 352 // PerfClassTraceTime is used to measure time for class loading related events.
 353 // This class tracks cumulative time and exclusive time for specific event types.
 354 // During the execution of one event, other event types (e.g. class loading and
 355 // resolution) as well as recursive calls of the same event type could happen.
 356 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
 357 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
 358 // instances have been created as multiple events are happening.
 359 class PerfClassTraceTime {
 360  public:
 361   enum {
 362     CLASS_LOAD   = 0,




  90   char *name;                   /* entry name */
  91   jlong time;                   /* modification time */
  92   jlong size;                   /* size of uncompressed data */
  93   jlong csize;                  /* size of compressed data (zero if uncompressed) */
  94   jint crc;                     /* crc of uncompressed data */
  95   char *comment;                /* optional zip file comment */
  96   jbyte *extra;                 /* optional extra data */
  97   jlong pos;                    /* position of LOC header (if negative) or data */
  98 } jzentry;
  99 
 100 
 101 class ClassPathZipEntry: public ClassPathEntry {
 102  private:
 103   jzfile* _zip;        // The zip archive
 104   char*   _zip_name;   // Name of zip archive
 105  public:
 106   bool is_jar_file()  { return true;  }
 107   const char* name()  { return _zip_name; }
 108   ClassPathZipEntry(jzfile* zip, const char* zip_name);
 109   ~ClassPathZipEntry();
 110   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 111   ClassFileStream* open_stream(const char* name, TRAPS);
 112   void contents_do(void f(const char* name, void* context), void* context);
 113   // Debugging
 114   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 115   NOT_PRODUCT(bool is_rt_jar();)
 116 };
 117 
 118 
 119 // For lazier loading of boot class path entries
 120 class LazyClassPathEntry: public ClassPathEntry {
 121  private:
 122   char* _path; // dir or file
 123   struct stat _st;
 124   MetaIndex* _meta_index;
 125   bool _has_error;
 126   bool _throw_exception;
 127   volatile ClassPathEntry* _resolved_entry;
 128   ClassPathEntry* resolve_entry(TRAPS);
 129  public:
 130   bool is_jar_file();
 131   const char* name()  { return _path; }
 132   LazyClassPathEntry(char* path, const struct stat* st, bool throw_exception);
 133   virtual ~LazyClassPathEntry();
 134   u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS);
 135 
 136   ClassFileStream* open_stream(const char* name, TRAPS);
 137   void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; }
 138   virtual bool is_lazy();
 139   // Debugging
 140   NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);)
 141   NOT_PRODUCT(bool is_rt_jar();)
 142 };
 143 
 144 class PackageHashtable;
 145 class PackageInfo;
 146 class SharedPathsMiscInfo;
 147 template <MEMFLAGS F> class HashtableBucket;
 148 
 149 class ClassLoader: AllStatic {
 150  public:
 151   enum SomeConstants {
 152     package_hash_table_size = 31  // Number of buckets
 153   };
 154  protected:
 155   friend class LazyClassPathEntry;
 156 
 157   // Performance counters
 158   static PerfCounter* _perf_accumulated_time;
 159   static PerfCounter* _perf_classes_inited;
 160   static PerfCounter* _perf_class_init_time;
 161   static PerfCounter* _perf_class_init_selftime;
 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_class_parse_time;
 169   static PerfCounter* _perf_class_parse_selftime;
 170   static PerfCounter* _perf_sys_class_lookup_time;
 171   static PerfCounter* _perf_shared_classload_time;
 172   static PerfCounter* _perf_sys_classload_time;
 173   static PerfCounter* _perf_app_classload_time;
 174   static PerfCounter* _perf_app_classload_selftime;


 176   static PerfCounter* _perf_define_appclasses;
 177   static PerfCounter* _perf_define_appclass_time;
 178   static PerfCounter* _perf_define_appclass_selftime;
 179   static PerfCounter* _perf_app_classfile_bytes_read;
 180   static PerfCounter* _perf_sys_classfile_bytes_read;
 181 
 182   static PerfCounter* _sync_systemLoaderLockContentionRate;
 183   static PerfCounter* _sync_nonSystemLoaderLockContentionRate;
 184   static PerfCounter* _sync_JVMFindLoadedClassLockFreeCounter;
 185   static PerfCounter* _sync_JVMDefineClassLockFreeCounter;
 186   static PerfCounter* _sync_JNIDefineClassLockFreeCounter;
 187 
 188   static PerfCounter* _unsafe_defineClassCallCounter;
 189   static PerfCounter* _isUnsyncloadClass;
 190   static PerfCounter* _load_instance_class_failCounter;
 191 
 192   // First entry in linked list of ClassPathEntry instances
 193   static ClassPathEntry* _first_entry;
 194   // Last entry in linked list of ClassPathEntry instances
 195   static ClassPathEntry* _last_entry;
 196   static int _num_entries;
 197 
 198   // Hash table used to keep track of loaded packages
 199   static PackageHashtable* _package_hash_table;
 200   static const char* _shared_archive;
 201 
 202   // Info used by CDS
 203   CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;)
 204 
 205   // Hash function
 206   static unsigned int hash(const char *s, int n);
 207   // Returns the package file name corresponding to the specified package
 208   // or class name, or null if not found.
 209   static PackageInfo* lookup_package(const char *pkgname);
 210   // Adds a new package entry for the specified class or package name and
 211   // corresponding directory or jar file name.
 212   static bool add_package(const char *pkgname, int classpath_index, TRAPS);
 213 
 214   // Initialization
 215   static void setup_bootstrap_meta_index();
 216   static void setup_meta_index(const char* meta_index_path, const char* meta_index_dir,
 217                                int start_index);
 218   static void setup_bootstrap_search_path();
 219   static void setup_search_path(char *class_path);
 220 
 221   static void load_zip_library();
 222   static ClassPathEntry* create_class_path_entry(char *path, const struct stat* st,
 223                                                  bool lazy, bool throw_exception, TRAPS);
 224 
 225   // Canonicalizes path names, so strcmp will work properly. This is mainly
 226   // to avoid confusing the zip library
 227   static bool get_canonical_path(char* orig, char* out, int len);
 228  public:
 229   static bool update_class_path_entry_list(char *path,
 230                                            bool check_for_duplicates,
 231                                            bool throw_exception=true);
 232   static void print_bootclasspath();
 233 
 234   // Timing
 235   static PerfCounter* perf_accumulated_time()         { return _perf_accumulated_time; }
 236   static PerfCounter* perf_classes_inited()           { return _perf_classes_inited; }
 237   static PerfCounter* perf_class_init_time()          { return _perf_class_init_time; }
 238   static PerfCounter* perf_class_init_selftime()      { return _perf_class_init_selftime; }
 239   static PerfCounter* perf_classes_verified()         { return _perf_classes_verified; }
 240   static PerfCounter* perf_class_verify_time()        { return _perf_class_verify_time; }
 241   static PerfCounter* perf_class_verify_selftime()    { return _perf_class_verify_selftime; }
 242   static PerfCounter* perf_classes_linked()           { return _perf_classes_linked; }
 243   static PerfCounter* perf_class_link_time()          { return _perf_class_link_time; }
 244   static PerfCounter* perf_class_link_selftime()      { return _perf_class_link_selftime; }
 245   static PerfCounter* perf_class_parse_time()         { return _perf_class_parse_time; }
 246   static PerfCounter* perf_class_parse_selftime()     { return _perf_class_parse_selftime; }
 247   static PerfCounter* perf_sys_class_lookup_time()    { return _perf_sys_class_lookup_time; }
 248   static PerfCounter* perf_shared_classload_time()    { return _perf_shared_classload_time; }
 249   static PerfCounter* perf_sys_classload_time()       { return _perf_sys_classload_time; }
 250   static PerfCounter* perf_app_classload_time()       { return _perf_app_classload_time; }
 251   static PerfCounter* perf_app_classload_selftime()   { return _perf_app_classload_selftime; }


 294 
 295   // Load individual .class file
 296   static instanceKlassHandle load_classfile(Symbol* h_name, TRAPS);
 297 
 298   // If the specified package has been loaded by the system, then returns
 299   // the name of the directory or ZIP file that the package was loaded from.
 300   // Returns null if the package was not loaded.
 301   // Note: The specified name can either be the name of a class or package.
 302   // If a package name is specified, then it must be "/"-separator and also
 303   // end with a trailing "/".
 304   static oop get_system_package(const char* name, TRAPS);
 305 
 306   // Returns an array of Java strings representing all of the currently
 307   // loaded system packages.
 308   // Note: The package names returned are "/"-separated and end with a
 309   // trailing "/".
 310   static objArrayOop get_system_packages(TRAPS);
 311 
 312   // Initialization
 313   static void initialize();
 314   CDS_ONLY(static void initialize_shared_path();)
 315   static void create_package_info_table();
 316   static void create_package_info_table(HashtableBucket<mtClass> *t, int length,
 317                                         int number_of_entries);
 318   static int compute_Object_vtable();
 319 
 320   static ClassPathEntry* classpath_entry(int n) {
 321     ClassPathEntry* e = ClassLoader::_first_entry;
 322     while (--n >= 0) {
 323       assert(e != NULL, "Not that many classpath entries.");
 324       e = e->next();
 325     }
 326     return e;
 327   }
 328 
 329 #if INCLUDE_CDS
 330   // Sharing dump and restore
 331   static void copy_package_info_buckets(char** top, char* end);
 332   static void copy_package_info_table(char** top, char* end);
 333 
 334   static void  check_shared_classpath(const char *path);
 335   static void  finalize_shared_paths_misc_info();
 336   static int   get_shared_paths_misc_info_size();
 337   static void* get_shared_paths_misc_info();
 338   static bool  check_shared_paths_misc_info(void* info, int size);
 339   static void  exit_with_path_failure(const char* error, const char* message);
 340 #endif
 341 
 342   static void  trace_class_path(const char* msg, const char* name = NULL);
 343 
 344   // VM monitoring and management support
 345   static jlong classloader_time_ms();
 346   static jlong class_method_total_size();
 347   static jlong class_init_count();
 348   static jlong class_init_time_ms();
 349   static jlong class_verify_time_ms();
 350   static jlong class_link_count();
 351   static jlong class_link_time_ms();
 352 
 353   // indicates if class path already contains a entry (exact match by name)
 354   static bool contains_entry(ClassPathEntry* entry);
 355 
 356   // adds a class path list
 357   static void add_to_list(ClassPathEntry* new_entry);
 358 
 359   // creates a class path zip entry (returns NULL if JAR file cannot be opened)
 360   static ClassPathZipEntry* create_class_path_zip_entry(const char *apath);
 361 
 362   // Debugging
 363   static void verify()              PRODUCT_RETURN;
 364 
 365   // Force compilation of all methods in all classes in bootstrap class path (stress test)
 366 #ifndef PRODUCT
 367  protected:
 368   static int _compile_the_world_class_counter;
 369   static int _compile_the_world_method_counter;
 370  public:
 371   static void compile_the_world();
 372   static void compile_the_world_in(char* name, Handle loader, TRAPS);
 373   static int  compile_the_world_counter() { return _compile_the_world_class_counter; }
 374 #endif //PRODUCT
 375 };
 376 
 377 // PerfClassTraceTime is used to measure time for class loading related events.
 378 // This class tracks cumulative time and exclusive time for specific event types.
 379 // During the execution of one event, other event types (e.g. class loading and
 380 // resolution) as well as recursive calls of the same event type could happen.
 381 // Only one elapsed timer (cumulative) and one thread-local self timer (exclusive)
 382 // (i.e. only one event type) are active at a time even multiple PerfClassTraceTime
 383 // instances have been created as multiple events are happening.
 384 class PerfClassTraceTime {
 385  public:
 386   enum {
 387     CLASS_LOAD   = 0,