src/share/vm/classfile/systemDictionary.hpp

Wed, 08 Apr 2009 10:56:49 -0700

author
jrose
date
Wed, 08 Apr 2009 10:56:49 -0700
changeset 1145
e5b0439ef4ae
parent 1100
c89f86385056
child 1161
be93aad57795
permissions
-rw-r--r--

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

mercurial