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