242 Opt, // preload tried; NULL if not present 243 #if INCLUDE_JVMCI 244 Jvmci, // preload tried; error if not present if JVMCI enabled 245 #endif 246 OPTION_LIMIT, 247 CEIL_LG_OPTION_LIMIT = 2 // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT) 248 }; 249 250 251 // Returns a class with a given class name and class loader. Loads the 252 // class if needed. If not found a NoClassDefFoundError or a 253 // ClassNotFoundException is thrown, depending on the value on the 254 // throw_error flag. For most uses the throw_error argument should be set 255 // to true. 256 257 static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); 258 // Convenient call for null loader and protection domain. 259 static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS); 260 protected: 261 // handle error translation for resolve_or_null results 262 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, KlassHandle klass_h, TRAPS); 263 264 public: 265 266 // Returns a class with a given class name and class loader. 267 // Loads the class if needed. If not found NULL is returned. 268 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 269 // Version with null loader and protection domain 270 static Klass* resolve_or_null(Symbol* class_name, TRAPS); 271 272 // Resolve a superclass or superinterface. Called from ClassFileParser, 273 // parse_interfaces, resolve_instance_class_or_null, load_shared_class 274 // "child_name" is the class whose super class or interface is being resolved. 275 static Klass* resolve_super_or_fail(Symbol* child_name, 276 Symbol* class_name, 277 Handle class_loader, 278 Handle protection_domain, 279 bool is_superclass, 280 TRAPS); 281 282 // Parse new stream. This won't update the system dictionary or 283 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. 284 // Also used by Unsafe_DefineAnonymousClass 285 static Klass* parse_stream(Symbol* class_name, 286 Handle class_loader, 287 Handle protection_domain, 288 ClassFileStream* st, 289 TRAPS) { 290 return parse_stream(class_name, 291 class_loader, 292 protection_domain, 293 st, 294 NULL, // host klass 295 NULL, // cp_patches 296 THREAD); 297 } 298 static Klass* parse_stream(Symbol* class_name, 299 Handle class_loader, 300 Handle protection_domain, 301 ClassFileStream* st, 302 const InstanceKlass* host_klass, 303 GrowableArray<Handle>* cp_patches, 304 TRAPS); 305 306 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) 307 static Klass* resolve_from_stream(Symbol* class_name, 308 Handle class_loader, 309 Handle protection_domain, 310 ClassFileStream* st, 311 TRAPS); 312 313 // Lookup an already loaded class. If not found NULL is returned. 314 static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 315 316 // Lookup an already loaded instance or array class. 317 // Do not make any queries to class loaders; consult only the cache. 318 // If not found NULL is returned. 319 static Klass* find_instance_or_array_klass(Symbol* class_name, 320 Handle class_loader, 321 Handle protection_domain, 322 TRAPS); 323 324 // Lookup an instance or array class that has already been loaded 325 // either into the given class loader, or else into another class 326 // loader that is constrained (via loader constraints) to produce 327 // a consistent class. Do not take protection domains into account. 499 static ClassLoaderData* register_loader(Handle class_loader, TRAPS); 500 protected: 501 // Mirrors for primitive classes (created eagerly) 502 static oop check_mirror(oop m) { 503 assert(m != NULL, "mirror not initialized"); 504 return m; 505 } 506 507 public: 508 // Note: java_lang_Class::primitive_type is the inverse of java_mirror 509 510 // Check class loader constraints 511 static bool add_loader_constraint(Symbol* name, Handle loader1, 512 Handle loader2, TRAPS); 513 static Symbol* check_signature_loaders(Symbol* signature, Handle loader1, 514 Handle loader2, bool is_method, TRAPS); 515 516 // JSR 292 517 // find a java.lang.invoke.MethodHandle.invoke* method for a given signature 518 // (asks Java to compute it if necessary, except in a compiler thread) 519 static methodHandle find_method_handle_invoker(KlassHandle klass, 520 Symbol* name, 521 Symbol* signature, 522 KlassHandle accessing_klass, 523 Handle *appendix_result, 524 Handle *method_type_result, 525 TRAPS); 526 // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic) 527 // (does not ask Java, since this is a low-level intrinsic defined by the JVM) 528 static methodHandle find_method_handle_intrinsic(vmIntrinsics::ID iid, 529 Symbol* signature, 530 TRAPS); 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 KlassHandle accessing_klass, 535 TRAPS); 536 537 // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry 538 static Handle link_method_handle_constant(KlassHandle caller, 539 int ref_kind, //e.g., JVM_REF_invokeVirtual 540 KlassHandle callee, 541 Symbol* name, 542 Symbol* signature, 543 TRAPS); 544 545 // ask Java to create a dynamic call site, while linking an invokedynamic op 546 static methodHandle find_dynamic_call_site_invoker(KlassHandle caller, 547 Handle bootstrap_method, 548 Symbol* name, 549 Symbol* type, 550 Handle *appendix_result, 551 Handle *method_type_result, 552 TRAPS); 553 554 // Utility for printing loader "name" as part of tracing constraints 555 static const char* loader_name(const oop loader); 556 static const char* loader_name(const ClassLoaderData* loader_data); 557 558 // Record the error when the first attempt to resolve a reference from a constant 559 // pool entry to a class fails. 560 static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error, 561 Symbol* message); 562 static void delete_resolution_error(ConstantPool* pool); 563 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which, 564 Symbol** message); 565 566 protected: 598 static int _number_of_modifications; 599 600 // Lock object for system class loader 601 static oop _system_loader_lock_obj; 602 603 // Constraints on class loaders 604 static LoaderConstraintTable* _loader_constraints; 605 606 // Resolution errors 607 static ResolutionErrorTable* _resolution_errors; 608 609 // Invoke methods (JSR 292) 610 static SymbolPropertyTable* _invoke_method_table; 611 612 public: 613 // for VM_CounterDecay iteration support 614 friend class CounterDecay; 615 static Klass* try_get_next_class(); 616 617 protected: 618 static void validate_protection_domain(instanceKlassHandle klass, 619 Handle class_loader, 620 Handle protection_domain, TRAPS); 621 622 friend class VM_PopulateDumpSharedSpace; 623 friend class TraversePlaceholdersClosure; 624 static Dictionary* dictionary() { return _dictionary; } 625 static Dictionary* shared_dictionary() { return _shared_dictionary; } 626 static PlaceholderTable* placeholders() { return _placeholders; } 627 static LoaderConstraintTable* constraints() { return _loader_constraints; } 628 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } 629 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } 630 631 // Basic loading operations 632 static Klass* resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 633 static Klass* resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 634 static instanceKlassHandle handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); 635 // Wait on SystemDictionary_lock; unlocks lockObject before 636 // waiting; relocks lockObject with correct recursion count 637 // after waiting, but before reentering SystemDictionary_lock 638 // to preserve lock order semantics. 639 static void double_lock_wait(Handle lockObject, TRAPS); 640 static void define_instance_class(instanceKlassHandle k, TRAPS); 641 static instanceKlassHandle find_or_define_instance_class(Symbol* class_name, 642 Handle class_loader, 643 instanceKlassHandle k, TRAPS); 644 static bool is_shared_class_visible(Symbol* class_name, instanceKlassHandle ik, 645 Handle class_loader, TRAPS); 646 static instanceKlassHandle load_shared_class(instanceKlassHandle ik, 647 Handle class_loader, 648 Handle protection_domain, 649 TRAPS); 650 static instanceKlassHandle load_instance_class(Symbol* class_name, Handle class_loader, TRAPS); 651 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); 652 static void check_loader_lock_contention(Handle loader_lock, TRAPS); 653 static bool is_parallelCapable(Handle class_loader); 654 static bool is_parallelDefine(Handle class_loader); 655 656 public: 657 static instanceKlassHandle load_shared_class(Symbol* class_name, 658 Handle class_loader, 659 TRAPS); 660 static bool is_system_class_loader(oop class_loader); 661 static bool is_platform_class_loader(oop class_loader); 662 663 protected: 664 static Klass* find_shared_class(Symbol* class_name); 665 666 // Setup link to hierarchy 667 static void add_to_hierarchy(instanceKlassHandle k, TRAPS); 668 669 // We pass in the hashtable index so we can calculate it outside of 670 // the SystemDictionary_lock. 671 672 // Basic find on loaded classes 673 static Klass* find_class(int index, unsigned int hash, 674 Symbol* name, ClassLoaderData* loader_data); 675 static Klass* find_class(Symbol* class_name, ClassLoaderData* loader_data); 676 677 // Basic find on classes in the midst of being loaded 678 static Symbol* find_placeholder(Symbol* name, ClassLoaderData* loader_data); 679 680 // Add a placeholder for a class being loaded 681 static void add_placeholder(int index, 682 Symbol* class_name, 683 ClassLoaderData* loader_data); 684 static void remove_placeholder(int index, 685 Symbol* class_name, 686 ClassLoaderData* loader_data); 687 688 // Performs cleanups after resolve_super_or_fail. This typically needs 689 // to be called on failure. 690 // Won't throw, but can block. 691 static void resolution_cleanups(Symbol* class_name, 692 ClassLoaderData* loader_data, 693 TRAPS); 694 695 // Initialization 696 static void initialize_preloaded_classes(TRAPS); 697 698 // Class loader constraints 699 static void check_constraints(int index, unsigned int hash, 700 instanceKlassHandle k, Handle loader, 701 bool defining, TRAPS); 702 static void update_dictionary(int d_index, unsigned int d_hash, 703 int p_index, unsigned int p_hash, 704 instanceKlassHandle k, Handle loader, 705 TRAPS); 706 707 // Variables holding commonly used klasses (preloaded) 708 static InstanceKlass* _well_known_klasses[]; 709 710 // Lazily loaded klasses 711 static InstanceKlass* volatile _abstract_ownable_synchronizer_klass; 712 713 // table of box klasses (int_klass, etc.) 714 static InstanceKlass* _box_klasses[T_VOID+1]; 715 716 static oop _java_system_loader; 717 718 static bool _has_loadClassInternal; 719 static bool _has_checkPackageAccess; 720 }; 721 722 #endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP | 242 Opt, // preload tried; NULL if not present 243 #if INCLUDE_JVMCI 244 Jvmci, // preload tried; error if not present if JVMCI enabled 245 #endif 246 OPTION_LIMIT, 247 CEIL_LG_OPTION_LIMIT = 2 // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT) 248 }; 249 250 251 // Returns a class with a given class name and class loader. Loads the 252 // class if needed. If not found a NoClassDefFoundError or a 253 // ClassNotFoundException is thrown, depending on the value on the 254 // throw_error flag. For most uses the throw_error argument should be set 255 // to true. 256 257 static Klass* resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS); 258 // Convenient call for null loader and protection domain. 259 static Klass* resolve_or_fail(Symbol* class_name, bool throw_error, TRAPS); 260 protected: 261 // handle error translation for resolve_or_null results 262 static Klass* handle_resolution_exception(Symbol* class_name, bool throw_error, Klass* klass, TRAPS); 263 264 public: 265 266 // Returns a class with a given class name and class loader. 267 // Loads the class if needed. If not found NULL is returned. 268 static Klass* resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 269 // Version with null loader and protection domain 270 static Klass* resolve_or_null(Symbol* class_name, TRAPS); 271 272 // Resolve a superclass or superinterface. Called from ClassFileParser, 273 // parse_interfaces, resolve_instance_class_or_null, load_shared_class 274 // "child_name" is the class whose super class or interface is being resolved. 275 static Klass* resolve_super_or_fail(Symbol* child_name, 276 Symbol* class_name, 277 Handle class_loader, 278 Handle protection_domain, 279 bool is_superclass, 280 TRAPS); 281 282 // Parse new stream. This won't update the system dictionary or 283 // class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses. 284 // Also used by Unsafe_DefineAnonymousClass 285 static InstanceKlass* parse_stream(Symbol* class_name, 286 Handle class_loader, 287 Handle protection_domain, 288 ClassFileStream* st, 289 TRAPS) { 290 return parse_stream(class_name, 291 class_loader, 292 protection_domain, 293 st, 294 NULL, // host klass 295 NULL, // cp_patches 296 THREAD); 297 } 298 static InstanceKlass* parse_stream(Symbol* class_name, 299 Handle class_loader, 300 Handle protection_domain, 301 ClassFileStream* st, 302 const InstanceKlass* host_klass, 303 GrowableArray<Handle>* cp_patches, 304 TRAPS); 305 306 // Resolve from stream (called by jni_DefineClass and JVM_DefineClass) 307 static InstanceKlass* resolve_from_stream(Symbol* class_name, 308 Handle class_loader, 309 Handle protection_domain, 310 ClassFileStream* st, 311 TRAPS); 312 313 // Lookup an already loaded class. If not found NULL is returned. 314 static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 315 316 // Lookup an already loaded instance or array class. 317 // Do not make any queries to class loaders; consult only the cache. 318 // If not found NULL is returned. 319 static Klass* find_instance_or_array_klass(Symbol* class_name, 320 Handle class_loader, 321 Handle protection_domain, 322 TRAPS); 323 324 // Lookup an instance or array class that has already been loaded 325 // either into the given class loader, or else into another class 326 // loader that is constrained (via loader constraints) to produce 327 // a consistent class. Do not take protection domains into account. 499 static ClassLoaderData* register_loader(Handle class_loader, TRAPS); 500 protected: 501 // Mirrors for primitive classes (created eagerly) 502 static oop check_mirror(oop m) { 503 assert(m != NULL, "mirror not initialized"); 504 return m; 505 } 506 507 public: 508 // Note: java_lang_Class::primitive_type is the inverse of java_mirror 509 510 // Check class loader constraints 511 static bool add_loader_constraint(Symbol* name, Handle loader1, 512 Handle loader2, TRAPS); 513 static Symbol* check_signature_loaders(Symbol* signature, Handle loader1, 514 Handle loader2, bool is_method, TRAPS); 515 516 // JSR 292 517 // find a java.lang.invoke.MethodHandle.invoke* method for a given signature 518 // (asks Java to compute it if necessary, except in a compiler thread) 519 static methodHandle find_method_handle_invoker(Klass* klass, 520 Symbol* name, 521 Symbol* signature, 522 Klass* accessing_klass, 523 Handle *appendix_result, 524 Handle *method_type_result, 525 TRAPS); 526 // for a given signature, find the internal MethodHandle method (linkTo* or invokeBasic) 527 // (does not ask Java, since this is a low-level intrinsic defined by the JVM) 528 static methodHandle find_method_handle_intrinsic(vmIntrinsics::ID iid, 529 Symbol* signature, 530 TRAPS); 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 // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry 538 static Handle link_method_handle_constant(Klass* caller, 539 int ref_kind, //e.g., JVM_REF_invokeVirtual 540 Klass* callee, 541 Symbol* name, 542 Symbol* signature, 543 TRAPS); 544 545 // ask Java to create a dynamic call site, while linking an invokedynamic op 546 static methodHandle find_dynamic_call_site_invoker(Klass* caller, 547 Handle bootstrap_method, 548 Symbol* name, 549 Symbol* type, 550 Handle *appendix_result, 551 Handle *method_type_result, 552 TRAPS); 553 554 // Utility for printing loader "name" as part of tracing constraints 555 static const char* loader_name(const oop loader); 556 static const char* loader_name(const ClassLoaderData* loader_data); 557 558 // Record the error when the first attempt to resolve a reference from a constant 559 // pool entry to a class fails. 560 static void add_resolution_error(const constantPoolHandle& pool, int which, Symbol* error, 561 Symbol* message); 562 static void delete_resolution_error(ConstantPool* pool); 563 static Symbol* find_resolution_error(const constantPoolHandle& pool, int which, 564 Symbol** message); 565 566 protected: 598 static int _number_of_modifications; 599 600 // Lock object for system class loader 601 static oop _system_loader_lock_obj; 602 603 // Constraints on class loaders 604 static LoaderConstraintTable* _loader_constraints; 605 606 // Resolution errors 607 static ResolutionErrorTable* _resolution_errors; 608 609 // Invoke methods (JSR 292) 610 static SymbolPropertyTable* _invoke_method_table; 611 612 public: 613 // for VM_CounterDecay iteration support 614 friend class CounterDecay; 615 static Klass* try_get_next_class(); 616 617 protected: 618 static void validate_protection_domain(InstanceKlass* klass, 619 Handle class_loader, 620 Handle protection_domain, TRAPS); 621 622 friend class VM_PopulateDumpSharedSpace; 623 friend class TraversePlaceholdersClosure; 624 static Dictionary* dictionary() { return _dictionary; } 625 static Dictionary* shared_dictionary() { return _shared_dictionary; } 626 static PlaceholderTable* placeholders() { return _placeholders; } 627 static LoaderConstraintTable* constraints() { return _loader_constraints; } 628 static ResolutionErrorTable* resolution_errors() { return _resolution_errors; } 629 static SymbolPropertyTable* invoke_method_table() { return _invoke_method_table; } 630 631 // Basic loading operations 632 static Klass* resolve_instance_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 633 static Klass* resolve_array_class_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS); 634 static InstanceKlass* handle_parallel_super_load(Symbol* class_name, Symbol* supername, Handle class_loader, Handle protection_domain, Handle lockObject, TRAPS); 635 // Wait on SystemDictionary_lock; unlocks lockObject before 636 // waiting; relocks lockObject with correct recursion count 637 // after waiting, but before reentering SystemDictionary_lock 638 // to preserve lock order semantics. 639 static void double_lock_wait(Handle lockObject, TRAPS); 640 static void define_instance_class(InstanceKlass* k, TRAPS); 641 static InstanceKlass* find_or_define_instance_class(Symbol* class_name, 642 Handle class_loader, 643 InstanceKlass* k, TRAPS); 644 static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik, 645 Handle class_loader, TRAPS); 646 static InstanceKlass* load_shared_class(InstanceKlass* ik, 647 Handle class_loader, 648 Handle protection_domain, 649 TRAPS); 650 static InstanceKlass* load_instance_class(Symbol* class_name, Handle class_loader, TRAPS); 651 static Handle compute_loader_lock_object(Handle class_loader, TRAPS); 652 static void check_loader_lock_contention(Handle loader_lock, TRAPS); 653 static bool is_parallelCapable(Handle class_loader); 654 static bool is_parallelDefine(Handle class_loader); 655 656 public: 657 static InstanceKlass* load_shared_class(Symbol* class_name, 658 Handle class_loader, 659 TRAPS); 660 static bool is_system_class_loader(oop class_loader); 661 static bool is_platform_class_loader(oop class_loader); 662 663 protected: 664 static InstanceKlass* find_shared_class(Symbol* class_name); 665 666 // Setup link to hierarchy 667 static void add_to_hierarchy(InstanceKlass* k, TRAPS); 668 669 // We pass in the hashtable index so we can calculate it outside of 670 // the SystemDictionary_lock. 671 672 // Basic find on loaded classes 673 static InstanceKlass* find_class(int index, unsigned int hash, 674 Symbol* name, ClassLoaderData* loader_data); 675 static InstanceKlass* find_class(Symbol* class_name, ClassLoaderData* loader_data); 676 677 // Basic find on classes in the midst of being loaded 678 static Symbol* find_placeholder(Symbol* name, ClassLoaderData* loader_data); 679 680 // Add a placeholder for a class being loaded 681 static void add_placeholder(int index, 682 Symbol* class_name, 683 ClassLoaderData* loader_data); 684 static void remove_placeholder(int index, 685 Symbol* class_name, 686 ClassLoaderData* loader_data); 687 688 // Performs cleanups after resolve_super_or_fail. This typically needs 689 // to be called on failure. 690 // Won't throw, but can block. 691 static void resolution_cleanups(Symbol* class_name, 692 ClassLoaderData* loader_data, 693 TRAPS); 694 695 // Initialization 696 static void initialize_preloaded_classes(TRAPS); 697 698 // Class loader constraints 699 static void check_constraints(int index, unsigned int hash, 700 InstanceKlass* k, Handle loader, 701 bool defining, TRAPS); 702 static void update_dictionary(int d_index, unsigned int d_hash, 703 int p_index, unsigned int p_hash, 704 InstanceKlass* k, Handle loader, 705 TRAPS); 706 707 // Variables holding commonly used klasses (preloaded) 708 static InstanceKlass* _well_known_klasses[]; 709 710 // Lazily loaded klasses 711 static InstanceKlass* volatile _abstract_ownable_synchronizer_klass; 712 713 // table of box klasses (int_klass, etc.) 714 static InstanceKlass* _box_klasses[T_VOID+1]; 715 716 static oop _java_system_loader; 717 718 static bool _has_loadClassInternal; 719 static bool _has_checkPackageAccess; 720 }; 721 722 #endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARY_HPP |