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