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