src/share/vm/oops/instanceKlass.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8721
575f637864df
parent 8604
04d83ba48607
child 9041
95a08233f46c
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 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
dbuck@8716 530 // find a local method (returns NULL if not found)
dbuck@8716 531 Method* find_local_method(Symbol* name, Symbol* signature,
dbuck@8716 532 OverpassLookupMode overpass_mode,
dbuck@8716 533 StaticLookupMode static_mode,
dbuck@8716 534 PrivateLookupMode private_mode) const;
dbuck@8716 535
dbuck@8716 536 // find a local method from given methods array (returns NULL if not found)
dbuck@8716 537 static Method* find_local_method(Array<Method*>* methods,
dbuck@8716 538 Symbol* name, Symbol* signature,
dbuck@8716 539 OverpassLookupMode overpass_mode,
dbuck@8716 540 StaticLookupMode static_mode,
dbuck@8716 541 PrivateLookupMode private_mode);
dbuck@8716 542
drchase@7499 543 // true if method matches signature and conforms to skipping_X conditions.
dbuck@8716 544 static bool method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static, bool skipping_private);
drchase@7499 545
dbuck@8716 546 // find a local method index in methods or default_methods (returns -1 if not found)
dbuck@8716 547 static int find_method_index(Array<Method*>* methods,
dbuck@8716 548 Symbol* name, Symbol* signature,
dbuck@8716 549 OverpassLookupMode overpass_mode,
dbuck@8716 550 StaticLookupMode static_mode,
dbuck@8716 551 PrivateLookupMode private_mode);
dbuck@8716 552
aoqi@0 553
aoqi@0 554 // lookup operation (returns NULL if not found)
dbuck@8716 555 Method* uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const;
aoqi@0 556
aoqi@0 557 // lookup a method in all the interfaces that this class implements
aoqi@0 558 // (returns NULL if not found)
dbuck@8716 559 Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature, DefaultsLookupMode defaults_mode) const;
aoqi@0 560
aoqi@0 561 // lookup a method in local defaults then in all interfaces
aoqi@0 562 // (returns NULL if not found)
aoqi@0 563 Method* lookup_method_in_ordered_interfaces(Symbol* name, Symbol* signature) const;
aoqi@0 564
aoqi@0 565 // Find method indices by name. If a method with the specified name is
aoqi@0 566 // found the index to the first method is returned, and 'end' is filled in
aoqi@0 567 // with the index of first non-name-matching method. If no method is found
aoqi@0 568 // -1 is returned.
aoqi@0 569 int find_method_by_name(Symbol* name, int* end);
aoqi@0 570 static int find_method_by_name(Array<Method*>* methods, Symbol* name, int* end);
aoqi@0 571
aoqi@0 572 // constant pool
aoqi@0 573 ConstantPool* constants() const { return _constants; }
aoqi@0 574 void set_constants(ConstantPool* c) { _constants = c; }
aoqi@0 575
aoqi@0 576 // protection domain
aoqi@0 577 oop protection_domain() const;
aoqi@0 578
aoqi@0 579 // signers
aoqi@0 580 objArrayOop signers() const;
aoqi@0 581
aoqi@0 582 // host class
aoqi@0 583 Klass* host_klass() const {
aoqi@0 584 Klass** hk = (Klass**)adr_host_klass();
aoqi@0 585 if (hk == NULL) {
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");
aoqi@0 589 return *hk;
aoqi@0 590 }
aoqi@0 591 }
aoqi@0 592 void set_host_klass(Klass* host) {
aoqi@0 593 assert(is_anonymous(), "not anonymous");
aoqi@0 594 Klass** addr = (Klass**)adr_host_klass();
aoqi@0 595 assert(addr != NULL, "no reversed space");
aoqi@0 596 if (addr != NULL) {
aoqi@0 597 *addr = host;
aoqi@0 598 }
aoqi@0 599 }
aoqi@0 600 bool is_anonymous() const {
aoqi@0 601 return (_misc_flags & _misc_is_anonymous) != 0;
aoqi@0 602 }
aoqi@0 603 void set_is_anonymous(bool value) {
aoqi@0 604 if (value) {
aoqi@0 605 _misc_flags |= _misc_is_anonymous;
aoqi@0 606 } else {
aoqi@0 607 _misc_flags &= ~_misc_is_anonymous;
aoqi@0 608 }
aoqi@0 609 }
aoqi@0 610
aoqi@0 611 // Oop that keeps the metadata for this class from being unloaded
aoqi@0 612 // in places where the metadata is stored in other places, like nmethods
aoqi@0 613 oop klass_holder() const {
aoqi@0 614 return is_anonymous() ? java_mirror() : class_loader();
aoqi@0 615 }
aoqi@0 616
aoqi@0 617 bool is_contended() const {
aoqi@0 618 return (_misc_flags & _misc_is_contended) != 0;
aoqi@0 619 }
aoqi@0 620 void set_is_contended(bool value) {
aoqi@0 621 if (value) {
aoqi@0 622 _misc_flags |= _misc_is_contended;
aoqi@0 623 } else {
aoqi@0 624 _misc_flags &= ~_misc_is_contended;
aoqi@0 625 }
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 // source file name
aoqi@0 629 Symbol* source_file_name() const {
aoqi@0 630 return (_source_file_name_index == 0) ?
aoqi@0 631 (Symbol*)NULL : _constants->symbol_at(_source_file_name_index);
aoqi@0 632 }
aoqi@0 633 u2 source_file_name_index() const {
aoqi@0 634 return _source_file_name_index;
aoqi@0 635 }
aoqi@0 636 void set_source_file_name_index(u2 sourcefile_index) {
aoqi@0 637 _source_file_name_index = sourcefile_index;
aoqi@0 638 }
aoqi@0 639
aoqi@0 640 // minor and major version numbers of class file
aoqi@0 641 u2 minor_version() const { return _minor_version; }
aoqi@0 642 void set_minor_version(u2 minor_version) { _minor_version = minor_version; }
aoqi@0 643 u2 major_version() const { return _major_version; }
aoqi@0 644 void set_major_version(u2 major_version) { _major_version = major_version; }
aoqi@0 645
aoqi@0 646 // source debug extension
aoqi@0 647 char* source_debug_extension() const { return _source_debug_extension; }
aoqi@0 648 void set_source_debug_extension(char* array, int length);
aoqi@0 649
aoqi@0 650 // symbol unloading support (refcount already added)
aoqi@0 651 Symbol* array_name() { return _array_name; }
aoqi@0 652 void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; }
aoqi@0 653
aoqi@0 654 // nonstatic oop-map blocks
aoqi@0 655 static int nonstatic_oop_map_size(unsigned int oop_map_count) {
aoqi@0 656 return oop_map_count * OopMapBlock::size_in_words();
aoqi@0 657 }
aoqi@0 658 unsigned int nonstatic_oop_map_count() const {
aoqi@0 659 return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
aoqi@0 660 }
aoqi@0 661 int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
aoqi@0 662 void set_nonstatic_oop_map_size(int words) {
aoqi@0 663 _nonstatic_oop_map_size = words;
aoqi@0 664 }
aoqi@0 665
aoqi@0 666 // RedefineClasses() support for previous versions:
aoqi@0 667 void add_previous_version(instanceKlassHandle ikh, BitMap *emcp_methods,
aoqi@0 668 int emcp_method_count);
aoqi@0 669 // If the _previous_versions array is non-NULL, then this klass
aoqi@0 670 // has been redefined at least once even if we aren't currently
aoqi@0 671 // tracking a previous version.
aoqi@0 672 bool has_been_redefined() const { return _previous_versions != NULL; }
aoqi@0 673 bool has_previous_version() const;
aoqi@0 674 void init_previous_versions() {
aoqi@0 675 _previous_versions = NULL;
aoqi@0 676 }
aoqi@0 677 GrowableArray<PreviousVersionNode *>* previous_versions() const {
aoqi@0 678 return _previous_versions;
aoqi@0 679 }
aoqi@0 680
sspitsyn@7683 681 InstanceKlass* get_klass_version(int version);
aoqi@0 682 static void purge_previous_versions(InstanceKlass* ik);
aoqi@0 683
aoqi@0 684 // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation
aoqi@0 685 void set_cached_class_file(JvmtiCachedClassFileData *data) {
aoqi@0 686 _cached_class_file = data;
aoqi@0 687 }
aoqi@0 688 JvmtiCachedClassFileData * get_cached_class_file() { return _cached_class_file; }
aoqi@0 689 jint get_cached_class_file_len();
aoqi@0 690 unsigned char * get_cached_class_file_bytes();
aoqi@0 691
aoqi@0 692 // JVMTI: Support for caching of field indices, types, and offsets
aoqi@0 693 void set_jvmti_cached_class_field_map(JvmtiCachedClassFieldMap* descriptor) {
aoqi@0 694 _jvmti_cached_class_field_map = descriptor;
aoqi@0 695 }
aoqi@0 696 JvmtiCachedClassFieldMap* jvmti_cached_class_field_map() const {
aoqi@0 697 return _jvmti_cached_class_field_map;
aoqi@0 698 }
aoqi@0 699
aoqi@0 700 bool has_default_methods() const {
aoqi@0 701 return (_misc_flags & _misc_has_default_methods) != 0;
aoqi@0 702 }
aoqi@0 703 void set_has_default_methods(bool b) {
aoqi@0 704 if (b) {
aoqi@0 705 _misc_flags |= _misc_has_default_methods;
aoqi@0 706 } else {
aoqi@0 707 _misc_flags &= ~_misc_has_default_methods;
aoqi@0 708 }
aoqi@0 709 }
aoqi@0 710
acorn@7290 711 bool declares_default_methods() const {
acorn@7290 712 return (_misc_flags & _misc_declares_default_methods) != 0;
acorn@7290 713 }
acorn@7290 714 void set_declares_default_methods(bool b) {
acorn@7290 715 if (b) {
acorn@7290 716 _misc_flags |= _misc_declares_default_methods;
acorn@7290 717 } else {
acorn@7290 718 _misc_flags &= ~_misc_declares_default_methods;
acorn@7290 719 }
acorn@7290 720 }
acorn@7290 721
aoqi@0 722 // for adding methods, ConstMethod::UNSET_IDNUM means no more ids available
aoqi@0 723 inline u2 next_method_idnum();
aoqi@0 724 void set_initial_method_idnum(u2 value) { _idnum_allocated_count = value; }
aoqi@0 725
aoqi@0 726 // generics support
aoqi@0 727 Symbol* generic_signature() const {
aoqi@0 728 return (_generic_signature_index == 0) ?
aoqi@0 729 (Symbol*)NULL : _constants->symbol_at(_generic_signature_index);
aoqi@0 730 }
aoqi@0 731 u2 generic_signature_index() const {
aoqi@0 732 return _generic_signature_index;
aoqi@0 733 }
aoqi@0 734 void set_generic_signature_index(u2 sig_index) {
aoqi@0 735 _generic_signature_index = sig_index;
aoqi@0 736 }
aoqi@0 737
aoqi@0 738 u2 enclosing_method_data(int offset);
aoqi@0 739 u2 enclosing_method_class_index() {
aoqi@0 740 return enclosing_method_data(enclosing_method_class_index_offset);
aoqi@0 741 }
aoqi@0 742 u2 enclosing_method_method_index() {
aoqi@0 743 return enclosing_method_data(enclosing_method_method_index_offset);
aoqi@0 744 }
aoqi@0 745 void set_enclosing_method_indices(u2 class_index,
aoqi@0 746 u2 method_index);
aoqi@0 747
aoqi@0 748 // jmethodID support
aoqi@0 749 static jmethodID get_jmethod_id(instanceKlassHandle ik_h,
aoqi@0 750 methodHandle method_h);
aoqi@0 751 static jmethodID get_jmethod_id_fetch_or_update(instanceKlassHandle ik_h,
aoqi@0 752 size_t idnum, jmethodID new_id, jmethodID* new_jmeths,
aoqi@0 753 jmethodID* to_dealloc_id_p,
aoqi@0 754 jmethodID** to_dealloc_jmeths_p);
aoqi@0 755 static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
aoqi@0 756 size_t *length_p, jmethodID* id_p);
aoqi@0 757 jmethodID jmethod_id_or_null(Method* method);
aoqi@0 758
aoqi@0 759 // annotations support
aoqi@0 760 Annotations* annotations() const { return _annotations; }
aoqi@0 761 void set_annotations(Annotations* anno) { _annotations = anno; }
aoqi@0 762
aoqi@0 763 AnnotationArray* class_annotations() const {
aoqi@0 764 return (_annotations != NULL) ? _annotations->class_annotations() : NULL;
aoqi@0 765 }
aoqi@0 766 Array<AnnotationArray*>* fields_annotations() const {
aoqi@0 767 return (_annotations != NULL) ? _annotations->fields_annotations() : NULL;
aoqi@0 768 }
aoqi@0 769 AnnotationArray* class_type_annotations() const {
aoqi@0 770 return (_annotations != NULL) ? _annotations->class_type_annotations() : NULL;
aoqi@0 771 }
aoqi@0 772 Array<AnnotationArray*>* fields_type_annotations() const {
aoqi@0 773 return (_annotations != NULL) ? _annotations->fields_type_annotations() : NULL;
aoqi@0 774 }
aoqi@0 775 // allocation
aoqi@0 776 instanceOop allocate_instance(TRAPS);
aoqi@0 777
aoqi@0 778 // additional member function to return a handle
aoqi@0 779 instanceHandle allocate_instance_handle(TRAPS) { return instanceHandle(THREAD, allocate_instance(THREAD)); }
aoqi@0 780
aoqi@0 781 objArrayOop allocate_objArray(int n, int length, TRAPS);
aoqi@0 782 // Helper function
aoqi@0 783 static instanceOop register_finalizer(instanceOop i, TRAPS);
aoqi@0 784
aoqi@0 785 // Check whether reflection/jni/jvm code is allowed to instantiate this class;
aoqi@0 786 // if not, throw either an Error or an Exception.
aoqi@0 787 virtual void check_valid_for_instantiation(bool throwError, TRAPS);
aoqi@0 788
aoqi@0 789 // initialization
aoqi@0 790 void call_class_initializer(TRAPS);
aoqi@0 791 void set_initialization_state_and_notify(ClassState state, TRAPS);
aoqi@0 792
aoqi@0 793 // OopMapCache support
aoqi@0 794 OopMapCache* oop_map_cache() { return _oop_map_cache; }
aoqi@0 795 void set_oop_map_cache(OopMapCache *cache) { _oop_map_cache = cache; }
aoqi@0 796 void mask_for(methodHandle method, int bci, InterpreterOopMap* entry);
aoqi@0 797
aoqi@0 798 // JNI identifier support (for static fields - for jni performance)
aoqi@0 799 JNIid* jni_ids() { return _jni_ids; }
aoqi@0 800 void set_jni_ids(JNIid* ids) { _jni_ids = ids; }
aoqi@0 801 JNIid* jni_id_for(int offset);
aoqi@0 802
aoqi@0 803 // maintenance of deoptimization dependencies
aoqi@0 804 int mark_dependent_nmethods(DepChange& changes);
aoqi@0 805 void add_dependent_nmethod(nmethod* nm);
stefank@8185 806 void remove_dependent_nmethod(nmethod* nm, bool delete_immediately);
aoqi@0 807
aoqi@0 808 // On-stack replacement support
aoqi@0 809 nmethod* osr_nmethods_head() const { return _osr_nmethods_head; };
aoqi@0 810 void set_osr_nmethods_head(nmethod* h) { _osr_nmethods_head = h; };
aoqi@0 811 void add_osr_nmethod(nmethod* n);
aoqi@0 812 void remove_osr_nmethod(nmethod* n);
thartmann@7325 813 int mark_osr_nmethods(const Method* m);
aoqi@0 814 nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
aoqi@0 815
aoqi@0 816 // Breakpoint support (see methods on Method* for details)
aoqi@0 817 BreakpointInfo* breakpoints() const { return _breakpoints; };
aoqi@0 818 void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
aoqi@0 819
aoqi@0 820 // support for stub routines
aoqi@0 821 static ByteSize init_state_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
aoqi@0 822 TRACE_DEFINE_OFFSET;
aoqi@0 823 static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
aoqi@0 824
aoqi@0 825 // subclass/subinterface checks
aoqi@0 826 bool implements_interface(Klass* k) const;
aoqi@0 827 bool is_same_or_direct_interface(Klass* k) const;
aoqi@0 828
dsamersoff@8049 829 #ifdef ASSERT
dsamersoff@8049 830 // check whether this class or one of its superclasses was redefined
dsamersoff@8049 831 bool has_redefined_this_or_super() const;
dsamersoff@8049 832 #endif
dsamersoff@8049 833
aoqi@0 834 // Access to the implementor of an interface.
aoqi@0 835 Klass* implementor() const
aoqi@0 836 {
aoqi@0 837 Klass** k = adr_implementor();
aoqi@0 838 if (k == NULL) {
aoqi@0 839 return NULL;
aoqi@0 840 } else {
aoqi@0 841 return *k;
aoqi@0 842 }
aoqi@0 843 }
aoqi@0 844
aoqi@0 845 void set_implementor(Klass* k) {
aoqi@0 846 assert(is_interface(), "not interface");
aoqi@0 847 Klass** addr = adr_implementor();
aoqi@0 848 assert(addr != NULL, "null addr");
aoqi@0 849 if (addr != NULL) {
aoqi@0 850 *addr = k;
aoqi@0 851 }
aoqi@0 852 }
aoqi@0 853
aoqi@0 854 int nof_implementors() const {
aoqi@0 855 Klass* k = implementor();
aoqi@0 856 if (k == NULL) {
aoqi@0 857 return 0;
aoqi@0 858 } else if (k != this) {
aoqi@0 859 return 1;
aoqi@0 860 } else {
aoqi@0 861 return 2;
aoqi@0 862 }
aoqi@0 863 }
aoqi@0 864
aoqi@0 865 void add_implementor(Klass* k); // k is a new class that implements this interface
aoqi@0 866 void init_implementor(); // initialize
aoqi@0 867
aoqi@0 868 // link this class into the implementors list of every interface it implements
aoqi@0 869 void process_interfaces(Thread *thread);
aoqi@0 870
aoqi@0 871 // virtual operations from Klass
aoqi@0 872 bool is_leaf_class() const { return _subklass == NULL; }
aoqi@0 873 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);
aoqi@0 874 bool compute_is_subtype_of(Klass* k);
aoqi@0 875 bool can_be_primary_super_slow() const;
aoqi@0 876 int oop_size(oop obj) const { return size_helper(); }
aoqi@0 877 bool oop_is_instance_slow() const { return true; }
aoqi@0 878
aoqi@0 879 // Iterators
aoqi@0 880 void do_local_static_fields(FieldClosure* cl);
aoqi@0 881 void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
aoqi@0 882 void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
aoqi@0 883
aoqi@0 884 void methods_do(void f(Method* method));
aoqi@0 885 void array_klasses_do(void f(Klass* k));
aoqi@0 886 void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
aoqi@0 887 bool super_types_do(SuperTypeClosure* blk);
aoqi@0 888
aoqi@0 889 // Casting from Klass*
aoqi@0 890 static InstanceKlass* cast(Klass* k) {
dsamersoff@8049 891 assert(k == NULL || k->is_klass(), "must be");
dsamersoff@8049 892 assert(k == NULL || k->oop_is_instance(), "cast to InstanceKlass");
aoqi@0 893 return (InstanceKlass*) k;
aoqi@0 894 }
aoqi@0 895
aoqi@0 896 InstanceKlass* java_super() const {
aoqi@0 897 return (super() == NULL) ? NULL : cast(super());
aoqi@0 898 }
aoqi@0 899
aoqi@0 900 // Sizing (in words)
aoqi@0 901 static int header_size() { return align_object_offset(sizeof(InstanceKlass)/HeapWordSize); }
aoqi@0 902
aoqi@0 903 static int size(int vtable_length, int itable_length,
aoqi@0 904 int nonstatic_oop_map_size,
aoqi@0 905 bool is_interface, bool is_anonymous) {
aoqi@0 906 return align_object_size(header_size() +
aoqi@0 907 align_object_offset(vtable_length) +
aoqi@0 908 align_object_offset(itable_length) +
aoqi@0 909 ((is_interface || is_anonymous) ?
aoqi@0 910 align_object_offset(nonstatic_oop_map_size) :
aoqi@0 911 nonstatic_oop_map_size) +
aoqi@0 912 (is_interface ? (int)sizeof(Klass*)/HeapWordSize : 0) +
aoqi@0 913 (is_anonymous ? (int)sizeof(Klass*)/HeapWordSize : 0));
aoqi@0 914 }
aoqi@0 915 int size() const { return size(vtable_length(),
aoqi@0 916 itable_length(),
aoqi@0 917 nonstatic_oop_map_size(),
aoqi@0 918 is_interface(),
aoqi@0 919 is_anonymous());
aoqi@0 920 }
aoqi@0 921 #if INCLUDE_SERVICES
aoqi@0 922 virtual void collect_statistics(KlassSizeStats *sz) const;
aoqi@0 923 #endif
aoqi@0 924
aoqi@0 925 static int vtable_start_offset() { return header_size(); }
aoqi@0 926 static int vtable_length_offset() { return offset_of(InstanceKlass, _vtable_len) / HeapWordSize; }
aoqi@0 927
aoqi@0 928 intptr_t* start_of_vtable() const { return ((intptr_t*)this) + vtable_start_offset(); }
aoqi@0 929 intptr_t* start_of_itable() const { return start_of_vtable() + align_object_offset(vtable_length()); }
aoqi@0 930 int itable_offset_in_words() const { return start_of_itable() - (intptr_t*)this; }
aoqi@0 931
aoqi@0 932 intptr_t* end_of_itable() const { return start_of_itable() + itable_length(); }
aoqi@0 933
aoqi@0 934 address static_field_addr(int offset);
aoqi@0 935
aoqi@0 936 OopMapBlock* start_of_nonstatic_oop_maps() const {
aoqi@0 937 return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length()));
aoqi@0 938 }
aoqi@0 939
aoqi@0 940 Klass** end_of_nonstatic_oop_maps() const {
aoqi@0 941 return (Klass**)(start_of_nonstatic_oop_maps() +
aoqi@0 942 nonstatic_oop_map_count());
aoqi@0 943 }
aoqi@0 944
aoqi@0 945 Klass** adr_implementor() const {
aoqi@0 946 if (is_interface()) {
aoqi@0 947 return (Klass**)end_of_nonstatic_oop_maps();
aoqi@0 948 } else {
aoqi@0 949 return NULL;
aoqi@0 950 }
aoqi@0 951 };
aoqi@0 952
aoqi@0 953 Klass** adr_host_klass() const {
aoqi@0 954 if (is_anonymous()) {
aoqi@0 955 Klass** adr_impl = adr_implementor();
aoqi@0 956 if (adr_impl != NULL) {
aoqi@0 957 return adr_impl + 1;
aoqi@0 958 } else {
aoqi@0 959 return end_of_nonstatic_oop_maps();
aoqi@0 960 }
aoqi@0 961 } else {
aoqi@0 962 return NULL;
aoqi@0 963 }
aoqi@0 964 }
aoqi@0 965
aoqi@0 966 // Use this to return the size of an instance in heap words:
aoqi@0 967 int size_helper() const {
aoqi@0 968 return layout_helper_to_size_helper(layout_helper());
aoqi@0 969 }
aoqi@0 970
aoqi@0 971 // This bit is initialized in classFileParser.cpp.
aoqi@0 972 // It is false under any of the following conditions:
aoqi@0 973 // - the class is abstract (including any interface)
aoqi@0 974 // - the class has a finalizer (if !RegisterFinalizersAtInit)
aoqi@0 975 // - the class size is larger than FastAllocateSizeLimit
aoqi@0 976 // - the class is java/lang/Class, which cannot be allocated directly
aoqi@0 977 bool can_be_fastpath_allocated() const {
aoqi@0 978 return !layout_helper_needs_slow_path(layout_helper());
aoqi@0 979 }
aoqi@0 980
aoqi@0 981 // Java vtable/itable
aoqi@0 982 klassVtable* vtable() const; // return new klassVtable wrapper
aoqi@0 983 inline Method* method_at_vtable(int index);
aoqi@0 984 klassItable* itable() const; // return new klassItable wrapper
aoqi@0 985 Method* method_at_itable(Klass* holder, int index, TRAPS);
aoqi@0 986
aoqi@0 987 #if INCLUDE_JVMTI
sspitsyn@7636 988 void adjust_default_methods(InstanceKlass* holder, bool* trace_name_printed);
aoqi@0 989 #endif // INCLUDE_JVMTI
aoqi@0 990
aoqi@0 991 // Garbage collection
aoqi@0 992 void oop_follow_contents(oop obj);
aoqi@0 993 int oop_adjust_pointers(oop obj);
aoqi@0 994
stefank@8185 995 void clean_weak_instanceklass_links(BoolObjectClosure* is_alive);
aoqi@0 996 void clean_implementors_list(BoolObjectClosure* is_alive);
aoqi@0 997 void clean_method_data(BoolObjectClosure* is_alive);
stefank@6992 998 void clean_dependent_nmethods();
aoqi@0 999
aoqi@0 1000 // Explicit metaspace deallocation of fields
aoqi@0 1001 // For RedefineClasses and class file parsing errors, we need to deallocate
aoqi@0 1002 // instanceKlasses and the metadata they point to.
aoqi@0 1003 void deallocate_contents(ClassLoaderData* loader_data);
aoqi@0 1004 static void deallocate_methods(ClassLoaderData* loader_data,
aoqi@0 1005 Array<Method*>* methods);
aoqi@0 1006 void static deallocate_interfaces(ClassLoaderData* loader_data,
aoqi@0 1007 Klass* super_klass,
aoqi@0 1008 Array<Klass*>* local_interfaces,
aoqi@0 1009 Array<Klass*>* transitive_interfaces);
aoqi@0 1010
aoqi@0 1011 // The constant pool is on stack if any of the methods are executing or
aoqi@0 1012 // referenced by handles.
aoqi@0 1013 bool on_stack() const { return _constants->on_stack(); }
aoqi@0 1014
aoqi@0 1015 // callbacks for actions during class unloading
aoqi@0 1016 static void notify_unload_class(InstanceKlass* ik);
aoqi@0 1017 static void release_C_heap_structures(InstanceKlass* ik);
aoqi@0 1018
aoqi@0 1019 // Parallel Scavenge and Parallel Old
aoqi@0 1020 PARALLEL_GC_DECLS
aoqi@0 1021
aoqi@0 1022 // Naming
aoqi@0 1023 const char* signature_name() const;
aoqi@0 1024
aoqi@0 1025 // Iterators
aoqi@0 1026 int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) {
aoqi@0 1027 return oop_oop_iterate_v(obj, blk);
aoqi@0 1028 }
aoqi@0 1029
aoqi@0 1030 int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
aoqi@0 1031 return oop_oop_iterate_v_m(obj, blk, mr);
aoqi@0 1032 }
aoqi@0 1033
aoqi@0 1034 #define InstanceKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
aoqi@0 1035 int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk); \
aoqi@0 1036 int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk, \
aoqi@0 1037 MemRegion mr);
aoqi@0 1038
aoqi@0 1039 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_DECL)
aoqi@0 1040 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_DECL)
aoqi@0 1041
aoqi@0 1042 #if INCLUDE_ALL_GCS
aoqi@0 1043 #define InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
aoqi@0 1044 int oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* blk);
aoqi@0 1045
aoqi@0 1046 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
aoqi@0 1047 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DECL)
aoqi@0 1048 #endif // INCLUDE_ALL_GCS
aoqi@0 1049
aoqi@0 1050 u2 idnum_allocated_count() const { return _idnum_allocated_count; }
aoqi@0 1051
iklam@7089 1052 public:
iklam@7089 1053 void set_in_error_state() {
iklam@7089 1054 assert(DumpSharedSpaces, "only call this when dumping archive");
iklam@7089 1055 _init_state = initialization_error;
iklam@7089 1056 }
iklam@7089 1057 bool check_sharing_error_state();
iklam@7089 1058
aoqi@0 1059 private:
aoqi@0 1060 // initialization state
aoqi@0 1061 #ifdef ASSERT
aoqi@0 1062 void set_init_state(ClassState state);
aoqi@0 1063 #else
aoqi@0 1064 void set_init_state(ClassState state) { _init_state = (u1)state; }
aoqi@0 1065 #endif
aoqi@0 1066 void set_rewritten() { _misc_flags |= _misc_rewritten; }
aoqi@0 1067 void set_init_thread(Thread *thread) { _init_thread = thread; }
aoqi@0 1068
aoqi@0 1069 // The RedefineClasses() API can cause new method idnums to be needed
aoqi@0 1070 // which will cause the caches to grow. Safety requires different
aoqi@0 1071 // cache management logic if the caches can grow instead of just
aoqi@0 1072 // going from NULL to non-NULL.
aoqi@0 1073 bool idnum_can_increment() const { return has_been_redefined(); }
aoqi@0 1074 jmethodID* methods_jmethod_ids_acquire() const
aoqi@0 1075 { return (jmethodID*)OrderAccess::load_ptr_acquire(&_methods_jmethod_ids); }
aoqi@0 1076 void release_set_methods_jmethod_ids(jmethodID* jmeths)
aoqi@0 1077 { OrderAccess::release_store_ptr(&_methods_jmethod_ids, jmeths); }
aoqi@0 1078
aoqi@0 1079 // Lock during initialization
aoqi@0 1080 public:
aoqi@0 1081 // Lock for (1) initialization; (2) access to the ConstantPool of this class.
aoqi@0 1082 // Must be one per class and it has to be a VM internal object so java code
aoqi@0 1083 // cannot lock it (like the mirror).
aoqi@0 1084 // It has to be an object not a Mutex because it's held through java calls.
aoqi@0 1085 oop init_lock() const;
aoqi@0 1086 private:
aoqi@0 1087 void fence_and_clear_init_lock();
aoqi@0 1088
aoqi@0 1089 // Static methods that are used to implement member methods where an exposed this pointer
aoqi@0 1090 // is needed due to possible GCs
aoqi@0 1091 static bool link_class_impl (instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS);
aoqi@0 1092 static bool verify_code (instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS);
aoqi@0 1093 static void initialize_impl (instanceKlassHandle this_oop, TRAPS);
acorn@7290 1094 static void initialize_super_interfaces (instanceKlassHandle this_oop, TRAPS);
aoqi@0 1095 static void eager_initialize_impl (instanceKlassHandle this_oop);
aoqi@0 1096 static void set_initialization_state_and_notify_impl (instanceKlassHandle this_oop, ClassState state, TRAPS);
aoqi@0 1097 static void call_class_initializer_impl (instanceKlassHandle this_oop, TRAPS);
aoqi@0 1098 static Klass* array_klass_impl (instanceKlassHandle this_oop, bool or_null, int n, TRAPS);
aoqi@0 1099 static void do_local_static_fields_impl (instanceKlassHandle this_oop, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
aoqi@0 1100 /* jni_id_for_impl for jfieldID only */
aoqi@0 1101 static JNIid* jni_id_for_impl (instanceKlassHandle this_oop, int offset);
aoqi@0 1102
aoqi@0 1103 // Returns the array class for the n'th dimension
aoqi@0 1104 Klass* array_klass_impl(bool or_null, int n, TRAPS);
aoqi@0 1105
aoqi@0 1106 // Returns the array class with this class as element type
aoqi@0 1107 Klass* array_klass_impl(bool or_null, TRAPS);
aoqi@0 1108
aoqi@0 1109 // find a local method (returns NULL if not found)
dbuck@8716 1110 Method* find_method_impl(Symbol* name, Symbol* signature,
dbuck@8716 1111 OverpassLookupMode overpass_mode,
dbuck@8716 1112 StaticLookupMode static_mode,
dbuck@8716 1113 PrivateLookupMode private_mode) const;
dbuck@8716 1114 static Method* find_method_impl(Array<Method*>* methods,
dbuck@8716 1115 Symbol* name, Symbol* signature,
dbuck@8716 1116 OverpassLookupMode overpass_mode,
dbuck@8716 1117 StaticLookupMode static_mode,
dbuck@8716 1118 PrivateLookupMode private_mode);
aoqi@0 1119
aoqi@0 1120 // Free CHeap allocated fields.
aoqi@0 1121 void release_C_heap_structures();
aoqi@0 1122 public:
aoqi@0 1123 // CDS support - remove and restore oops from metadata. Oops are not shared.
aoqi@0 1124 virtual void remove_unshareable_info();
iklam@7089 1125 virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
aoqi@0 1126
aoqi@0 1127 // jvm support
aoqi@0 1128 jint compute_modifier_flags(TRAPS) const;
aoqi@0 1129
aoqi@0 1130 // JSR-292 support
aoqi@0 1131 MemberNameTable* member_names() { return _member_names; }
aoqi@0 1132 void set_member_names(MemberNameTable* member_names) { _member_names = member_names; }
kevinw@8721 1133 oop add_member_name(Handle member_name, bool intern);
aoqi@0 1134
aoqi@0 1135 public:
aoqi@0 1136 // JVMTI support
aoqi@0 1137 jint jvmti_class_status() const;
aoqi@0 1138
aoqi@0 1139 public:
aoqi@0 1140 // Printing
aoqi@0 1141 #ifndef PRODUCT
aoqi@0 1142 void print_on(outputStream* st) const;
aoqi@0 1143 #endif
aoqi@0 1144 void print_value_on(outputStream* st) const;
aoqi@0 1145
aoqi@0 1146 void oop_print_value_on(oop obj, outputStream* st);
aoqi@0 1147
aoqi@0 1148 #ifndef PRODUCT
aoqi@0 1149 void oop_print_on (oop obj, outputStream* st);
aoqi@0 1150
aoqi@0 1151 void print_dependent_nmethods(bool verbose = false);
aoqi@0 1152 bool is_dependent_nmethod(nmethod* nm);
aoqi@0 1153 #endif
aoqi@0 1154
aoqi@0 1155 const char* internal_name() const;
aoqi@0 1156
aoqi@0 1157 // Verification
aoqi@0 1158 void verify_on(outputStream* st);
aoqi@0 1159
aoqi@0 1160 void oop_verify_on(oop obj, outputStream* st);
aoqi@0 1161 };
aoqi@0 1162
aoqi@0 1163 inline Method* InstanceKlass::method_at_vtable(int index) {
aoqi@0 1164 #ifndef PRODUCT
aoqi@0 1165 assert(index >= 0, "valid vtable index");
aoqi@0 1166 if (DebugVtables) {
aoqi@0 1167 verify_vtable_index(index);
aoqi@0 1168 }
aoqi@0 1169 #endif
aoqi@0 1170 vtableEntry* ve = (vtableEntry*)start_of_vtable();
aoqi@0 1171 return ve[index].method();
aoqi@0 1172 }
aoqi@0 1173
aoqi@0 1174 // for adding methods
aoqi@0 1175 // UNSET_IDNUM return means no more ids available
aoqi@0 1176 inline u2 InstanceKlass::next_method_idnum() {
aoqi@0 1177 if (_idnum_allocated_count == ConstMethod::MAX_IDNUM) {
aoqi@0 1178 return ConstMethod::UNSET_IDNUM; // no more ids available
aoqi@0 1179 } else {
aoqi@0 1180 return _idnum_allocated_count++;
aoqi@0 1181 }
aoqi@0 1182 }
aoqi@0 1183
aoqi@0 1184
aoqi@0 1185 /* JNIid class for jfieldIDs only */
aoqi@0 1186 class JNIid: public CHeapObj<mtClass> {
aoqi@0 1187 friend class VMStructs;
aoqi@0 1188 private:
aoqi@0 1189 Klass* _holder;
aoqi@0 1190 JNIid* _next;
aoqi@0 1191 int _offset;
aoqi@0 1192 #ifdef ASSERT
aoqi@0 1193 bool _is_static_field_id;
aoqi@0 1194 #endif
aoqi@0 1195
aoqi@0 1196 public:
aoqi@0 1197 // Accessors
aoqi@0 1198 Klass* holder() const { return _holder; }
aoqi@0 1199 int offset() const { return _offset; }
aoqi@0 1200 JNIid* next() { return _next; }
aoqi@0 1201 // Constructor
aoqi@0 1202 JNIid(Klass* holder, int offset, JNIid* next);
aoqi@0 1203 // Identifier lookup
aoqi@0 1204 JNIid* find(int offset);
aoqi@0 1205
aoqi@0 1206 bool find_local_field(fieldDescriptor* fd) {
aoqi@0 1207 return InstanceKlass::cast(holder())->find_local_field_from_offset(offset(), true, fd);
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210 static void deallocate(JNIid* id);
aoqi@0 1211 // Debugging
aoqi@0 1212 #ifdef ASSERT
aoqi@0 1213 bool is_static_field_id() const { return _is_static_field_id; }
aoqi@0 1214 void set_is_static_field_id() { _is_static_field_id = true; }
aoqi@0 1215 #endif
aoqi@0 1216 void verify(Klass* holder);
aoqi@0 1217 };
aoqi@0 1218
aoqi@0 1219
aoqi@0 1220 // If breakpoints are more numerous than just JVMTI breakpoints,
aoqi@0 1221 // consider compressing this data structure.
aoqi@0 1222 // It is currently a simple linked list defined in method.hpp.
aoqi@0 1223
aoqi@0 1224 class BreakpointInfo;
aoqi@0 1225
aoqi@0 1226
aoqi@0 1227 // A collection point for interesting information about the previous
aoqi@0 1228 // version(s) of an InstanceKlass. A GrowableArray of PreviousVersionNodes
aoqi@0 1229 // is attached to the InstanceKlass as needed. See PreviousVersionWalker below.
aoqi@0 1230 class PreviousVersionNode : public CHeapObj<mtClass> {
aoqi@0 1231 private:
aoqi@0 1232 ConstantPool* _prev_constant_pool;
aoqi@0 1233
aoqi@0 1234 // If the previous version of the InstanceKlass doesn't have any
aoqi@0 1235 // EMCP methods, then _prev_EMCP_methods will be NULL. If all the
aoqi@0 1236 // EMCP methods have been collected, then _prev_EMCP_methods can
aoqi@0 1237 // have a length of zero.
aoqi@0 1238 GrowableArray<Method*>* _prev_EMCP_methods;
aoqi@0 1239
aoqi@0 1240 public:
aoqi@0 1241 PreviousVersionNode(ConstantPool* prev_constant_pool,
aoqi@0 1242 GrowableArray<Method*>* prev_EMCP_methods);
aoqi@0 1243 ~PreviousVersionNode();
aoqi@0 1244 ConstantPool* prev_constant_pool() const {
aoqi@0 1245 return _prev_constant_pool;
aoqi@0 1246 }
aoqi@0 1247 GrowableArray<Method*>* prev_EMCP_methods() const {
aoqi@0 1248 return _prev_EMCP_methods;
aoqi@0 1249 }
aoqi@0 1250 };
aoqi@0 1251
aoqi@0 1252
aoqi@0 1253 // Helper object for walking previous versions.
aoqi@0 1254 class PreviousVersionWalker : public StackObj {
aoqi@0 1255 private:
aoqi@0 1256 Thread* _thread;
aoqi@0 1257 GrowableArray<PreviousVersionNode *>* _previous_versions;
aoqi@0 1258 int _current_index;
aoqi@0 1259
aoqi@0 1260 // A pointer to the current node object so we can handle the deletes.
aoqi@0 1261 PreviousVersionNode* _current_p;
aoqi@0 1262
aoqi@0 1263 // The constant pool handle keeps all the methods in this class from being
aoqi@0 1264 // deallocated from the metaspace during class unloading.
aoqi@0 1265 constantPoolHandle _current_constant_pool_handle;
aoqi@0 1266
aoqi@0 1267 public:
aoqi@0 1268 PreviousVersionWalker(Thread* thread, InstanceKlass *ik);
aoqi@0 1269
aoqi@0 1270 // Return the interesting information for the next previous version
aoqi@0 1271 // of the klass. Returns NULL if there are no more previous versions.
aoqi@0 1272 PreviousVersionNode* next_previous_version();
aoqi@0 1273 };
aoqi@0 1274
aoqi@0 1275
aoqi@0 1276 //
aoqi@0 1277 // nmethodBucket is used to record dependent nmethods for
aoqi@0 1278 // deoptimization. nmethod dependencies are actually <klass, method>
aoqi@0 1279 // pairs but we really only care about the klass part for purposes of
aoqi@0 1280 // finding nmethods which might need to be deoptimized. Instead of
aoqi@0 1281 // recording the method, a count of how many times a particular nmethod
aoqi@0 1282 // was recorded is kept. This ensures that any recording errors are
aoqi@0 1283 // noticed since an nmethod should be removed as many times are it's
aoqi@0 1284 // added.
aoqi@0 1285 //
aoqi@0 1286 class nmethodBucket: public CHeapObj<mtClass> {
aoqi@0 1287 friend class VMStructs;
aoqi@0 1288 private:
aoqi@0 1289 nmethod* _nmethod;
aoqi@0 1290 int _count;
aoqi@0 1291 nmethodBucket* _next;
aoqi@0 1292
aoqi@0 1293 public:
aoqi@0 1294 nmethodBucket(nmethod* nmethod, nmethodBucket* next) {
aoqi@0 1295 _nmethod = nmethod;
aoqi@0 1296 _next = next;
aoqi@0 1297 _count = 1;
aoqi@0 1298 }
aoqi@0 1299 int count() { return _count; }
aoqi@0 1300 int increment() { _count += 1; return _count; }
stefank@6992 1301 int decrement();
aoqi@0 1302 nmethodBucket* next() { return _next; }
aoqi@0 1303 void set_next(nmethodBucket* b) { _next = b; }
aoqi@0 1304 nmethod* get_nmethod() { return _nmethod; }
aoqi@0 1305 };
aoqi@0 1306
aoqi@0 1307 // An iterator that's used to access the inner classes indices in the
aoqi@0 1308 // InstanceKlass::_inner_classes array.
aoqi@0 1309 class InnerClassesIterator : public StackObj {
aoqi@0 1310 private:
aoqi@0 1311 Array<jushort>* _inner_classes;
aoqi@0 1312 int _length;
aoqi@0 1313 int _idx;
aoqi@0 1314 public:
aoqi@0 1315
aoqi@0 1316 InnerClassesIterator(instanceKlassHandle k) {
aoqi@0 1317 _inner_classes = k->inner_classes();
aoqi@0 1318 if (k->inner_classes() != NULL) {
aoqi@0 1319 _length = _inner_classes->length();
aoqi@0 1320 // The inner class array's length should be the multiple of
aoqi@0 1321 // inner_class_next_offset if it only contains the InnerClasses
aoqi@0 1322 // attribute data, or it should be
aoqi@0 1323 // n*inner_class_next_offset+enclosing_method_attribute_size
aoqi@0 1324 // if it also contains the EnclosingMethod data.
aoqi@0 1325 assert((_length % InstanceKlass::inner_class_next_offset == 0 ||
aoqi@0 1326 _length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size),
aoqi@0 1327 "just checking");
aoqi@0 1328 // Remove the enclosing_method portion if exists.
aoqi@0 1329 if (_length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size) {
aoqi@0 1330 _length -= InstanceKlass::enclosing_method_attribute_size;
aoqi@0 1331 }
aoqi@0 1332 } else {
aoqi@0 1333 _length = 0;
aoqi@0 1334 }
aoqi@0 1335 _idx = 0;
aoqi@0 1336 }
aoqi@0 1337
aoqi@0 1338 int length() const {
aoqi@0 1339 return _length;
aoqi@0 1340 }
aoqi@0 1341
aoqi@0 1342 void next() {
aoqi@0 1343 _idx += InstanceKlass::inner_class_next_offset;
aoqi@0 1344 }
aoqi@0 1345
aoqi@0 1346 bool done() const {
aoqi@0 1347 return (_idx >= _length);
aoqi@0 1348 }
aoqi@0 1349
aoqi@0 1350 u2 inner_class_info_index() const {
aoqi@0 1351 return _inner_classes->at(
aoqi@0 1352 _idx + InstanceKlass::inner_class_inner_class_info_offset);
aoqi@0 1353 }
aoqi@0 1354
aoqi@0 1355 void set_inner_class_info_index(u2 index) {
aoqi@0 1356 _inner_classes->at_put(
aoqi@0 1357 _idx + InstanceKlass::inner_class_inner_class_info_offset, index);
aoqi@0 1358 }
aoqi@0 1359
aoqi@0 1360 u2 outer_class_info_index() const {
aoqi@0 1361 return _inner_classes->at(
aoqi@0 1362 _idx + InstanceKlass::inner_class_outer_class_info_offset);
aoqi@0 1363 }
aoqi@0 1364
aoqi@0 1365 void set_outer_class_info_index(u2 index) {
aoqi@0 1366 _inner_classes->at_put(
aoqi@0 1367 _idx + InstanceKlass::inner_class_outer_class_info_offset, index);
aoqi@0 1368 }
aoqi@0 1369
aoqi@0 1370 u2 inner_name_index() const {
aoqi@0 1371 return _inner_classes->at(
aoqi@0 1372 _idx + InstanceKlass::inner_class_inner_name_offset);
aoqi@0 1373 }
aoqi@0 1374
aoqi@0 1375 void set_inner_name_index(u2 index) {
aoqi@0 1376 _inner_classes->at_put(
aoqi@0 1377 _idx + InstanceKlass::inner_class_inner_name_offset, index);
aoqi@0 1378 }
aoqi@0 1379
aoqi@0 1380 u2 inner_access_flags() const {
aoqi@0 1381 return _inner_classes->at(
aoqi@0 1382 _idx + InstanceKlass::inner_class_access_flags_offset);
aoqi@0 1383 }
aoqi@0 1384 };
aoqi@0 1385
aoqi@0 1386 #endif // SHARE_VM_OOPS_INSTANCEKLASS_HPP

mercurial