< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page




  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_KLASS_HPP
  26 #define SHARE_VM_OOPS_KLASS_HPP
  27 
  28 #include "gc/shared/specialized_oop_closures.hpp"
  29 #include "memory/iterator.hpp"
  30 #include "memory/memRegion.hpp"

  31 #include "oops/metadata.hpp"
  32 #include "oops/oop.hpp"
  33 #include "oops/oopHandle.hpp"
  34 #include "trace/traceMacros.hpp"
  35 #include "utilities/accessFlags.hpp"
  36 #include "utilities/macros.hpp"
  37 
  38 //
  39 // A Klass provides:
  40 //  1: language level class object (method dictionary etc.)
  41 //  2: provide vm dispatch behavior for the object
  42 // Both functions are combined into one C++ class.
  43 
  44 // One reason for the oop/klass dichotomy in the implementation is
  45 // that we don't want a C++ vtbl pointer in every object.  Thus,
  46 // normal oops don't have any virtual functions.  Instead, they
  47 // forward all "virtual" functions to their klass, which does have
  48 // a vtbl and does the C++ dispatch depending on the object's
  49 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
  50 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!


 145   jlong    _last_biased_lock_bulk_revocation_time;
 146   markOop  _prototype_header;   // Used when biased locking is both enabled and disabled for this type
 147   jint     _biased_lock_revocation_count;
 148 
 149   // vtable length
 150   int _vtable_len;
 151 
 152 private:
 153   // This is an index into FileMapHeader::_classpath_entry_table[], to
 154   // associate this class with the JAR file where it's loaded from during
 155   // dump time. If a class is not loaded from the shared archive, this field is
 156   // -1.
 157   jshort _shared_class_path_index;
 158 
 159   friend class SharedClassUtil;
 160 protected:
 161 
 162   // Constructor
 163   Klass();
 164 
 165   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();



 166 
 167  public:
 168   enum DefaultsLookupMode { find_defaults, skip_defaults };
 169   enum OverpassLookupMode { find_overpass, skip_overpass };
 170   enum StaticLookupMode   { find_static,   skip_static };
 171   enum PrivateLookupMode  { find_private,  skip_private };
 172 
 173   bool is_klass() const volatile { return true; }
 174 
 175   // super
 176   Klass* super() const               { return _super; }
 177   void set_super(Klass* k)           { _super = k; }
 178 
 179   // initializes _super link, _primary_supers & _secondary_supers arrays
 180   void initialize_supers(Klass* k, TRAPS);
 181   void initialize_supers_impl1(Klass* k);
 182   void initialize_supers_impl2(Klass* k);
 183 
 184   // klass-specific helper for initializing _secondary_supers
 185   virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);


 566   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
 567   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
 568   bool has_final_method() const         { return _access_flags.has_final_method(); }
 569   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
 570   void set_has_final_method()           { _access_flags.set_has_final_method(); }
 571   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
 572   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
 573   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
 574   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
 575   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
 576   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
 577 
 578   bool is_cloneable() const;
 579   void set_is_cloneable();
 580 
 581   // Biased locking support
 582   // Note: the prototype header is always set up to be at least the
 583   // prototype markOop. If biased locking is enabled it may further be
 584   // biasable and have an epoch.
 585   markOop prototype_header() const      { return _prototype_header; }



 586   // NOTE: once instances of this klass are floating around in the
 587   // system, this header must only be updated at a safepoint.
 588   // NOTE 2: currently we only ever set the prototype header to the
 589   // biasable prototype for instanceKlasses. There is no technical
 590   // reason why it could not be done for arrayKlasses aside from
 591   // wanting to reduce the initial scope of this optimization. There
 592   // are potential problems in setting the bias pattern for
 593   // JVM-internal oops.
 594   inline void set_prototype_header(markOop header);
 595   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
 596 
 597   int  biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
 598   // Atomically increments biased_lock_revocation_count and returns updated value
 599   int atomic_incr_biased_lock_revocation_count();
 600   void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
 601   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
 602   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 603 
 604   TRACE_DEFINE_TRACE_ID_METHODS;
 605 


 672   // Verification
 673   virtual void verify_on(outputStream* st);
 674   void verify() { verify_on(tty); }
 675 
 676 #ifndef PRODUCT
 677   bool verify_vtable_index(int index);
 678   bool verify_itable_index(int index);
 679 #endif
 680 
 681   virtual void oop_verify_on(oop obj, outputStream* st);
 682 
 683   static bool is_null(narrowKlass obj);
 684   static bool is_null(Klass* obj);
 685 
 686   // klass encoding for klass pointer in objects.
 687   static narrowKlass encode_klass_not_null(Klass* v);
 688   static narrowKlass encode_klass(Klass* v);
 689 
 690   static Klass* decode_klass_not_null(narrowKlass v);
 691   static Klass* decode_klass(narrowKlass v);



 692 };
 693 
 694 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions.
 695 #define nvs_nv_to_bool true
 696 #define nvs_v_to_bool  false
 697 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool
 698 
 699 // Oop iteration macros for declarations.
 700 // Used to generate declarations in the *Klass header files.
 701 
 702 #define OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix)                                    \
 703   void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure);                        \
 704   void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr);
 705 
 706 #if INCLUDE_ALL_GCS
 707 #define OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix)               \
 708   void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure);
 709 #endif // INCLUDE_ALL_GCS
 710 
 711 




  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_KLASS_HPP
  26 #define SHARE_VM_OOPS_KLASS_HPP
  27 
  28 #include "gc/shared/specialized_oop_closures.hpp"
  29 #include "memory/iterator.hpp"
  30 #include "memory/memRegion.hpp"
  31 #include "oops/markOop.hpp"
  32 #include "oops/metadata.hpp"
  33 #include "oops/oop.hpp"
  34 #include "oops/oopHandle.hpp"
  35 #include "trace/traceMacros.hpp"
  36 #include "utilities/accessFlags.hpp"
  37 #include "utilities/macros.hpp"
  38 
  39 //
  40 // A Klass provides:
  41 //  1: language level class object (method dictionary etc.)
  42 //  2: provide vm dispatch behavior for the object
  43 // Both functions are combined into one C++ class.
  44 
  45 // One reason for the oop/klass dichotomy in the implementation is
  46 // that we don't want a C++ vtbl pointer in every object.  Thus,
  47 // normal oops don't have any virtual functions.  Instead, they
  48 // forward all "virtual" functions to their klass, which does have
  49 // a vtbl and does the C++ dispatch depending on the object's
  50 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
  51 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!


 146   jlong    _last_biased_lock_bulk_revocation_time;
 147   markOop  _prototype_header;   // Used when biased locking is both enabled and disabled for this type
 148   jint     _biased_lock_revocation_count;
 149 
 150   // vtable length
 151   int _vtable_len;
 152 
 153 private:
 154   // This is an index into FileMapHeader::_classpath_entry_table[], to
 155   // associate this class with the JAR file where it's loaded from during
 156   // dump time. If a class is not loaded from the shared archive, this field is
 157   // -1.
 158   jshort _shared_class_path_index;
 159 
 160   friend class SharedClassUtil;
 161 protected:
 162 
 163   // Constructor
 164   Klass();
 165 
 166   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, bool is_value, TRAPS) throw();
 167   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 168    return operator new (size, loader_data, word_size, false, THREAD);
 169   }
 170 
 171  public:
 172   enum DefaultsLookupMode { find_defaults, skip_defaults };
 173   enum OverpassLookupMode { find_overpass, skip_overpass };
 174   enum StaticLookupMode   { find_static,   skip_static };
 175   enum PrivateLookupMode  { find_private,  skip_private };
 176 
 177   bool is_klass() const volatile { return true; }
 178 
 179   // super
 180   Klass* super() const               { return _super; }
 181   void set_super(Klass* k)           { _super = k; }
 182 
 183   // initializes _super link, _primary_supers & _secondary_supers arrays
 184   void initialize_supers(Klass* k, TRAPS);
 185   void initialize_supers_impl1(Klass* k);
 186   void initialize_supers_impl2(Klass* k);
 187 
 188   // klass-specific helper for initializing _secondary_supers
 189   virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots);


 570   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
 571   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
 572   bool has_final_method() const         { return _access_flags.has_final_method(); }
 573   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
 574   void set_has_final_method()           { _access_flags.set_has_final_method(); }
 575   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
 576   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
 577   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
 578   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
 579   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
 580   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
 581 
 582   bool is_cloneable() const;
 583   void set_is_cloneable();
 584 
 585   // Biased locking support
 586   // Note: the prototype header is always set up to be at least the
 587   // prototype markOop. If biased locking is enabled it may further be
 588   // biasable and have an epoch.
 589   markOop prototype_header() const      { return _prototype_header; }
 590   static inline markOop default_prototype_header(Klass* k) {
 591     return (k == NULL) ? markOopDesc::prototype() : k->prototype_header();
 592   }
 593   // NOTE: once instances of this klass are floating around in the
 594   // system, this header must only be updated at a safepoint.
 595   // NOTE 2: currently we only ever set the prototype header to the
 596   // biasable prototype for instanceKlasses. There is no technical
 597   // reason why it could not be done for arrayKlasses aside from
 598   // wanting to reduce the initial scope of this optimization. There
 599   // are potential problems in setting the bias pattern for
 600   // JVM-internal oops.
 601   inline void set_prototype_header(markOop header);
 602   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
 603 
 604   int  biased_lock_revocation_count() const { return (int) _biased_lock_revocation_count; }
 605   // Atomically increments biased_lock_revocation_count and returns updated value
 606   int atomic_incr_biased_lock_revocation_count();
 607   void set_biased_lock_revocation_count(int val) { _biased_lock_revocation_count = (jint) val; }
 608   jlong last_biased_lock_bulk_revocation_time() { return _last_biased_lock_bulk_revocation_time; }
 609   void  set_last_biased_lock_bulk_revocation_time(jlong cur_time) { _last_biased_lock_bulk_revocation_time = cur_time; }
 610 
 611   TRACE_DEFINE_TRACE_ID_METHODS;
 612 


 679   // Verification
 680   virtual void verify_on(outputStream* st);
 681   void verify() { verify_on(tty); }
 682 
 683 #ifndef PRODUCT
 684   bool verify_vtable_index(int index);
 685   bool verify_itable_index(int index);
 686 #endif
 687 
 688   virtual void oop_verify_on(oop obj, outputStream* st);
 689 
 690   static bool is_null(narrowKlass obj);
 691   static bool is_null(Klass* obj);
 692 
 693   // klass encoding for klass pointer in objects.
 694   static narrowKlass encode_klass_not_null(Klass* v);
 695   static narrowKlass encode_klass(Klass* v);
 696 
 697   static Klass* decode_klass_not_null(narrowKlass v);
 698   static Klass* decode_klass(narrowKlass v);
 699 
 700   static bool decode_ptr_is_value_type(narrowKlass v);
 701   static bool ptr_is_value_type(Klass* v);
 702 };
 703 
 704 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions.
 705 #define nvs_nv_to_bool true
 706 #define nvs_v_to_bool  false
 707 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool
 708 
 709 // Oop iteration macros for declarations.
 710 // Used to generate declarations in the *Klass header files.
 711 
 712 #define OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix)                                    \
 713   void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure);                        \
 714   void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr);
 715 
 716 #if INCLUDE_ALL_GCS
 717 #define OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix)               \
 718   void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure);
 719 #endif // INCLUDE_ALL_GCS
 720 
 721 


< prev index next >