src/share/vm/classfile/systemDictionary.hpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 1014
0fbdb4381b99
child 1145
e5b0439ef4ae
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

duke@435 1 /*
xdono@1014 2 * Copyright 1997-2009 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;
jrose@1100 164 friend class SystemDictionaryHandles;
duke@435 165 NOT_PRODUCT(friend class instanceKlassKlass;)
duke@435 166
duke@435 167 public:
jrose@567 168 enum WKID {
jrose@567 169 NO_WKID = 0,
jrose@567 170
jrose@567 171 #define WK_KLASS_ENUM(name, ignore_s, ignore_o) WK_KLASS_ENUM_NAME(name),
jrose@567 172 WK_KLASSES_DO(WK_KLASS_ENUM)
jrose@567 173 #undef WK_KLASS_ENUM
jrose@567 174
jrose@567 175 WKID_LIMIT,
jrose@567 176
jrose@567 177 FIRST_WKID = NO_WKID + 1
jrose@567 178 };
jrose@567 179
jrose@567 180 enum InitOption {
jrose@567 181 Pre, // preloaded; error if not present
jrose@567 182
jrose@567 183 // Order is significant. Options before this point require resolve_or_fail.
jrose@567 184 // Options after this point will use resolve_or_null instead.
jrose@567 185
jrose@567 186 Opt, // preload tried; NULL if not present
jrose@567 187 Opt_Only_JDK14NewRef, // preload tried; use only with NewReflection
jrose@567 188 Opt_Only_JDK15, // preload tried; use only with JDK1.5+
jrose@567 189 Opt_Kernel, // preload tried only #ifdef KERNEL
jrose@567 190 OPTION_LIMIT,
jrose@567 191 CEIL_LG_OPTION_LIMIT = 4 // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT)
jrose@567 192 };
jrose@567 193
jrose@567 194
duke@435 195 // Returns a class with a given class name and class loader. Loads the
duke@435 196 // class if needed. If not found a NoClassDefFoundError or a
duke@435 197 // ClassNotFoundException is thrown, depending on the value on the
duke@435 198 // throw_error flag. For most uses the throw_error argument should be set
duke@435 199 // to true.
duke@435 200
duke@435 201 static klassOop resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS);
duke@435 202 // Convenient call for null loader and protection domain.
duke@435 203 static klassOop resolve_or_fail(symbolHandle class_name, bool throw_error, TRAPS);
duke@435 204 private:
duke@435 205 // handle error translation for resolve_or_null results
duke@435 206 static klassOop handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS);
duke@435 207
duke@435 208 public:
duke@435 209
duke@435 210 // Returns a class with a given class name and class loader.
duke@435 211 // Loads the class if needed. If not found NULL is returned.
duke@435 212 static klassOop resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
duke@435 213 // Version with null loader and protection domain
duke@435 214 static klassOop resolve_or_null(symbolHandle class_name, TRAPS);
duke@435 215
duke@435 216 // Resolve a superclass or superinterface. Called from ClassFileParser,
duke@435 217 // parse_interfaces, resolve_instance_class_or_null, load_shared_class
duke@435 218 // "child_name" is the class whose super class or interface is being resolved.
duke@435 219 static klassOop resolve_super_or_fail(symbolHandle child_name,
duke@435 220 symbolHandle class_name,
duke@435 221 Handle class_loader,
duke@435 222 Handle protection_domain,
duke@435 223 bool is_superclass,
duke@435 224 TRAPS);
duke@435 225
duke@435 226 // Parse new stream. This won't update the system dictionary or
duke@435 227 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses.
duke@435 228 static klassOop parse_stream(symbolHandle class_name,
duke@435 229 Handle class_loader,
duke@435 230 Handle protection_domain,
duke@435 231 ClassFileStream* st,
jrose@866 232 TRAPS) {
jrose@866 233 KlassHandle nullHandle;
jrose@866 234 return parse_stream(class_name, class_loader, protection_domain, st, nullHandle, NULL, THREAD);
jrose@866 235 }
jrose@866 236 static klassOop parse_stream(symbolHandle class_name,
jrose@866 237 Handle class_loader,
jrose@866 238 Handle protection_domain,
jrose@866 239 ClassFileStream* st,
jrose@866 240 KlassHandle host_klass,
jrose@866 241 GrowableArray<Handle>* cp_patches,
duke@435 242 TRAPS);
duke@435 243
duke@435 244 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
duke@435 245 static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader, Handle protection_domain, ClassFileStream* st, TRAPS);
duke@435 246
duke@435 247 // Lookup an already loaded class. If not found NULL is returned.
duke@435 248 static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
duke@435 249
duke@435 250 // Lookup an already loaded instance or array class.
duke@435 251 // Do not make any queries to class loaders; consult only the cache.
duke@435 252 // If not found NULL is returned.
duke@435 253 static klassOop find_instance_or_array_klass(symbolHandle class_name,
duke@435 254 Handle class_loader,
duke@435 255 Handle protection_domain,
duke@435 256 TRAPS);
duke@435 257
jrose@567 258 // If the given name is known to vmSymbols, return the well-know klass:
jrose@567 259 static klassOop find_well_known_klass(symbolOop class_name);
jrose@567 260
duke@435 261 // Lookup an instance or array class that has already been loaded
duke@435 262 // either into the given class loader, or else into another class
duke@435 263 // loader that is constrained (via loader constraints) to produce
duke@435 264 // a consistent class. Do not take protection domains into account.
duke@435 265 // Do not make any queries to class loaders; consult only the cache.
duke@435 266 // Return NULL if the class is not found.
duke@435 267 //
duke@435 268 // This function is a strict superset of find_instance_or_array_klass.
duke@435 269 // This function (the unchecked version) makes a conservative prediction
duke@435 270 // of the result of the checked version, assuming successful lookup.
duke@435 271 // If both functions return non-null, they must return the same value.
duke@435 272 // Also, the unchecked version may sometimes be non-null where the
duke@435 273 // checked version is null. This can occur in several ways:
duke@435 274 // 1. No query has yet been made to the class loader.
duke@435 275 // 2. The class loader was queried, but chose not to delegate.
duke@435 276 // 3. ClassLoader.checkPackageAccess rejected a proposed protection domain.
duke@435 277 // 4. Loading was attempted, but there was a linkage error of some sort.
duke@435 278 // In all of these cases, the loader constraints on this type are
duke@435 279 // satisfied, and it is safe for classes in the given class loader
duke@435 280 // to manipulate strongly-typed values of the found class, subject
duke@435 281 // to local linkage and access checks.
duke@435 282 static klassOop find_constrained_instance_or_array_klass(symbolHandle class_name,
duke@435 283 Handle class_loader,
duke@435 284 TRAPS);
duke@435 285
duke@435 286 // Iterate over all klasses in dictionary
duke@435 287 // Just the classes from defining class loaders
duke@435 288 static void classes_do(void f(klassOop));
duke@435 289 // Added for initialize_itable_for_klass to handle exceptions
duke@435 290 static void classes_do(void f(klassOop, TRAPS), TRAPS);
duke@435 291 // All classes, and their class loaders
duke@435 292 static void classes_do(void f(klassOop, oop));
duke@435 293 // All classes, and their class loaders
duke@435 294 // (added for helpers that use HandleMarks and ResourceMarks)
duke@435 295 static void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
duke@435 296 // All entries in the placeholder table and their class loaders
duke@435 297 static void placeholders_do(void f(symbolOop, oop));
duke@435 298
duke@435 299 // Iterate over all methods in all klasses in dictionary
duke@435 300 static void methods_do(void f(methodOop));
duke@435 301
duke@435 302 // Garbage collection support
duke@435 303
duke@435 304 // This method applies "blk->do_oop" to all the pointers to "system"
duke@435 305 // classes and loaders.
duke@435 306 static void always_strong_oops_do(OopClosure* blk);
duke@435 307 static void always_strong_classes_do(OopClosure* blk);
duke@435 308 // This method applies "blk->do_oop" to all the placeholders.
duke@435 309 static void placeholders_do(OopClosure* blk);
duke@435 310
duke@435 311 // Unload (that is, break root links to) all unmarked classes and
duke@435 312 // loaders. Returns "true" iff something was unloaded.
duke@435 313 static bool do_unloading(BoolObjectClosure* is_alive);
duke@435 314
duke@435 315 // Applies "f->do_oop" to all root oops in the system dictionary.
duke@435 316 static void oops_do(OopClosure* f);
duke@435 317
duke@435 318 // System loader lock
duke@435 319 static oop system_loader_lock() { return _system_loader_lock_obj; }
duke@435 320
duke@435 321 private:
duke@435 322 // Traverses preloaded oops: various system classes. These are
duke@435 323 // guaranteed to be in the perm gen.
duke@435 324 static void preloaded_oops_do(OopClosure* f);
duke@435 325 static void lazily_loaded_oops_do(OopClosure* f);
duke@435 326
duke@435 327 public:
duke@435 328 // Sharing support.
duke@435 329 static void reorder_dictionary();
duke@435 330 static void copy_buckets(char** top, char* end);
duke@435 331 static void copy_table(char** top, char* end);
duke@435 332 static void reverse();
duke@435 333 static void set_shared_dictionary(HashtableBucket* t, int length,
duke@435 334 int number_of_entries);
duke@435 335 // Printing
duke@435 336 static void print() PRODUCT_RETURN;
duke@435 337 static void print_class_statistics() PRODUCT_RETURN;
duke@435 338 static void print_method_statistics() PRODUCT_RETURN;
duke@435 339
duke@435 340 // Number of contained klasses
duke@435 341 // This is both fully loaded classes and classes in the process
duke@435 342 // of being loaded
duke@435 343 static int number_of_classes();
duke@435 344
duke@435 345 // Monotonically increasing counter which grows as classes are
duke@435 346 // loaded or modifications such as hot-swapping or setting/removing
duke@435 347 // of breakpoints are performed
duke@435 348 static inline int number_of_modifications() { assert_locked_or_safepoint(Compile_lock); return _number_of_modifications; }
duke@435 349 // Needed by evolution and breakpoint code
duke@435 350 static inline void notice_modification() { assert_locked_or_safepoint(Compile_lock); ++_number_of_modifications; }
duke@435 351
duke@435 352 // Verification
duke@435 353 static void verify();
duke@435 354
duke@435 355 #ifdef ASSERT
duke@435 356 static bool is_internal_format(symbolHandle class_name);
duke@435 357 #endif
duke@435 358
duke@435 359 // Verify class is in dictionary
duke@435 360 static void verify_obj_klass_present(Handle obj,
duke@435 361 symbolHandle class_name,
duke@435 362 Handle class_loader);
duke@435 363
duke@435 364 // Initialization
duke@435 365 static void initialize(TRAPS);
duke@435 366
duke@435 367 // Fast access to commonly used classes (preloaded)
duke@435 368 static klassOop check_klass(klassOop k) {
duke@435 369 assert(k != NULL, "preloaded klass not initialized");
duke@435 370 return k;
duke@435 371 }
duke@435 372
jrose@567 373 static klassOop check_klass_Pre(klassOop k) { return check_klass(k); }
jrose@567 374 static klassOop check_klass_Opt(klassOop k) { return k; }
jrose@567 375 static klassOop check_klass_Opt_Kernel(klassOop k) { return k; } //== Opt
jrose@567 376 static klassOop check_klass_Opt_Only_JDK15(klassOop k) {
jrose@567 377 assert(JDK_Version::is_gte_jdk15x_version(), "JDK 1.5 only");
jrose@567 378 return k;
jrose@567 379 }
jrose@567 380 static klassOop check_klass_Opt_Only_JDK14NewRef(klassOop k) {
duke@435 381 assert(JDK_Version::is_gte_jdk14x_version() && UseNewReflection, "JDK 1.4 only");
jrose@567 382 // despite the optional loading, if you use this it must be present:
jrose@567 383 return check_klass(k);
duke@435 384 }
duke@435 385
jrose@567 386 static bool initialize_wk_klass(WKID id, int init_opt, TRAPS);
jrose@567 387 static void initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS);
jrose@567 388 static void initialize_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) {
jrose@567 389 int limit = (int)end_id + 1;
jrose@567 390 initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
jrose@567 391 }
duke@435 392
jrose@567 393 public:
jrose@567 394 #define WK_KLASS_DECLARE(name, ignore_symbol, option) \
jrose@567 395 static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
jrose@567 396 WK_KLASSES_DO(WK_KLASS_DECLARE);
jrose@567 397 #undef WK_KLASS_DECLARE
duke@435 398
jrose@567 399 // Local definition for direct access to the private array:
jrose@582 400 #define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]
duke@435 401
duke@435 402 static klassOop box_klass(BasicType t) {
duke@435 403 assert((uint)t < T_VOID+1, "range check");
duke@435 404 return check_klass(_box_klasses[t]);
duke@435 405 }
duke@435 406 static BasicType box_klass_type(klassOop k); // inverse of box_klass
duke@435 407
duke@435 408 // methods returning lazily loaded klasses
duke@435 409 // The corresponding method to load the class must be called before calling them.
duke@435 410 static klassOop abstract_ownable_synchronizer_klass() { return check_klass(_abstract_ownable_synchronizer_klass); }
duke@435 411
duke@435 412 static void load_abstract_ownable_synchronizer_klass(TRAPS);
duke@435 413
duke@435 414 private:
duke@435 415 // Tells whether ClassLoader.loadClassInternal is present
duke@435 416 static bool has_loadClassInternal() { return _has_loadClassInternal; }
duke@435 417
duke@435 418 public:
duke@435 419 // Tells whether ClassLoader.checkPackageAccess is present
duke@435 420 static bool has_checkPackageAccess() { return _has_checkPackageAccess; }
duke@435 421
jrose@567 422 static bool class_klass_loaded() { return WK_KLASS(class_klass) != NULL; }
jrose@567 423 static bool cloneable_klass_loaded() { return WK_KLASS(cloneable_klass) != NULL; }
duke@435 424
duke@435 425 // Returns default system loader
duke@435 426 static oop java_system_loader();
duke@435 427
duke@435 428 // Compute the default system loader
duke@435 429 static void compute_java_system_loader(TRAPS);
duke@435 430
duke@435 431 private:
duke@435 432 // Mirrors for primitive classes (created eagerly)
duke@435 433 static oop check_mirror(oop m) {
duke@435 434 assert(m != NULL, "mirror not initialized");
duke@435 435 return m;
duke@435 436 }
duke@435 437
duke@435 438 public:
duke@435 439 // Note: java_lang_Class::primitive_type is the inverse of java_mirror
duke@435 440
duke@435 441 // Check class loader constraints
duke@435 442 static bool add_loader_constraint(symbolHandle name, Handle loader1,
duke@435 443 Handle loader2, TRAPS);
duke@435 444 static char* check_signature_loaders(symbolHandle signature, Handle loader1,
duke@435 445 Handle loader2, bool is_method, TRAPS);
duke@435 446
duke@435 447 // Utility for printing loader "name" as part of tracing constraints
duke@435 448 static const char* loader_name(oop loader) {
duke@435 449 return ((loader) == NULL ? "<bootloader>" :
duke@435 450 instanceKlass::cast((loader)->klass())->name()->as_C_string() );
duke@435 451 }
duke@435 452
duke@435 453 // Record the error when the first attempt to resolve a reference from a constant
duke@435 454 // pool entry to a class fails.
duke@435 455 static void add_resolution_error(constantPoolHandle pool, int which, symbolHandle error);
duke@435 456 static symbolOop find_resolution_error(constantPoolHandle pool, int which);
duke@435 457
duke@435 458 private:
duke@435 459
duke@435 460 enum Constants {
duke@435 461 _loader_constraint_size = 107, // number of entries in constraint table
duke@435 462 _resolution_error_size = 107, // number of entries in resolution error table
duke@435 463 _nof_buckets = 1009 // number of buckets in hash table
duke@435 464 };
duke@435 465
duke@435 466
duke@435 467 // Static variables
duke@435 468
duke@435 469 // Hashtable holding loaded classes.
duke@435 470 static Dictionary* _dictionary;
duke@435 471
duke@435 472 // Hashtable holding placeholders for classes being loaded.
duke@435 473 static PlaceholderTable* _placeholders;
duke@435 474
duke@435 475 // Hashtable holding classes from the shared archive.
duke@435 476 static Dictionary* _shared_dictionary;
duke@435 477
duke@435 478 // Monotonically increasing counter which grows with
duke@435 479 // _number_of_classes as well as hot-swapping and breakpoint setting
duke@435 480 // and removal.
duke@435 481 static int _number_of_modifications;
duke@435 482
duke@435 483 // Lock object for system class loader
duke@435 484 static oop _system_loader_lock_obj;
duke@435 485
duke@435 486 // Constraints on class loaders
duke@435 487 static LoaderConstraintTable* _loader_constraints;
duke@435 488
duke@435 489 // Resolution errors
duke@435 490 static ResolutionErrorTable* _resolution_errors;
duke@435 491
duke@435 492 public:
duke@435 493 // for VM_CounterDecay iteration support
duke@435 494 friend class CounterDecay;
duke@435 495 static klassOop try_get_next_class();
duke@435 496
duke@435 497 private:
duke@435 498 static void validate_protection_domain(instanceKlassHandle klass,
duke@435 499 Handle class_loader,
duke@435 500 Handle protection_domain, TRAPS);
duke@435 501
duke@435 502 friend class VM_PopulateDumpSharedSpace;
duke@435 503 friend class TraversePlaceholdersClosure;
duke@435 504 static Dictionary* dictionary() { return _dictionary; }
duke@435 505 static Dictionary* shared_dictionary() { return _shared_dictionary; }
duke@435 506 static PlaceholderTable* placeholders() { return _placeholders; }
duke@435 507 static LoaderConstraintTable* constraints() { return _loader_constraints; }
duke@435 508 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; }
duke@435 509
duke@435 510 // Basic loading operations
duke@435 511 static klassOop resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
duke@435 512 static klassOop resolve_array_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
duke@435 513 static instanceKlassHandle handle_parallel_super_load(symbolHandle class_name, symbolHandle supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS);
duke@435 514 // Wait on SystemDictionary_lock; unlocks lockObject before
duke@435 515 // waiting; relocks lockObject with correct recursion count
duke@435 516 // after waiting, but before reentering SystemDictionary_lock
duke@435 517 // to preserve lock order semantics.
duke@435 518 static void double_lock_wait(Handle lockObject, TRAPS);
duke@435 519 static void define_instance_class(instanceKlassHandle k, TRAPS);
duke@435 520 static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name,
duke@435 521 Handle class_loader,
duke@435 522 instanceKlassHandle k, TRAPS);
duke@435 523 static instanceKlassHandle load_shared_class(symbolHandle class_name,
duke@435 524 Handle class_loader, TRAPS);
duke@435 525 static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
duke@435 526 Handle class_loader, TRAPS);
duke@435 527 static instanceKlassHandle load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS);
duke@435 528 static Handle compute_loader_lock_object(Handle class_loader, TRAPS);
duke@435 529 static void check_loader_lock_contention(Handle loader_lock, TRAPS);
acorn@949 530 static bool is_parallelCapable(Handle class_loader);
duke@435 531
duke@435 532 static klassOop find_shared_class(symbolHandle class_name);
duke@435 533
duke@435 534 // Setup link to hierarchy
duke@435 535 static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
duke@435 536
duke@435 537 private:
duke@435 538 // We pass in the hashtable index so we can calculate it outside of
duke@435 539 // the SystemDictionary_lock.
duke@435 540
duke@435 541 // Basic find on loaded classes
duke@435 542 static klassOop find_class(int index, unsigned int hash,
duke@435 543 symbolHandle name, Handle loader);
duke@435 544
duke@435 545 // Basic find on classes in the midst of being loaded
duke@435 546 static symbolOop find_placeholder(int index, unsigned int hash,
duke@435 547 symbolHandle name, Handle loader);
duke@435 548
duke@435 549 // Basic find operation of loaded classes and classes in the midst
duke@435 550 // of loading; used for assertions and verification only.
duke@435 551 static oop find_class_or_placeholder(symbolHandle class_name,
duke@435 552 Handle class_loader);
duke@435 553
duke@435 554 // Updating entry in dictionary
duke@435 555 // Add a completely loaded class
duke@435 556 static void add_klass(int index, symbolHandle class_name,
duke@435 557 Handle class_loader, KlassHandle obj);
duke@435 558
duke@435 559 // Add a placeholder for a class being loaded
duke@435 560 static void add_placeholder(int index,
duke@435 561 symbolHandle class_name,
duke@435 562 Handle class_loader);
duke@435 563 static void remove_placeholder(int index,
duke@435 564 symbolHandle class_name,
duke@435 565 Handle class_loader);
duke@435 566
duke@435 567 // Performs cleanups after resolve_super_or_fail. This typically needs
duke@435 568 // to be called on failure.
duke@435 569 // Won't throw, but can block.
duke@435 570 static void resolution_cleanups(symbolHandle class_name,
duke@435 571 Handle class_loader,
duke@435 572 TRAPS);
duke@435 573
duke@435 574 // Initialization
duke@435 575 static void initialize_preloaded_classes(TRAPS);
duke@435 576
duke@435 577 // Class loader constraints
duke@435 578 static void check_constraints(int index, unsigned int hash,
duke@435 579 instanceKlassHandle k, Handle loader,
duke@435 580 bool defining, TRAPS);
duke@435 581 static void update_dictionary(int d_index, unsigned int d_hash,
duke@435 582 int p_index, unsigned int p_hash,
duke@435 583 instanceKlassHandle k, Handle loader, TRAPS);
duke@435 584
duke@435 585 // Variables holding commonly used klasses (preloaded)
jrose@567 586 static klassOop _well_known_klasses[];
duke@435 587
duke@435 588 // Lazily loaded klasses
duke@435 589 static volatile klassOop _abstract_ownable_synchronizer_klass;
duke@435 590
jrose@567 591 // table of box klasses (int_klass, etc.)
duke@435 592 static klassOop _box_klasses[T_VOID+1];
duke@435 593
duke@435 594 static oop _java_system_loader;
duke@435 595
duke@435 596 static bool _has_loadClassInternal;
duke@435 597 static bool _has_checkPackageAccess;
duke@435 598 };
jrose@1100 599
jrose@1100 600 // Cf. vmSymbols vs. vmSymbolHandles
jrose@1100 601 class SystemDictionaryHandles : AllStatic {
jrose@1100 602 public:
jrose@1100 603 #define WK_KLASS_HANDLE_DECLARE(name, ignore_symbol, option) \
jrose@1100 604 static KlassHandle name() { \
jrose@1100 605 SystemDictionary::name(); \
jrose@1100 606 klassOop* loc = &SystemDictionary::_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]; \
jrose@1100 607 return KlassHandle(loc, true); \
jrose@1100 608 }
jrose@1100 609 WK_KLASSES_DO(WK_KLASS_HANDLE_DECLARE);
jrose@1100 610 #undef WK_KLASS_HANDLE_DECLARE
jrose@1100 611
jrose@1100 612 static KlassHandle box_klass(BasicType t);
jrose@1100 613 };

mercurial