src/share/vm/oops/instanceKlass.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7761
d8f133adf05d
parent 7535
7ae4e26cb1e0
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

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

mercurial