Sat, 01 Dec 2007 00:00:00 +0000
Initial load
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 system dictionary stores all loaded classes and maps: |
duke@435 | 26 | // |
duke@435 | 27 | // [class name,class loader] -> class i.e. [symbolOop,oop] -> klassOop |
duke@435 | 28 | // |
duke@435 | 29 | // Classes are loaded lazily. The default VM class loader is |
duke@435 | 30 | // represented as NULL. |
duke@435 | 31 | |
duke@435 | 32 | // The underlying data structure is an open hash table with a fixed number |
duke@435 | 33 | // of buckets. During loading the loader object is locked, (for the VM loader |
duke@435 | 34 | // a private lock object is used). Class loading can thus be done concurrently, |
duke@435 | 35 | // but only by different loaders. |
duke@435 | 36 | // |
duke@435 | 37 | // During loading a placeholder (name, loader) is temporarily placed in |
duke@435 | 38 | // a side data structure, and is used to detect ClassCircularityErrors |
duke@435 | 39 | // and to perform verification during GC. A GC can occur in the midst |
duke@435 | 40 | // of class loading, as we call out to Java, have to take locks, etc. |
duke@435 | 41 | // |
duke@435 | 42 | // When class loading is finished, a new entry is added to the system |
duke@435 | 43 | // dictionary and the place holder is removed. Note that the protection |
duke@435 | 44 | // domain field of the system dictionary has not yet been filled in when |
duke@435 | 45 | // the "real" system dictionary entry is created. |
duke@435 | 46 | // |
duke@435 | 47 | // Clients of this class who are interested in finding if a class has |
duke@435 | 48 | // been completely loaded -- not classes in the process of being loaded -- |
duke@435 | 49 | // can read the SystemDictionary unlocked. This is safe because |
duke@435 | 50 | // - entries are only deleted at safepoints |
duke@435 | 51 | // - readers cannot come to a safepoint while actively examining |
duke@435 | 52 | // an entry (an entry cannot be deleted from under a reader) |
duke@435 | 53 | // - entries must be fully formed before they are available to concurrent |
duke@435 | 54 | // readers (we must ensure write ordering) |
duke@435 | 55 | // |
duke@435 | 56 | // Note that placeholders are deleted at any time, as they are removed |
duke@435 | 57 | // when a class is completely loaded. Therefore, readers as well as writers |
duke@435 | 58 | // of placeholders must hold the SystemDictionary_lock. |
duke@435 | 59 | // |
duke@435 | 60 | |
duke@435 | 61 | class Dictionary; |
duke@435 | 62 | class PlaceholderTable; |
duke@435 | 63 | class LoaderConstraintTable; |
duke@435 | 64 | class HashtableBucket; |
duke@435 | 65 | class ResolutionErrorTable; |
duke@435 | 66 | |
duke@435 | 67 | class SystemDictionary : AllStatic { |
duke@435 | 68 | friend class VMStructs; |
duke@435 | 69 | friend class CompactingPermGenGen; |
duke@435 | 70 | NOT_PRODUCT(friend class instanceKlassKlass;) |
duke@435 | 71 | |
duke@435 | 72 | public: |
duke@435 | 73 | // Returns a class with a given class name and class loader. Loads the |
duke@435 | 74 | // class if needed. If not found a NoClassDefFoundError or a |
duke@435 | 75 | // ClassNotFoundException is thrown, depending on the value on the |
duke@435 | 76 | // throw_error flag. For most uses the throw_error argument should be set |
duke@435 | 77 | // to true. |
duke@435 | 78 | |
duke@435 | 79 | static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); |
duke@435 | 80 | // Convenient call for null loader and protection domain. |
duke@435 | 81 | static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS); |
duke@435 | 82 | private: |
duke@435 | 83 | // handle error translation for resolve_or_null results |
duke@435 | 84 | static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS); |
duke@435 | 85 | |
duke@435 | 86 | public: |
duke@435 | 87 | |
duke@435 | 88 | // Returns a class with a given class name and class loader. |
duke@435 | 89 | // Loads the class if needed. If not found NULL is returned. |
duke@435 | 90 | static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 91 | // Version with null loader and protection domain |
duke@435 | 92 | static klassOop resolve_or_null(symbolHandle class_name, TRAPS); |
duke@435 | 93 | |
duke@435 | 94 | // Resolve a superclass or superinterface. Called from ClassFileParser, |
duke@435 | 95 | // parse_interfaces, resolve_instance_class_or_null, load_shared_class |
duke@435 | 96 | // "child_name" is the class whose super class or interface is being resolved. |
duke@435 | 97 | static klassOop resolve_super_or_fail(symbolHandle child_name, |
duke@435 | 98 | symbolHandle class_name, |
duke@435 | 99 | Handle class_loader, |
duke@435 | 100 | Handle protection_domain, |
duke@435 | 101 | bool is_superclass, |
duke@435 | 102 | TRAPS); |
duke@435 | 103 | |
duke@435 | 104 | // Parse new stream. This won't update the system dictionary or |
duke@435 | 105 | // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. |
duke@435 | 106 | static klassOop parse_stream(symbolHandle class_name, |
duke@435 | 107 | Handle class_loader, |
duke@435 | 108 | Handle protection_domain, |
duke@435 | 109 | ClassFileStream* st, |
duke@435 | 110 | TRAPS); |
duke@435 | 111 | |
duke@435 | 112 | // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) |
duke@435 | 113 | static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, Handle protection_domain, ClassFileStream* st, TRAPS); |
duke@435 | 114 | |
duke@435 | 115 | // Lookup an already loaded class. If not found NULL is returned. |
duke@435 | 116 | static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 117 | |
duke@435 | 118 | // Lookup an already loaded instance or array class. |
duke@435 | 119 | // Do not make any queries to class loaders; consult only the cache. |
duke@435 | 120 | // If not found NULL is returned. |
duke@435 | 121 | static klassOop find_instance_or_array_klass(symbolHandle class_name, |
duke@435 | 122 | Handle class_loader, |
duke@435 | 123 | Handle protection_domain, |
duke@435 | 124 | TRAPS); |
duke@435 | 125 | |
duke@435 | 126 | // Lookup an instance or array class that has already been loaded |
duke@435 | 127 | // either into the given class loader, or else into another class |
duke@435 | 128 | // loader that is constrained (via loader constraints) to produce |
duke@435 | 129 | // a consistent class. Do not take protection domains into account. |
duke@435 | 130 | // Do not make any queries to class loaders; consult only the cache. |
duke@435 | 131 | // Return NULL if the class is not found. |
duke@435 | 132 | // |
duke@435 | 133 | // This function is a strict superset of find_instance_or_array_klass. |
duke@435 | 134 | // This function (the unchecked version) makes a conservative prediction |
duke@435 | 135 | // of the result of the checked version, assuming successful lookup. |
duke@435 | 136 | // If both functions return non-null, they must return the same value. |
duke@435 | 137 | // Also, the unchecked version may sometimes be non-null where the |
duke@435 | 138 | // checked version is null. This can occur in several ways: |
duke@435 | 139 | // 1. No query has yet been made to the class loader. |
duke@435 | 140 | // 2. The class loader was queried, but chose not to delegate. |
duke@435 | 141 | // 3. ClassLoader.checkPackageAccess rejected a proposed protection domain. |
duke@435 | 142 | // 4. Loading was attempted, but there was a linkage error of some sort. |
duke@435 | 143 | // In all of these cases, the loader constraints on this type are |
duke@435 | 144 | // satisfied, and it is safe for classes in the given class loader |
duke@435 | 145 | // to manipulate strongly-typed values of the found class, subject |
duke@435 | 146 | // to local linkage and access checks. |
duke@435 | 147 | static klassOop find_constrained_instance_or_array_klass(symbolHandle class_name, |
duke@435 | 148 | Handle class_loader, |
duke@435 | 149 | TRAPS); |
duke@435 | 150 | |
duke@435 | 151 | // Iterate over all klasses in dictionary |
duke@435 | 152 | // Just the classes from defining class loaders |
duke@435 | 153 | static void classes_do(void f(klassOop)); |
duke@435 | 154 | // Added for initialize_itable_for_klass to handle exceptions |
duke@435 | 155 | static void classes_do(void f(klassOop, TRAPS), TRAPS); |
duke@435 | 156 | // All classes, and their class loaders |
duke@435 | 157 | static void classes_do(void f(klassOop, oop)); |
duke@435 | 158 | // All classes, and their class loaders |
duke@435 | 159 | // (added for helpers that use HandleMarks and ResourceMarks) |
duke@435 | 160 | static void classes_do(void f(klassOop, oop, TRAPS), TRAPS); |
duke@435 | 161 | // All entries in the placeholder table and their class loaders |
duke@435 | 162 | static void placeholders_do(void f(symbolOop, oop)); |
duke@435 | 163 | |
duke@435 | 164 | // Iterate over all methods in all klasses in dictionary |
duke@435 | 165 | static void methods_do(void f(methodOop)); |
duke@435 | 166 | |
duke@435 | 167 | // Garbage collection support |
duke@435 | 168 | |
duke@435 | 169 | // This method applies "blk->do_oop" to all the pointers to "system" |
duke@435 | 170 | // classes and loaders. |
duke@435 | 171 | static void always_strong_oops_do(OopClosure* blk); |
duke@435 | 172 | static void always_strong_classes_do(OopClosure* blk); |
duke@435 | 173 | // This method applies "blk->do_oop" to all the placeholders. |
duke@435 | 174 | static void placeholders_do(OopClosure* blk); |
duke@435 | 175 | |
duke@435 | 176 | // Unload (that is, break root links to) all unmarked classes and |
duke@435 | 177 | // loaders. Returns "true" iff something was unloaded. |
duke@435 | 178 | static bool do_unloading(BoolObjectClosure* is_alive); |
duke@435 | 179 | |
duke@435 | 180 | // Applies "f->do_oop" to all root oops in the system dictionary. |
duke@435 | 181 | static void oops_do(OopClosure* f); |
duke@435 | 182 | |
duke@435 | 183 | // System loader lock |
duke@435 | 184 | static oop system_loader_lock() { return _system_loader_lock_obj; } |
duke@435 | 185 | |
duke@435 | 186 | private: |
duke@435 | 187 | // Traverses preloaded oops: various system classes. These are |
duke@435 | 188 | // guaranteed to be in the perm gen. |
duke@435 | 189 | static void preloaded_oops_do(OopClosure* f); |
duke@435 | 190 | static void lazily_loaded_oops_do(OopClosure* f); |
duke@435 | 191 | |
duke@435 | 192 | public: |
duke@435 | 193 | // Sharing support. |
duke@435 | 194 | static void reorder_dictionary(); |
duke@435 | 195 | static void copy_buckets(char** top, char* end); |
duke@435 | 196 | static void copy_table(char** top, char* end); |
duke@435 | 197 | static void reverse(); |
duke@435 | 198 | static void set_shared_dictionary(HashtableBucket* t, int length, |
duke@435 | 199 | int number_of_entries); |
duke@435 | 200 | // Printing |
duke@435 | 201 | static void print() PRODUCT_RETURN; |
duke@435 | 202 | static void print_class_statistics() PRODUCT_RETURN; |
duke@435 | 203 | static void print_method_statistics() PRODUCT_RETURN; |
duke@435 | 204 | |
duke@435 | 205 | // Number of contained klasses |
duke@435 | 206 | // This is both fully loaded classes and classes in the process |
duke@435 | 207 | // of being loaded |
duke@435 | 208 | static int number_of_classes(); |
duke@435 | 209 | |
duke@435 | 210 | // Monotonically increasing counter which grows as classes are |
duke@435 | 211 | // loaded or modifications such as hot-swapping or setting/removing |
duke@435 | 212 | // of breakpoints are performed |
duke@435 | 213 | static inline int number_of_modifications() { assert_locked_or_safepoint(Compile_lock); return _number_of_modifications; } |
duke@435 | 214 | // Needed by evolution and breakpoint code |
duke@435 | 215 | static inline void notice_modification() { assert_locked_or_safepoint(Compile_lock); ++_number_of_modifications; } |
duke@435 | 216 | |
duke@435 | 217 | // Verification |
duke@435 | 218 | static void verify(); |
duke@435 | 219 | |
duke@435 | 220 | #ifdef ASSERT |
duke@435 | 221 | static bool is_internal_format(symbolHandle class_name); |
duke@435 | 222 | #endif |
duke@435 | 223 | |
duke@435 | 224 | // Verify class is in dictionary |
duke@435 | 225 | static void verify_obj_klass_present(Handle obj, |
duke@435 | 226 | symbolHandle class_name, |
duke@435 | 227 | Handle class_loader); |
duke@435 | 228 | |
duke@435 | 229 | // Initialization |
duke@435 | 230 | static void initialize(TRAPS); |
duke@435 | 231 | |
duke@435 | 232 | // Fast access to commonly used classes (preloaded) |
duke@435 | 233 | static klassOop check_klass(klassOop k) { |
duke@435 | 234 | assert(k != NULL, "preloaded klass not initialized"); |
duke@435 | 235 | return k; |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | public: |
duke@435 | 239 | static klassOop object_klass() { return check_klass(_object_klass); } |
duke@435 | 240 | static klassOop string_klass() { return check_klass(_string_klass); } |
duke@435 | 241 | static klassOop class_klass() { return check_klass(_class_klass); } |
duke@435 | 242 | static klassOop cloneable_klass() { return check_klass(_cloneable_klass); } |
duke@435 | 243 | static klassOop classloader_klass() { return check_klass(_classloader_klass); } |
duke@435 | 244 | static klassOop serializable_klass() { return check_klass(_serializable_klass); } |
duke@435 | 245 | static klassOop system_klass() { return check_klass(_system_klass); } |
duke@435 | 246 | |
duke@435 | 247 | static klassOop throwable_klass() { return check_klass(_throwable_klass); } |
duke@435 | 248 | static klassOop error_klass() { return check_klass(_error_klass); } |
duke@435 | 249 | static klassOop threaddeath_klass() { return check_klass(_threaddeath_klass); } |
duke@435 | 250 | static klassOop exception_klass() { return check_klass(_exception_klass); } |
duke@435 | 251 | static klassOop runtime_exception_klass() { return check_klass(_runtime_exception_klass); } |
duke@435 | 252 | static klassOop classNotFoundException_klass() { return check_klass(_classNotFoundException_klass); } |
duke@435 | 253 | static klassOop noClassDefFoundError_klass() { return check_klass(_noClassDefFoundError_klass); } |
duke@435 | 254 | static klassOop linkageError_klass() { return check_klass(_linkageError_klass); } |
duke@435 | 255 | static klassOop ClassCastException_klass() { return check_klass(_classCastException_klass); } |
duke@435 | 256 | static klassOop ArrayStoreException_klass() { return check_klass(_arrayStoreException_klass); } |
duke@435 | 257 | static klassOop virtualMachineError_klass() { return check_klass(_virtualMachineError_klass); } |
duke@435 | 258 | static klassOop OutOfMemoryError_klass() { return check_klass(_outOfMemoryError_klass); } |
duke@435 | 259 | static klassOop StackOverflowError_klass() { return check_klass(_StackOverflowError_klass); } |
duke@435 | 260 | static klassOop IllegalMonitorStateException_klass() { return check_klass(_illegalMonitorStateException_klass); } |
duke@435 | 261 | static klassOop protectionDomain_klass() { return check_klass(_protectionDomain_klass); } |
duke@435 | 262 | static klassOop AccessControlContext_klass() { return check_klass(_AccessControlContext_klass); } |
duke@435 | 263 | static klassOop reference_klass() { return check_klass(_reference_klass); } |
duke@435 | 264 | static klassOop soft_reference_klass() { return check_klass(_soft_reference_klass); } |
duke@435 | 265 | static klassOop weak_reference_klass() { return check_klass(_weak_reference_klass); } |
duke@435 | 266 | static klassOop final_reference_klass() { return check_klass(_final_reference_klass); } |
duke@435 | 267 | static klassOop phantom_reference_klass() { return check_klass(_phantom_reference_klass); } |
duke@435 | 268 | static klassOop finalizer_klass() { return check_klass(_finalizer_klass); } |
duke@435 | 269 | |
duke@435 | 270 | static klassOop thread_klass() { return check_klass(_thread_klass); } |
duke@435 | 271 | static klassOop threadGroup_klass() { return check_klass(_threadGroup_klass); } |
duke@435 | 272 | static klassOop properties_klass() { return check_klass(_properties_klass); } |
duke@435 | 273 | static klassOop reflect_accessible_object_klass() { return check_klass(_reflect_accessible_object_klass); } |
duke@435 | 274 | static klassOop reflect_field_klass() { return check_klass(_reflect_field_klass); } |
duke@435 | 275 | static klassOop reflect_method_klass() { return check_klass(_reflect_method_klass); } |
duke@435 | 276 | static klassOop reflect_constructor_klass() { return check_klass(_reflect_constructor_klass); } |
duke@435 | 277 | static klassOop reflect_method_accessor_klass() { |
duke@435 | 278 | assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only"); |
duke@435 | 279 | return check_klass(_reflect_method_accessor_klass); |
duke@435 | 280 | } |
duke@435 | 281 | static klassOop reflect_constructor_accessor_klass() { |
duke@435 | 282 | assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only"); |
duke@435 | 283 | return check_klass(_reflect_constructor_accessor_klass); |
duke@435 | 284 | } |
duke@435 | 285 | // NOTE: needed too early in bootstrapping process to have checks based on JDK version |
duke@435 | 286 | static klassOop reflect_magic_klass() { return _reflect_magic_klass; } |
duke@435 | 287 | static klassOop reflect_delegating_classloader_klass() { return _reflect_delegating_classloader_klass; } |
duke@435 | 288 | static klassOop reflect_constant_pool_klass() { |
duke@435 | 289 | assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only"); |
duke@435 | 290 | return _reflect_constant_pool_klass; |
duke@435 | 291 | } |
duke@435 | 292 | static klassOop reflect_unsafe_static_field_accessor_impl_klass() { |
duke@435 | 293 | assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only"); |
duke@435 | 294 | return _reflect_unsafe_static_field_accessor_impl_klass; |
duke@435 | 295 | } |
duke@435 | 296 | |
duke@435 | 297 | static klassOop vector_klass() { return check_klass(_vector_klass); } |
duke@435 | 298 | static klassOop hashtable_klass() { return check_klass(_hashtable_klass); } |
duke@435 | 299 | static klassOop stringBuffer_klass() { return check_klass(_stringBuffer_klass); } |
duke@435 | 300 | static klassOop stackTraceElement_klass() { return check_klass(_stackTraceElement_klass); } |
duke@435 | 301 | |
duke@435 | 302 | static klassOop java_nio_Buffer_klass() { return check_klass(_java_nio_Buffer_klass); } |
duke@435 | 303 | |
duke@435 | 304 | static klassOop sun_misc_AtomicLongCSImpl_klass() { return _sun_misc_AtomicLongCSImpl_klass; } |
duke@435 | 305 | |
duke@435 | 306 | // To support incremental JRE downloads (KERNEL JRE). Null if not present. |
duke@435 | 307 | static klassOop sun_jkernel_DownloadManager_klass() { return _sun_jkernel_DownloadManager_klass; } |
duke@435 | 308 | |
duke@435 | 309 | static klassOop boolean_klass() { return check_klass(_boolean_klass); } |
duke@435 | 310 | static klassOop char_klass() { return check_klass(_char_klass); } |
duke@435 | 311 | static klassOop float_klass() { return check_klass(_float_klass); } |
duke@435 | 312 | static klassOop double_klass() { return check_klass(_double_klass); } |
duke@435 | 313 | static klassOop byte_klass() { return check_klass(_byte_klass); } |
duke@435 | 314 | static klassOop short_klass() { return check_klass(_short_klass); } |
duke@435 | 315 | static klassOop int_klass() { return check_klass(_int_klass); } |
duke@435 | 316 | static klassOop long_klass() { return check_klass(_long_klass); } |
duke@435 | 317 | |
duke@435 | 318 | static klassOop box_klass(BasicType t) { |
duke@435 | 319 | assert((uint)t < T_VOID+1, "range check"); |
duke@435 | 320 | return check_klass(_box_klasses[t]); |
duke@435 | 321 | } |
duke@435 | 322 | static BasicType box_klass_type(klassOop k); // inverse of box_klass |
duke@435 | 323 | |
duke@435 | 324 | // methods returning lazily loaded klasses |
duke@435 | 325 | // The corresponding method to load the class must be called before calling them. |
duke@435 | 326 | static klassOop abstract_ownable_synchronizer_klass() { return check_klass(_abstract_ownable_synchronizer_klass); } |
duke@435 | 327 | |
duke@435 | 328 | static void load_abstract_ownable_synchronizer_klass(TRAPS); |
duke@435 | 329 | |
duke@435 | 330 | private: |
duke@435 | 331 | // Tells whether ClassLoader.loadClassInternal is present |
duke@435 | 332 | static bool has_loadClassInternal() { return _has_loadClassInternal; } |
duke@435 | 333 | |
duke@435 | 334 | public: |
duke@435 | 335 | // Tells whether ClassLoader.checkPackageAccess is present |
duke@435 | 336 | static bool has_checkPackageAccess() { return _has_checkPackageAccess; } |
duke@435 | 337 | |
duke@435 | 338 | static bool class_klass_loaded() { return _class_klass != NULL; } |
duke@435 | 339 | static bool cloneable_klass_loaded() { return _cloneable_klass != NULL; } |
duke@435 | 340 | |
duke@435 | 341 | // Returns default system loader |
duke@435 | 342 | static oop java_system_loader(); |
duke@435 | 343 | |
duke@435 | 344 | // Compute the default system loader |
duke@435 | 345 | static void compute_java_system_loader(TRAPS); |
duke@435 | 346 | |
duke@435 | 347 | private: |
duke@435 | 348 | // Mirrors for primitive classes (created eagerly) |
duke@435 | 349 | static oop check_mirror(oop m) { |
duke@435 | 350 | assert(m != NULL, "mirror not initialized"); |
duke@435 | 351 | return m; |
duke@435 | 352 | } |
duke@435 | 353 | |
duke@435 | 354 | public: |
duke@435 | 355 | // Note: java_lang_Class::primitive_type is the inverse of java_mirror |
duke@435 | 356 | |
duke@435 | 357 | // Check class loader constraints |
duke@435 | 358 | static bool add_loader_constraint(symbolHandle name, Handle loader1, |
duke@435 | 359 | Handle loader2, TRAPS); |
duke@435 | 360 | static char* check_signature_loaders(symbolHandle signature, Handle loader1, |
duke@435 | 361 | Handle loader2, bool is_method, TRAPS); |
duke@435 | 362 | |
duke@435 | 363 | // Utility for printing loader "name" as part of tracing constraints |
duke@435 | 364 | static const char* loader_name(oop loader) { |
duke@435 | 365 | return ((loader) == NULL ? "<bootloader>" : |
duke@435 | 366 | instanceKlass::cast((loader)->klass())->name()->as_C_string() ); |
duke@435 | 367 | } |
duke@435 | 368 | |
duke@435 | 369 | // Record the error when the first attempt to resolve a reference from a constant |
duke@435 | 370 | // pool entry to a class fails. |
duke@435 | 371 | static void add_resolution_error(constantPoolHandle pool, int which, symbolHandle error); |
duke@435 | 372 | static symbolOop find_resolution_error(constantPoolHandle pool, int which); |
duke@435 | 373 | |
duke@435 | 374 | private: |
duke@435 | 375 | |
duke@435 | 376 | enum Constants { |
duke@435 | 377 | _loader_constraint_size = 107, // number of entries in constraint table |
duke@435 | 378 | _resolution_error_size = 107, // number of entries in resolution error table |
duke@435 | 379 | _nof_buckets = 1009 // number of buckets in hash table |
duke@435 | 380 | }; |
duke@435 | 381 | |
duke@435 | 382 | |
duke@435 | 383 | // Static variables |
duke@435 | 384 | |
duke@435 | 385 | // Hashtable holding loaded classes. |
duke@435 | 386 | static Dictionary* _dictionary; |
duke@435 | 387 | |
duke@435 | 388 | // Hashtable holding placeholders for classes being loaded. |
duke@435 | 389 | static PlaceholderTable* _placeholders; |
duke@435 | 390 | |
duke@435 | 391 | // Hashtable holding classes from the shared archive. |
duke@435 | 392 | static Dictionary* _shared_dictionary; |
duke@435 | 393 | |
duke@435 | 394 | // Monotonically increasing counter which grows with |
duke@435 | 395 | // _number_of_classes as well as hot-swapping and breakpoint setting |
duke@435 | 396 | // and removal. |
duke@435 | 397 | static int _number_of_modifications; |
duke@435 | 398 | |
duke@435 | 399 | // Lock object for system class loader |
duke@435 | 400 | static oop _system_loader_lock_obj; |
duke@435 | 401 | |
duke@435 | 402 | // Constraints on class loaders |
duke@435 | 403 | static LoaderConstraintTable* _loader_constraints; |
duke@435 | 404 | |
duke@435 | 405 | // Resolution errors |
duke@435 | 406 | static ResolutionErrorTable* _resolution_errors; |
duke@435 | 407 | |
duke@435 | 408 | public: |
duke@435 | 409 | // for VM_CounterDecay iteration support |
duke@435 | 410 | friend class CounterDecay; |
duke@435 | 411 | static klassOop try_get_next_class(); |
duke@435 | 412 | |
duke@435 | 413 | private: |
duke@435 | 414 | static void validate_protection_domain(instanceKlassHandle klass, |
duke@435 | 415 | Handle class_loader, |
duke@435 | 416 | Handle protection_domain, TRAPS); |
duke@435 | 417 | |
duke@435 | 418 | friend class VM_PopulateDumpSharedSpace; |
duke@435 | 419 | friend class TraversePlaceholdersClosure; |
duke@435 | 420 | static Dictionary* dictionary() { return _dictionary; } |
duke@435 | 421 | static Dictionary* shared_dictionary() { return _shared_dictionary; } |
duke@435 | 422 | static PlaceholderTable* placeholders() { return _placeholders; } |
duke@435 | 423 | static LoaderConstraintTable* constraints() { return _loader_constraints; } |
duke@435 | 424 | static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } |
duke@435 | 425 | |
duke@435 | 426 | // Basic loading operations |
duke@435 | 427 | static klassOop resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 428 | static klassOop resolve_array_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 429 | static instanceKlassHandle handle_parallel_super_load(symbolHandle class_name, symbolHandle supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); |
duke@435 | 430 | // Wait on SystemDictionary_lock; unlocks lockObject before |
duke@435 | 431 | // waiting; relocks lockObject with correct recursion count |
duke@435 | 432 | // after waiting, but before reentering SystemDictionary_lock |
duke@435 | 433 | // to preserve lock order semantics. |
duke@435 | 434 | static void double_lock_wait(Handle lockObject, TRAPS); |
duke@435 | 435 | static void define_instance_class(instanceKlassHandle k, TRAPS); |
duke@435 | 436 | static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name, |
duke@435 | 437 | Handle class_loader, |
duke@435 | 438 | instanceKlassHandle k, TRAPS); |
duke@435 | 439 | static instanceKlassHandle load_shared_class(symbolHandle class_name, |
duke@435 | 440 | Handle class_loader, TRAPS); |
duke@435 | 441 | static instanceKlassHandle load_shared_class(instanceKlassHandle ik, |
duke@435 | 442 | Handle class_loader, TRAPS); |
duke@435 | 443 | static instanceKlassHandle load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS); |
duke@435 | 444 | static Handle compute_loader_lock_object(Handle class_loader, TRAPS); |
duke@435 | 445 | static void check_loader_lock_contention(Handle loader_lock, TRAPS); |
duke@435 | 446 | |
duke@435 | 447 | static klassOop find_shared_class(symbolHandle class_name); |
duke@435 | 448 | |
duke@435 | 449 | // Setup link to hierarchy |
duke@435 | 450 | static void add_to_hierarchy(instanceKlassHandle k, TRAPS); |
duke@435 | 451 | |
duke@435 | 452 | private: |
duke@435 | 453 | // We pass in the hashtable index so we can calculate it outside of |
duke@435 | 454 | // the SystemDictionary_lock. |
duke@435 | 455 | |
duke@435 | 456 | // Basic find on loaded classes |
duke@435 | 457 | static klassOop find_class(int index, unsigned int hash, |
duke@435 | 458 | symbolHandle name, Handle loader); |
duke@435 | 459 | |
duke@435 | 460 | // Basic find on classes in the midst of being loaded |
duke@435 | 461 | static symbolOop find_placeholder(int index, unsigned int hash, |
duke@435 | 462 | symbolHandle name, Handle loader); |
duke@435 | 463 | |
duke@435 | 464 | // Basic find operation of loaded classes and classes in the midst |
duke@435 | 465 | // of loading; used for assertions and verification only. |
duke@435 | 466 | static oop find_class_or_placeholder(symbolHandle class_name, |
duke@435 | 467 | Handle class_loader); |
duke@435 | 468 | |
duke@435 | 469 | // Updating entry in dictionary |
duke@435 | 470 | // Add a completely loaded class |
duke@435 | 471 | static void add_klass(int index, symbolHandle class_name, |
duke@435 | 472 | Handle class_loader, KlassHandle obj); |
duke@435 | 473 | |
duke@435 | 474 | // Add a placeholder for a class being loaded |
duke@435 | 475 | static void add_placeholder(int index, |
duke@435 | 476 | symbolHandle class_name, |
duke@435 | 477 | Handle class_loader); |
duke@435 | 478 | static void remove_placeholder(int index, |
duke@435 | 479 | symbolHandle class_name, |
duke@435 | 480 | Handle class_loader); |
duke@435 | 481 | |
duke@435 | 482 | // Performs cleanups after resolve_super_or_fail. This typically needs |
duke@435 | 483 | // to be called on failure. |
duke@435 | 484 | // Won't throw, but can block. |
duke@435 | 485 | static void resolution_cleanups(symbolHandle class_name, |
duke@435 | 486 | Handle class_loader, |
duke@435 | 487 | TRAPS); |
duke@435 | 488 | |
duke@435 | 489 | // Initialization |
duke@435 | 490 | static void initialize_preloaded_classes(TRAPS); |
duke@435 | 491 | |
duke@435 | 492 | // Class loader constraints |
duke@435 | 493 | static void check_constraints(int index, unsigned int hash, |
duke@435 | 494 | instanceKlassHandle k, Handle loader, |
duke@435 | 495 | bool defining, TRAPS); |
duke@435 | 496 | static void update_dictionary(int d_index, unsigned int d_hash, |
duke@435 | 497 | int p_index, unsigned int p_hash, |
duke@435 | 498 | instanceKlassHandle k, Handle loader, TRAPS); |
duke@435 | 499 | |
duke@435 | 500 | // Variables holding commonly used klasses (preloaded) |
duke@435 | 501 | static klassOop _object_klass; |
duke@435 | 502 | static klassOop _string_klass; |
duke@435 | 503 | static klassOop _class_klass; |
duke@435 | 504 | static klassOop _cloneable_klass; |
duke@435 | 505 | static klassOop _classloader_klass; |
duke@435 | 506 | static klassOop _serializable_klass; |
duke@435 | 507 | static klassOop _system_klass; |
duke@435 | 508 | |
duke@435 | 509 | static klassOop _throwable_klass; |
duke@435 | 510 | static klassOop _error_klass; |
duke@435 | 511 | static klassOop _threaddeath_klass; |
duke@435 | 512 | static klassOop _exception_klass; |
duke@435 | 513 | static klassOop _runtime_exception_klass; |
duke@435 | 514 | static klassOop _classNotFoundException_klass; |
duke@435 | 515 | static klassOop _noClassDefFoundError_klass; |
duke@435 | 516 | static klassOop _linkageError_klass; |
duke@435 | 517 | static klassOop _classCastException_klass; |
duke@435 | 518 | static klassOop _arrayStoreException_klass; |
duke@435 | 519 | static klassOop _virtualMachineError_klass; |
duke@435 | 520 | static klassOop _outOfMemoryError_klass; |
duke@435 | 521 | static klassOop _StackOverflowError_klass; |
duke@435 | 522 | static klassOop _illegalMonitorStateException_klass; |
duke@435 | 523 | static klassOop _protectionDomain_klass; |
duke@435 | 524 | static klassOop _AccessControlContext_klass; |
duke@435 | 525 | static klassOop _reference_klass; |
duke@435 | 526 | static klassOop _soft_reference_klass; |
duke@435 | 527 | static klassOop _weak_reference_klass; |
duke@435 | 528 | static klassOop _final_reference_klass; |
duke@435 | 529 | static klassOop _phantom_reference_klass; |
duke@435 | 530 | static klassOop _finalizer_klass; |
duke@435 | 531 | |
duke@435 | 532 | static klassOop _thread_klass; |
duke@435 | 533 | static klassOop _threadGroup_klass; |
duke@435 | 534 | static klassOop _properties_klass; |
duke@435 | 535 | static klassOop _reflect_accessible_object_klass; |
duke@435 | 536 | static klassOop _reflect_field_klass; |
duke@435 | 537 | static klassOop _reflect_method_klass; |
duke@435 | 538 | static klassOop _reflect_constructor_klass; |
duke@435 | 539 | // 1.4 reflection implementation |
duke@435 | 540 | static klassOop _reflect_magic_klass; |
duke@435 | 541 | static klassOop _reflect_method_accessor_klass; |
duke@435 | 542 | static klassOop _reflect_constructor_accessor_klass; |
duke@435 | 543 | static klassOop _reflect_delegating_classloader_klass; |
duke@435 | 544 | // 1.5 annotations implementation |
duke@435 | 545 | static klassOop _reflect_constant_pool_klass; |
duke@435 | 546 | static klassOop _reflect_unsafe_static_field_accessor_impl_klass; |
duke@435 | 547 | |
duke@435 | 548 | static klassOop _stringBuffer_klass; |
duke@435 | 549 | static klassOop _vector_klass; |
duke@435 | 550 | static klassOop _hashtable_klass; |
duke@435 | 551 | |
duke@435 | 552 | static klassOop _stackTraceElement_klass; |
duke@435 | 553 | |
duke@435 | 554 | static klassOop _java_nio_Buffer_klass; |
duke@435 | 555 | |
duke@435 | 556 | static klassOop _sun_misc_AtomicLongCSImpl_klass; |
duke@435 | 557 | |
duke@435 | 558 | // KERNEL JRE support. |
duke@435 | 559 | static klassOop _sun_jkernel_DownloadManager_klass; |
duke@435 | 560 | |
duke@435 | 561 | // Lazily loaded klasses |
duke@435 | 562 | static volatile klassOop _abstract_ownable_synchronizer_klass; |
duke@435 | 563 | |
duke@435 | 564 | // Box klasses |
duke@435 | 565 | static klassOop _boolean_klass; |
duke@435 | 566 | static klassOop _char_klass; |
duke@435 | 567 | static klassOop _float_klass; |
duke@435 | 568 | static klassOop _double_klass; |
duke@435 | 569 | static klassOop _byte_klass; |
duke@435 | 570 | static klassOop _short_klass; |
duke@435 | 571 | static klassOop _int_klass; |
duke@435 | 572 | static klassOop _long_klass; |
duke@435 | 573 | |
duke@435 | 574 | // table of same |
duke@435 | 575 | static klassOop _box_klasses[T_VOID+1]; |
duke@435 | 576 | |
duke@435 | 577 | static oop _java_system_loader; |
duke@435 | 578 | |
duke@435 | 579 | static bool _has_loadClassInternal; |
duke@435 | 580 | static bool _has_checkPackageAccess; |
duke@435 | 581 | }; |