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 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 | |
jrose@567 | 67 | // Certain classes are preloaded, such as java.lang.Object and java.lang.String. |
jrose@567 | 68 | // They are all "well-known", in the sense that no class loader is allowed |
jrose@567 | 69 | // to provide a different definition. |
jrose@567 | 70 | // |
jrose@567 | 71 | // These klasses must all have names defined in vmSymbols. |
jrose@567 | 72 | |
jrose@567 | 73 | #define WK_KLASS_ENUM_NAME(kname) kname##_knum |
jrose@567 | 74 | |
jrose@567 | 75 | // Each well-known class has a short klass name (like object_klass), |
jrose@567 | 76 | // a vmSymbol name (like java_lang_Object), and a flag word |
jrose@567 | 77 | // that makes some minor distinctions, like whether the klass |
jrose@567 | 78 | // is preloaded, optional, release-specific, etc. |
jrose@567 | 79 | // The order of these definitions is significant; it is the order in which |
jrose@567 | 80 | // preloading is actually performed by initialize_preloaded_classes. |
jrose@567 | 81 | |
jrose@567 | 82 | #define WK_KLASSES_DO(template) \ |
jrose@567 | 83 | /* well-known classes */ \ |
jrose@567 | 84 | template(object_klass, java_lang_Object, Pre) \ |
jrose@567 | 85 | template(string_klass, java_lang_String, Pre) \ |
jrose@567 | 86 | template(class_klass, java_lang_Class, Pre) \ |
jrose@567 | 87 | template(cloneable_klass, java_lang_Cloneable, Pre) \ |
jrose@567 | 88 | template(classloader_klass, java_lang_ClassLoader, Pre) \ |
jrose@567 | 89 | template(serializable_klass, java_io_Serializable, Pre) \ |
jrose@567 | 90 | template(system_klass, java_lang_System, Pre) \ |
jrose@567 | 91 | template(throwable_klass, java_lang_Throwable, Pre) \ |
jrose@567 | 92 | template(error_klass, java_lang_Error, Pre) \ |
jrose@567 | 93 | template(threaddeath_klass, java_lang_ThreadDeath, Pre) \ |
jrose@567 | 94 | template(exception_klass, java_lang_Exception, Pre) \ |
jrose@567 | 95 | template(runtime_exception_klass, java_lang_RuntimeException, Pre) \ |
jrose@567 | 96 | template(protectionDomain_klass, java_security_ProtectionDomain, Pre) \ |
jrose@567 | 97 | template(AccessControlContext_klass, java_security_AccessControlContext, Pre) \ |
jrose@567 | 98 | template(classNotFoundException_klass, java_lang_ClassNotFoundException, Pre) \ |
jrose@567 | 99 | template(noClassDefFoundError_klass, java_lang_NoClassDefFoundError, Pre) \ |
jrose@567 | 100 | template(linkageError_klass, java_lang_LinkageError, Pre) \ |
jrose@567 | 101 | template(ClassCastException_klass, java_lang_ClassCastException, Pre) \ |
jrose@567 | 102 | template(ArrayStoreException_klass, java_lang_ArrayStoreException, Pre) \ |
jrose@567 | 103 | template(virtualMachineError_klass, java_lang_VirtualMachineError, Pre) \ |
jrose@567 | 104 | template(OutOfMemoryError_klass, java_lang_OutOfMemoryError, Pre) \ |
jrose@567 | 105 | template(StackOverflowError_klass, java_lang_StackOverflowError, Pre) \ |
jrose@567 | 106 | template(IllegalMonitorStateException_klass, java_lang_IllegalMonitorStateException, Pre) \ |
jrose@567 | 107 | template(reference_klass, java_lang_ref_Reference, Pre) \ |
jrose@567 | 108 | \ |
jrose@567 | 109 | /* Preload ref klasses and set reference types */ \ |
jrose@567 | 110 | template(soft_reference_klass, java_lang_ref_SoftReference, Pre) \ |
jrose@567 | 111 | template(weak_reference_klass, java_lang_ref_WeakReference, Pre) \ |
jrose@567 | 112 | template(final_reference_klass, java_lang_ref_FinalReference, Pre) \ |
jrose@567 | 113 | template(phantom_reference_klass, java_lang_ref_PhantomReference, Pre) \ |
jrose@567 | 114 | template(finalizer_klass, java_lang_ref_Finalizer, Pre) \ |
jrose@567 | 115 | \ |
jrose@567 | 116 | template(thread_klass, java_lang_Thread, Pre) \ |
jrose@567 | 117 | template(threadGroup_klass, java_lang_ThreadGroup, Pre) \ |
jrose@567 | 118 | template(properties_klass, java_util_Properties, Pre) \ |
jrose@567 | 119 | template(reflect_accessible_object_klass, java_lang_reflect_AccessibleObject, Pre) \ |
jrose@567 | 120 | template(reflect_field_klass, java_lang_reflect_Field, Pre) \ |
jrose@567 | 121 | template(reflect_method_klass, java_lang_reflect_Method, Pre) \ |
jrose@567 | 122 | template(reflect_constructor_klass, java_lang_reflect_Constructor, Pre) \ |
jrose@567 | 123 | \ |
jrose@567 | 124 | /* NOTE: needed too early in bootstrapping process to have checks based on JDK version */ \ |
jrose@567 | 125 | /* Universe::is_gte_jdk14x_version() is not set up by this point. */ \ |
jrose@567 | 126 | /* It's okay if this turns out to be NULL in non-1.4 JDKs. */ \ |
jrose@567 | 127 | template(reflect_magic_klass, sun_reflect_MagicAccessorImpl, Opt) \ |
jrose@567 | 128 | template(reflect_method_accessor_klass, sun_reflect_MethodAccessorImpl, Opt_Only_JDK14NewRef) \ |
jrose@567 | 129 | template(reflect_constructor_accessor_klass, sun_reflect_ConstructorAccessorImpl, Opt_Only_JDK14NewRef) \ |
jrose@567 | 130 | template(reflect_delegating_classloader_klass, sun_reflect_DelegatingClassLoader, Opt) \ |
jrose@567 | 131 | template(reflect_constant_pool_klass, sun_reflect_ConstantPool, Opt_Only_JDK15) \ |
jrose@567 | 132 | template(reflect_unsafe_static_field_accessor_impl_klass, sun_reflect_UnsafeStaticFieldAccessorImpl, Opt_Only_JDK15) \ |
jrose@567 | 133 | \ |
jrose@567 | 134 | template(vector_klass, java_util_Vector, Pre) \ |
jrose@567 | 135 | template(hashtable_klass, java_util_Hashtable, Pre) \ |
jrose@567 | 136 | template(stringBuffer_klass, java_lang_StringBuffer, Pre) \ |
jrose@567 | 137 | \ |
jrose@567 | 138 | /* It's NULL in non-1.4 JDKs. */ \ |
jrose@567 | 139 | template(stackTraceElement_klass, java_lang_StackTraceElement, Opt) \ |
jrose@567 | 140 | /* Universe::is_gte_jdk14x_version() is not set up by this point. */ \ |
jrose@567 | 141 | /* It's okay if this turns out to be NULL in non-1.4 JDKs. */ \ |
jrose@567 | 142 | template(java_nio_Buffer_klass, java_nio_Buffer, Opt) \ |
jrose@567 | 143 | \ |
jrose@567 | 144 | /* If this class isn't present, it won't be referenced. */ \ |
jrose@567 | 145 | template(sun_misc_AtomicLongCSImpl_klass, sun_misc_AtomicLongCSImpl, Opt) \ |
jrose@567 | 146 | \ |
jrose@567 | 147 | template(sun_jkernel_DownloadManager_klass, sun_jkernel_DownloadManager, Opt_Kernel) \ |
jrose@567 | 148 | \ |
jrose@567 | 149 | /* Preload boxing klasses */ \ |
jrose@567 | 150 | template(boolean_klass, java_lang_Boolean, Pre) \ |
jrose@567 | 151 | template(char_klass, java_lang_Character, Pre) \ |
jrose@567 | 152 | template(float_klass, java_lang_Float, Pre) \ |
jrose@567 | 153 | template(double_klass, java_lang_Double, Pre) \ |
jrose@567 | 154 | template(byte_klass, java_lang_Byte, Pre) \ |
jrose@567 | 155 | template(short_klass, java_lang_Short, Pre) \ |
jrose@567 | 156 | template(int_klass, java_lang_Integer, Pre) \ |
jrose@567 | 157 | template(long_klass, java_lang_Long, Pre) \ |
jrose@567 | 158 | /*end*/ |
jrose@567 | 159 | |
jrose@567 | 160 | |
duke@435 | 161 | class SystemDictionary : AllStatic { |
duke@435 | 162 | friend class VMStructs; |
duke@435 | 163 | friend class CompactingPermGenGen; |
duke@435 | 164 | NOT_PRODUCT(friend class instanceKlassKlass;) |
duke@435 | 165 | |
duke@435 | 166 | public: |
jrose@567 | 167 | enum WKID { |
jrose@567 | 168 | NO_WKID = 0, |
jrose@567 | 169 | |
jrose@567 | 170 | #define WK_KLASS_ENUM(name, ignore_s, ignore_o) WK_KLASS_ENUM_NAME(name), |
jrose@567 | 171 | WK_KLASSES_DO(WK_KLASS_ENUM) |
jrose@567 | 172 | #undef WK_KLASS_ENUM |
jrose@567 | 173 | |
jrose@567 | 174 | WKID_LIMIT, |
jrose@567 | 175 | |
jrose@567 | 176 | FIRST_WKID = NO_WKID + 1 |
jrose@567 | 177 | }; |
jrose@567 | 178 | |
jrose@567 | 179 | enum InitOption { |
jrose@567 | 180 | Pre, // preloaded; error if not present |
jrose@567 | 181 | |
jrose@567 | 182 | // Order is significant. Options before this point require resolve_or_fail. |
jrose@567 | 183 | // Options after this point will use resolve_or_null instead. |
jrose@567 | 184 | |
jrose@567 | 185 | Opt, // preload tried; NULL if not present |
jrose@567 | 186 | Opt_Only_JDK14NewRef, // preload tried; use only with NewReflection |
jrose@567 | 187 | Opt_Only_JDK15, // preload tried; use only with JDK1.5+ |
jrose@567 | 188 | Opt_Kernel, // preload tried only #ifdef KERNEL |
jrose@567 | 189 | OPTION_LIMIT, |
jrose@567 | 190 | CEIL_LG_OPTION_LIMIT = 4 // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT) |
jrose@567 | 191 | }; |
jrose@567 | 192 | |
jrose@567 | 193 | |
duke@435 | 194 | // Returns a class with a given class name and class loader. Loads the |
duke@435 | 195 | // class if needed. If not found a NoClassDefFoundError or a |
duke@435 | 196 | // ClassNotFoundException is thrown, depending on the value on the |
duke@435 | 197 | // throw_error flag. For most uses the throw_error argument should be set |
duke@435 | 198 | // to true. |
duke@435 | 199 | |
duke@435 | 200 | static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); |
duke@435 | 201 | // Convenient call for null loader and protection domain. |
duke@435 | 202 | static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS); |
duke@435 | 203 | private: |
duke@435 | 204 | // handle error translation for resolve_or_null results |
duke@435 | 205 | static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS); |
duke@435 | 206 | |
duke@435 | 207 | public: |
duke@435 | 208 | |
duke@435 | 209 | // Returns a class with a given class name and class loader. |
duke@435 | 210 | // Loads the class if needed. If not found NULL is returned. |
duke@435 | 211 | static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 212 | // Version with null loader and protection domain |
duke@435 | 213 | static klassOop resolve_or_null(symbolHandle class_name, TRAPS); |
duke@435 | 214 | |
duke@435 | 215 | // Resolve a superclass or superinterface. Called from ClassFileParser, |
duke@435 | 216 | // parse_interfaces, resolve_instance_class_or_null, load_shared_class |
duke@435 | 217 | // "child_name" is the class whose super class or interface is being resolved. |
duke@435 | 218 | static klassOop resolve_super_or_fail(symbolHandle child_name, |
duke@435 | 219 | symbolHandle class_name, |
duke@435 | 220 | Handle class_loader, |
duke@435 | 221 | Handle protection_domain, |
duke@435 | 222 | bool is_superclass, |
duke@435 | 223 | TRAPS); |
duke@435 | 224 | |
duke@435 | 225 | // Parse new stream. This won't update the system dictionary or |
duke@435 | 226 | // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. |
duke@435 | 227 | static klassOop parse_stream(symbolHandle class_name, |
duke@435 | 228 | Handle class_loader, |
duke@435 | 229 | Handle protection_domain, |
duke@435 | 230 | ClassFileStream* st, |
duke@435 | 231 | TRAPS); |
duke@435 | 232 | |
duke@435 | 233 | // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) |
duke@435 | 234 | static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, Handle protection_domain, ClassFileStream* st, TRAPS); |
duke@435 | 235 | |
duke@435 | 236 | // Lookup an already loaded class. If not found NULL is returned. |
duke@435 | 237 | static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 238 | |
duke@435 | 239 | // Lookup an already loaded instance or array class. |
duke@435 | 240 | // Do not make any queries to class loaders; consult only the cache. |
duke@435 | 241 | // If not found NULL is returned. |
duke@435 | 242 | static klassOop find_instance_or_array_klass(symbolHandle class_name, |
duke@435 | 243 | Handle class_loader, |
duke@435 | 244 | Handle protection_domain, |
duke@435 | 245 | TRAPS); |
duke@435 | 246 | |
jrose@567 | 247 | // If the given name is known to vmSymbols, return the well-know klass: |
jrose@567 | 248 | static klassOop find_well_known_klass(symbolOop class_name); |
jrose@567 | 249 | |
duke@435 | 250 | // Lookup an instance or array class that has already been loaded |
duke@435 | 251 | // either into the given class loader, or else into another class |
duke@435 | 252 | // loader that is constrained (via loader constraints) to produce |
duke@435 | 253 | // a consistent class. Do not take protection domains into account. |
duke@435 | 254 | // Do not make any queries to class loaders; consult only the cache. |
duke@435 | 255 | // Return NULL if the class is not found. |
duke@435 | 256 | // |
duke@435 | 257 | // This function is a strict superset of find_instance_or_array_klass. |
duke@435 | 258 | // This function (the unchecked version) makes a conservative prediction |
duke@435 | 259 | // of the result of the checked version, assuming successful lookup. |
duke@435 | 260 | // If both functions return non-null, they must return the same value. |
duke@435 | 261 | // Also, the unchecked version may sometimes be non-null where the |
duke@435 | 262 | // checked version is null. This can occur in several ways: |
duke@435 | 263 | // 1. No query has yet been made to the class loader. |
duke@435 | 264 | // 2. The class loader was queried, but chose not to delegate. |
duke@435 | 265 | // 3. ClassLoader.checkPackageAccess rejected a proposed protection domain. |
duke@435 | 266 | // 4. Loading was attempted, but there was a linkage error of some sort. |
duke@435 | 267 | // In all of these cases, the loader constraints on this type are |
duke@435 | 268 | // satisfied, and it is safe for classes in the given class loader |
duke@435 | 269 | // to manipulate strongly-typed values of the found class, subject |
duke@435 | 270 | // to local linkage and access checks. |
duke@435 | 271 | static klassOop find_constrained_instance_or_array_klass(symbolHandle class_name, |
duke@435 | 272 | Handle class_loader, |
duke@435 | 273 | TRAPS); |
duke@435 | 274 | |
duke@435 | 275 | // Iterate over all klasses in dictionary |
duke@435 | 276 | // Just the classes from defining class loaders |
duke@435 | 277 | static void classes_do(void f(klassOop)); |
duke@435 | 278 | // Added for initialize_itable_for_klass to handle exceptions |
duke@435 | 279 | static void classes_do(void f(klassOop, TRAPS), TRAPS); |
duke@435 | 280 | // All classes, and their class loaders |
duke@435 | 281 | static void classes_do(void f(klassOop, oop)); |
duke@435 | 282 | // All classes, and their class loaders |
duke@435 | 283 | // (added for helpers that use HandleMarks and ResourceMarks) |
duke@435 | 284 | static void classes_do(void f(klassOop, oop, TRAPS), TRAPS); |
duke@435 | 285 | // All entries in the placeholder table and their class loaders |
duke@435 | 286 | static void placeholders_do(void f(symbolOop, oop)); |
duke@435 | 287 | |
duke@435 | 288 | // Iterate over all methods in all klasses in dictionary |
duke@435 | 289 | static void methods_do(void f(methodOop)); |
duke@435 | 290 | |
duke@435 | 291 | // Garbage collection support |
duke@435 | 292 | |
duke@435 | 293 | // This method applies "blk->do_oop" to all the pointers to "system" |
duke@435 | 294 | // classes and loaders. |
duke@435 | 295 | static void always_strong_oops_do(OopClosure* blk); |
duke@435 | 296 | static void always_strong_classes_do(OopClosure* blk); |
duke@435 | 297 | // This method applies "blk->do_oop" to all the placeholders. |
duke@435 | 298 | static void placeholders_do(OopClosure* blk); |
duke@435 | 299 | |
duke@435 | 300 | // Unload (that is, break root links to) all unmarked classes and |
duke@435 | 301 | // loaders. Returns "true" iff something was unloaded. |
duke@435 | 302 | static bool do_unloading(BoolObjectClosure* is_alive); |
duke@435 | 303 | |
duke@435 | 304 | // Applies "f->do_oop" to all root oops in the system dictionary. |
duke@435 | 305 | static void oops_do(OopClosure* f); |
duke@435 | 306 | |
duke@435 | 307 | // System loader lock |
duke@435 | 308 | static oop system_loader_lock() { return _system_loader_lock_obj; } |
duke@435 | 309 | |
duke@435 | 310 | private: |
duke@435 | 311 | // Traverses preloaded oops: various system classes. These are |
duke@435 | 312 | // guaranteed to be in the perm gen. |
duke@435 | 313 | static void preloaded_oops_do(OopClosure* f); |
duke@435 | 314 | static void lazily_loaded_oops_do(OopClosure* f); |
duke@435 | 315 | |
duke@435 | 316 | public: |
duke@435 | 317 | // Sharing support. |
duke@435 | 318 | static void reorder_dictionary(); |
duke@435 | 319 | static void copy_buckets(char** top, char* end); |
duke@435 | 320 | static void copy_table(char** top, char* end); |
duke@435 | 321 | static void reverse(); |
duke@435 | 322 | static void set_shared_dictionary(HashtableBucket* t, int length, |
duke@435 | 323 | int number_of_entries); |
duke@435 | 324 | // Printing |
duke@435 | 325 | static void print() PRODUCT_RETURN; |
duke@435 | 326 | static void print_class_statistics() PRODUCT_RETURN; |
duke@435 | 327 | static void print_method_statistics() PRODUCT_RETURN; |
duke@435 | 328 | |
duke@435 | 329 | // Number of contained klasses |
duke@435 | 330 | // This is both fully loaded classes and classes in the process |
duke@435 | 331 | // of being loaded |
duke@435 | 332 | static int number_of_classes(); |
duke@435 | 333 | |
duke@435 | 334 | // Monotonically increasing counter which grows as classes are |
duke@435 | 335 | // loaded or modifications such as hot-swapping or setting/removing |
duke@435 | 336 | // of breakpoints are performed |
duke@435 | 337 | static inline int number_of_modifications() { assert_locked_or_safepoint(Compile_lock); return _number_of_modifications; } |
duke@435 | 338 | // Needed by evolution and breakpoint code |
duke@435 | 339 | static inline void notice_modification() { assert_locked_or_safepoint(Compile_lock); ++_number_of_modifications; } |
duke@435 | 340 | |
duke@435 | 341 | // Verification |
duke@435 | 342 | static void verify(); |
duke@435 | 343 | |
duke@435 | 344 | #ifdef ASSERT |
duke@435 | 345 | static bool is_internal_format(symbolHandle class_name); |
duke@435 | 346 | #endif |
duke@435 | 347 | |
duke@435 | 348 | // Verify class is in dictionary |
duke@435 | 349 | static void verify_obj_klass_present(Handle obj, |
duke@435 | 350 | symbolHandle class_name, |
duke@435 | 351 | Handle class_loader); |
duke@435 | 352 | |
duke@435 | 353 | // Initialization |
duke@435 | 354 | static void initialize(TRAPS); |
duke@435 | 355 | |
duke@435 | 356 | // Fast access to commonly used classes (preloaded) |
duke@435 | 357 | static klassOop check_klass(klassOop k) { |
duke@435 | 358 | assert(k != NULL, "preloaded klass not initialized"); |
duke@435 | 359 | return k; |
duke@435 | 360 | } |
duke@435 | 361 | |
jrose@567 | 362 | static klassOop check_klass_Pre(klassOop k) { return check_klass(k); } |
jrose@567 | 363 | static klassOop check_klass_Opt(klassOop k) { return k; } |
jrose@567 | 364 | static klassOop check_klass_Opt_Kernel(klassOop k) { return k; } //== Opt |
jrose@567 | 365 | static klassOop check_klass_Opt_Only_JDK15(klassOop k) { |
jrose@567 | 366 | assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only"); |
jrose@567 | 367 | return k; |
jrose@567 | 368 | } |
jrose@567 | 369 | static klassOop check_klass_Opt_Only_JDK14NewRef(klassOop k) { |
duke@435 | 370 | assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only"); |
jrose@567 | 371 | // despite the optional loading, if you use this it must be present: |
jrose@567 | 372 | return check_klass(k); |
duke@435 | 373 | } |
duke@435 | 374 | |
jrose@567 | 375 | static bool initialize_wk_klass(WKID id, int init_opt, TRAPS); |
jrose@567 | 376 | static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS); |
jrose@567 | 377 | static void initialize_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) { |
jrose@567 | 378 | int limit = (int)end_id + 1; |
jrose@567 | 379 | initialize_wk_klasses_until((WKID) limit, start_id, THREAD); |
jrose@567 | 380 | } |
duke@435 | 381 | |
jrose@567 | 382 | public: |
jrose@567 | 383 | #define WK_KLASS_DECLARE(name, ignore_symbol, option) \ |
jrose@567 | 384 | static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } |
jrose@567 | 385 | WK_KLASSES_DO(WK_KLASS_DECLARE); |
jrose@567 | 386 | #undef WK_KLASS_DECLARE |
duke@435 | 387 | |
jrose@567 | 388 | // Local definition for direct access to the private array: |
jrose@582 | 389 | #define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] |
duke@435 | 390 | |
duke@435 | 391 | static klassOop box_klass(BasicType t) { |
duke@435 | 392 | assert((uint)t < T_VOID+1, "range check"); |
duke@435 | 393 | return check_klass(_box_klasses[t]); |
duke@435 | 394 | } |
duke@435 | 395 | static BasicType box_klass_type(klassOop k); // inverse of box_klass |
duke@435 | 396 | |
duke@435 | 397 | // methods returning lazily loaded klasses |
duke@435 | 398 | // The corresponding method to load the class must be called before calling them. |
duke@435 | 399 | static klassOop abstract_ownable_synchronizer_klass() { return check_klass(_abstract_ownable_synchronizer_klass); } |
duke@435 | 400 | |
duke@435 | 401 | static void load_abstract_ownable_synchronizer_klass(TRAPS); |
duke@435 | 402 | |
duke@435 | 403 | private: |
duke@435 | 404 | // Tells whether ClassLoader.loadClassInternal is present |
duke@435 | 405 | static bool has_loadClassInternal() { return _has_loadClassInternal; } |
duke@435 | 406 | |
duke@435 | 407 | public: |
duke@435 | 408 | // Tells whether ClassLoader.checkPackageAccess is present |
duke@435 | 409 | static bool has_checkPackageAccess() { return _has_checkPackageAccess; } |
duke@435 | 410 | |
jrose@567 | 411 | static bool class_klass_loaded() { return WK_KLASS(class_klass) != NULL; } |
jrose@567 | 412 | static bool cloneable_klass_loaded() { return WK_KLASS(cloneable_klass) != NULL; } |
duke@435 | 413 | |
duke@435 | 414 | // Returns default system loader |
duke@435 | 415 | static oop java_system_loader(); |
duke@435 | 416 | |
duke@435 | 417 | // Compute the default system loader |
duke@435 | 418 | static void compute_java_system_loader(TRAPS); |
duke@435 | 419 | |
duke@435 | 420 | private: |
duke@435 | 421 | // Mirrors for primitive classes (created eagerly) |
duke@435 | 422 | static oop check_mirror(oop m) { |
duke@435 | 423 | assert(m != NULL, "mirror not initialized"); |
duke@435 | 424 | return m; |
duke@435 | 425 | } |
duke@435 | 426 | |
duke@435 | 427 | public: |
duke@435 | 428 | // Note: java_lang_Class::primitive_type is the inverse of java_mirror |
duke@435 | 429 | |
duke@435 | 430 | // Check class loader constraints |
duke@435 | 431 | static bool add_loader_constraint(symbolHandle name, Handle loader1, |
duke@435 | 432 | Handle loader2, TRAPS); |
duke@435 | 433 | static char* check_signature_loaders(symbolHandle signature, Handle loader1, |
duke@435 | 434 | Handle loader2, bool is_method, TRAPS); |
duke@435 | 435 | |
duke@435 | 436 | // Utility for printing loader "name" as part of tracing constraints |
duke@435 | 437 | static const char* loader_name(oop loader) { |
duke@435 | 438 | return ((loader) == NULL ? "<bootloader>" : |
duke@435 | 439 | instanceKlass::cast((loader)->klass())->name()->as_C_string() ); |
duke@435 | 440 | } |
duke@435 | 441 | |
duke@435 | 442 | // Record the error when the first attempt to resolve a reference from a constant |
duke@435 | 443 | // pool entry to a class fails. |
duke@435 | 444 | static void add_resolution_error(constantPoolHandle pool, int which, symbolHandle error); |
duke@435 | 445 | static symbolOop find_resolution_error(constantPoolHandle pool, int which); |
duke@435 | 446 | |
duke@435 | 447 | private: |
duke@435 | 448 | |
duke@435 | 449 | enum Constants { |
duke@435 | 450 | _loader_constraint_size = 107, // number of entries in constraint table |
duke@435 | 451 | _resolution_error_size = 107, // number of entries in resolution error table |
duke@435 | 452 | _nof_buckets = 1009 // number of buckets in hash table |
duke@435 | 453 | }; |
duke@435 | 454 | |
duke@435 | 455 | |
duke@435 | 456 | // Static variables |
duke@435 | 457 | |
duke@435 | 458 | // Hashtable holding loaded classes. |
duke@435 | 459 | static Dictionary* _dictionary; |
duke@435 | 460 | |
duke@435 | 461 | // Hashtable holding placeholders for classes being loaded. |
duke@435 | 462 | static PlaceholderTable* _placeholders; |
duke@435 | 463 | |
duke@435 | 464 | // Hashtable holding classes from the shared archive. |
duke@435 | 465 | static Dictionary* _shared_dictionary; |
duke@435 | 466 | |
duke@435 | 467 | // Monotonically increasing counter which grows with |
duke@435 | 468 | // _number_of_classes as well as hot-swapping and breakpoint setting |
duke@435 | 469 | // and removal. |
duke@435 | 470 | static int _number_of_modifications; |
duke@435 | 471 | |
duke@435 | 472 | // Lock object for system class loader |
duke@435 | 473 | static oop _system_loader_lock_obj; |
duke@435 | 474 | |
duke@435 | 475 | // Constraints on class loaders |
duke@435 | 476 | static LoaderConstraintTable* _loader_constraints; |
duke@435 | 477 | |
duke@435 | 478 | // Resolution errors |
duke@435 | 479 | static ResolutionErrorTable* _resolution_errors; |
duke@435 | 480 | |
duke@435 | 481 | public: |
duke@435 | 482 | // for VM_CounterDecay iteration support |
duke@435 | 483 | friend class CounterDecay; |
duke@435 | 484 | static klassOop try_get_next_class(); |
duke@435 | 485 | |
duke@435 | 486 | private: |
duke@435 | 487 | static void validate_protection_domain(instanceKlassHandle klass, |
duke@435 | 488 | Handle class_loader, |
duke@435 | 489 | Handle protection_domain, TRAPS); |
duke@435 | 490 | |
duke@435 | 491 | friend class VM_PopulateDumpSharedSpace; |
duke@435 | 492 | friend class TraversePlaceholdersClosure; |
duke@435 | 493 | static Dictionary* dictionary() { return _dictionary; } |
duke@435 | 494 | static Dictionary* shared_dictionary() { return _shared_dictionary; } |
duke@435 | 495 | static PlaceholderTable* placeholders() { return _placeholders; } |
duke@435 | 496 | static LoaderConstraintTable* constraints() { return _loader_constraints; } |
duke@435 | 497 | static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } |
duke@435 | 498 | |
duke@435 | 499 | // Basic loading operations |
duke@435 | 500 | static klassOop resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 501 | static klassOop resolve_array_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS); |
duke@435 | 502 | static instanceKlassHandle handle_parallel_super_load(symbolHandle class_name, symbolHandle supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); |
duke@435 | 503 | // Wait on SystemDictionary_lock; unlocks lockObject before |
duke@435 | 504 | // waiting; relocks lockObject with correct recursion count |
duke@435 | 505 | // after waiting, but before reentering SystemDictionary_lock |
duke@435 | 506 | // to preserve lock order semantics. |
duke@435 | 507 | static void double_lock_wait(Handle lockObject, TRAPS); |
duke@435 | 508 | static void define_instance_class(instanceKlassHandle k, TRAPS); |
duke@435 | 509 | static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name, |
duke@435 | 510 | Handle class_loader, |
duke@435 | 511 | instanceKlassHandle k, TRAPS); |
duke@435 | 512 | static instanceKlassHandle load_shared_class(symbolHandle class_name, |
duke@435 | 513 | Handle class_loader, TRAPS); |
duke@435 | 514 | static instanceKlassHandle load_shared_class(instanceKlassHandle ik, |
duke@435 | 515 | Handle class_loader, TRAPS); |
duke@435 | 516 | static instanceKlassHandle load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS); |
duke@435 | 517 | static Handle compute_loader_lock_object(Handle class_loader, TRAPS); |
duke@435 | 518 | static void check_loader_lock_contention(Handle loader_lock, TRAPS); |
duke@435 | 519 | |
duke@435 | 520 | static klassOop find_shared_class(symbolHandle class_name); |
duke@435 | 521 | |
duke@435 | 522 | // Setup link to hierarchy |
duke@435 | 523 | static void add_to_hierarchy(instanceKlassHandle k, TRAPS); |
duke@435 | 524 | |
duke@435 | 525 | private: |
duke@435 | 526 | // We pass in the hashtable index so we can calculate it outside of |
duke@435 | 527 | // the SystemDictionary_lock. |
duke@435 | 528 | |
duke@435 | 529 | // Basic find on loaded classes |
duke@435 | 530 | static klassOop find_class(int index, unsigned int hash, |
duke@435 | 531 | symbolHandle name, Handle loader); |
duke@435 | 532 | |
duke@435 | 533 | // Basic find on classes in the midst of being loaded |
duke@435 | 534 | static symbolOop find_placeholder(int index, unsigned int hash, |
duke@435 | 535 | symbolHandle name, Handle loader); |
duke@435 | 536 | |
duke@435 | 537 | // Basic find operation of loaded classes and classes in the midst |
duke@435 | 538 | // of loading; used for assertions and verification only. |
duke@435 | 539 | static oop find_class_or_placeholder(symbolHandle class_name, |
duke@435 | 540 | Handle class_loader); |
duke@435 | 541 | |
duke@435 | 542 | // Updating entry in dictionary |
duke@435 | 543 | // Add a completely loaded class |
duke@435 | 544 | static void add_klass(int index, symbolHandle class_name, |
duke@435 | 545 | Handle class_loader, KlassHandle obj); |
duke@435 | 546 | |
duke@435 | 547 | // Add a placeholder for a class being loaded |
duke@435 | 548 | static void add_placeholder(int index, |
duke@435 | 549 | symbolHandle class_name, |
duke@435 | 550 | Handle class_loader); |
duke@435 | 551 | static void remove_placeholder(int index, |
duke@435 | 552 | symbolHandle class_name, |
duke@435 | 553 | Handle class_loader); |
duke@435 | 554 | |
duke@435 | 555 | // Performs cleanups after resolve_super_or_fail. This typically needs |
duke@435 | 556 | // to be called on failure. |
duke@435 | 557 | // Won't throw, but can block. |
duke@435 | 558 | static void resolution_cleanups(symbolHandle class_name, |
duke@435 | 559 | Handle class_loader, |
duke@435 | 560 | TRAPS); |
duke@435 | 561 | |
duke@435 | 562 | // Initialization |
duke@435 | 563 | static void initialize_preloaded_classes(TRAPS); |
duke@435 | 564 | |
duke@435 | 565 | // Class loader constraints |
duke@435 | 566 | static void check_constraints(int index, unsigned int hash, |
duke@435 | 567 | instanceKlassHandle k, Handle loader, |
duke@435 | 568 | bool defining, TRAPS); |
duke@435 | 569 | static void update_dictionary(int d_index, unsigned int d_hash, |
duke@435 | 570 | int p_index, unsigned int p_hash, |
duke@435 | 571 | instanceKlassHandle k, Handle loader, TRAPS); |
duke@435 | 572 | |
duke@435 | 573 | // Variables holding commonly used klasses (preloaded) |
jrose@567 | 574 | static klassOop _well_known_klasses[]; |
duke@435 | 575 | |
duke@435 | 576 | // Lazily loaded klasses |
duke@435 | 577 | static volatile klassOop _abstract_ownable_synchronizer_klass; |
duke@435 | 578 | |
jrose@567 | 579 | // table of box klasses (int_klass, etc.) |
duke@435 | 580 | static klassOop _box_klasses[T_VOID+1]; |
duke@435 | 581 | |
duke@435 | 582 | static oop _java_system_loader; |
duke@435 | 583 | |
duke@435 | 584 | static bool _has_loadClassInternal; |
duke@435 | 585 | static bool _has_checkPackageAccess; |
duke@435 | 586 | }; |