Fri, 06 Jun 2008 13:43:36 -0400
Merge
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // The VM class loader. |
duke@435 | 26 | #include <sys/stat.h> |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | // Meta-index (optional, to be able to skip opening boot classpath jar files) |
duke@435 | 30 | class MetaIndex: public CHeapObj { |
duke@435 | 31 | private: |
duke@435 | 32 | char** _meta_package_names; |
duke@435 | 33 | int _num_meta_package_names; |
duke@435 | 34 | public: |
duke@435 | 35 | MetaIndex(char** meta_package_names, int num_meta_package_names); |
duke@435 | 36 | ~MetaIndex(); |
duke@435 | 37 | bool may_contain(const char* class_name); |
duke@435 | 38 | }; |
duke@435 | 39 | |
duke@435 | 40 | |
duke@435 | 41 | // Class path entry (directory or zip file) |
duke@435 | 42 | |
duke@435 | 43 | class ClassPathEntry: public CHeapObj { |
duke@435 | 44 | private: |
duke@435 | 45 | ClassPathEntry* _next; |
duke@435 | 46 | public: |
duke@435 | 47 | // Next entry in class path |
duke@435 | 48 | ClassPathEntry* next() { return _next; } |
duke@435 | 49 | void set_next(ClassPathEntry* next) { |
duke@435 | 50 | // may have unlocked readers, so write atomically. |
duke@435 | 51 | OrderAccess::release_store_ptr(&_next, next); |
duke@435 | 52 | } |
duke@435 | 53 | virtual bool is_jar_file() = 0; |
duke@435 | 54 | virtual const char* name() = 0; |
duke@435 | 55 | virtual bool is_lazy(); |
duke@435 | 56 | // Constructor |
duke@435 | 57 | ClassPathEntry(); |
duke@435 | 58 | // Attempt to locate file_name through this class path entry. |
duke@435 | 59 | // Returns a class file parsing stream if successfull. |
duke@435 | 60 | virtual ClassFileStream* open_stream(const char* name) = 0; |
duke@435 | 61 | // Debugging |
duke@435 | 62 | NOT_PRODUCT(virtual void compile_the_world(Handle loader, TRAPS) = 0;) |
duke@435 | 63 | NOT_PRODUCT(virtual bool is_rt_jar() = 0;) |
duke@435 | 64 | }; |
duke@435 | 65 | |
duke@435 | 66 | |
duke@435 | 67 | class ClassPathDirEntry: public ClassPathEntry { |
duke@435 | 68 | private: |
duke@435 | 69 | char* _dir; // Name of directory |
duke@435 | 70 | public: |
duke@435 | 71 | bool is_jar_file() { return false; } |
duke@435 | 72 | const char* name() { return _dir; } |
duke@435 | 73 | ClassPathDirEntry(char* dir); |
duke@435 | 74 | ClassFileStream* open_stream(const char* name); |
duke@435 | 75 | // Debugging |
duke@435 | 76 | NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);) |
duke@435 | 77 | NOT_PRODUCT(bool is_rt_jar();) |
duke@435 | 78 | }; |
duke@435 | 79 | |
duke@435 | 80 | |
duke@435 | 81 | // Type definitions for zip file and zip file entry |
duke@435 | 82 | typedef void* jzfile; |
duke@435 | 83 | typedef struct { |
duke@435 | 84 | char *name; /* entry name */ |
duke@435 | 85 | jlong time; /* modification time */ |
duke@435 | 86 | jlong size; /* size of uncompressed data */ |
duke@435 | 87 | jlong csize; /* size of compressed data (zero if uncompressed) */ |
duke@435 | 88 | jint crc; /* crc of uncompressed data */ |
duke@435 | 89 | char *comment; /* optional zip file comment */ |
duke@435 | 90 | jbyte *extra; /* optional extra data */ |
duke@435 | 91 | jlong pos; /* position of LOC header (if negative) or data */ |
duke@435 | 92 | } jzentry; |
duke@435 | 93 | |
duke@435 | 94 | |
duke@435 | 95 | class ClassPathZipEntry: public ClassPathEntry { |
duke@435 | 96 | private: |
duke@435 | 97 | jzfile* _zip; // The zip archive |
duke@435 | 98 | char* _zip_name; // Name of zip archive |
duke@435 | 99 | public: |
duke@435 | 100 | bool is_jar_file() { return true; } |
duke@435 | 101 | const char* name() { return _zip_name; } |
duke@435 | 102 | ClassPathZipEntry(jzfile* zip, const char* zip_name); |
duke@435 | 103 | ~ClassPathZipEntry(); |
duke@435 | 104 | ClassFileStream* open_stream(const char* name); |
duke@435 | 105 | void contents_do(void f(const char* name, void* context), void* context); |
duke@435 | 106 | // Debugging |
duke@435 | 107 | NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);) |
duke@435 | 108 | NOT_PRODUCT(void compile_the_world12(Handle loader, TRAPS);) // JDK 1.2 version |
duke@435 | 109 | NOT_PRODUCT(void compile_the_world13(Handle loader, TRAPS);) // JDK 1.3 version |
duke@435 | 110 | NOT_PRODUCT(bool is_rt_jar();) |
duke@435 | 111 | NOT_PRODUCT(bool is_rt_jar12();) |
duke@435 | 112 | NOT_PRODUCT(bool is_rt_jar13();) |
duke@435 | 113 | }; |
duke@435 | 114 | |
duke@435 | 115 | |
duke@435 | 116 | // For lazier loading of boot class path entries |
duke@435 | 117 | class LazyClassPathEntry: public ClassPathEntry { |
duke@435 | 118 | private: |
duke@435 | 119 | char* _path; // dir or file |
duke@435 | 120 | struct stat _st; |
duke@435 | 121 | MetaIndex* _meta_index; |
duke@435 | 122 | volatile ClassPathEntry* _resolved_entry; |
duke@435 | 123 | ClassPathEntry* resolve_entry(); |
duke@435 | 124 | public: |
duke@435 | 125 | bool is_jar_file(); |
duke@435 | 126 | const char* name() { return _path; } |
duke@435 | 127 | LazyClassPathEntry(char* path, struct stat st); |
duke@435 | 128 | ClassFileStream* open_stream(const char* name); |
duke@435 | 129 | void set_meta_index(MetaIndex* meta_index) { _meta_index = meta_index; } |
duke@435 | 130 | virtual bool is_lazy(); |
duke@435 | 131 | // Debugging |
duke@435 | 132 | NOT_PRODUCT(void compile_the_world(Handle loader, TRAPS);) |
duke@435 | 133 | NOT_PRODUCT(bool is_rt_jar();) |
duke@435 | 134 | }; |
duke@435 | 135 | |
duke@435 | 136 | class PackageHashtable; |
duke@435 | 137 | class PackageInfo; |
duke@435 | 138 | class HashtableBucket; |
duke@435 | 139 | |
duke@435 | 140 | class ClassLoader: AllStatic { |
duke@435 | 141 | public: |
duke@435 | 142 | enum SomeConstants { |
duke@435 | 143 | package_hash_table_size = 31 // Number of buckets |
duke@435 | 144 | }; |
duke@435 | 145 | private: |
duke@435 | 146 | friend class LazyClassPathEntry; |
duke@435 | 147 | |
duke@435 | 148 | // Performance counters |
duke@435 | 149 | static PerfCounter* _perf_accumulated_time; |
duke@435 | 150 | static PerfCounter* _perf_classes_inited; |
duke@435 | 151 | static PerfCounter* _perf_class_init_time; |
duke@435 | 152 | static PerfCounter* _perf_class_verify_time; |
duke@435 | 153 | static PerfCounter* _perf_classes_linked; |
duke@435 | 154 | static PerfCounter* _perf_class_link_time; |
duke@435 | 155 | |
duke@435 | 156 | static PerfCounter* _sync_systemLoaderLockContentionRate; |
duke@435 | 157 | static PerfCounter* _sync_nonSystemLoaderLockContentionRate; |
duke@435 | 158 | static PerfCounter* _sync_JVMFindLoadedClassLockFreeCounter; |
duke@435 | 159 | static PerfCounter* _sync_JVMDefineClassLockFreeCounter; |
duke@435 | 160 | static PerfCounter* _sync_JNIDefineClassLockFreeCounter; |
duke@435 | 161 | |
duke@435 | 162 | static PerfCounter* _unsafe_defineClassCallCounter; |
duke@435 | 163 | static PerfCounter* _isUnsyncloadClass; |
duke@435 | 164 | static PerfCounter* _load_instance_class_failCounter; |
duke@435 | 165 | |
duke@435 | 166 | // First entry in linked list of ClassPathEntry instances |
duke@435 | 167 | static ClassPathEntry* _first_entry; |
duke@435 | 168 | // Last entry in linked list of ClassPathEntry instances |
duke@435 | 169 | static ClassPathEntry* _last_entry; |
duke@435 | 170 | // Hash table used to keep track of loaded packages |
duke@435 | 171 | static PackageHashtable* _package_hash_table; |
duke@435 | 172 | static const char* _shared_archive; |
duke@435 | 173 | |
duke@435 | 174 | // Hash function |
duke@435 | 175 | static unsigned int hash(const char *s, int n); |
duke@435 | 176 | // Returns the package file name corresponding to the specified package |
duke@435 | 177 | // or class name, or null if not found. |
duke@435 | 178 | static PackageInfo* lookup_package(const char *pkgname); |
duke@435 | 179 | // Adds a new package entry for the specified class or package name and |
duke@435 | 180 | // corresponding directory or jar file name. |
duke@435 | 181 | static bool add_package(const char *pkgname, int classpath_index, TRAPS); |
duke@435 | 182 | |
duke@435 | 183 | // Initialization |
duke@435 | 184 | static void setup_meta_index(); |
duke@435 | 185 | static void setup_bootstrap_search_path(); |
duke@435 | 186 | static void load_zip_library(); |
duke@435 | 187 | static void create_class_path_entry(char *path, struct stat st, ClassPathEntry **new_entry, bool lazy); |
duke@435 | 188 | |
duke@435 | 189 | // Canonicalizes path names, so strcmp will work properly. This is mainly |
duke@435 | 190 | // to avoid confusing the zip library |
duke@435 | 191 | static bool get_canonical_path(char* orig, char* out, int len); |
duke@435 | 192 | public: |
duke@435 | 193 | // Used by the kernel jvm. |
duke@435 | 194 | static void update_class_path_entry_list(const char *path, |
duke@435 | 195 | bool check_for_duplicates); |
duke@435 | 196 | static void print_bootclasspath(); |
duke@435 | 197 | |
duke@435 | 198 | // Timing |
duke@435 | 199 | static PerfCounter* perf_accumulated_time() { return _perf_accumulated_time; } |
duke@435 | 200 | static PerfCounter* perf_classes_inited() { return _perf_classes_inited; } |
duke@435 | 201 | static PerfCounter* perf_class_init_time() { return _perf_class_init_time; } |
duke@435 | 202 | static PerfCounter* perf_class_verify_time() { return _perf_class_verify_time; } |
duke@435 | 203 | static PerfCounter* perf_classes_linked() { return _perf_classes_linked; } |
duke@435 | 204 | static PerfCounter* perf_class_link_time() { return _perf_class_link_time; } |
duke@435 | 205 | |
duke@435 | 206 | // Record how often system loader lock object is contended |
duke@435 | 207 | static PerfCounter* sync_systemLoaderLockContentionRate() { |
duke@435 | 208 | return _sync_systemLoaderLockContentionRate; |
duke@435 | 209 | } |
duke@435 | 210 | |
duke@435 | 211 | // Record how often non system loader lock object is contended |
duke@435 | 212 | static PerfCounter* sync_nonSystemLoaderLockContentionRate() { |
duke@435 | 213 | return _sync_nonSystemLoaderLockContentionRate; |
duke@435 | 214 | } |
duke@435 | 215 | |
duke@435 | 216 | // Record how many calls to JVM_FindLoadedClass w/o holding a lock |
duke@435 | 217 | static PerfCounter* sync_JVMFindLoadedClassLockFreeCounter() { |
duke@435 | 218 | return _sync_JVMFindLoadedClassLockFreeCounter; |
duke@435 | 219 | } |
duke@435 | 220 | |
duke@435 | 221 | // Record how many calls to JVM_DefineClass w/o holding a lock |
duke@435 | 222 | static PerfCounter* sync_JVMDefineClassLockFreeCounter() { |
duke@435 | 223 | return _sync_JVMDefineClassLockFreeCounter; |
duke@435 | 224 | } |
duke@435 | 225 | |
duke@435 | 226 | // Record how many calls to jni_DefineClass w/o holding a lock |
duke@435 | 227 | static PerfCounter* sync_JNIDefineClassLockFreeCounter() { |
duke@435 | 228 | return _sync_JNIDefineClassLockFreeCounter; |
duke@435 | 229 | } |
duke@435 | 230 | |
duke@435 | 231 | // Record how many calls to Unsafe_DefineClass |
duke@435 | 232 | static PerfCounter* unsafe_defineClassCallCounter() { |
duke@435 | 233 | return _unsafe_defineClassCallCounter; |
duke@435 | 234 | } |
duke@435 | 235 | |
duke@435 | 236 | // Record how many times SystemDictionary::load_instance_class call |
duke@435 | 237 | // fails with linkageError when Unsyncloadclass flag is set. |
duke@435 | 238 | static PerfCounter* load_instance_class_failCounter() { |
duke@435 | 239 | return _load_instance_class_failCounter; |
duke@435 | 240 | } |
duke@435 | 241 | |
duke@435 | 242 | // Load individual .class file |
duke@435 | 243 | static instanceKlassHandle load_classfile(symbolHandle h_name, TRAPS); |
duke@435 | 244 | |
duke@435 | 245 | // If the specified package has been loaded by the system, then returns |
duke@435 | 246 | // the name of the directory or ZIP file that the package was loaded from. |
duke@435 | 247 | // Returns null if the package was not loaded. |
duke@435 | 248 | // Note: The specified name can either be the name of a class or package. |
duke@435 | 249 | // If a package name is specified, then it must be "/"-separator and also |
duke@435 | 250 | // end with a trailing "/". |
duke@435 | 251 | static oop get_system_package(const char* name, TRAPS); |
duke@435 | 252 | |
duke@435 | 253 | // Returns an array of Java strings representing all of the currently |
duke@435 | 254 | // loaded system packages. |
duke@435 | 255 | // Note: The package names returned are "/"-separated and end with a |
duke@435 | 256 | // trailing "/". |
duke@435 | 257 | static objArrayOop get_system_packages(TRAPS); |
duke@435 | 258 | |
duke@435 | 259 | // Initialization |
duke@435 | 260 | static void initialize(); |
duke@435 | 261 | static void create_package_info_table(); |
duke@435 | 262 | static void create_package_info_table(HashtableBucket *t, int length, |
duke@435 | 263 | int number_of_entries); |
duke@435 | 264 | static int compute_Object_vtable(); |
duke@435 | 265 | |
duke@435 | 266 | static ClassPathEntry* classpath_entry(int n) { |
duke@435 | 267 | ClassPathEntry* e = ClassLoader::_first_entry; |
duke@435 | 268 | while (--n >= 0) { |
duke@435 | 269 | assert(e != NULL, "Not that many classpath entries."); |
duke@435 | 270 | e = e->next(); |
duke@435 | 271 | } |
duke@435 | 272 | return e; |
duke@435 | 273 | } |
duke@435 | 274 | |
duke@435 | 275 | // Sharing dump and restore |
duke@435 | 276 | static void copy_package_info_buckets(char** top, char* end); |
duke@435 | 277 | static void copy_package_info_table(char** top, char* end); |
duke@435 | 278 | |
duke@435 | 279 | // VM monitoring and management support |
duke@435 | 280 | static jlong classloader_time_ms(); |
duke@435 | 281 | static jlong class_method_total_size(); |
duke@435 | 282 | static jlong class_init_count(); |
duke@435 | 283 | static jlong class_init_time_ms(); |
duke@435 | 284 | static jlong class_verify_time_ms(); |
duke@435 | 285 | static jlong class_link_count(); |
duke@435 | 286 | static jlong class_link_time_ms(); |
duke@435 | 287 | |
duke@435 | 288 | // indicates if class path already contains a entry (exact match by name) |
duke@435 | 289 | static bool contains_entry(ClassPathEntry* entry); |
duke@435 | 290 | |
duke@435 | 291 | // adds a class path list |
duke@435 | 292 | static void add_to_list(ClassPathEntry* new_entry); |
duke@435 | 293 | |
duke@435 | 294 | // creates a class path zip entry (returns NULL if JAR file cannot be opened) |
duke@435 | 295 | static ClassPathZipEntry* create_class_path_zip_entry(const char *apath); |
duke@435 | 296 | |
duke@435 | 297 | // Debugging |
duke@435 | 298 | static void verify() PRODUCT_RETURN; |
duke@435 | 299 | |
duke@435 | 300 | // Force compilation of all methods in all classes in bootstrap class path (stress test) |
duke@435 | 301 | #ifndef PRODUCT |
duke@435 | 302 | private: |
duke@435 | 303 | static int _compile_the_world_counter; |
duke@435 | 304 | public: |
duke@435 | 305 | static void compile_the_world(); |
duke@435 | 306 | static void compile_the_world_in(char* name, Handle loader, TRAPS); |
duke@435 | 307 | static int compile_the_world_counter() { return _compile_the_world_counter; } |
duke@435 | 308 | #endif //PRODUCT |
duke@435 | 309 | }; |