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