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