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