JVM source code practice - OOP Klass model

Posted by stopblackholes on Thu, 28 Nov 2019 20:24:27 +0100

> Github original link

1 OOP Klass (ordinary object pointer) model

OOP Klass model is used to describe the properties and behaviors of class It is designed as OOP and Klass because we don't want each object to have a C ++ vtbl pointer. Therefore, ordinary oops has no virtual function Instead, they forward all "virtual" functions to their Klass, which has vtbl and performs C + + scheduling based on the actual type of object.

1.1 OOP

oopDesc is the highest parent of an object class. The {name}Desc class describes the format of Java objects, which can be accessed from C + +.

  • Path / hotspot/share/oops/oop.hpp

For a complete class hierarchy, read src/hotspot/share/oops/oopsHierarchy.hpp

  • OOP system

1.2 Klass

  • Klass system Klass object provides
  • Language level class objects (method dictionaries, etc.)
  • Providing virtual machine scheduling behavior for objects
class Klass : public Metadata {
  friend class VMStructs;
  friend class JVMCIVMStructs;
  // If you add a new field that points to any metadata object, you must add this field to Klass:: metasface? Pointers? Do()
  // Note: common fields are put together at the beginning of klass structure for better cache behavior (although it may not be much different, it can certainly not cause harm)
  enum { _primary_super_limit = 8 };

  // The "layout helper" is a combined descriptor of object layout.
  // For klasses which are neither instance nor array, the value is zero.
  // For instances, layout helper is a positive number, the instance size.
  // This size is already passed through align_object_size and scaled to bytes.
  // The low order bit is set if instances of this class cannot be
  // allocated using the fastpath.
  // For arrays, layout helper is a negative number, containing four
  // distinct bytes, as follows:
  //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
  // where:
  //    tag is 0x80 if the elements are oops, 0xC0 if non-oops
  //    hsz is array header size in bytes (i.e., offset of first element)
  //    ebt is the BasicType of the elements
  //    esz is the element size in bytes
  // This packed word is arranged so as to be quickly unpacked by the
  // various fast paths that use the various subfields.
  // The esz bits can be used directly by a SLL instruction, without masking.
  // Note that the array-kind tag looks like 0x00 for instance klasses,
  // since their length in bytes is always less than 24Mb.
  // Final note:  This comes first, immediately after C++ vtable,
  // because it is frequently queried.
  jint        _layout_helper;

  // Klass identifier used to implement devirtualized oop closure dispatching.
  const KlassID _id;

  // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
  // and _primary_supers all help make fast subtype checks.  See big discussion
  // in doc/server_compiler/checktype.txt
  // Where to look to observe a supertype (it is &_secondary_super_cache for
  // secondary supers, else is &_primary_supers[depth()].
  juint       _super_check_offset;

  // Class name. Instance classes: Java / Lang / string, etc. array classes: [I,
  // [Ljava/lang/String;, etc.  Set to zero for all other kinds of classes.
  Symbol*     _name;

  // Cache of last observed secondary supertype
  Klass*      _secondary_super_cache;
  // Array of all secondary supertypes
  Array<klass*>* _secondary_supers;
  // Ordered list of all primary supertypes
  Klass*      _primary_supers[_primary_super_limit];
  // java/lang/Class instance mirroring this class
  OopHandle _java_mirror;
  // Superclass
  Klass*      _super;
  // First subclass (NULL if none); _subklass-&gt;next_sibling() is next one
  Klass* volatile _subklass;
  // Sibling link (or NULL); links all subklasses of a klass
  Klass* volatile _next_sibling;

  // All klasses loaded by a class loader are chained through these links
  Klass*      _next_link;
  // The VM to class loader representation used to load this class.
  //Provide access to the corresponding java.lang.ClassLoader instance
  ClassLoaderData* _class_loader_data;

  jint        _modifier_flags;  // Processed access flag, used by Class.getModifiers
  AccessFlags _access_flags;    // Access flag The differences between classes / interfaces are stored here


  // Implementation and statistics of biased locking
  // 64 bit block first to avoid fragmentation
  jlong    _last_biased_lock_bulk_revocation_time;
  markOop  _prototype_header;   // Used when biased locking is both enabled and disabled for this type
  jint     _biased_lock_revocation_count;

  // Virtual table length
  int _vtable_len;

>This article is based on the platform of blog one article multiple sending OpenWrite Release! </klass*>

Topics: Big Data Java github less