1 /* 2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP 26 #define SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP 27 28 #include "classfile/classLoaderData.hpp" 29 #include "oops/objArrayOop.hpp" 30 #include "oops/symbol.hpp" 31 #include "runtime/java.hpp" 32 #include "runtime/mutexLocker.hpp" 33 #include "runtime/reflectionUtils.hpp" 34 #include "runtime/signature.hpp" 35 #include "utilities/hashtable.hpp" 36 37 class ClassInstanceInfo : public StackObj { 38 private: 39 InstanceKlass* _dynamic_nest_host; 40 Handle _class_data; 41 42 public: 43 ClassInstanceInfo() { 44 _dynamic_nest_host = NULL; 45 _class_data = Handle(); 46 } 47 ClassInstanceInfo(InstanceKlass* dynamic_nest_host, Handle class_data) { 48 _dynamic_nest_host = dynamic_nest_host; 49 _class_data = class_data; 50 } 51 52 InstanceKlass* dynamic_nest_host() const { return _dynamic_nest_host; } 53 Handle class_data() const { return _class_data; } 54 friend class ClassLoadInfo; 55 }; 56 57 class ClassLoadInfo : public StackObj { 58 private: 59 Handle _protection_domain; 60 const InstanceKlass* _unsafe_anonymous_host; 61 GrowableArray<Handle>* _cp_patches; 62 ClassInstanceInfo _class_hidden_info; 63 bool _is_hidden; 64 bool _is_strong_hidden; 65 bool _can_access_vm_annotations; 66 67 public: 68 ClassLoadInfo(); 69 ClassLoadInfo(Handle protection_domain); 70 ClassLoadInfo(Handle protection_domain, const InstanceKlass* unsafe_anonymous_host, 71 GrowableArray<Handle>* cp_patches, InstanceKlass* dynamic_nest_host, 72 Handle class_data, bool is_hidden, bool is_strong_hidden, 73 bool can_access_vm_annotations); 74 75 Handle protection_domain() const { return _protection_domain; } 76 const InstanceKlass* unsafe_anonymous_host() const { return _unsafe_anonymous_host; } 77 GrowableArray<Handle>* cp_patches() const { return _cp_patches; } 78 const ClassInstanceInfo* class_hidden_info_ptr() const { return &_class_hidden_info; } 79 bool is_hidden() const { return _is_hidden; } 80 bool is_strong_hidden() const { return _is_strong_hidden; } 81 bool can_access_vm_annotations() const { return _can_access_vm_annotations; } 82 }; 83 84 // The dictionary in each ClassLoaderData stores all loaded classes, either 85 // initiatied by its class loader or defined by its class loader: 86 // 87 // class loader -> ClassLoaderData -> [class, protection domain set] 88 // 89 // Classes are loaded lazily. The default VM class loader is 90 // represented as NULL. 91 92 // The underlying data structure is an open hash table (Dictionary) per 93 // ClassLoaderData with a fixed number of buckets. During loading the 94 // class loader object is locked, (for the VM loader a private lock object is used). 95 // The global SystemDictionary_lock is held for all additions into the ClassLoaderData 96 // dictionaries. TODO: fix lock granularity so that class loading can 97 // be done concurrently, but only by different loaders. 98 // 99 // During loading a placeholder (name, loader) is temporarily placed in 100 // a side data structure, and is used to detect ClassCircularityErrors 101 // and to perform verification during GC. A GC can occur in the midst 102 // of class loading, as we call out to Java, have to take locks, etc. 103 // 104 // When class loading is finished, a new entry is added to the dictionary 105 // of the class loader and the placeholder is removed. Note that the protection 106 // domain field of the dictionary entry has not yet been filled in when 107 // the "real" dictionary entry is created. 108 // 109 // Clients of this class who are interested in finding if a class has 110 // been completely loaded -- not classes in the process of being loaded -- 111 // can read the dictionary unlocked. This is safe because 112 // - entries are only deleted at safepoints 113 // - readers cannot come to a safepoint while actively examining 114 // an entry (an entry cannot be deleted from under a reader) 115 // - entries must be fully formed before they are available to concurrent 116 // readers (we must ensure write ordering) 117 // 118 // Note that placeholders are deleted at any time, as they are removed 119 // when a class is completely loaded. Therefore, readers as well as writers 120 // of placeholders must hold the SystemDictionary_lock. 121 // 122 123 class BootstrapInfo; 124 class ClassFileStream; 125 class Dictionary; 126 class PlaceholderTable; 127 class LoaderConstraintTable; 128 template <MEMFLAGS F> class HashtableBucket; 129 class ResolutionErrorTable; 130 class SymbolPropertyTable; 131 class ProtectionDomainCacheTable; 132 class ProtectionDomainCacheEntry; 133 class GCTimer; 134 class EventClassLoad; 135 136 #define WK_KLASS_ENUM_NAME(kname) kname##_knum 137 138 // Certain classes, such as java.lang.Object and java.lang.String, 139 // are "well-known", in the sense that no class loader is allowed 140 // to provide a different definition. 141 // 142 // Each well-known class has a short klass name (like object_klass), 143 // and a vmSymbol name (like java_lang_Object). 144 // 145 // The order of these definitions is significant: the classes are 146 // resolved during early VM start-up by resolve_well_known_classes 147 // in this order. Changing the order may require careful restructuring 148 // of the VM start-up sequence. 149 // 150 #define WK_KLASSES_DO(do_klass) \ 151 /* well-known classes */ \ 152 do_klass(Object_klass, java_lang_Object ) \ 153 do_klass(String_klass, java_lang_String ) \ 154 do_klass(Class_klass, java_lang_Class ) \ 155 do_klass(Cloneable_klass, java_lang_Cloneable ) \ 156 do_klass(ClassLoader_klass, java_lang_ClassLoader ) \ 157 do_klass(Serializable_klass, java_io_Serializable ) \ 158 do_klass(System_klass, java_lang_System ) \ 159 do_klass(Throwable_klass, java_lang_Throwable ) \ 160 do_klass(Error_klass, java_lang_Error ) \ 161 do_klass(ThreadDeath_klass, java_lang_ThreadDeath ) \ 162 do_klass(Exception_klass, java_lang_Exception ) \ 163 do_klass(RuntimeException_klass, java_lang_RuntimeException ) \ 164 do_klass(SecurityManager_klass, java_lang_SecurityManager ) \ 165 do_klass(ProtectionDomain_klass, java_security_ProtectionDomain ) \ 166 do_klass(AccessControlContext_klass, java_security_AccessControlContext ) \ 167 do_klass(AccessController_klass, java_security_AccessController ) \ 168 do_klass(SecureClassLoader_klass, java_security_SecureClassLoader ) \ 169 do_klass(ClassNotFoundException_klass, java_lang_ClassNotFoundException ) \ 170 do_klass(Record_klass, java_lang_Record ) \ 171 do_klass(NoClassDefFoundError_klass, java_lang_NoClassDefFoundError ) \ 172 do_klass(LinkageError_klass, java_lang_LinkageError ) \ 173 do_klass(ClassCastException_klass, java_lang_ClassCastException ) \ 174 do_klass(ArrayStoreException_klass, java_lang_ArrayStoreException ) \ 175 do_klass(VirtualMachineError_klass, java_lang_VirtualMachineError ) \ 176 do_klass(OutOfMemoryError_klass, java_lang_OutOfMemoryError ) \ 177 do_klass(StackOverflowError_klass, java_lang_StackOverflowError ) \ 178 do_klass(IllegalMonitorStateException_klass, java_lang_IllegalMonitorStateException ) \ 179 do_klass(Reference_klass, java_lang_ref_Reference ) \ 180 \ 181 /* ref klasses and set reference types */ \ 182 do_klass(SoftReference_klass, java_lang_ref_SoftReference ) \ 183 do_klass(WeakReference_klass, java_lang_ref_WeakReference ) \ 184 do_klass(FinalReference_klass, java_lang_ref_FinalReference ) \ 185 do_klass(PhantomReference_klass, java_lang_ref_PhantomReference ) \ 186 do_klass(Finalizer_klass, java_lang_ref_Finalizer ) \ 187 \ 188 do_klass(Thread_klass, java_lang_Thread ) \ 189 do_klass(ThreadGroup_klass, java_lang_ThreadGroup ) \ 190 do_klass(Properties_klass, java_util_Properties ) \ 191 do_klass(Module_klass, java_lang_Module ) \ 192 do_klass(reflect_AccessibleObject_klass, java_lang_reflect_AccessibleObject ) \ 193 do_klass(reflect_Field_klass, java_lang_reflect_Field ) \ 194 do_klass(reflect_Parameter_klass, java_lang_reflect_Parameter ) \ 195 do_klass(reflect_Method_klass, java_lang_reflect_Method ) \ 196 do_klass(reflect_Constructor_klass, java_lang_reflect_Constructor ) \ 197 \ 198 /* NOTE: needed too early in bootstrapping process to have checks based on JDK version */ \ 199 /* It's okay if this turns out to be NULL in non-1.4 JDKs. */ \ 200 do_klass(reflect_MagicAccessorImpl_klass, reflect_MagicAccessorImpl ) \ 201 do_klass(reflect_MethodAccessorImpl_klass, reflect_MethodAccessorImpl ) \ 202 do_klass(reflect_ConstructorAccessorImpl_klass, reflect_ConstructorAccessorImpl ) \ 203 do_klass(reflect_DelegatingClassLoader_klass, reflect_DelegatingClassLoader ) \ 204 do_klass(reflect_ConstantPool_klass, reflect_ConstantPool ) \ 205 do_klass(reflect_UnsafeStaticFieldAccessorImpl_klass, reflect_UnsafeStaticFieldAccessorImpl ) \ 206 do_klass(reflect_CallerSensitive_klass, reflect_CallerSensitive ) \ 207 do_klass(reflect_NativeConstructorAccessorImpl_klass, reflect_NativeConstructorAccessorImpl ) \ 208 \ 209 /* support for dynamic typing; it's OK if these are NULL in earlier JDKs */ \ 210 do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle ) \ 211 do_klass(MethodHandle_klass, java_lang_invoke_MethodHandle ) \ 212 do_klass(VarHandle_klass, java_lang_invoke_VarHandle ) \ 213 do_klass(MemberName_klass, java_lang_invoke_MemberName ) \ 214 do_klass(ResolvedMethodName_klass, java_lang_invoke_ResolvedMethodName ) \ 215 do_klass(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives ) \ 216 do_klass(LambdaForm_klass, java_lang_invoke_LambdaForm ) \ 217 do_klass(MethodType_klass, java_lang_invoke_MethodType ) \ 218 do_klass(BootstrapMethodError_klass, java_lang_BootstrapMethodError ) \ 219 do_klass(CallSite_klass, java_lang_invoke_CallSite ) \ 220 do_klass(Context_klass, java_lang_invoke_MethodHandleNatives_CallSiteContext ) \ 221 do_klass(ConstantCallSite_klass, java_lang_invoke_ConstantCallSite ) \ 222 do_klass(MutableCallSite_klass, java_lang_invoke_MutableCallSite ) \ 223 do_klass(VolatileCallSite_klass, java_lang_invoke_VolatileCallSite ) \ 224 /* Note: MethodHandle must be first, and VolatileCallSite last in group */ \ 225 \ 226 do_klass(AssertionStatusDirectives_klass, java_lang_AssertionStatusDirectives ) \ 227 do_klass(StringBuffer_klass, java_lang_StringBuffer ) \ 228 do_klass(StringBuilder_klass, java_lang_StringBuilder ) \ 229 do_klass(UnsafeConstants_klass, jdk_internal_misc_UnsafeConstants ) \ 230 do_klass(internal_Unsafe_klass, jdk_internal_misc_Unsafe ) \ 231 do_klass(module_Modules_klass, jdk_internal_module_Modules ) \ 232 \ 233 /* support for CDS */ \ 234 do_klass(ByteArrayInputStream_klass, java_io_ByteArrayInputStream ) \ 235 do_klass(URL_klass, java_net_URL ) \ 236 do_klass(Jar_Manifest_klass, java_util_jar_Manifest ) \ 237 do_klass(jdk_internal_loader_ClassLoaders_klass, jdk_internal_loader_ClassLoaders ) \ 238 do_klass(jdk_internal_loader_ClassLoaders_AppClassLoader_klass, jdk_internal_loader_ClassLoaders_AppClassLoader) \ 239 do_klass(jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass, jdk_internal_loader_ClassLoaders_PlatformClassLoader) \ 240 do_klass(CodeSource_klass, java_security_CodeSource ) \ 241 \ 242 do_klass(StackTraceElement_klass, java_lang_StackTraceElement ) \ 243 \ 244 /* It's okay if this turns out to be NULL in non-1.4 JDKs. */ \ 245 do_klass(nio_Buffer_klass, java_nio_Buffer ) \ 246 \ 247 /* Stack Walking */ \ 248 do_klass(StackWalker_klass, java_lang_StackWalker ) \ 249 do_klass(AbstractStackWalker_klass, java_lang_StackStreamFactory_AbstractStackWalker ) \ 250 do_klass(StackFrameInfo_klass, java_lang_StackFrameInfo ) \ 251 do_klass(LiveStackFrameInfo_klass, java_lang_LiveStackFrameInfo ) \ 252 \ 253 /* support for stack dump lock analysis */ \ 254 do_klass(java_util_concurrent_locks_AbstractOwnableSynchronizer_klass, java_util_concurrent_locks_AbstractOwnableSynchronizer) \ 255 \ 256 /* boxing klasses */ \ 257 do_klass(Boolean_klass, java_lang_Boolean ) \ 258 do_klass(Character_klass, java_lang_Character ) \ 259 do_klass(Float_klass, java_lang_Float ) \ 260 do_klass(Double_klass, java_lang_Double ) \ 261 do_klass(Byte_klass, java_lang_Byte ) \ 262 do_klass(Short_klass, java_lang_Short ) \ 263 do_klass(Integer_klass, java_lang_Integer ) \ 264 do_klass(Long_klass, java_lang_Long ) \ 265 \ 266 /* force inline of iterators */ \ 267 do_klass(Iterator_klass, java_util_Iterator ) \ 268 \ 269 /* support for records */ \ 270 do_klass(RecordComponent_klass, java_lang_reflect_RecordComponent ) \ 271 \ 272 /*end*/ 273 274 class SystemDictionary : AllStatic { 275 friend class BootstrapInfo; 276 friend class VMStructs; 277 278 public: 279 enum WKID { 280 NO_WKID = 0, 281 282 #define WK_KLASS_ENUM(name, symbol) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name), 283 WK_KLASSES_DO(WK_KLASS_ENUM) 284 #undef WK_KLASS_ENUM 285 286 WKID_LIMIT, 287 288 FIRST_WKID = NO_WKID + 1 289 }; 290 291 // Returns a class with a given class name and class loader. Loads the 292 // class if needed. If not found a NoClassDefFoundError or a 293 // ClassNotFoundException is thrown, depending on the value on the 294 // throw_error flag. For most uses the throw_error argument should be set 295 // to true. 296 297 static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); 298 // Convenient call for null loader and protection domain. 299 static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS); 300 protected: 301 // handle error translation for resolve_or_null results 302 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS); 303 304 public: 305 306 // Returns a class with a given class name and class loader. 307 // Loads the class if needed. If not found NULL is returned. 308 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 309 // Version with null loader and protection domain 310 static Klass* resolve_or_null(Symbol* class_name, TRAPS); 311 312 // Resolve a superclass or superinterface. Called from ClassFileParser, 313 // parse_interfaces, resolve_instance_class_or_null, load_shared_class 314 // "child_name" is the class whose super class or interface is being resolved. 315 static InstanceKlass* resolve_super_or_fail(Symbol* child_name, 316 Symbol* class_name, 317 Handle class_loader, 318 Handle protection_domain, 319 bool is_superclass, 320 TRAPS); 321 322 // Parse new stream. This won't update the dictionary or class 323 // hierarchy, simply parse the stream. Used by JVMTI RedefineClasses 324 // and by Unsafe_DefineAnonymousClass and jvm_lookup_define_class. 325 static InstanceKlass* parse_stream(Symbol* class_name, 326 Handle class_loader, 327 ClassFileStream* st, 328 const ClassLoadInfo& cl_info, 329 TRAPS); 330 331 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) 332 static InstanceKlass* resolve_from_stream(Symbol* class_name, 333 Handle class_loader, 334 Handle protection_domain, 335 ClassFileStream* st, 336 TRAPS); 337 338 // Lookup an already loaded class. If not found NULL is returned. 339 static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 340 341 // Lookup an already loaded instance or array class. 342 // Do not make any queries to class loaders; consult only the cache. 343 // If not found NULL is returned. 344 static Klass* find_instance_or_array_klass(Symbol* class_name, 345 Handle class_loader, 346 Handle protection_domain, 347 TRAPS); 348 349 // Lookup an instance or array class that has already been loaded 350 // either into the given class loader, or else into another class 351 // loader that is constrained (via loader constraints) to produce 352 // a consistent class. Do not take protection domains into account. 353 // Do not make any queries to class loaders; consult only the cache. 354 // Return NULL if the class is not found. 355 // 356 // This function is a strict superset of find_instance_or_array_klass. 357 // This function (the unchecked version) makes a conservative prediction 358 // of the result of the checked version, assuming successful lookup. 359 // If both functions return non-null, they must return the same value. 360 // Also, the unchecked version may sometimes be non-null where the 361 // checked version is null. This can occur in several ways: 362 // 1. No query has yet been made to the class loader. 363 // 2. The class loader was queried, but chose not to delegate. 364 // 3. ClassLoader.checkPackageAccess rejected a proposed protection domain. 365 // 4. Loading was attempted, but there was a linkage error of some sort. 366 // In all of these cases, the loader constraints on this type are 367 // satisfied, and it is safe for classes in the given class loader 368 // to manipulate strongly-typed values of the found class, subject 369 // to local linkage and access checks. 370 static Klass* find_constrained_instance_or_array_klass(Symbol* class_name, 371 Handle class_loader, 372 TRAPS); 373 374 static void classes_do(MetaspaceClosure* it); 375 // Iterate over all methods in all klasses 376 377 static void methods_do(void f(Method*)); 378 379 // Garbage collection support 380 381 // Unload (that is, break root links to) all unmarked classes and 382 // loaders. Returns "true" iff something was unloaded. 383 static bool do_unloading(GCTimer* gc_timer); 384 385 // Applies "f->do_oop" to all root oops in the system dictionary. 386 // If include_handles is true (the default), then the handles in the 387 // vm_global OopStorage object are included. 388 static void oops_do(OopClosure* f, bool include_handles = true); 389 390 // System loader lock 391 static oop system_loader_lock() { return _system_loader_lock_obj; } 392 393 // Protection Domain Table 394 static ProtectionDomainCacheTable* pd_cache_table() { return _pd_cache_table; } 395 396 public: 397 // Printing 398 static void print(); 399 static void print_on(outputStream* st); 400 static void dump(outputStream* st, bool verbose); 401 402 // Verification 403 static void verify(); 404 405 // Initialization 406 static void initialize(TRAPS); 407 408 // Checked fast access to the well-known classes -- so that you don't try to use them 409 // before they are resolved. 410 static InstanceKlass* check_klass(InstanceKlass* k) { 411 assert(k != NULL, "klass not loaded"); 412 return k; 413 } 414 415 static bool resolve_wk_klass(WKID id, TRAPS); 416 static void resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS); 417 static void resolve_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) { 418 int limit = (int)end_id + 1; 419 resolve_wk_klasses_until((WKID) limit, start_id, THREAD); 420 } 421 public: 422 #define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] 423 424 #define WK_KLASS_DECLARE(name, symbol) \ 425 static InstanceKlass* name() { return check_klass(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \ 426 static InstanceKlass** name##_addr() { \ 427 return &_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]; \ 428 } \ 429 static bool name##_is_loaded() { \ 430 return is_wk_klass_loaded(WK_KLASS(name)); \ 431 } 432 WK_KLASSES_DO(WK_KLASS_DECLARE); 433 #undef WK_KLASS_DECLARE 434 435 static InstanceKlass* well_known_klass(WKID id) { 436 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); 437 return _well_known_klasses[id]; 438 } 439 440 static InstanceKlass** well_known_klass_addr(WKID id) { 441 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); 442 return &_well_known_klasses[id]; 443 } 444 static void well_known_klasses_do(MetaspaceClosure* it); 445 446 static InstanceKlass* box_klass(BasicType t) { 447 assert((uint)t < T_VOID+1, "range check"); 448 return check_klass(_box_klasses[t]); 449 } 450 static BasicType box_klass_type(Klass* k); // inverse of box_klass 451 #ifdef ASSERT 452 static bool is_well_known_klass(Klass* k) { 453 return is_well_known_klass(k->name()); 454 } 455 static bool is_well_known_klass(Symbol* class_name); 456 #endif 457 458 protected: 459 // Returns the class loader data to be used when looking up/updating the 460 // system dictionary. 461 static ClassLoaderData *class_loader_data(Handle class_loader) { 462 return ClassLoaderData::class_loader_data(class_loader()); 463 } 464 465 static bool is_wk_klass_loaded(InstanceKlass* klass) { 466 return !(klass == NULL || !klass->is_loaded()); 467 } 468 469 public: 470 static bool Object_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(Object_klass)); } 471 static bool Class_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(Class_klass)); } 472 static bool Cloneable_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(Cloneable_klass)); } 473 static bool Parameter_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(reflect_Parameter_klass)); } 474 static bool ClassLoader_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(ClassLoader_klass)); } 475 476 // Returns java system loader 477 static oop java_system_loader(); 478 479 // Returns java platform loader 480 static oop java_platform_loader(); 481 482 // Compute the java system and platform loaders 483 static void compute_java_loaders(TRAPS); 484 485 // Register a new class loader 486 static ClassLoaderData* register_loader(Handle class_loader, bool create_mirror_cld = false); 487 protected: 488 // Mirrors for primitive classes (created eagerly) 489 static oop check_mirror(oop m) { 490 assert(m != NULL, "mirror not initialized"); 491 return m; 492 } 493 494 public: 495 // Note: java_lang_Class::primitive_type is the inverse of java_mirror 496 497 // Check class loader constraints 498 static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1, 499 Handle loader2, TRAPS); 500 static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked, 501 Handle loader1, Handle loader2, bool is_method, TRAPS); 502 503 // JSR 292 504 // find a java.lang.invoke.MethodHandle.invoke* method for a given signature 505 // (asks Java to compute it if necessary, except in a compiler thread) 506 static Method* find_method_handle_invoker(Klass* klass, 507 Symbol* name, 508 Symbol* signature, 509 Klass* accessing_klass, 510 Handle *appendix_result, 511 TRAPS); 512 // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic) 513 // (does not ask Java, since this is a low-level intrinsic defined by the JVM) 514 static Method* find_method_handle_intrinsic(vmIntrinsics::ID iid, 515 Symbol* signature, 516 TRAPS); 517 518 // compute java_mirror (java.lang.Class instance) for a type ("I", "[[B", "LFoo;", etc.) 519 // Either the accessing_klass or the CL/PD can be non-null, but not both. 520 static Handle find_java_mirror_for_type(Symbol* signature, 521 Klass* accessing_klass, 522 Handle class_loader, 523 Handle protection_domain, 524 SignatureStream::FailureMode failure_mode, 525 TRAPS); 526 static Handle find_java_mirror_for_type(Symbol* signature, 527 Klass* accessing_klass, 528 SignatureStream::FailureMode failure_mode, 529 TRAPS) { 530 // callee will fill in CL/PD from AK, if they are needed 531 return find_java_mirror_for_type(signature, accessing_klass, Handle(), Handle(), 532 failure_mode, THREAD); 533 } 534 535 // find a java.lang.invoke.MethodType object for a given signature 536 // (asks Java to compute it if necessary, except in a compiler thread) 537 static Handle find_method_handle_type(Symbol* signature, 538 Klass* accessing_klass, 539 TRAPS); 540 541 // find a java.lang.Class object for a given signature 542 static Handle find_field_handle_type(Symbol* signature, 543 Klass* accessing_klass, 544 TRAPS); 545 546 // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry 547 static Handle link_method_handle_constant(Klass* caller, 548 int ref_kind, //e.g., JVM_REF_invokeVirtual 549 Klass* callee, 550 Symbol* name, 551 Symbol* signature, 552 TRAPS); 553 554 // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry 555 static void invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS); 556 557 // Record the error when the first attempt to resolve a reference from a constant 558 // pool entry to a class fails. 559 static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error, 560 Symbol* message); 561 static void delete_resolution_error(ConstantPool* pool); 562 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which, 563 Symbol** message); 564 565 566 // Record a nest host resolution/validation error 567 static void add_nest_host_error(const constantPoolHandle& pool, int which, 568 const char* message); 569 static const char* find_nest_host_error(const constantPoolHandle& pool, int which); 570 571 static ProtectionDomainCacheEntry* cache_get(Handle protection_domain); 572 573 protected: 574 575 enum Constants { 576 _loader_constraint_size = 107, // number of entries in constraint table 577 _resolution_error_size = 107, // number of entries in resolution error table 578 _invoke_method_size = 139, // number of entries in invoke method table 579 _placeholder_table_size = 1009 // number of entries in hash table for placeholders 580 }; 581 582 583 // Static tables owned by the SystemDictionary 584 585 // Hashtable holding placeholders for classes being loaded. 586 static PlaceholderTable* _placeholders; 587 588 // Lock object for system class loader 589 static oop _system_loader_lock_obj; 590 591 // Constraints on class loaders 592 static LoaderConstraintTable* _loader_constraints; 593 594 // Resolution errors 595 static ResolutionErrorTable* _resolution_errors; 596 597 // Invoke methods (JSR 292) 598 static SymbolPropertyTable* _invoke_method_table; 599 600 // ProtectionDomain cache 601 static ProtectionDomainCacheTable* _pd_cache_table; 602 603 protected: 604 static void validate_protection_domain(InstanceKlass* klass, 605 Handle class_loader, 606 Handle protection_domain, TRAPS); 607 608 friend class VM_PopulateDumpSharedSpace; 609 friend class TraversePlaceholdersClosure; 610 static PlaceholderTable* placeholders() { return _placeholders; } 611 static LoaderConstraintTable* constraints() { return _loader_constraints; } 612 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } 613 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } 614 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld); 615 616 // Basic loading operations 617 static InstanceKlass* resolve_instance_class_or_null_helper(Symbol* name, 618 Handle class_loader, 619 Handle protection_domain, 620 TRAPS); 621 static InstanceKlass* resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 622 static Klass* resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 623 static InstanceKlass* handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); 624 // Wait on SystemDictionary_lock; unlocks lockObject before 625 // waiting; relocks lockObject with correct recursion count 626 // after waiting, but before reentering SystemDictionary_lock 627 // to preserve lock order semantics. 628 static void double_lock_wait(Handle lockObject, TRAPS); 629 static void define_instance_class(InstanceKlass* k, TRAPS); 630 static InstanceKlass* find_or_define_instance_class(Symbol* class_name, 631 Handle class_loader, 632 InstanceKlass* k, TRAPS); 633 static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik, 634 PackageEntry* pkg_entry, 635 Handle class_loader, TRAPS); 636 static bool check_shared_class_super_type(InstanceKlass* child, InstanceKlass* super, 637 Handle class_loader, Handle protection_domain, 638 bool is_superclass, TRAPS); 639 static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader, 640 Handle protection_domain, TRAPS); 641 static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik, 642 Handle class_loader, 643 Handle protection_domain, 644 PackageEntry* pkg_entry, 645 TRAPS); 646 static InstanceKlass* load_shared_class(InstanceKlass* ik, 647 Handle class_loader, 648 Handle protection_domain, 649 const ClassFileStream *cfs, 650 PackageEntry* pkg_entry, 651 TRAPS); 652 // Second part of load_shared_class 653 static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data, TRAPS) NOT_CDS_RETURN; 654 static InstanceKlass* load_shared_boot_class(Symbol* class_name, 655 PackageEntry* pkg_entry, 656 TRAPS); 657 static InstanceKlass* load_instance_class(Symbol* class_name, Handle class_loader, TRAPS); 658 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); 659 static void check_loader_lock_contention(Handle loader_lock, TRAPS); 660 static bool is_parallelCapable(Handle class_loader); 661 static bool is_parallelDefine(Handle class_loader); 662 663 public: 664 static bool is_system_class_loader(oop class_loader); 665 static bool is_platform_class_loader(oop class_loader); 666 static bool is_boot_class_loader(oop class_loader) { return class_loader == NULL; } 667 static bool is_builtin_class_loader(oop class_loader) { 668 return is_boot_class_loader(class_loader) || 669 is_platform_class_loader(class_loader) || 670 is_system_class_loader(class_loader); 671 } 672 // Returns TRUE if the method is a non-public member of class java.lang.Object. 673 static bool is_nonpublic_Object_method(Method* m) { 674 assert(m != NULL, "Unexpected NULL Method*"); 675 return !m->is_public() && m->method_holder() == SystemDictionary::Object_klass(); 676 } 677 678 // Return Symbol or throw exception if name given is can not be a valid Symbol. 679 static Symbol* class_name_symbol(const char* name, Symbol* exception, TRAPS); 680 681 protected: 682 // Setup link to hierarchy 683 static void add_to_hierarchy(InstanceKlass* k, TRAPS); 684 685 // Basic find on loaded classes 686 static InstanceKlass* find_class(unsigned int hash, 687 Symbol* name, Dictionary* dictionary); 688 static InstanceKlass* find_class(Symbol* class_name, ClassLoaderData* loader_data); 689 690 // Basic find on classes in the midst of being loaded 691 static Symbol* find_placeholder(Symbol* name, ClassLoaderData* loader_data); 692 693 // Resolve well-known classes so they can be used like SystemDictionary::String_klass() 694 static void resolve_well_known_classes(TRAPS); 695 // quick resolve using CDS for well-known classes only. 696 static void quick_resolve(InstanceKlass* klass, ClassLoaderData* loader_data, Handle domain, TRAPS) NOT_CDS_RETURN; 697 698 // Class loader constraints 699 static void check_constraints(unsigned int hash, 700 InstanceKlass* k, Handle loader, 701 bool defining, TRAPS); 702 static void update_dictionary(unsigned int d_hash, 703 int p_index, unsigned int p_hash, 704 InstanceKlass* k, Handle loader, 705 TRAPS); 706 707 static InstanceKlass* _well_known_klasses[]; 708 709 // table of box klasses (int_klass, etc.) 710 static InstanceKlass* _box_klasses[T_VOID+1]; 711 712 private: 713 static oop _java_system_loader; 714 static oop _java_platform_loader; 715 716 public: 717 static TableStatistics placeholders_statistics(); 718 static TableStatistics loader_constraints_statistics(); 719 static TableStatistics protection_domain_cache_statistics(); 720 }; 721 722 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP