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_ClassLoaders_klass, jdk_internal_loader_ClassLoaders ) \ 239 do_klass(jdk_internal_loader_ClassLoaders_AppClassLoader_klass, jdk_internal_loader_ClassLoaders_AppClassLoader) \ 240 do_klass(jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass, jdk_internal_loader_ClassLoaders_PlatformClassLoader) \ 241 do_klass(CodeSource_klass, java_security_CodeSource ) \ 242 \ 243 do_klass(StackTraceElement_klass, java_lang_StackTraceElement ) \ 244 \ 245 /* It's okay if this turns out to be NULL in non-1.4 JDKs. */ \ 246 do_klass(nio_Buffer_klass, java_nio_Buffer ) \ 247 \ 248 /* Stack Walking */ \ 249 do_klass(StackWalker_klass, java_lang_StackWalker ) \ 250 do_klass(AbstractStackWalker_klass, java_lang_StackStreamFactory_AbstractStackWalker ) \ 251 do_klass(StackFrameInfo_klass, java_lang_StackFrameInfo ) \ 252 do_klass(LiveStackFrameInfo_klass, java_lang_LiveStackFrameInfo ) \ 253 \ 254 /* support for stack dump lock analysis */ \ 255 do_klass(java_util_concurrent_locks_AbstractOwnableSynchronizer_klass, java_util_concurrent_locks_AbstractOwnableSynchronizer) \ 256 \ 257 /* boxing klasses */ \ 258 do_klass(Boolean_klass, java_lang_Boolean ) \ 259 do_klass(Character_klass, java_lang_Character ) \ 260 do_klass(Float_klass, java_lang_Float ) \ 261 do_klass(Double_klass, java_lang_Double ) \ 262 do_klass(Byte_klass, java_lang_Byte ) \ 263 do_klass(Short_klass, java_lang_Short ) \ 264 do_klass(Integer_klass, java_lang_Integer ) \ 265 do_klass(Long_klass, java_lang_Long ) \ 266 \ 267 /* force inline of iterators */ \ 268 do_klass(Iterator_klass, java_util_Iterator ) \ 269 \ 270 /* support for records */ \ 271 do_klass(RecordComponent_klass, java_lang_reflect_RecordComponent ) \ 272 \ 273 /*end*/ 274 275 class SystemDictionary : AllStatic { 276 friend class BootstrapInfo; 277 friend class VMStructs; 278 279 public: 280 enum WKID { 281 NO_WKID = 0, 282 283 #define WK_KLASS_ENUM(name, symbol) WK_KLASS_ENUM_NAME(name), WK_KLASS_ENUM_NAME(symbol) = WK_KLASS_ENUM_NAME(name), 284 WK_KLASSES_DO(WK_KLASS_ENUM) 285 #undef WK_KLASS_ENUM 286 287 WKID_LIMIT, 288 289 FIRST_WKID = NO_WKID + 1 290 }; 291 292 // Returns a class with a given class name and class loader. Loads the 293 // class if needed. If not found a NoClassDefFoundError or a 294 // ClassNotFoundException is thrown, depending on the value on the 295 // throw_error flag. For most uses the throw_error argument should be set 296 // to true. 297 298 static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); 299 // Convenient call for null loader and protection domain. 300 static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS); 301 protected: 302 // handle error translation for resolve_or_null results 303 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS); 304 305 public: 306 307 // Returns a class with a given class name and class loader. 308 // Loads the class if needed. If not found NULL is returned. 309 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 310 // Version with null loader and protection domain 311 static Klass* resolve_or_null(Symbol* class_name, TRAPS); 312 313 // Resolve a superclass or superinterface. Called from ClassFileParser, 314 // parse_interfaces, resolve_instance_class_or_null, load_shared_class 315 // "child_name" is the class whose super class or interface is being resolved. 316 static InstanceKlass* resolve_super_or_fail(Symbol* child_name, 317 Symbol* class_name, 318 Handle class_loader, 319 Handle protection_domain, 320 bool is_superclass, 321 TRAPS); 322 323 // Parse new stream. This won't update the dictionary or class 324 // hierarchy, simply parse the stream. Used by JVMTI RedefineClasses 325 // and by Unsafe_DefineAnonymousClass and jvm_lookup_define_class. 326 static InstanceKlass* parse_stream(Symbol* class_name, 327 Handle class_loader, 328 ClassFileStream* st, 329 const ClassLoadInfo& cl_info, 330 TRAPS); 331 332 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) 333 static InstanceKlass* resolve_from_stream(Symbol* class_name, 334 Handle class_loader, 335 Handle protection_domain, 336 ClassFileStream* st, 337 TRAPS); 338 339 // Lookup an already loaded class. If not found NULL is returned. 340 static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 341 342 // Lookup an already loaded instance or array class. 343 // Do not make any queries to class loaders; consult only the cache. 344 // If not found NULL is returned. 345 static Klass* find_instance_or_array_klass(Symbol* class_name, 346 Handle class_loader, 347 Handle protection_domain, 348 TRAPS); 349 350 // Lookup an instance or array class that has already been loaded 351 // either into the given class loader, or else into another class 352 // loader that is constrained (via loader constraints) to produce 353 // a consistent class. Do not take protection domains into account. 354 // Do not make any queries to class loaders; consult only the cache. 355 // Return NULL if the class is not found. 356 // 357 // This function is a strict superset of find_instance_or_array_klass. 358 // This function (the unchecked version) makes a conservative prediction 359 // of the result of the checked version, assuming successful lookup. 360 // If both functions return non-null, they must return the same value. 361 // Also, the unchecked version may sometimes be non-null where the 362 // checked version is null. This can occur in several ways: 363 // 1. No query has yet been made to the class loader. 364 // 2. The class loader was queried, but chose not to delegate. 365 // 3. ClassLoader.checkPackageAccess rejected a proposed protection domain. 366 // 4. Loading was attempted, but there was a linkage error of some sort. 367 // In all of these cases, the loader constraints on this type are 368 // satisfied, and it is safe for classes in the given class loader 369 // to manipulate strongly-typed values of the found class, subject 370 // to local linkage and access checks. 371 static Klass* find_constrained_instance_or_array_klass(Symbol* class_name, 372 Handle class_loader, 373 TRAPS); 374 375 static void classes_do(MetaspaceClosure* it); 376 // Iterate over all methods in all klasses 377 378 static void methods_do(void f(Method*)); 379 380 // Garbage collection support 381 382 // Unload (that is, break root links to) all unmarked classes and 383 // loaders. Returns "true" iff something was unloaded. 384 static bool do_unloading(GCTimer* gc_timer); 385 386 // System loader lock 387 static oop system_loader_lock(); 388 389 // Protection Domain Table 390 static ProtectionDomainCacheTable* pd_cache_table() { return _pd_cache_table; } 391 392 public: 393 // Printing 394 static void print(); 395 static void print_on(outputStream* st); 396 static void dump(outputStream* st, bool verbose); 397 398 // Verification 399 static void verify(); 400 401 // Initialization 402 static void initialize(TRAPS); 403 404 // Checked fast access to the well-known classes -- so that you don't try to use them 405 // before they are resolved. 406 static InstanceKlass* check_klass(InstanceKlass* k) { 407 assert(k != NULL, "klass not loaded"); 408 return k; 409 } 410 411 static bool resolve_wk_klass(WKID id, TRAPS); 412 static void resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS); 413 static void resolve_wk_klasses_through(WKID end_id, WKID &start_id, TRAPS) { 414 int limit = (int)end_id + 1; 415 resolve_wk_klasses_until((WKID) limit, start_id, THREAD); 416 } 417 public: 418 #define WK_KLASS(name) _well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)] 419 420 #define WK_KLASS_DECLARE(name, symbol) \ 421 static InstanceKlass* name() { return check_klass(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \ 422 static InstanceKlass** name##_addr() { \ 423 return &_well_known_klasses[SystemDictionary::WK_KLASS_ENUM_NAME(name)]; \ 424 } \ 425 static bool name##_is_loaded() { \ 426 return is_wk_klass_loaded(WK_KLASS(name)); \ 427 } 428 WK_KLASSES_DO(WK_KLASS_DECLARE); 429 #undef WK_KLASS_DECLARE 430 431 static InstanceKlass* well_known_klass(WKID id) { 432 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); 433 return _well_known_klasses[id]; 434 } 435 436 static InstanceKlass** well_known_klass_addr(WKID id) { 437 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); 438 return &_well_known_klasses[id]; 439 } 440 static void well_known_klasses_do(MetaspaceClosure* it); 441 442 static InstanceKlass* box_klass(BasicType t) { 443 assert((uint)t < T_VOID+1, "range check"); 444 return check_klass(_box_klasses[t]); 445 } 446 static BasicType box_klass_type(Klass* k); // inverse of box_klass 447 #ifdef ASSERT 448 static bool is_well_known_klass(Klass* k) { 449 return is_well_known_klass(k->name()); 450 } 451 static bool is_well_known_klass(Symbol* class_name); 452 #endif 453 454 protected: 455 // Returns the class loader data to be used when looking up/updating the 456 // system dictionary. 457 static ClassLoaderData *class_loader_data(Handle class_loader) { 458 return ClassLoaderData::class_loader_data(class_loader()); 459 } 460 461 static bool is_wk_klass_loaded(InstanceKlass* klass) { 462 return !(klass == NULL || !klass->is_loaded()); 463 } 464 465 public: 466 static bool Object_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(Object_klass)); } 467 static bool Class_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(Class_klass)); } 468 static bool Cloneable_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(Cloneable_klass)); } 469 static bool Parameter_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(reflect_Parameter_klass)); } 470 static bool ClassLoader_klass_loaded() { return is_wk_klass_loaded(WK_KLASS(ClassLoader_klass)); } 471 472 // Returns java system loader 473 static oop java_system_loader(); 474 475 // Returns java platform loader 476 static oop java_platform_loader(); 477 478 // Compute the java system and platform loaders 479 static void compute_java_loaders(TRAPS); 480 481 // Register a new class loader 482 static ClassLoaderData* register_loader(Handle class_loader, bool create_mirror_cld = false); 483 protected: 484 // Mirrors for primitive classes (created eagerly) 485 static oop check_mirror(oop m) { 486 assert(m != NULL, "mirror not initialized"); 487 return m; 488 } 489 490 public: 491 // Note: java_lang_Class::primitive_type is the inverse of java_mirror 492 493 // Check class loader constraints 494 static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1, 495 Handle loader2, TRAPS); 496 static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked, 497 Handle loader1, Handle loader2, bool is_method, TRAPS); 498 499 // JSR 292 500 // find a java.lang.invoke.MethodHandle.invoke* method for a given signature 501 // (asks Java to compute it if necessary, except in a compiler thread) 502 static Method* find_method_handle_invoker(Klass* klass, 503 Symbol* name, 504 Symbol* signature, 505 Klass* accessing_klass, 506 Handle *appendix_result, 507 TRAPS); 508 // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic) 509 // (does not ask Java, since this is a low-level intrinsic defined by the JVM) 510 static Method* find_method_handle_intrinsic(vmIntrinsics::ID iid, 511 Symbol* signature, 512 TRAPS); 513 514 // compute java_mirror (java.lang.Class instance) for a type ("I", "[[B", "LFoo;", etc.) 515 // Either the accessing_klass or the CL/PD can be non-null, but not both. 516 static Handle find_java_mirror_for_type(Symbol* signature, 517 Klass* accessing_klass, 518 Handle class_loader, 519 Handle protection_domain, 520 SignatureStream::FailureMode failure_mode, 521 TRAPS); 522 static Handle find_java_mirror_for_type(Symbol* signature, 523 Klass* accessing_klass, 524 SignatureStream::FailureMode failure_mode, 525 TRAPS) { 526 // callee will fill in CL/PD from AK, if they are needed 527 return find_java_mirror_for_type(signature, accessing_klass, Handle(), Handle(), 528 failure_mode, THREAD); 529 } 530 531 // find a java.lang.invoke.MethodType object for a given signature 532 // (asks Java to compute it if necessary, except in a compiler thread) 533 static Handle find_method_handle_type(Symbol* signature, 534 Klass* accessing_klass, 535 TRAPS); 536 537 // find a java.lang.Class object for a given signature 538 static Handle find_field_handle_type(Symbol* signature, 539 Klass* accessing_klass, 540 TRAPS); 541 542 // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry 543 static Handle link_method_handle_constant(Klass* caller, 544 int ref_kind, //e.g., JVM_REF_invokeVirtual 545 Klass* callee, 546 Symbol* name, 547 Symbol* signature, 548 TRAPS); 549 550 // ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry 551 static void invoke_bootstrap_method(BootstrapInfo& bootstrap_specifier, TRAPS); 552 553 // Record the error when the first attempt to resolve a reference from a constant 554 // pool entry to a class fails. 555 static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error, 556 Symbol* message); 557 static void delete_resolution_error(ConstantPool* pool); 558 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which, 559 Symbol** message); 560 561 562 // Record a nest host resolution/validation error 563 static void add_nest_host_error(const constantPoolHandle& pool, int which, 564 const char* message); 565 static const char* find_nest_host_error(const constantPoolHandle& pool, int which); 566 567 static ProtectionDomainCacheEntry* cache_get(Handle protection_domain); 568 569 protected: 570 571 enum Constants { 572 _loader_constraint_size = 107, // number of entries in constraint table 573 _resolution_error_size = 107, // number of entries in resolution error table 574 _invoke_method_size = 139, // number of entries in invoke method table 575 _placeholder_table_size = 1009 // number of entries in hash table for placeholders 576 }; 577 578 579 // Static tables owned by the SystemDictionary 580 581 // Hashtable holding placeholders for classes being loaded. 582 static PlaceholderTable* _placeholders; 583 584 // Lock object for system class loader 585 static OopHandle _system_loader_lock_obj; 586 587 // Constraints on class loaders 588 static LoaderConstraintTable* _loader_constraints; 589 590 // Resolution errors 591 static ResolutionErrorTable* _resolution_errors; 592 593 // Invoke methods (JSR 292) 594 static SymbolPropertyTable* _invoke_method_table; 595 596 // ProtectionDomain cache 597 static ProtectionDomainCacheTable* _pd_cache_table; 598 599 protected: 600 static void validate_protection_domain(InstanceKlass* klass, 601 Handle class_loader, 602 Handle protection_domain, TRAPS); 603 604 friend class VM_PopulateDumpSharedSpace; 605 friend class TraversePlaceholdersClosure; 606 static PlaceholderTable* placeholders() { return _placeholders; } 607 static LoaderConstraintTable* constraints() { return _loader_constraints; } 608 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } 609 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } 610 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld); 611 612 // Basic loading operations 613 static InstanceKlass* resolve_instance_class_or_null_helper(Symbol* name, 614 Handle class_loader, 615 Handle protection_domain, 616 TRAPS); 617 static InstanceKlass* resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 618 static Klass* resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 619 static InstanceKlass* handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); 620 // Wait on SystemDictionary_lock; unlocks lockObject before 621 // waiting; relocks lockObject with correct recursion count 622 // after waiting, but before reentering SystemDictionary_lock 623 // to preserve lock order semantics. 624 static void double_lock_wait(Handle lockObject, TRAPS); 625 static void define_instance_class(InstanceKlass* k, TRAPS); 626 static InstanceKlass* find_or_define_instance_class(Symbol* class_name, 627 Handle class_loader, 628 InstanceKlass* k, TRAPS); 629 static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik, 630 PackageEntry* pkg_entry, 631 Handle class_loader, TRAPS); 632 static bool is_shared_class_visible_impl(Symbol* class_name, 633 InstanceKlass* ik, 634 PackageEntry* pkg_entry, 635 Handle class_loader, TRAPS); 636 static bool is_shared_class_visible_impl_old(Symbol* class_name, InstanceKlass* ik, 637 PackageEntry* pkg_entry, 638 Handle class_loader, 639 class SharedClassPathEntry* ent, 640 ClassLoaderData* loader_data, TRAPS); 641 static bool check_shared_class_super_type(InstanceKlass* child, InstanceKlass* super, 642 Handle class_loader, Handle protection_domain, 643 bool is_superclass, TRAPS); 644 static bool check_shared_class_super_types(InstanceKlass* ik, Handle class_loader, 645 Handle protection_domain, TRAPS); 646 static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik, 647 Handle class_loader, 648 Handle protection_domain, 649 PackageEntry* pkg_entry, 650 TRAPS); 651 static InstanceKlass* load_shared_class(InstanceKlass* ik, 652 Handle class_loader, 653 Handle protection_domain, 654 const ClassFileStream *cfs, 655 PackageEntry* pkg_entry, 656 TRAPS); 657 // Second part of load_shared_class 658 static void load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data, TRAPS) NOT_CDS_RETURN; 659 static InstanceKlass* load_shared_boot_class(Symbol* class_name, 660 PackageEntry* pkg_entry, 661 TRAPS); 662 static InstanceKlass* load_instance_class(Symbol* class_name, Handle class_loader, TRAPS); 663 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); 664 static void check_loader_lock_contention(Handle loader_lock, TRAPS); 665 static bool is_parallelCapable(Handle class_loader); 666 static bool is_parallelDefine(Handle class_loader); 667 668 public: 669 static bool is_system_class_loader(oop class_loader); 670 static bool is_platform_class_loader(oop class_loader); 671 static bool is_boot_class_loader(oop class_loader) { return class_loader == NULL; } 672 static bool is_builtin_class_loader(oop class_loader) { 673 return is_boot_class_loader(class_loader) || 674 is_platform_class_loader(class_loader) || 675 is_system_class_loader(class_loader); 676 } 677 // Returns TRUE if the method is a non-public member of class java.lang.Object. 678 static bool is_nonpublic_Object_method(Method* m) { 679 assert(m != NULL, "Unexpected NULL Method*"); 680 return !m->is_public() && m->method_holder() == SystemDictionary::Object_klass(); 681 } 682 683 // Return Symbol or throw exception if name given is can not be a valid Symbol. 684 static Symbol* class_name_symbol(const char* name, Symbol* exception, TRAPS); 685 686 protected: 687 // Setup link to hierarchy 688 static void add_to_hierarchy(InstanceKlass* k, TRAPS); 689 690 // Basic find on loaded classes 691 static InstanceKlass* find_class(unsigned int hash, 692 Symbol* name, Dictionary* dictionary); 693 static InstanceKlass* find_class(Symbol* class_name, ClassLoaderData* loader_data); 694 695 // Basic find on classes in the midst of being loaded 696 static Symbol* find_placeholder(Symbol* name, ClassLoaderData* loader_data); 697 698 // Resolve well-known classes so they can be used like SystemDictionary::String_klass() 699 static void resolve_well_known_classes(TRAPS); 700 // quick resolve using CDS for well-known classes only. 701 static void quick_resolve(InstanceKlass* klass, ClassLoaderData* loader_data, Handle domain, TRAPS) NOT_CDS_RETURN; 702 703 // Class loader constraints 704 static void check_constraints(unsigned int hash, 705 InstanceKlass* k, Handle loader, 706 bool defining, TRAPS); 707 static void update_dictionary(unsigned int d_hash, 708 int p_index, unsigned int p_hash, 709 InstanceKlass* k, Handle loader, 710 TRAPS); 711 712 static InstanceKlass* _well_known_klasses[]; 713 714 // table of box klasses (int_klass, etc.) 715 static InstanceKlass* _box_klasses[T_VOID+1]; 716 717 private: 718 static OopHandle _java_system_loader; 719 static OopHandle _java_platform_loader; 720 721 public: 722 static TableStatistics placeholders_statistics(); 723 static TableStatistics loader_constraints_statistics(); 724 static TableStatistics protection_domain_cache_statistics(); 725 }; 726 727 #endif // SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP