src/share/vm/oops/instanceKlass.hpp

Thu, 26 Jul 2018 16:04:06 +0800

author
aoqi
date
Thu, 26 Jul 2018 16:04:06 +0800
changeset 9203
53eec13fbaa5
parent 9184
fbcbfd2753b5
parent 9041
95a08233f46c
child 9448
73d689add964
permissions
-rw-r--r--

Merge

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

mercurial