rev 58452 : imported patch pkg_name_from_class
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_OOPS_INSTANCEKLASS_HPP 26 #define SHARE_OOPS_INSTANCEKLASS_HPP 27 28 #include "classfile/classLoaderData.hpp" 29 #include "memory/referenceType.hpp" 30 #include "oops/annotations.hpp" 31 #include "oops/constMethod.hpp" 32 #include "oops/fieldInfo.hpp" 33 #include "oops/instanceOop.hpp" 34 #include "oops/klassVtable.hpp" 35 #include "runtime/handles.hpp" 36 #include "runtime/os.hpp" 37 #include "utilities/accessFlags.hpp" 38 #include "utilities/align.hpp" 39 #include "utilities/macros.hpp" 40 #if INCLUDE_JFR 41 #include "jfr/support/jfrKlassExtension.hpp" 42 #endif 43 44 class RecordComponent; 45 46 // An InstanceKlass is the VM level representation of a Java class. 47 // It contains all information needed for at class at execution runtime. 48 49 // InstanceKlass embedded field layout (after declared fields): 50 // [EMBEDDED Java vtable ] size in words = vtable_len 51 // [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size 52 // The embedded nonstatic oop-map blocks are short pairs (offset, length) 53 // indicating where oops are located in instances of this klass. 54 // [EMBEDDED implementor of the interface] only exist for interface 55 // [EMBEDDED unsafe_anonymous_host klass] only exist for an unsafe anonymous class (JSR 292 enabled) 56 // [EMBEDDED fingerprint ] only if should_store_fingerprint()==true 57 58 59 // forward declaration for class -- see below for definition 60 #if INCLUDE_JVMTI 61 class BreakpointInfo; 62 #endif 63 class ClassFileParser; 64 class ClassFileStream; 65 class KlassDepChange; 66 class DependencyContext; 67 class fieldDescriptor; 68 class jniIdMapBase; 69 class JNIid; 70 class JvmtiCachedClassFieldMap; 71 class nmethodBucket; 72 class OopMapCache; 73 class InterpreterOopMap; 74 class PackageEntry; 75 class ModuleEntry; 76 77 // This is used in iterators below. 78 class FieldClosure: public StackObj { 79 public: 80 virtual void do_field(fieldDescriptor* fd) = 0; 81 }; 82 83 #ifndef PRODUCT 84 // Print fields. 85 // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields. 86 class FieldPrinter: public FieldClosure { 87 oop _obj; 88 outputStream* _st; 89 public: 90 FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {} 91 void do_field(fieldDescriptor* fd); 92 }; 93 #endif // !PRODUCT 94 95 // Describes where oops are located in instances of this klass. 96 class OopMapBlock { 97 public: 98 // Byte offset of the first oop mapped by this block. 99 int offset() const { return _offset; } 100 void set_offset(int offset) { _offset = offset; } 101 102 // Number of oops in this block. 103 uint count() const { return _count; } 104 void set_count(uint count) { _count = count; } 105 106 void increment_count(int diff) { _count += diff; } 107 108 int offset_span() const { return _count * heapOopSize; } 109 110 int end_offset() const { 111 return offset() + offset_span(); 112 } 113 114 bool is_contiguous(int another_offset) const { 115 return another_offset == end_offset(); 116 } 117 118 // sizeof(OopMapBlock) in words. 119 static const int size_in_words() { 120 return align_up((int)sizeof(OopMapBlock), wordSize) >> 121 LogBytesPerWord; 122 } 123 124 static int compare_offset(const OopMapBlock* a, const OopMapBlock* b) { 125 return a->offset() - b->offset(); 126 } 127 128 private: 129 int _offset; 130 uint _count; 131 }; 132 133 struct JvmtiCachedClassFileData; 134 135 class InstanceKlass: public Klass { 136 friend class VMStructs; 137 friend class JVMCIVMStructs; 138 friend class ClassFileParser; 139 friend class CompileReplay; 140 141 public: 142 static const KlassID ID = InstanceKlassID; 143 144 protected: 145 InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id = ID); 146 147 public: 148 InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } 149 150 // See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description 151 // of the class loading & initialization procedure, and the use of the states. 152 enum ClassState { 153 allocated, // allocated (but not yet linked) 154 loaded, // loaded and inserted in class hierarchy (but not linked yet) 155 linked, // successfully linked/verified (but not initialized yet) 156 being_initialized, // currently running class initializer 157 fully_initialized, // initialized (successfull final state) 158 initialization_error // error happened during initialization 159 }; 160 161 private: 162 static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS); 163 164 protected: 165 // If you add a new field that points to any metaspace object, you 166 // must add this field to InstanceKlass::metaspace_pointers_do(). 167 168 // Annotations for this class 169 Annotations* _annotations; 170 // Package this class is defined in 171 PackageEntry* _package_entry; 172 // Array classes holding elements of this class. 173 Klass* volatile _array_klasses; 174 // Constant pool for this class. 175 ConstantPool* _constants; 176 // The InnerClasses attribute and EnclosingMethod attribute. The 177 // _inner_classes is an array of shorts. If the class has InnerClasses 178 // attribute, then the _inner_classes array begins with 4-tuples of shorts 179 // [inner_class_info_index, outer_class_info_index, 180 // inner_name_index, inner_class_access_flags] for the InnerClasses 181 // attribute. If the EnclosingMethod attribute exists, it occupies the 182 // last two shorts [class_index, method_index] of the array. If only 183 // the InnerClasses attribute exists, the _inner_classes array length is 184 // number_of_inner_classes * 4. If the class has both InnerClasses 185 // and EnclosingMethod attributes the _inner_classes array length is 186 // number_of_inner_classes * 4 + enclosing_method_attribute_size. 187 Array<jushort>* _inner_classes; 188 189 // The NestMembers attribute. An array of shorts, where each is a 190 // class info index for the class that is a nest member. This data 191 // has not been validated. 192 Array<jushort>* _nest_members; 193 194 // The NestHost attribute. The class info index for the class 195 // that is the nest-host of this class. This data has not been validated. 196 jushort _nest_host_index; 197 198 // Resolved nest-host klass: either true nest-host or self if we are not nested. 199 // By always being set it makes nest-member access checks simpler. 200 InstanceKlass* _nest_host; 201 202 // The contents of the Record attribute. 203 Array<RecordComponent*>* _record_components; 204 205 // the source debug extension for this klass, NULL if not specified. 206 // Specified as UTF-8 string without terminating zero byte in the classfile, 207 // it is stored in the instanceklass as a NULL-terminated UTF-8 string 208 const char* _source_debug_extension; 209 // Array name derived from this class which needs unreferencing 210 // if this class is unloaded. 211 Symbol* _array_name; 212 213 // Number of heapOopSize words used by non-static fields in this klass 214 // (including inherited fields but after header_size()). 215 int _nonstatic_field_size; 216 int _static_field_size; // number words used by static fields (oop and non-oop) in this klass 217 // Constant pool index to the utf8 entry of the Generic signature, 218 // or 0 if none. 219 u2 _generic_signature_index; 220 // Constant pool index to the utf8 entry for the name of source file 221 // containing this klass, 0 if not specified. 222 u2 _source_file_name_index; 223 u2 _static_oop_field_count;// number of static oop fields in this klass 224 u2 _java_fields_count; // The number of declared Java fields 225 int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks 226 227 int _itable_len; // length of Java itable (in words) 228 // _is_marked_dependent can be set concurrently, thus cannot be part of the 229 // _misc_flags. 230 bool _is_marked_dependent; // used for marking during flushing and deoptimization 231 232 // The low two bits of _misc_flags contains the kind field. 233 // This can be used to quickly discriminate among the four kinds of 234 // InstanceKlass. 235 236 static const unsigned _misc_kind_field_size = 2; 237 static const unsigned _misc_kind_field_pos = 0; 238 static const unsigned _misc_kind_field_mask = (1u << _misc_kind_field_size) - 1u; 239 240 static const unsigned _misc_kind_other = 0; // concrete InstanceKlass 241 static const unsigned _misc_kind_reference = 1; // InstanceRefKlass 242 static const unsigned _misc_kind_class_loader = 2; // InstanceClassLoaderKlass 243 static const unsigned _misc_kind_mirror = 3; // InstanceMirrorKlass 244 245 // Start after _misc_kind field. 246 enum { 247 _misc_rewritten = 1 << 2, // methods rewritten. 248 _misc_has_nonstatic_fields = 1 << 3, // for sizing with UseCompressedOops 249 _misc_should_verify_class = 1 << 4, // allow caching of preverification 250 _misc_is_unsafe_anonymous = 1 << 5, // has embedded _unsafe_anonymous_host field 251 _misc_is_contended = 1 << 6, // marked with contended annotation 252 _misc_has_nonstatic_concrete_methods = 1 << 7, // class/superclass/implemented interfaces has non-static, concrete methods 253 _misc_declares_nonstatic_concrete_methods = 1 << 8, // directly declares non-static, concrete methods 254 _misc_has_been_redefined = 1 << 9, // class has been redefined 255 _misc_has_passed_fingerprint_check = 1 << 10, // when this class was loaded, the fingerprint computed from its 256 // code source was found to be matching the value recorded by AOT. 257 _misc_is_scratch_class = 1 << 11, // class is the redefined scratch class 258 _misc_is_shared_boot_class = 1 << 12, // defining class loader is boot class loader 259 _misc_is_shared_platform_class = 1 << 13, // defining class loader is platform class loader 260 _misc_is_shared_app_class = 1 << 14, // defining class loader is app class loader 261 _misc_has_resolved_methods = 1 << 15, // resolved methods table entries added for this class 262 _misc_is_being_redefined = 1 << 16, // used for locking redefinition 263 _misc_has_contended_annotations = 1 << 17 // has @Contended annotation 264 }; 265 u2 shared_loader_type_bits() const { 266 return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class; 267 } 268 u4 _misc_flags; 269 u2 _minor_version; // minor version number of class file 270 u2 _major_version; // major version number of class file 271 Thread* _init_thread; // Pointer to current thread doing initialization (to handle recursive initialization) 272 OopMapCache* volatile _oop_map_cache; // OopMapCache for all methods in the klass (allocated lazily) 273 JNIid* _jni_ids; // First JNI identifier for static fields in this class 274 jmethodID* volatile _methods_jmethod_ids; // jmethodIDs corresponding to method_idnum, or NULL if none 275 nmethodBucket* volatile _dep_context; // packed DependencyContext structure 276 uint64_t volatile _dep_context_last_cleaned; 277 nmethod* _osr_nmethods_head; // Head of list of on-stack replacement nmethods for this class 278 #if INCLUDE_JVMTI 279 BreakpointInfo* _breakpoints; // bpt lists, managed by Method* 280 // Linked instanceKlasses of previous versions 281 InstanceKlass* _previous_versions; 282 // JVMTI fields can be moved to their own structure - see 6315920 283 // JVMTI: cached class file, before retransformable agent modified it in CFLH 284 JvmtiCachedClassFileData* _cached_class_file; 285 #endif 286 287 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change 288 289 // Class states are defined as ClassState (see above). 290 // Place the _init_state here to utilize the unused 2-byte after 291 // _idnum_allocated_count. 292 u1 _init_state; // state of class 293 u1 _reference_type; // reference type 294 295 u2 _this_class_index; // constant pool entry 296 #if INCLUDE_JVMTI 297 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration 298 #endif 299 300 NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies 301 302 // Method array. 303 Array<Method*>* _methods; 304 // Default Method Array, concrete methods inherited from interfaces 305 Array<Method*>* _default_methods; 306 // Interfaces (InstanceKlass*s) this class declares locally to implement. 307 Array<InstanceKlass*>* _local_interfaces; 308 // Interfaces (InstanceKlass*s) this class implements transitively. 309 Array<InstanceKlass*>* _transitive_interfaces; 310 // Int array containing the original order of method in the class file (for JVMTI). 311 Array<int>* _method_ordering; 312 // Int array containing the vtable_indices for default_methods 313 // offset matches _default_methods offset 314 Array<int>* _default_vtable_indices; 315 316 // Instance and static variable information, starts with 6-tuples of shorts 317 // [access, name index, sig index, initval index, low_offset, high_offset] 318 // for all fields, followed by the generic signature data at the end of 319 // the array. Only fields with generic signature attributes have the generic 320 // signature data set in the array. The fields array looks like following: 321 // 322 // f1: [access, name index, sig index, initial value index, low_offset, high_offset] 323 // f2: [access, name index, sig index, initial value index, low_offset, high_offset] 324 // ... 325 // fn: [access, name index, sig index, initial value index, low_offset, high_offset] 326 // [generic signature index] 327 // [generic signature index] 328 // ... 329 Array<u2>* _fields; 330 331 // embedded Java vtable follows here 332 // embedded Java itables follows here 333 // embedded static fields follows here 334 // embedded nonstatic oop-map blocks follows here 335 // embedded implementor of this interface follows here 336 // The embedded implementor only exists if the current klass is an 337 // iterface. The possible values of the implementor fall into following 338 // three cases: 339 // NULL: no implementor. 340 // A Klass* that's not itself: one implementor. 341 // Itself: more than one implementors. 342 // embedded unsafe_anonymous_host klass follows here 343 // The embedded host klass only exists in an unsafe anonymous class for 344 // dynamic language support (JSR 292 enabled). The host class grants 345 // its access privileges to this class also. The host class is either 346 // named, or a previously loaded unsafe anonymous class. A non-anonymous class 347 // or an anonymous class loaded through normal classloading does not 348 // have this embedded field. 349 // 350 351 friend class SystemDictionary; 352 353 static bool _disable_method_binary_search; 354 355 public: 356 // The three BUILTIN class loader types 357 bool is_shared_boot_class() const { 358 return (_misc_flags & _misc_is_shared_boot_class) != 0; 359 } 360 bool is_shared_platform_class() const { 361 return (_misc_flags & _misc_is_shared_platform_class) != 0; 362 } 363 bool is_shared_app_class() const { 364 return (_misc_flags & _misc_is_shared_app_class) != 0; 365 } 366 // The UNREGISTERED class loader type 367 bool is_shared_unregistered_class() const { 368 return (_misc_flags & shared_loader_type_bits()) == 0; 369 } 370 371 void clear_shared_class_loader_type() { 372 _misc_flags &= ~shared_loader_type_bits(); 373 } 374 375 void set_shared_class_loader_type(s2 loader_type); 376 377 bool has_nonstatic_fields() const { 378 return (_misc_flags & _misc_has_nonstatic_fields) != 0; 379 } 380 void set_has_nonstatic_fields(bool b) { 381 if (b) { 382 _misc_flags |= _misc_has_nonstatic_fields; 383 } else { 384 _misc_flags &= ~_misc_has_nonstatic_fields; 385 } 386 } 387 388 // field sizes 389 int nonstatic_field_size() const { return _nonstatic_field_size; } 390 void set_nonstatic_field_size(int size) { _nonstatic_field_size = size; } 391 392 int static_field_size() const { return _static_field_size; } 393 void set_static_field_size(int size) { _static_field_size = size; } 394 395 int static_oop_field_count() const { return (int)_static_oop_field_count; } 396 void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; } 397 398 // Java itable 399 int itable_length() const { return _itable_len; } 400 void set_itable_length(int len) { _itable_len = len; } 401 402 // array klasses 403 Klass* array_klasses() const { return _array_klasses; } 404 inline Klass* array_klasses_acquire() const; // load with acquire semantics 405 void set_array_klasses(Klass* k) { _array_klasses = k; } 406 inline void release_set_array_klasses(Klass* k); // store with release semantics 407 408 // methods 409 Array<Method*>* methods() const { return _methods; } 410 void set_methods(Array<Method*>* a) { _methods = a; } 411 Method* method_with_idnum(int idnum); 412 Method* method_with_orig_idnum(int idnum); 413 Method* method_with_orig_idnum(int idnum, int version); 414 415 // method ordering 416 Array<int>* method_ordering() const { return _method_ordering; } 417 void set_method_ordering(Array<int>* m) { _method_ordering = m; } 418 void copy_method_ordering(const intArray* m, TRAPS); 419 420 // default_methods 421 Array<Method*>* default_methods() const { return _default_methods; } 422 void set_default_methods(Array<Method*>* a) { _default_methods = a; } 423 424 // default method vtable_indices 425 Array<int>* default_vtable_indices() const { return _default_vtable_indices; } 426 void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; } 427 Array<int>* create_new_default_vtable_indices(int len, TRAPS); 428 429 // interfaces 430 Array<InstanceKlass*>* local_interfaces() const { return _local_interfaces; } 431 void set_local_interfaces(Array<InstanceKlass*>* a) { 432 guarantee(_local_interfaces == NULL || a == NULL, "Just checking"); 433 _local_interfaces = a; } 434 435 Array<InstanceKlass*>* transitive_interfaces() const { return _transitive_interfaces; } 436 void set_transitive_interfaces(Array<InstanceKlass*>* a) { 437 guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking"); 438 _transitive_interfaces = a; 439 } 440 441 private: 442 friend class fieldDescriptor; 443 FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); } 444 445 public: 446 int field_offset (int index) const { return field(index)->offset(); } 447 int field_access_flags(int index) const { return field(index)->access_flags(); } 448 Symbol* field_name (int index) const { return field(index)->name(constants()); } 449 Symbol* field_signature (int index) const { return field(index)->signature(constants()); } 450 451 // Number of Java declared fields 452 int java_fields_count() const { return (int)_java_fields_count; } 453 454 Array<u2>* fields() const { return _fields; } 455 void set_fields(Array<u2>* f, u2 java_fields_count) { 456 guarantee(_fields == NULL || f == NULL, "Just checking"); 457 _fields = f; 458 _java_fields_count = java_fields_count; 459 } 460 461 // inner classes 462 Array<u2>* inner_classes() const { return _inner_classes; } 463 void set_inner_classes(Array<u2>* f) { _inner_classes = f; } 464 465 // nest members 466 Array<u2>* nest_members() const { return _nest_members; } 467 void set_nest_members(Array<u2>* m) { _nest_members = m; } 468 469 // nest-host index 470 jushort nest_host_index() const { return _nest_host_index; } 471 void set_nest_host_index(u2 i) { _nest_host_index = i; } 472 473 // record components 474 Array<RecordComponent*>* record_components() const { return _record_components; } 475 void set_record_components(Array<RecordComponent*>* record_components) { 476 _record_components = record_components; 477 } 478 bool is_record() const { return _record_components != NULL; } 479 480 private: 481 // Called to verify that k is a member of this nest - does not look at k's nest-host 482 bool has_nest_member(InstanceKlass* k, TRAPS) const; 483 484 public: 485 // Returns nest-host class, resolving and validating it if needed 486 // Returns NULL if an exception occurs during loading, or validation fails 487 InstanceKlass* nest_host(Symbol* validationException, TRAPS); 488 // Check if this klass is a nestmate of k - resolves this nest-host and k's 489 bool has_nestmate_access_to(InstanceKlass* k, TRAPS); 490 491 enum InnerClassAttributeOffset { 492 // From http://mirror.eng/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc10.html#18814 493 inner_class_inner_class_info_offset = 0, 494 inner_class_outer_class_info_offset = 1, 495 inner_class_inner_name_offset = 2, 496 inner_class_access_flags_offset = 3, 497 inner_class_next_offset = 4 498 }; 499 500 enum EnclosingMethodAttributeOffset { 501 enclosing_method_class_index_offset = 0, 502 enclosing_method_method_index_offset = 1, 503 enclosing_method_attribute_size = 2 504 }; 505 506 // method override check 507 bool is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS); 508 509 // package 510 PackageEntry* package() const { return _package_entry; } 511 ModuleEntry* module() const; 512 bool in_unnamed_package() const { return (_package_entry == NULL); } 513 void set_package(PackageEntry* p) { _package_entry = p; } 514 void set_package(ClassLoaderData* loader_data, TRAPS); 515 bool is_same_class_package(const Klass* class2) const; 516 bool is_same_class_package(oop other_class_loader, const Symbol* other_class_name) const; 517 518 // find an enclosing class 519 InstanceKlass* compute_enclosing_class(bool* inner_is_member, TRAPS) const; 520 521 // Find InnerClasses attribute and return outer_class_info_index & inner_name_index. 522 bool find_inner_classes_attr(int* ooff, int* noff, TRAPS) const; 523 524 private: 525 // Check prohibited package ("java/" only loadable by boot or platform loaders) 526 static void check_prohibited_package(Symbol* class_name, 527 ClassLoaderData* loader_data, 528 TRAPS); 529 public: 530 // initialization state 531 bool is_loaded() const { return _init_state >= loaded; } 532 bool is_linked() const { return _init_state >= linked; } 533 bool is_initialized() const { return _init_state == fully_initialized; } 534 bool is_not_initialized() const { return _init_state < being_initialized; } 535 bool is_being_initialized() const { return _init_state == being_initialized; } 536 bool is_in_error_state() const { return _init_state == initialization_error; } 537 bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; } 538 ClassState init_state() { return (ClassState)_init_state; } 539 bool is_rewritten() const { return (_misc_flags & _misc_rewritten) != 0; } 540 541 // defineClass specified verification 542 bool should_verify_class() const { 543 return (_misc_flags & _misc_should_verify_class) != 0; 544 } 545 void set_should_verify_class(bool value) { 546 if (value) { 547 _misc_flags |= _misc_should_verify_class; 548 } else { 549 _misc_flags &= ~_misc_should_verify_class; 550 } 551 } 552 553 // marking 554 bool is_marked_dependent() const { return _is_marked_dependent; } 555 void set_is_marked_dependent(bool value) { _is_marked_dependent = value; } 556 557 // initialization (virtuals from Klass) 558 bool should_be_initialized() const; // means that initialize should be called 559 void initialize(TRAPS); 560 void link_class(TRAPS); 561 bool link_class_or_fail(TRAPS); // returns false on failure 562 void rewrite_class(TRAPS); 563 void link_methods(TRAPS); 564 Method* class_initializer() const; 565 566 // set the class to initialized if no static initializer is present 567 void eager_initialize(Thread *thread); 568 569 // reference type 570 ReferenceType reference_type() const { return (ReferenceType)_reference_type; } 571 void set_reference_type(ReferenceType t) { 572 assert(t == (u1)t, "overflow"); 573 _reference_type = (u1)t; 574 } 575 576 // this class cp index 577 u2 this_class_index() const { return _this_class_index; } 578 void set_this_class_index(u2 index) { _this_class_index = index; } 579 580 static ByteSize reference_type_offset() { return in_ByteSize(offset_of(InstanceKlass, _reference_type)); } 581 582 // find local field, returns true if found 583 bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const; 584 // find field in direct superinterfaces, returns the interface in which the field is defined 585 Klass* find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const; 586 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined 587 Klass* find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const; 588 // find instance or static fields according to JVM spec 5.4.3.2, returns the klass in which the field is defined 589 Klass* find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const; 590 591 // find a non-static or static field given its offset within the class. 592 bool contains_field_offset(int offset); 593 594 bool find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const; 595 bool find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const; 596 597 private: 598 inline static int quick_search(const Array<Method*>* methods, const Symbol* name); 599 600 public: 601 static void disable_method_binary_search() { 602 _disable_method_binary_search = true; 603 } 604 605 // find a local method (returns NULL if not found) 606 Method* find_method(const Symbol* name, const Symbol* signature) const; 607 static Method* find_method(const Array<Method*>* methods, 608 const Symbol* name, 609 const Symbol* signature); 610 611 // find a local method, but skip static methods 612 Method* find_instance_method(const Symbol* name, const Symbol* signature, 613 PrivateLookupMode private_mode = find_private) const; 614 static Method* find_instance_method(const Array<Method*>* methods, 615 const Symbol* name, 616 const Symbol* signature, 617 PrivateLookupMode private_mode = find_private); 618 619 // find a local method (returns NULL if not found) 620 Method* find_local_method(const Symbol* name, 621 const Symbol* signature, 622 OverpassLookupMode overpass_mode, 623 StaticLookupMode static_mode, 624 PrivateLookupMode private_mode) const; 625 626 // find a local method from given methods array (returns NULL if not found) 627 static Method* find_local_method(const Array<Method*>* methods, 628 const Symbol* name, 629 const Symbol* signature, 630 OverpassLookupMode overpass_mode, 631 StaticLookupMode static_mode, 632 PrivateLookupMode private_mode); 633 634 // find a local method index in methods or default_methods (returns -1 if not found) 635 static int find_method_index(const Array<Method*>* methods, 636 const Symbol* name, 637 const Symbol* signature, 638 OverpassLookupMode overpass_mode, 639 StaticLookupMode static_mode, 640 PrivateLookupMode private_mode); 641 642 // lookup operation (returns NULL if not found) 643 Method* uncached_lookup_method(const Symbol* name, 644 const Symbol* signature, 645 OverpassLookupMode overpass_mode, 646 PrivateLookupMode private_mode = find_private) const; 647 648 // lookup a method in all the interfaces that this class implements 649 // (returns NULL if not found) 650 Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature, DefaultsLookupMode defaults_mode) const; 651 652 // lookup a method in local defaults then in all interfaces 653 // (returns NULL if not found) 654 Method* lookup_method_in_ordered_interfaces(Symbol* name, Symbol* signature) const; 655 656 // Find method indices by name. If a method with the specified name is 657 // found the index to the first method is returned, and 'end' is filled in 658 // with the index of first non-name-matching method. If no method is found 659 // -1 is returned. 660 int find_method_by_name(const Symbol* name, int* end) const; 661 static int find_method_by_name(const Array<Method*>* methods, 662 const Symbol* name, int* end); 663 664 // constant pool 665 ConstantPool* constants() const { return _constants; } 666 void set_constants(ConstantPool* c) { _constants = c; } 667 668 // protection domain 669 oop protection_domain() const; 670 671 // signers 672 objArrayOop signers() const; 673 674 // host class 675 InstanceKlass* unsafe_anonymous_host() const { 676 InstanceKlass** hk = adr_unsafe_anonymous_host(); 677 if (hk == NULL) { 678 assert(!is_unsafe_anonymous(), "Unsafe anonymous classes have host klasses"); 679 return NULL; 680 } else { 681 assert(*hk != NULL, "host klass should always be set if the address is not null"); 682 assert(is_unsafe_anonymous(), "Only unsafe anonymous classes have host klasses"); 683 return *hk; 684 } 685 } 686 void set_unsafe_anonymous_host(const InstanceKlass* host) { 687 assert(is_unsafe_anonymous(), "not unsafe anonymous"); 688 const InstanceKlass** addr = (const InstanceKlass **)adr_unsafe_anonymous_host(); 689 assert(addr != NULL, "no reversed space"); 690 if (addr != NULL) { 691 *addr = host; 692 } 693 } 694 bool is_unsafe_anonymous() const { 695 return (_misc_flags & _misc_is_unsafe_anonymous) != 0; 696 } 697 void set_is_unsafe_anonymous(bool value) { 698 if (value) { 699 _misc_flags |= _misc_is_unsafe_anonymous; 700 } else { 701 _misc_flags &= ~_misc_is_unsafe_anonymous; 702 } 703 } 704 705 bool is_contended() const { 706 return (_misc_flags & _misc_is_contended) != 0; 707 } 708 void set_is_contended(bool value) { 709 if (value) { 710 _misc_flags |= _misc_is_contended; 711 } else { 712 _misc_flags &= ~_misc_is_contended; 713 } 714 } 715 716 // source file name 717 Symbol* source_file_name() const { 718 return (_source_file_name_index == 0) ? 719 (Symbol*)NULL : _constants->symbol_at(_source_file_name_index); 720 } 721 u2 source_file_name_index() const { 722 return _source_file_name_index; 723 } 724 void set_source_file_name_index(u2 sourcefile_index) { 725 _source_file_name_index = sourcefile_index; 726 } 727 728 // minor and major version numbers of class file 729 u2 minor_version() const { return _minor_version; } 730 void set_minor_version(u2 minor_version) { _minor_version = minor_version; } 731 u2 major_version() const { return _major_version; } 732 void set_major_version(u2 major_version) { _major_version = major_version; } 733 734 // source debug extension 735 const char* source_debug_extension() const { return _source_debug_extension; } 736 void set_source_debug_extension(const char* array, int length); 737 738 // symbol unloading support (refcount already added) 739 Symbol* array_name() { return _array_name; } 740 void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; } 741 742 // nonstatic oop-map blocks 743 static int nonstatic_oop_map_size(unsigned int oop_map_count) { 744 return oop_map_count * OopMapBlock::size_in_words(); 745 } 746 unsigned int nonstatic_oop_map_count() const { 747 return _nonstatic_oop_map_size / OopMapBlock::size_in_words(); 748 } 749 int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; } 750 void set_nonstatic_oop_map_size(int words) { 751 _nonstatic_oop_map_size = words; 752 } 753 754 bool has_contended_annotations() const { 755 return ((_misc_flags & _misc_has_contended_annotations) != 0); 756 } 757 void set_has_contended_annotations(bool value) { 758 if (value) { 759 _misc_flags |= _misc_has_contended_annotations; 760 } else { 761 _misc_flags &= ~_misc_has_contended_annotations; 762 } 763 } 764 765 #if INCLUDE_JVMTI 766 // Redefinition locking. Class can only be redefined by one thread at a time. 767 bool is_being_redefined() const { 768 return ((_misc_flags & _misc_is_being_redefined) != 0); 769 } 770 void set_is_being_redefined(bool value) { 771 if (value) { 772 _misc_flags |= _misc_is_being_redefined; 773 } else { 774 _misc_flags &= ~_misc_is_being_redefined; 775 } 776 } 777 778 // RedefineClasses() support for previous versions: 779 void add_previous_version(InstanceKlass* ik, int emcp_method_count); 780 void purge_previous_version_list(); 781 782 InstanceKlass* previous_versions() const { return _previous_versions; } 783 #else 784 InstanceKlass* previous_versions() const { return NULL; } 785 #endif 786 787 InstanceKlass* get_klass_version(int version) { 788 for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) { 789 if (ik->constants()->version() == version) { 790 return ik; 791 } 792 } 793 return NULL; 794 } 795 796 bool has_been_redefined() const { 797 return (_misc_flags & _misc_has_been_redefined) != 0; 798 } 799 void set_has_been_redefined() { 800 _misc_flags |= _misc_has_been_redefined; 801 } 802 803 bool has_passed_fingerprint_check() const { 804 return (_misc_flags & _misc_has_passed_fingerprint_check) != 0; 805 } 806 void set_has_passed_fingerprint_check(bool b) { 807 if (b) { 808 _misc_flags |= _misc_has_passed_fingerprint_check; 809 } else { 810 _misc_flags &= ~_misc_has_passed_fingerprint_check; 811 } 812 } 813 bool supers_have_passed_fingerprint_checks(); 814 815 static bool should_store_fingerprint(bool is_unsafe_anonymous); 816 bool should_store_fingerprint() const { return should_store_fingerprint(is_unsafe_anonymous()); } 817 bool has_stored_fingerprint() const; 818 uint64_t get_stored_fingerprint() const; 819 void store_fingerprint(uint64_t fingerprint); 820 821 bool is_scratch_class() const { 822 return (_misc_flags & _misc_is_scratch_class) != 0; 823 } 824 825 void set_is_scratch_class() { 826 _misc_flags |= _misc_is_scratch_class; 827 } 828 829 bool has_resolved_methods() const { 830 return (_misc_flags & _misc_has_resolved_methods) != 0; 831 } 832 833 void set_has_resolved_methods() { 834 _misc_flags |= _misc_has_resolved_methods; 835 } 836 private: 837 838 void set_kind(unsigned kind) { 839 assert(kind <= _misc_kind_field_mask, "Invalid InstanceKlass kind"); 840 unsigned fmask = _misc_kind_field_mask << _misc_kind_field_pos; 841 unsigned flags = _misc_flags & ~fmask; 842 _misc_flags = (flags | (kind << _misc_kind_field_pos)); 843 } 844 845 bool is_kind(unsigned desired) const { 846 unsigned kind = (_misc_flags >> _misc_kind_field_pos) & _misc_kind_field_mask; 847 return kind == desired; 848 } 849 850 public: 851 852 // Other is anything that is not one of the more specialized kinds of InstanceKlass. 853 bool is_other_instance_klass() const { return is_kind(_misc_kind_other); } 854 bool is_reference_instance_klass() const { return is_kind(_misc_kind_reference); } 855 bool is_mirror_instance_klass() const { return is_kind(_misc_kind_mirror); } 856 bool is_class_loader_instance_klass() const { return is_kind(_misc_kind_class_loader); } 857 858 #if INCLUDE_JVMTI 859 860 void init_previous_versions() { 861 _previous_versions = NULL; 862 } 863 864 private: 865 static bool _has_previous_versions; 866 public: 867 static void purge_previous_versions(InstanceKlass* ik) { 868 if (ik->has_been_redefined()) { 869 ik->purge_previous_version_list(); 870 } 871 } 872 873 static bool has_previous_versions_and_reset(); 874 static bool has_previous_versions() { return _has_previous_versions; } 875 876 // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation 877 void set_cached_class_file(JvmtiCachedClassFileData *data) { 878 _cached_class_file = data; 879 } 880 JvmtiCachedClassFileData * get_cached_class_file(); 881 jint get_cached_class_file_len(); 882 unsigned char * get_cached_class_file_bytes(); 883 884 // JVMTI: Support for caching of field indices, types, and offsets 885 void set_jvmti_cached_class_field_map(JvmtiCachedClassFieldMap* descriptor) { 886 _jvmti_cached_class_field_map = descriptor; 887 } 888 JvmtiCachedClassFieldMap* jvmti_cached_class_field_map() const { 889 return _jvmti_cached_class_field_map; 890 } 891 #else // INCLUDE_JVMTI 892 893 static void purge_previous_versions(InstanceKlass* ik) { return; }; 894 static bool has_previous_versions_and_reset() { return false; } 895 896 void set_cached_class_file(JvmtiCachedClassFileData *data) { 897 assert(data == NULL, "unexpected call with JVMTI disabled"); 898 } 899 JvmtiCachedClassFileData * get_cached_class_file() { return (JvmtiCachedClassFileData *)NULL; } 900 901 #endif // INCLUDE_JVMTI 902 903 bool has_nonstatic_concrete_methods() const { 904 return (_misc_flags & _misc_has_nonstatic_concrete_methods) != 0; 905 } 906 void set_has_nonstatic_concrete_methods(bool b) { 907 if (b) { 908 _misc_flags |= _misc_has_nonstatic_concrete_methods; 909 } else { 910 _misc_flags &= ~_misc_has_nonstatic_concrete_methods; 911 } 912 } 913 914 bool declares_nonstatic_concrete_methods() const { 915 return (_misc_flags & _misc_declares_nonstatic_concrete_methods) != 0; 916 } 917 void set_declares_nonstatic_concrete_methods(bool b) { 918 if (b) { 919 _misc_flags |= _misc_declares_nonstatic_concrete_methods; 920 } else { 921 _misc_flags &= ~_misc_declares_nonstatic_concrete_methods; 922 } 923 } 924 925 // for adding methods, ConstMethod::UNSET_IDNUM means no more ids available 926 inline u2 next_method_idnum(); 927 void set_initial_method_idnum(u2 value) { _idnum_allocated_count = value; } 928 929 // generics support 930 Symbol* generic_signature() const { 931 return (_generic_signature_index == 0) ? 932 (Symbol*)NULL : _constants->symbol_at(_generic_signature_index); 933 } 934 u2 generic_signature_index() const { 935 return _generic_signature_index; 936 } 937 void set_generic_signature_index(u2 sig_index) { 938 _generic_signature_index = sig_index; 939 } 940 941 u2 enclosing_method_data(int offset) const; 942 u2 enclosing_method_class_index() const { 943 return enclosing_method_data(enclosing_method_class_index_offset); 944 } 945 u2 enclosing_method_method_index() { 946 return enclosing_method_data(enclosing_method_method_index_offset); 947 } 948 void set_enclosing_method_indices(u2 class_index, 949 u2 method_index); 950 951 // jmethodID support 952 jmethodID get_jmethod_id(const methodHandle& method_h); 953 jmethodID get_jmethod_id_fetch_or_update(size_t idnum, 954 jmethodID new_id, jmethodID* new_jmeths, 955 jmethodID* to_dealloc_id_p, 956 jmethodID** to_dealloc_jmeths_p); 957 static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum, 958 size_t *length_p, jmethodID* id_p); 959 void ensure_space_for_methodids(int start_offset = 0); 960 jmethodID jmethod_id_or_null(Method* method); 961 962 // annotations support 963 Annotations* annotations() const { return _annotations; } 964 void set_annotations(Annotations* anno) { _annotations = anno; } 965 966 AnnotationArray* class_annotations() const { 967 return (_annotations != NULL) ? _annotations->class_annotations() : NULL; 968 } 969 Array<AnnotationArray*>* fields_annotations() const { 970 return (_annotations != NULL) ? _annotations->fields_annotations() : NULL; 971 } 972 AnnotationArray* class_type_annotations() const { 973 return (_annotations != NULL) ? _annotations->class_type_annotations() : NULL; 974 } 975 Array<AnnotationArray*>* fields_type_annotations() const { 976 return (_annotations != NULL) ? _annotations->fields_type_annotations() : NULL; 977 } 978 // allocation 979 instanceOop allocate_instance(TRAPS); 980 981 // additional member function to return a handle 982 instanceHandle allocate_instance_handle(TRAPS); 983 984 objArrayOop allocate_objArray(int n, int length, TRAPS); 985 // Helper function 986 static instanceOop register_finalizer(instanceOop i, TRAPS); 987 988 // Check whether reflection/jni/jvm code is allowed to instantiate this class; 989 // if not, throw either an Error or an Exception. 990 virtual void check_valid_for_instantiation(bool throwError, TRAPS); 991 992 // initialization 993 void call_class_initializer(TRAPS); 994 void set_initialization_state_and_notify(ClassState state, TRAPS); 995 996 // OopMapCache support 997 OopMapCache* oop_map_cache() { return _oop_map_cache; } 998 void set_oop_map_cache(OopMapCache *cache) { _oop_map_cache = cache; } 999 void mask_for(const methodHandle& method, int bci, InterpreterOopMap* entry); 1000 1001 // JNI identifier support (for static fields - for jni performance) 1002 JNIid* jni_ids() { return _jni_ids; } 1003 void set_jni_ids(JNIid* ids) { _jni_ids = ids; } 1004 JNIid* jni_id_for(int offset); 1005 1006 // maintenance of deoptimization dependencies 1007 inline DependencyContext dependencies(); 1008 int mark_dependent_nmethods(KlassDepChange& changes); 1009 void add_dependent_nmethod(nmethod* nm); 1010 void remove_dependent_nmethod(nmethod* nm); 1011 void clean_dependency_context(); 1012 1013 // On-stack replacement support 1014 nmethod* osr_nmethods_head() const { return _osr_nmethods_head; }; 1015 void set_osr_nmethods_head(nmethod* h) { _osr_nmethods_head = h; }; 1016 void add_osr_nmethod(nmethod* n); 1017 bool remove_osr_nmethod(nmethod* n); 1018 int mark_osr_nmethods(const Method* m); 1019 nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const; 1020 1021 #if INCLUDE_JVMTI 1022 // Breakpoint support (see methods on Method* for details) 1023 BreakpointInfo* breakpoints() const { return _breakpoints; }; 1024 void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; }; 1025 #endif 1026 1027 // support for stub routines 1028 static ByteSize init_state_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_state)); } 1029 JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;) 1030 static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); } 1031 1032 // subclass/subinterface checks 1033 bool implements_interface(Klass* k) const; 1034 bool is_same_or_direct_interface(Klass* k) const; 1035 1036 #ifdef ASSERT 1037 // check whether this class or one of its superclasses was redefined 1038 bool has_redefined_this_or_super() const; 1039 #endif 1040 1041 // Access to the implementor of an interface. 1042 Klass* implementor() const; 1043 void set_implementor(Klass* k); 1044 int nof_implementors() const; 1045 void add_implementor(Klass* k); // k is a new class that implements this interface 1046 void init_implementor(); // initialize 1047 1048 // link this class into the implementors list of every interface it implements 1049 void process_interfaces(Thread *thread); 1050 1051 // virtual operations from Klass 1052 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots, 1053 Array<InstanceKlass*>* transitive_interfaces); 1054 bool can_be_primary_super_slow() const; 1055 int oop_size(oop obj) const { return size_helper(); } 1056 // slow because it's a virtual call and used for verifying the layout_helper. 1057 // Using the layout_helper bits, we can call is_instance_klass without a virtual call. 1058 DEBUG_ONLY(bool is_instance_klass_slow() const { return true; }) 1059 1060 // Iterators 1061 void do_local_static_fields(FieldClosure* cl); 1062 void do_nonstatic_fields(FieldClosure* cl); // including inherited fields 1063 void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS); 1064 1065 void methods_do(void f(Method* method)); 1066 void array_klasses_do(void f(Klass* k)); 1067 void array_klasses_do(void f(Klass* k, TRAPS), TRAPS); 1068 1069 static InstanceKlass* cast(Klass* k) { 1070 return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k))); 1071 } 1072 1073 static const InstanceKlass* cast(const Klass* k) { 1074 assert(k != NULL, "k should not be null"); 1075 assert(k->is_instance_klass(), "cast to InstanceKlass"); 1076 return static_cast<const InstanceKlass*>(k); 1077 } 1078 1079 virtual InstanceKlass* java_super() const { 1080 return (super() == NULL) ? NULL : cast(super()); 1081 } 1082 1083 // Sizing (in words) 1084 static int header_size() { return sizeof(InstanceKlass)/wordSize; } 1085 1086 static int size(int vtable_length, int itable_length, 1087 int nonstatic_oop_map_size, 1088 bool is_interface, bool is_unsafe_anonymous, bool has_stored_fingerprint) { 1089 return align_metadata_size(header_size() + 1090 vtable_length + 1091 itable_length + 1092 nonstatic_oop_map_size + 1093 (is_interface ? (int)sizeof(Klass*)/wordSize : 0) + 1094 (is_unsafe_anonymous ? (int)sizeof(Klass*)/wordSize : 0) + 1095 (has_stored_fingerprint ? (int)sizeof(uint64_t*)/wordSize : 0)); 1096 } 1097 int size() const { return size(vtable_length(), 1098 itable_length(), 1099 nonstatic_oop_map_size(), 1100 is_interface(), 1101 is_unsafe_anonymous(), 1102 has_stored_fingerprint()); 1103 } 1104 1105 intptr_t* start_of_itable() const { return (intptr_t*)start_of_vtable() + vtable_length(); } 1106 intptr_t* end_of_itable() const { return start_of_itable() + itable_length(); } 1107 1108 int itable_offset_in_words() const { return start_of_itable() - (intptr_t*)this; } 1109 1110 oop static_field_base_raw() { return java_mirror(); } 1111 1112 OopMapBlock* start_of_nonstatic_oop_maps() const { 1113 return (OopMapBlock*)(start_of_itable() + itable_length()); 1114 } 1115 1116 Klass** end_of_nonstatic_oop_maps() const { 1117 return (Klass**)(start_of_nonstatic_oop_maps() + 1118 nonstatic_oop_map_count()); 1119 } 1120 1121 Klass* volatile* adr_implementor() const { 1122 if (is_interface()) { 1123 return (Klass* volatile*)end_of_nonstatic_oop_maps(); 1124 } else { 1125 return NULL; 1126 } 1127 }; 1128 1129 InstanceKlass** adr_unsafe_anonymous_host() const { 1130 if (is_unsafe_anonymous()) { 1131 InstanceKlass** adr_impl = (InstanceKlass**)adr_implementor(); 1132 if (adr_impl != NULL) { 1133 return adr_impl + 1; 1134 } else { 1135 return (InstanceKlass **)end_of_nonstatic_oop_maps(); 1136 } 1137 } else { 1138 return NULL; 1139 } 1140 } 1141 1142 address adr_fingerprint() const { 1143 if (has_stored_fingerprint()) { 1144 InstanceKlass** adr_host = adr_unsafe_anonymous_host(); 1145 if (adr_host != NULL) { 1146 return (address)(adr_host + 1); 1147 } 1148 1149 Klass* volatile* adr_impl = adr_implementor(); 1150 if (adr_impl != NULL) { 1151 return (address)(adr_impl + 1); 1152 } 1153 1154 return (address)end_of_nonstatic_oop_maps(); 1155 } else { 1156 return NULL; 1157 } 1158 } 1159 1160 // Use this to return the size of an instance in heap words: 1161 int size_helper() const { 1162 return layout_helper_to_size_helper(layout_helper()); 1163 } 1164 1165 // This bit is initialized in classFileParser.cpp. 1166 // It is false under any of the following conditions: 1167 // - the class is abstract (including any interface) 1168 // - the class has a finalizer (if !RegisterFinalizersAtInit) 1169 // - the class size is larger than FastAllocateSizeLimit 1170 // - the class is java/lang/Class, which cannot be allocated directly 1171 bool can_be_fastpath_allocated() const { 1172 return !layout_helper_needs_slow_path(layout_helper()); 1173 } 1174 1175 // Java itable 1176 klassItable itable() const; // return klassItable wrapper 1177 Method* method_at_itable(Klass* holder, int index, TRAPS); 1178 1179 #if INCLUDE_JVMTI 1180 void adjust_default_methods(bool* trace_name_printed); 1181 #endif // INCLUDE_JVMTI 1182 1183 void clean_weak_instanceklass_links(); 1184 private: 1185 void clean_implementors_list(); 1186 void clean_method_data(); 1187 1188 public: 1189 // Explicit metaspace deallocation of fields 1190 // For RedefineClasses and class file parsing errors, we need to deallocate 1191 // instanceKlasses and the metadata they point to. 1192 void deallocate_contents(ClassLoaderData* loader_data); 1193 static void deallocate_methods(ClassLoaderData* loader_data, 1194 Array<Method*>* methods); 1195 void static deallocate_interfaces(ClassLoaderData* loader_data, 1196 const Klass* super_klass, 1197 Array<InstanceKlass*>* local_interfaces, 1198 Array<InstanceKlass*>* transitive_interfaces); 1199 void static deallocate_record_components(ClassLoaderData* loader_data, 1200 Array<RecordComponent*>* record_component); 1201 1202 // The constant pool is on stack if any of the methods are executing or 1203 // referenced by handles. 1204 bool on_stack() const { return _constants->on_stack(); } 1205 1206 // callbacks for actions during class unloading 1207 static void unload_class(InstanceKlass* ik); 1208 static void release_C_heap_structures(InstanceKlass* ik); 1209 1210 // Naming 1211 const char* signature_name() const; 1212 1213 // Extract package name from a fully qualified class name 1214 // *bad_class_name is set to true if there's a problem with parsing class_name, to 1215 // distinguish from a class_name with no package name, as both cases have a NULL return value 1216 static Symbol* package_from_name(const Symbol* class_name, bool* bad_class_name = NULL); 1217 1218 // Oop fields (and metadata) iterators 1219 // 1220 // The InstanceKlass iterators also visits the Object's klass. 1221 1222 // Forward iteration 1223 public: 1224 // Iterate over all oop fields in the oop maps. 1225 template <typename T, class OopClosureType> 1226 inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure); 1227 1228 // Iterate over all oop fields and metadata. 1229 template <typename T, class OopClosureType> 1230 inline void oop_oop_iterate(oop obj, OopClosureType* closure); 1231 1232 // Iterate over all oop fields in one oop map. 1233 template <typename T, class OopClosureType> 1234 inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure); 1235 1236 1237 // Reverse iteration 1238 // Iterate over all oop fields and metadata. 1239 template <typename T, class OopClosureType> 1240 inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure); 1241 1242 private: 1243 // Iterate over all oop fields in the oop maps. 1244 template <typename T, class OopClosureType> 1245 inline void oop_oop_iterate_oop_maps_reverse(oop obj, OopClosureType* closure); 1246 1247 // Iterate over all oop fields in one oop map. 1248 template <typename T, class OopClosureType> 1249 inline void oop_oop_iterate_oop_map_reverse(OopMapBlock* map, oop obj, OopClosureType* closure); 1250 1251 1252 // Bounded range iteration 1253 public: 1254 // Iterate over all oop fields in the oop maps. 1255 template <typename T, class OopClosureType> 1256 inline void oop_oop_iterate_oop_maps_bounded(oop obj, OopClosureType* closure, MemRegion mr); 1257 1258 // Iterate over all oop fields and metadata. 1259 template <typename T, class OopClosureType> 1260 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr); 1261 1262 private: 1263 // Iterate over all oop fields in one oop map. 1264 template <typename T, class OopClosureType> 1265 inline void oop_oop_iterate_oop_map_bounded(OopMapBlock* map, oop obj, OopClosureType* closure, MemRegion mr); 1266 1267 1268 public: 1269 u2 idnum_allocated_count() const { return _idnum_allocated_count; } 1270 1271 private: 1272 // initialization state 1273 void set_init_state(ClassState state); 1274 void set_rewritten() { _misc_flags |= _misc_rewritten; } 1275 void set_init_thread(Thread *thread) { _init_thread = thread; } 1276 1277 // The RedefineClasses() API can cause new method idnums to be needed 1278 // which will cause the caches to grow. Safety requires different 1279 // cache management logic if the caches can grow instead of just 1280 // going from NULL to non-NULL. 1281 bool idnum_can_increment() const { return has_been_redefined(); } 1282 inline jmethodID* methods_jmethod_ids_acquire() const; 1283 inline void release_set_methods_jmethod_ids(jmethodID* jmeths); 1284 1285 // Lock during initialization 1286 public: 1287 // Lock for (1) initialization; (2) access to the ConstantPool of this class. 1288 // Must be one per class and it has to be a VM internal object so java code 1289 // cannot lock it (like the mirror). 1290 // It has to be an object not a Mutex because it's held through java calls. 1291 oop init_lock() const; 1292 private: 1293 void fence_and_clear_init_lock(); 1294 1295 bool link_class_impl (TRAPS); 1296 bool verify_code (TRAPS); 1297 void initialize_impl (TRAPS); 1298 void initialize_super_interfaces (TRAPS); 1299 void eager_initialize_impl (); 1300 /* jni_id_for_impl for jfieldID only */ 1301 JNIid* jni_id_for_impl (int offset); 1302 1303 // Returns the array class for the n'th dimension 1304 Klass* array_klass_impl(bool or_null, int n, TRAPS); 1305 1306 // Returns the array class with this class as element type 1307 Klass* array_klass_impl(bool or_null, TRAPS); 1308 1309 // find a local method (returns NULL if not found) 1310 Method* find_method_impl(const Symbol* name, 1311 const Symbol* signature, 1312 OverpassLookupMode overpass_mode, 1313 StaticLookupMode static_mode, 1314 PrivateLookupMode private_mode) const; 1315 1316 static Method* find_method_impl(const Array<Method*>* methods, 1317 const Symbol* name, 1318 const Symbol* signature, 1319 OverpassLookupMode overpass_mode, 1320 StaticLookupMode static_mode, 1321 PrivateLookupMode private_mode); 1322 1323 // Free CHeap allocated fields. 1324 void release_C_heap_structures(); 1325 1326 #if INCLUDE_JVMTI 1327 // RedefineClasses support 1328 void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; } 1329 void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count); 1330 #endif 1331 public: 1332 // CDS support - remove and restore oops from metadata. Oops are not shared. 1333 virtual void remove_unshareable_info(); 1334 virtual void remove_java_mirror(); 1335 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS); 1336 1337 // jvm support 1338 jint compute_modifier_flags(TRAPS) const; 1339 1340 public: 1341 // JVMTI support 1342 jint jvmti_class_status() const; 1343 1344 virtual void metaspace_pointers_do(MetaspaceClosure* iter); 1345 1346 public: 1347 // Printing 1348 #ifndef PRODUCT 1349 void print_on(outputStream* st) const; 1350 #endif 1351 void print_value_on(outputStream* st) const; 1352 1353 void oop_print_value_on(oop obj, outputStream* st); 1354 1355 #ifndef PRODUCT 1356 void oop_print_on (oop obj, outputStream* st); 1357 1358 void print_dependent_nmethods(bool verbose = false); 1359 bool is_dependent_nmethod(nmethod* nm); 1360 bool verify_itable_index(int index); 1361 #endif 1362 1363 const char* internal_name() const; 1364 1365 // Verification 1366 void verify_on(outputStream* st); 1367 1368 void oop_verify_on(oop obj, outputStream* st); 1369 1370 // Logging 1371 void print_class_load_logging(ClassLoaderData* loader_data, 1372 const char* module_name, 1373 const ClassFileStream* cfs) const; 1374 }; 1375 1376 // for adding methods 1377 // UNSET_IDNUM return means no more ids available 1378 inline u2 InstanceKlass::next_method_idnum() { 1379 if (_idnum_allocated_count == ConstMethod::MAX_IDNUM) { 1380 return ConstMethod::UNSET_IDNUM; // no more ids available 1381 } else { 1382 return _idnum_allocated_count++; 1383 } 1384 } 1385 1386 1387 /* JNIid class for jfieldIDs only */ 1388 class JNIid: public CHeapObj<mtClass> { 1389 friend class VMStructs; 1390 private: 1391 Klass* _holder; 1392 JNIid* _next; 1393 int _offset; 1394 #ifdef ASSERT 1395 bool _is_static_field_id; 1396 #endif 1397 1398 public: 1399 // Accessors 1400 Klass* holder() const { return _holder; } 1401 int offset() const { return _offset; } 1402 JNIid* next() { return _next; } 1403 // Constructor 1404 JNIid(Klass* holder, int offset, JNIid* next); 1405 // Identifier lookup 1406 JNIid* find(int offset); 1407 1408 bool find_local_field(fieldDescriptor* fd) { 1409 return InstanceKlass::cast(holder())->find_local_field_from_offset(offset(), true, fd); 1410 } 1411 1412 static void deallocate(JNIid* id); 1413 // Debugging 1414 #ifdef ASSERT 1415 bool is_static_field_id() const { return _is_static_field_id; } 1416 void set_is_static_field_id() { _is_static_field_id = true; } 1417 #endif 1418 void verify(Klass* holder); 1419 }; 1420 1421 // An iterator that's used to access the inner classes indices in the 1422 // InstanceKlass::_inner_classes array. 1423 class InnerClassesIterator : public StackObj { 1424 private: 1425 Array<jushort>* _inner_classes; 1426 int _length; 1427 int _idx; 1428 public: 1429 1430 InnerClassesIterator(const InstanceKlass* k) { 1431 _inner_classes = k->inner_classes(); 1432 if (k->inner_classes() != NULL) { 1433 _length = _inner_classes->length(); 1434 // The inner class array's length should be the multiple of 1435 // inner_class_next_offset if it only contains the InnerClasses 1436 // attribute data, or it should be 1437 // n*inner_class_next_offset+enclosing_method_attribute_size 1438 // if it also contains the EnclosingMethod data. 1439 assert((_length % InstanceKlass::inner_class_next_offset == 0 || 1440 _length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size), 1441 "just checking"); 1442 // Remove the enclosing_method portion if exists. 1443 if (_length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size) { 1444 _length -= InstanceKlass::enclosing_method_attribute_size; 1445 } 1446 } else { 1447 _length = 0; 1448 } 1449 _idx = 0; 1450 } 1451 1452 int length() const { 1453 return _length; 1454 } 1455 1456 void next() { 1457 _idx += InstanceKlass::inner_class_next_offset; 1458 } 1459 1460 bool done() const { 1461 return (_idx >= _length); 1462 } 1463 1464 u2 inner_class_info_index() const { 1465 return _inner_classes->at( 1466 _idx + InstanceKlass::inner_class_inner_class_info_offset); 1467 } 1468 1469 void set_inner_class_info_index(u2 index) { 1470 _inner_classes->at_put( 1471 _idx + InstanceKlass::inner_class_inner_class_info_offset, index); 1472 } 1473 1474 u2 outer_class_info_index() const { 1475 return _inner_classes->at( 1476 _idx + InstanceKlass::inner_class_outer_class_info_offset); 1477 } 1478 1479 void set_outer_class_info_index(u2 index) { 1480 _inner_classes->at_put( 1481 _idx + InstanceKlass::inner_class_outer_class_info_offset, index); 1482 } 1483 1484 u2 inner_name_index() const { 1485 return _inner_classes->at( 1486 _idx + InstanceKlass::inner_class_inner_name_offset); 1487 } 1488 1489 void set_inner_name_index(u2 index) { 1490 _inner_classes->at_put( 1491 _idx + InstanceKlass::inner_class_inner_name_offset, index); 1492 } 1493 1494 u2 inner_access_flags() const { 1495 return _inner_classes->at( 1496 _idx + InstanceKlass::inner_class_access_flags_offset); 1497 } 1498 }; 1499 1500 #endif // SHARE_OOPS_INSTANCEKLASS_HPP --- EOF ---