30 #include "runtime/perfData.hpp" 31 #include "utilities/exceptions.hpp" 32 #include "utilities/macros.hpp" 33 34 // The VM class loader. 35 #include <sys/stat.h> 36 37 // Name of boot "modules" image 38 #define MODULES_IMAGE_NAME "modules" 39 40 // Class path entry (directory or zip file) 41 42 class JImageFile; 43 class ClassFileStream; 44 class PackageEntry; 45 template <typename T> class GrowableArray; 46 47 class ClassPathEntry : public CHeapObj<mtClass> { 48 private: 49 ClassPathEntry* volatile _next; 50 public: 51 ClassPathEntry* next() const; 52 virtual ~ClassPathEntry() {} 53 void set_next(ClassPathEntry* next); 54 virtual bool is_modules_image() const = 0; 55 virtual bool is_jar_file() const = 0; 56 // Is this entry created from the "Class-path" attribute from a JAR Manifest? 57 virtual bool from_class_path_attr() const = 0; 58 virtual const char* name() const = 0; 59 virtual JImageFile* jimage() const = 0; 60 virtual void close_jimage() = 0; 61 // Constructor 62 ClassPathEntry() : _next(NULL) {} 63 // Attempt to locate file_name through this class path entry. 64 // Returns a class file parsing stream if successfull. 65 virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0; 66 // Open the stream for a specific class loader 67 virtual ClassFileStream* open_stream_for_loader(const char* name, ClassLoaderData* loader_data, TRAPS) { 68 return open_stream(name, THREAD); 69 } 70 }; 71 72 class ClassPathDirEntry: public ClassPathEntry { 73 private: 74 const char* _dir; // Name of directory 75 public: 76 bool is_modules_image() const { return false; } 77 bool is_jar_file() const { return false; } 78 bool from_class_path_attr() const { return false; } 79 const char* name() const { return _dir; } 80 JImageFile* jimage() const { return NULL; } 81 void close_jimage() {} 82 ClassPathDirEntry(const char* dir); 83 virtual ~ClassPathDirEntry() {} 84 ClassFileStream* open_stream(const char* name, TRAPS); 85 }; 86 87 88 // Type definitions for zip file and zip file entry 89 typedef void* jzfile; 90 typedef struct { 91 char *name; /* entry name */ 92 jlong time; /* modification time */ 93 jlong size; /* size of uncompressed data */ 94 jlong csize; /* size of compressed data (zero if uncompressed) */ 95 jint crc; /* crc of uncompressed data */ 96 char *comment; /* optional zip file comment */ 97 jbyte *extra; /* optional extra data */ 98 jlong pos; /* position of LOC header (if negative) or data */ 99 } jzentry; 100 101 class ClassPathZipEntry: public ClassPathEntry { 102 private: 103 jzfile* _zip; // The zip archive 104 const char* _zip_name; // Name of zip archive 105 bool _from_class_path_attr; // From the "Class-path" attribute of a jar file 106 public: 107 bool is_modules_image() const { return false; } 108 bool is_jar_file() const { return true; } 109 bool from_class_path_attr() const { return _from_class_path_attr; } 110 const char* name() const { return _zip_name; } 111 JImageFile* jimage() const { return NULL; } 112 void close_jimage() {} 113 ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append, bool from_class_path_attr); 114 virtual ~ClassPathZipEntry(); 115 u1* open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS); 116 ClassFileStream* open_stream(const char* name, TRAPS); 117 void contents_do(void f(const char* name, void* context), void* context); 118 }; 119 120 121 // For java image files 122 class ClassPathImageEntry: public ClassPathEntry { 123 private: 124 JImageFile* _jimage; 125 const char* _name; 126 DEBUG_ONLY(static ClassPathImageEntry* _singleton;) 127 public: 128 bool is_modules_image() const; 129 bool is_jar_file() const { return false; } 130 bool from_class_path_attr() const { return false; } 131 bool is_open() const { return _jimage != NULL; } 132 const char* name() const { return _name == NULL ? "" : _name; } 133 JImageFile* jimage() const { return _jimage; } 134 void close_jimage(); 135 ClassPathImageEntry(JImageFile* jimage, const char* name); 136 virtual ~ClassPathImageEntry(); 137 ClassFileStream* open_stream(const char* name, TRAPS); 138 ClassFileStream* open_stream_for_loader(const char* name, ClassLoaderData* loader_data, TRAPS); 139 }; 140 141 // ModuleClassPathList contains a linked list of ClassPathEntry's 142 // that have been specified for a specific module. Currently, 143 // the only way to specify a module/path pair is via the --patch-module 144 // command line option. 145 class ModuleClassPathList : public CHeapObj<mtClass> { 146 private: 147 Symbol* _module_name; 148 // First and last entries of class path entries for a specific module 149 ClassPathEntry* _module_first_entry; 150 ClassPathEntry* _module_last_entry; 151 public: 152 Symbol* module_name() const { return _module_name; } 153 ClassPathEntry* module_first_entry() const { return _module_first_entry; } 154 ModuleClassPathList(Symbol* module_name); 155 ~ModuleClassPathList(); 156 void add_to_list(ClassPathEntry* new_entry); 157 }; 158 159 class SharedPathsMiscInfo; 160 161 class ClassLoader: AllStatic { 162 public: 163 enum ClassLoaderType { 164 BOOT_LOADER = 1, /* boot loader */ 165 PLATFORM_LOADER = 2, /* PlatformClassLoader */ 166 APP_LOADER = 3 /* AppClassLoader */ 167 }; 168 protected: 169 170 // Performance counters 171 static PerfCounter* _perf_accumulated_time; 172 static PerfCounter* _perf_classes_inited; 173 static PerfCounter* _perf_class_init_time; 174 static PerfCounter* _perf_class_init_selftime; 175 static PerfCounter* _perf_classes_verified; 176 static PerfCounter* _perf_class_verify_time; 177 static PerfCounter* _perf_class_verify_selftime; 178 static PerfCounter* _perf_classes_linked; 179 static PerfCounter* _perf_class_link_time; 180 static PerfCounter* _perf_class_link_selftime; 213 214 // 1. Contains the module/path pairs specified to --patch-module 215 static GrowableArray<ModuleClassPathList*>* _patch_mod_entries; 216 217 // 2. the base piece 218 // Contains the ClassPathEntry of the modular java runtime image. 219 // If no java runtime image is present, this indicates a 220 // build with exploded modules is being used instead. 221 static ClassPathEntry* _jrt_entry; 222 static GrowableArray<ModuleClassPathList*>* _exploded_entries; 223 enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules 224 225 // 3. the boot loader's append path 226 // [-Xbootclasspath/a]; [jvmti appended entries] 227 // Note: boot loader append path does not support named modules. 228 static ClassPathEntry* _first_append_entry; 229 // Last entry in linked list of appended ClassPathEntry instances 230 static ClassPathEntry* _last_append_entry; 231 232 // Info used by CDS 233 CDS_ONLY(static SharedPathsMiscInfo * _shared_paths_misc_info;) 234 235 CDS_ONLY(static ClassPathEntry* _app_classpath_entries;) 236 CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;) 237 CDS_ONLY(static ClassPathEntry* _module_path_entries;) 238 CDS_ONLY(static ClassPathEntry* _last_module_path_entry;) 239 CDS_ONLY(static void setup_app_search_path(const char* class_path);) 240 CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);) 241 static void add_to_app_classpath_entries(const char* path, 242 ClassPathEntry* entry, 243 bool check_for_duplicates); 244 CDS_ONLY(static void add_to_module_path_entries(const char* path, 245 ClassPathEntry* entry);) 246 public: 247 CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;}) 248 CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;}) 249 250 protected: 251 // Initialization: 252 // - setup the boot loader's system class path 253 // - setup the boot loader's patch mod entries, if present 254 // - create the ModuleEntry for java.base 399 400 static ClassPathEntry* get_next_boot_classpath_entry(ClassPathEntry* e); 401 402 // Helper function used by CDS code to get the number of app classpath 403 // entries during shared classpath setup time. 404 static int num_app_classpath_entries(); 405 406 // Helper function used by CDS code to get the number of module path 407 // entries during shared classpath setup time. 408 static int num_module_path_entries() { 409 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, 410 "Should only be called at CDS dump time"); 411 int num_entries = 0; 412 ClassPathEntry* e= ClassLoader::_module_path_entries; 413 while (e != NULL) { 414 num_entries ++; 415 e = e->next(); 416 } 417 return num_entries; 418 } 419 static void finalize_shared_paths_misc_info(); 420 static int get_shared_paths_misc_info_size(); 421 static void* get_shared_paths_misc_info(); 422 static bool check_shared_paths_misc_info(void* info, int size, bool is_static); 423 static void exit_with_path_failure(const char* error, const char* message); 424 static char* skip_uri_protocol(char* source); 425 static void record_result(InstanceKlass* ik, const ClassFileStream* stream, TRAPS); 426 #endif 427 static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name, 428 const char* file_name, jlong &size); 429 430 static void trace_class_path(const char* msg, const char* name = NULL); 431 432 // VM monitoring and management support 433 static jlong classloader_time_ms(); 434 static jlong class_method_total_size(); 435 static jlong class_init_count(); 436 static jlong class_init_time_ms(); 437 static jlong class_verify_time_ms(); 438 static jlong class_link_count(); 439 static jlong class_link_time_ms(); 440 441 // indicates if class path already contains a entry (exact match by name) 442 static bool contains_append_entry(const char* name); | 30 #include "runtime/perfData.hpp" 31 #include "utilities/exceptions.hpp" 32 #include "utilities/macros.hpp" 33 34 // The VM class loader. 35 #include <sys/stat.h> 36 37 // Name of boot "modules" image 38 #define MODULES_IMAGE_NAME "modules" 39 40 // Class path entry (directory or zip file) 41 42 class JImageFile; 43 class ClassFileStream; 44 class PackageEntry; 45 template <typename T> class GrowableArray; 46 47 class ClassPathEntry : public CHeapObj<mtClass> { 48 private: 49 ClassPathEntry* volatile _next; 50 protected: 51 const char* copy_path(const char*path); 52 public: 53 ClassPathEntry* next() const; 54 virtual ~ClassPathEntry() {} 55 void set_next(ClassPathEntry* next); 56 virtual bool is_modules_image() const { return false; } 57 virtual bool is_jar_file() const { return false; } 58 // Is this entry created from the "Class-path" attribute from a JAR Manifest? 59 virtual bool from_class_path_attr() const { return false; } 60 virtual const char* name() const = 0; 61 virtual JImageFile* jimage() const { return NULL; } 62 virtual void close_jimage() {} 63 // Constructor 64 ClassPathEntry() : _next(NULL) {} 65 // Attempt to locate file_name through this class path entry. 66 // Returns a class file parsing stream if successfull. 67 virtual ClassFileStream* open_stream(const char* name, TRAPS) = 0; 68 // Open the stream for a specific class loader 69 virtual ClassFileStream* open_stream_for_loader(const char* name, ClassLoaderData* loader_data, TRAPS) { 70 return open_stream(name, THREAD); 71 } 72 }; 73 74 class ClassPathDirEntry: public ClassPathEntry { 75 private: 76 const char* _dir; // Name of directory 77 public: 78 const char* name() const { return _dir; } 79 ClassPathDirEntry(const char* dir) { 80 _dir = copy_path(dir); 81 } 82 virtual ~ClassPathDirEntry() {} 83 ClassFileStream* open_stream(const char* name, TRAPS); 84 }; 85 86 // Type definitions for zip file and zip file entry 87 typedef void* jzfile; 88 typedef struct { 89 char *name; /* entry name */ 90 jlong time; /* modification time */ 91 jlong size; /* size of uncompressed data */ 92 jlong csize; /* size of compressed data (zero if uncompressed) */ 93 jint crc; /* crc of uncompressed data */ 94 char *comment; /* optional zip file comment */ 95 jbyte *extra; /* optional extra data */ 96 jlong pos; /* position of LOC header (if negative) or data */ 97 } jzentry; 98 99 class ClassPathZipEntry: public ClassPathEntry { 100 private: 101 jzfile* _zip; // The zip archive 102 const char* _zip_name; // Name of zip archive 103 bool _from_class_path_attr; // From the "Class-path" attribute of a jar file 104 public: 105 bool is_jar_file() const { return true; } 106 bool from_class_path_attr() const { return _from_class_path_attr; } 107 const char* name() const { return _zip_name; } 108 ClassPathZipEntry(jzfile* zip, const char* zip_name, bool is_boot_append, bool from_class_path_attr); 109 virtual ~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 }; 114 115 116 // For java image files 117 class ClassPathImageEntry: public ClassPathEntry { 118 private: 119 JImageFile* _jimage; 120 const char* _name; 121 DEBUG_ONLY(static ClassPathImageEntry* _singleton;) 122 public: 123 bool is_modules_image() const; 124 bool is_open() const { return _jimage != NULL; } 125 const char* name() const { return _name == NULL ? "" : _name; } 126 JImageFile* jimage() const { return _jimage; } 127 void close_jimage(); 128 ClassPathImageEntry(JImageFile* jimage, const char* name); 129 virtual ~ClassPathImageEntry(); 130 ClassFileStream* open_stream(const char* name, TRAPS); 131 ClassFileStream* open_stream_for_loader(const char* name, ClassLoaderData* loader_data, TRAPS); 132 }; 133 134 // ModuleClassPathList contains a linked list of ClassPathEntry's 135 // that have been specified for a specific module. Currently, 136 // the only way to specify a module/path pair is via the --patch-module 137 // command line option. 138 class ModuleClassPathList : public CHeapObj<mtClass> { 139 private: 140 Symbol* _module_name; 141 // First and last entries of class path entries for a specific module 142 ClassPathEntry* _module_first_entry; 143 ClassPathEntry* _module_last_entry; 144 public: 145 Symbol* module_name() const { return _module_name; } 146 ClassPathEntry* module_first_entry() const { return _module_first_entry; } 147 ModuleClassPathList(Symbol* module_name); 148 ~ModuleClassPathList(); 149 void add_to_list(ClassPathEntry* new_entry); 150 }; 151 152 class ClassLoader: AllStatic { 153 public: 154 enum ClassLoaderType { 155 BOOT_LOADER = 1, /* boot loader */ 156 PLATFORM_LOADER = 2, /* PlatformClassLoader */ 157 APP_LOADER = 3 /* AppClassLoader */ 158 }; 159 protected: 160 161 // Performance counters 162 static PerfCounter* _perf_accumulated_time; 163 static PerfCounter* _perf_classes_inited; 164 static PerfCounter* _perf_class_init_time; 165 static PerfCounter* _perf_class_init_selftime; 166 static PerfCounter* _perf_classes_verified; 167 static PerfCounter* _perf_class_verify_time; 168 static PerfCounter* _perf_class_verify_selftime; 169 static PerfCounter* _perf_classes_linked; 170 static PerfCounter* _perf_class_link_time; 171 static PerfCounter* _perf_class_link_selftime; 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 211 // build with exploded modules is being used instead. 212 static ClassPathEntry* _jrt_entry; 213 static GrowableArray<ModuleClassPathList*>* _exploded_entries; 214 enum { EXPLODED_ENTRY_SIZE = 80 }; // Initial number of exploded modules 215 216 // 3. the boot loader's append path 217 // [-Xbootclasspath/a]; [jvmti appended entries] 218 // Note: boot loader append path does not support named modules. 219 static ClassPathEntry* _first_append_entry; 220 // Last entry in linked list of appended ClassPathEntry instances 221 static ClassPathEntry* _last_append_entry; 222 223 // Info used by CDS 224 CDS_ONLY(static ClassPathEntry* _app_classpath_entries;) 225 CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;) 226 CDS_ONLY(static ClassPathEntry* _module_path_entries;) 227 CDS_ONLY(static ClassPathEntry* _last_module_path_entry;) 228 CDS_ONLY(static void setup_app_search_path(const char* class_path);) 229 CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);) 230 static void add_to_app_classpath_entries(const char* path, 231 ClassPathEntry* entry, 232 bool check_for_duplicates); 233 CDS_ONLY(static void add_to_module_path_entries(const char* path, 234 ClassPathEntry* entry);) 235 public: 236 CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;}) 237 CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;}) 238 239 protected: 240 // Initialization: 241 // - setup the boot loader's system class path 242 // - setup the boot loader's patch mod entries, if present 243 // - create the ModuleEntry for java.base 388 389 static ClassPathEntry* get_next_boot_classpath_entry(ClassPathEntry* e); 390 391 // Helper function used by CDS code to get the number of app classpath 392 // entries during shared classpath setup time. 393 static int num_app_classpath_entries(); 394 395 // Helper function used by CDS code to get the number of module path 396 // entries during shared classpath setup time. 397 static int num_module_path_entries() { 398 assert(DumpSharedSpaces || DynamicDumpSharedSpaces, 399 "Should only be called at CDS dump time"); 400 int num_entries = 0; 401 ClassPathEntry* e= ClassLoader::_module_path_entries; 402 while (e != NULL) { 403 num_entries ++; 404 e = e->next(); 405 } 406 return num_entries; 407 } 408 static void exit_with_path_failure(const char* error, const char* message); 409 static char* skip_uri_protocol(char* source); 410 static void record_result(InstanceKlass* ik, const ClassFileStream* stream, TRAPS); 411 #endif 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 = NULL); 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 426 // indicates if class path already contains a entry (exact match by name) 427 static bool contains_append_entry(const char* name); |