src/share/vm/oops/klass.hpp

Print this page
rev 6796 : [mq]: templateOopIterate
rev 6797 : [mq]: vaTests
rev 6798 : [mq]: oneSwitch
rev 6799 : [mq]: latestChanges
rev 6800 : [mq]: replaceTemplateDispatchWithMacroDispatch


  48 // Both functions are combined into one C++ class.
  49 
  50 // One reason for the oop/klass dichotomy in the implementation is
  51 // that we don't want a C++ vtbl pointer in every object.  Thus,
  52 // normal oops don't have any virtual functions.  Instead, they
  53 // forward all "virtual" functions to their klass, which does have
  54 // a vtbl and does the C++ dispatch depending on the object's
  55 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
  56 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
  57 
  58 // Forward declarations.
  59 template <class T> class Array;
  60 template <class T> class GrowableArray;
  61 class ClassLoaderData;
  62 class klassVtable;
  63 class ParCompactionManager;
  64 class KlassSizeStats;
  65 
  66 class Klass : public Metadata {
  67   friend class VMStructs;










  68  protected:


  69   // note: put frequently-used fields together at start of klass structure
  70   // for better cache behavior (may not make much of a difference but sure won't hurt)
  71   enum { _primary_super_limit = 8 };
  72 
  73   // The "layout helper" is a combined descriptor of object layout.
  74   // For klasses which are neither instance nor array, the value is zero.
  75   //
  76   // For instances, layout helper is a positive number, the instance size.
  77   // This size is already passed through align_object_size and scaled to bytes.
  78   // The low order bit is set if instances of this class cannot be
  79   // allocated using the fastpath.
  80   //
  81   // For arrays, layout helper is a negative number, containing four
  82   // distinct bytes, as follows:
  83   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
  84   // where:
  85   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops
  86   //    hsz is array header size in bytes (i.e., offset of first element)
  87   //    ebt is the BasicType of the elements
  88   //    esz is the element size in bytes
  89   // This packed word is arranged so as to be quickly unpacked by the
  90   // various fast paths that use the various subfields.
  91   //


 130 
 131   // The VM's representation of the ClassLoader used to load this class.
 132   // Provide access the corresponding instance java.lang.ClassLoader.
 133   ClassLoaderData* _class_loader_data;
 134 
 135   jint        _modifier_flags;  // Processed access flags, for use by Class.getModifiers.
 136   AccessFlags _access_flags;    // Access flags. The class/interface distinction is stored here.
 137 
 138   // Biased locking implementation and statistics
 139   // (the 64-bit chunk goes first, to avoid some fragmentation)
 140   jlong    _last_biased_lock_bulk_revocation_time;
 141   markOop  _prototype_header;   // Used when biased locking is both enabled and disabled for this type
 142   jint     _biased_lock_revocation_count;
 143 
 144   TRACE_DEFINE_KLASS_TRACE_ID;
 145 
 146   // Remembered sets support for the oops in the klasses.
 147   jbyte _modified_oops;             // Card Table Equivalent (YC/CMS support)
 148   jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 149 


 150   // Constructor
 151   Klass();

 152 
 153   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
 154 
 155  public:
 156   enum MethodLookupMode { normal, skip_overpass, skip_defaults };
 157 
 158   bool is_klass() const volatile { return true; }
 159 


 160   // super
 161   Klass* super() const               { return _super; }
 162   void set_super(Klass* k)           { _super = k; }
 163 
 164   // initializes _super link, _primary_supers & _secondary_supers arrays
 165   void initialize_supers(Klass* k, TRAPS);
 166   void initialize_supers_impl1(Klass* k);
 167   void initialize_supers_impl2(Klass* k);
 168 
 169   // klass-specific helper for initializing _secondary_supers
 170   virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);
 171 
 172   // java_super is the Java-level super type as specified by Class.getSuperClass.
 173   virtual Klass* java_super() const  { return NULL; }
 174 
 175   juint    super_check_offset() const  { return _super_check_offset; }
 176   void set_super_check_offset(juint o) { _super_check_offset = o; }
 177 
 178   Klass* secondary_super_cache() const     { return _secondary_super_cache; }
 179   void set_secondary_super_cache(Klass* k) { _secondary_super_cache = k; }


 540   // Atomically increments biased_lock_revocation_count and returns updated value
 541   int atomic_incr_biased_lock_revocation_count();
 542   void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
 543   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
 544   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 545 
 546   TRACE_DEFINE_KLASS_METHODS;
 547 
 548   // garbage collection support
 549   virtual void oops_do(OopClosure* cl);
 550 
 551   // Iff the class loader (or mirror for anonymous classes) is alive the
 552   // Klass is considered alive.
 553   // The is_alive closure passed in depends on the Garbage Collector used.
 554   bool is_loader_alive(BoolObjectClosure* is_alive);
 555 
 556   static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
 557   static void clean_subklass_tree(BoolObjectClosure* is_alive) {
 558     clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
 559   }
 560 
 561   // iterators
 562   virtual int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) = 0;
 563   virtual int oop_oop_iterate_v(oop obj, ExtendedOopClosure* blk) {
 564     return oop_oop_iterate(obj, blk);
 565   }
 566 
 567 #if INCLUDE_ALL_GCS
 568   // In case we don't have a specialized backward scanner use forward
 569   // iteration.
 570   virtual int oop_oop_iterate_backwards_v(oop obj, ExtendedOopClosure* blk) {
 571     return oop_oop_iterate_v(obj, blk);
 572   }
 573 #endif // INCLUDE_ALL_GCS
 574 
 575   // Iterates "blk" over all the oops in "obj" (of type "this") within "mr".
 576   // (I don't see why the _m should be required, but without it the Solaris
 577   // C++ gives warning messages about overridings of the "oop_oop_iterate"
 578   // defined above "hiding" this virtual function.  (DLD, 6/20/00)) */
 579   virtual int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) = 0;
 580   virtual int oop_oop_iterate_v_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
 581     return oop_oop_iterate_m(obj, blk, mr);
 582   }
 583 
 584   // Versions of the above iterators specialized to particular subtypes
 585   // of OopClosure, to avoid closure virtual calls.
 586 #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix)                \
 587   virtual int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk) {     \
 588     /* Default implementation reverts to general version. */                 \
 589     return oop_oop_iterate(obj, blk);                                        \
 590   }                                                                          \
 591                                                                              \
 592   /* Iterates "blk" over all the oops in "obj" (of type "this") within "mr". \
 593      (I don't see why the _m should be required, but without it the Solaris  \
 594      C++ gives warning messages about overridings of the "oop_oop_iterate"   \
 595      defined above "hiding" this virtual function.  (DLD, 6/20/00)) */       \
 596   virtual int oop_oop_iterate##nv_suffix##_m(oop obj,                        \
 597                                              OopClosureType* blk,            \
 598                                              MemRegion mr) {                 \
 599     return oop_oop_iterate_m(obj, blk, mr);                                  \
 600   }
 601 
 602   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL)
 603   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL)
 604 
 605 #if INCLUDE_ALL_GCS
 606 #define Klass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix)      \
 607   virtual int oop_oop_iterate_backwards##nv_suffix(oop obj,                  \
 608                                                    OopClosureType* blk) {    \
 609     /* Default implementation reverts to general version. */                 \
 610     return oop_oop_iterate_backwards_v(obj, blk);                            \
 611   }
 612 
 613   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
 614   SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_BACKWARDS_DECL)
 615 #endif // INCLUDE_ALL_GCS
 616 
 617   virtual void array_klasses_do(void f(Klass* k)) {}
 618 
 619   // Return self, except for abstract classes with exactly 1
 620   // implementor.  Then return the 1 concrete implementation.
 621   Klass *up_cast_abstract();
 622 
 623   // klass name
 624   Symbol* name() const                   { return _name; }
 625   void set_name(Symbol* n);
 626 
 627  public:
 628   // jvm support
 629   virtual jint compute_modifier_flags(TRAPS) const;
 630 
 631   // JVMTI support
 632   virtual jint jvmti_class_status() const;
 633 
 634   // Printing
 635   virtual void print_on(outputStream* st) const;




  48 // Both functions are combined into one C++ class.
  49 
  50 // One reason for the oop/klass dichotomy in the implementation is
  51 // that we don't want a C++ vtbl pointer in every object.  Thus,
  52 // normal oops don't have any virtual functions.  Instead, they
  53 // forward all "virtual" functions to their klass, which does have
  54 // a vtbl and does the C++ dispatch depending on the object's
  55 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
  56 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
  57 
  58 // Forward declarations.
  59 template <class T> class Array;
  60 template <class T> class GrowableArray;
  61 class ClassLoaderData;
  62 class klassVtable;
  63 class ParCompactionManager;
  64 class KlassSizeStats;
  65 
  66 class Klass : public Metadata {
  67   friend class VMStructs;
  68  public:
  69   enum DispatchTag {
  70     _instance,
  71     _instance_ref,
  72     _instance_mirror,
  73     _instance_class_loader,
  74     _type_array,
  75     _obj_array
  76   };
  77 
  78  protected:
  79   enum { _primary_super_limit = 8 };
  80 
  81   // note: put frequently-used fields together at start of klass structure
  82   // for better cache behavior (may not make much of a difference but sure won't hurt)

  83 
  84   // The "layout helper" is a combined descriptor of object layout.
  85   // For klasses which are neither instance nor array, the value is zero.
  86   //
  87   // For instances, layout helper is a positive number, the instance size.
  88   // This size is already passed through align_object_size and scaled to bytes.
  89   // The low order bit is set if instances of this class cannot be
  90   // allocated using the fastpath.
  91   //
  92   // For arrays, layout helper is a negative number, containing four
  93   // distinct bytes, as follows:
  94   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
  95   // where:
  96   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops
  97   //    hsz is array header size in bytes (i.e., offset of first element)
  98   //    ebt is the BasicType of the elements
  99   //    esz is the element size in bytes
 100   // This packed word is arranged so as to be quickly unpacked by the
 101   // various fast paths that use the various subfields.
 102   //


 141 
 142   // The VM's representation of the ClassLoader used to load this class.
 143   // Provide access the corresponding instance java.lang.ClassLoader.
 144   ClassLoaderData* _class_loader_data;
 145 
 146   jint        _modifier_flags;  // Processed access flags, for use by Class.getModifiers.
 147   AccessFlags _access_flags;    // Access flags. The class/interface distinction is stored here.
 148 
 149   // Biased locking implementation and statistics
 150   // (the 64-bit chunk goes first, to avoid some fragmentation)
 151   jlong    _last_biased_lock_bulk_revocation_time;
 152   markOop  _prototype_header;   // Used when biased locking is both enabled and disabled for this type
 153   jint     _biased_lock_revocation_count;
 154 
 155   TRACE_DEFINE_KLASS_TRACE_ID;
 156 
 157   // Remembered sets support for the oops in the klasses.
 158   jbyte _modified_oops;             // Card Table Equivalent (YC/CMS support)
 159   jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 160 
 161   const DispatchTag _dispatch_tag;
 162 
 163   // Constructor
 164   Klass(DispatchTag dispatch_tag, bool dummy /*ignored*/) : _dispatch_tag(_instance) {} // SSS: For Dummy objects
 165   Klass(DispatchTag dispatch_tag);
 166 
 167   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
 168 
 169  public:
 170   enum MethodLookupMode { normal, skip_overpass, skip_defaults };
 171 
 172   bool is_klass() const volatile { return true; }
 173   
 174   DispatchTag dispatch_tag() const { return _dispatch_tag; }
 175 
 176   // super
 177   Klass* super() const               { return _super; }
 178   void set_super(Klass* k)           { _super = k; }
 179 
 180   // initializes _super link, _primary_supers & _secondary_supers arrays
 181   void initialize_supers(Klass* k, TRAPS);
 182   void initialize_supers_impl1(Klass* k);
 183   void initialize_supers_impl2(Klass* k);
 184 
 185   // klass-specific helper for initializing _secondary_supers
 186   virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);
 187 
 188   // java_super is the Java-level super type as specified by Class.getSuperClass.
 189   virtual Klass* java_super() const  { return NULL; }
 190 
 191   juint    super_check_offset() const  { return _super_check_offset; }
 192   void set_super_check_offset(juint o) { _super_check_offset = o; }
 193 
 194   Klass* secondary_super_cache() const     { return _secondary_super_cache; }
 195   void set_secondary_super_cache(Klass* k) { _secondary_super_cache = k; }


 556   // Atomically increments biased_lock_revocation_count and returns updated value
 557   int atomic_incr_biased_lock_revocation_count();
 558   void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
 559   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
 560   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 561 
 562   TRACE_DEFINE_KLASS_METHODS;
 563 
 564   // garbage collection support
 565   virtual void oops_do(OopClosure* cl);
 566 
 567   // Iff the class loader (or mirror for anonymous classes) is alive the
 568   // Klass is considered alive.
 569   // The is_alive closure passed in depends on the Garbage Collector used.
 570   bool is_loader_alive(BoolObjectClosure* is_alive);
 571 
 572   static void clean_weak_klass_links(BoolObjectClosure* is_alive, bool clean_alive_klasses = true);
 573   static void clean_subklass_tree(BoolObjectClosure* is_alive) {
 574     clean_weak_klass_links(is_alive, false /* clean_alive_klasses */);
 575   }
























































 576 
 577   virtual void array_klasses_do(void f(Klass* k)) {}
 578 
 579   // Return self, except for abstract classes with exactly 1
 580   // implementor.  Then return the 1 concrete implementation.
 581   Klass *up_cast_abstract();
 582 
 583   // klass name
 584   Symbol* name() const                   { return _name; }
 585   void set_name(Symbol* n);
 586 
 587  public:
 588   // jvm support
 589   virtual jint compute_modifier_flags(TRAPS) const;
 590 
 591   // JVMTI support
 592   virtual jint jvmti_class_status() const;
 593 
 594   // Printing
 595   virtual void print_on(outputStream* st) const;