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