agent/src/share/classes/sun/jvm/hotspot/oops/Klass.java

Print this page
rev 146 : [mq]: mixa.layout.patch


  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.oops;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 import sun.jvm.hotspot.debugger.*;
  30 import sun.jvm.hotspot.runtime.*;
  31 import sun.jvm.hotspot.types.*;

  32 
  33 public class Klass extends Oop implements ClassConstants {
  34   static {
  35     VM.registerVMInitializedObserver(new Observer() {
  36         public void update(Observable o, Object data) {
  37           initialize(VM.getVM().getTypeDataBase());
  38         }
  39       });
  40   }
  41 
  42   // anon-enum constants for _layout_helper.
  43   public static int LH_INSTANCE_SLOW_PATH_BIT;
  44   public static int LH_LOG2_ELEMENT_SIZE_SHIFT;
  45   public static int LH_ELEMENT_TYPE_SHIFT;











  46   public static int LH_HEADER_SIZE_SHIFT;
  47   public static int LH_ARRAY_TAG_SHIFT;
  48   public static int LH_ARRAY_TAG_TYPE_VALUE;
  49   public static int LH_ARRAY_TAG_OBJ_VALUE;
  50 
  51   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
  52     Type type    = db.lookupType("Klass");
  53     javaMirror   = new OopField(type.getOopField("_java_mirror"), Oop.getHeaderSize());
  54     superField   = new OopField(type.getOopField("_super"), Oop.getHeaderSize());
  55     layoutHelper = new IntField(type.getJIntField("_layout_helper"), Oop.getHeaderSize());
  56     name         = new OopField(type.getOopField("_name"), Oop.getHeaderSize());
  57     accessFlags  = new CIntField(type.getCIntegerField("_access_flags"), Oop.getHeaderSize());
  58     subklass     = new OopField(type.getOopField("_subklass"), Oop.getHeaderSize());
  59     nextSibling  = new OopField(type.getOopField("_next_sibling"), Oop.getHeaderSize());
  60     allocCount   = new CIntField(type.getCIntegerField("_alloc_count"), Oop.getHeaderSize());
  61 
  62     LH_INSTANCE_SLOW_PATH_BIT  = db.lookupIntConstant("Klass::_lh_instance_slow_path_bit").intValue();
  63     LH_LOG2_ELEMENT_SIZE_SHIFT = db.lookupIntConstant("Klass::_lh_log2_element_size_shift").intValue();
  64     LH_ELEMENT_TYPE_SHIFT      = db.lookupIntConstant("Klass::_lh_element_type_shift").intValue();
  65     LH_HEADER_SIZE_SHIFT       = db.lookupIntConstant("Klass::_lh_header_size_shift").intValue();
  66     LH_ARRAY_TAG_SHIFT         = db.lookupIntConstant("Klass::_lh_array_tag_shift").intValue();
  67     LH_ARRAY_TAG_TYPE_VALUE    = db.lookupIntConstant("Klass::_lh_array_tag_type_value").intValue();
  68     LH_ARRAY_TAG_OBJ_VALUE     = db.lookupIntConstant("Klass::_lh_array_tag_obj_value").intValue();










  69   }
  70 
  71   Klass(OopHandle handle, ObjectHeap heap) {
  72     super(handle, heap);
  73   }
  74 
  75   // jvmdi support - see also class_status in VM code
  76   public int getClassStatus() {
  77     return 0; // overridden in derived classes
  78   }
  79 
  80   public boolean isKlass()             { return true; }
  81 
  82   // Fields
  83   private static OopField  javaMirror;
  84   private static OopField  superField;
  85   private static IntField layoutHelper;
  86   private static OopField  name;
  87   private static CIntField accessFlags;
  88   private static OopField  subklass;
  89   private static OopField  nextSibling;
  90   private static CIntField allocCount;
  91 
  92   // Accessors for declared fields
  93   public Instance getJavaMirror()       { return (Instance) javaMirror.getValue(this);   }
  94   public Klass    getSuper()            { return (Klass)    superField.getValue(this);   }
  95   public Klass    getJavaSuper()        { return null;  }
  96   public int      getLayoutHelper()     { return (int)           layoutHelper.getValue(this); }
  97   public Symbol   getName()             { return (Symbol)   name.getValue(this);         }
  98   public long     getAccessFlags()      { return            accessFlags.getValue(this);  }
  99   // Convenience routine
 100   public AccessFlags getAccessFlagsObj(){ return new AccessFlags(getAccessFlags());      }
 101   public Klass    getSubklassKlass()    { return (Klass)    subklass.getValue(this);     }
 102   public Klass    getNextSiblingKlass() { return (Klass)    nextSibling.getValue(this);  }
 103   public long     getAllocCount()       { return            allocCount.getValue(this);   }
 104 
































 105   // computed access flags - takes care of inner classes etc.
 106   // This is closer to actual source level than getAccessFlags() etc.
 107   public long computeModifierFlags() {
 108     return 0L; // Unless overridden, modifier_flags is 0.
 109   }
 110 
 111   // same as JVM_GetClassModifiers
 112   public final long getClassModifiers() {
 113     // unlike the VM counterpart we never have to deal with primitive type,
 114     // because we operator on Klass and not an instance of java.lang.Class.
 115     long flags = computeModifierFlags();
 116     if (isSuper()) {
 117        flags |= JVM_ACC_SUPER;
 118     }
 119     return flags;
 120   }
 121 
 122   // subclass check
 123   public boolean isSubclassOf(Klass k) {
 124     if (k != null) {




  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.oops;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 import sun.jvm.hotspot.debugger.*;
  30 import sun.jvm.hotspot.runtime.*;
  31 import sun.jvm.hotspot.types.*;
  32 import sun.jvm.hotspot.utilities.*;
  33 
  34 public class Klass extends Oop implements ClassConstants {
  35   static {
  36     VM.registerVMInitializedObserver(new Observer() {
  37         public void update(Observable o, Object data) {
  38           initialize(VM.getVM().getTypeDataBase());
  39         }
  40       });
  41   }
  42 
  43   // anon-enum constants for _layout_helper.
  44   public static int LH_FLAGS_BITS;
  45   public static int LH_FLAGS_SHIFT;
  46   public static int LH_FLAGS_LOW_BITS;
  47   public static int   LH_VARIABLE_FLAG;
  48   public static int   LH_ARRAY_FLAG;
  49   public static int   LH_FLAGS_EBT_MASK;
  50   public static int LH_ELEMENT_SIZE_BITS;
  51   public static int LH_ELEMENT_SIZE_SHIFT;
  52   public static int   LH_ELEMENT_SCALE_BITS;
  53   public static int   LH_ELEMENT_SIZEM_BITS;
  54   public static int   LH_ELEMENT_SIZEM_MASK_IP;
  55   public static int LH_SIZE_LOW_BITS;
  56   public static int   LH_SLOW_PATH_LOW_BIT;
  57   public static int LH_HEADER_SIZE_BITS;
  58   public static int LH_HEADER_SIZE_SHIFT;
  59   public static int LH_FIXED_SIZE_BITS;
  60   public static int LH_FIXED_SIZE_SHIFT;
  61 
  62 
  63   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
  64     Type type    = db.lookupType("Klass");
  65     javaMirror   = new OopField(type.getOopField("_java_mirror"), Oop.getHeaderSize());
  66     superField   = new OopField(type.getOopField("_super"), Oop.getHeaderSize());
  67     layoutHelper = new IntField(type.getJIntField("_layout_helper"), Oop.getHeaderSize());
  68     name         = new OopField(type.getOopField("_name"), Oop.getHeaderSize());
  69     accessFlags  = new CIntField(type.getCIntegerField("_access_flags"), Oop.getHeaderSize());
  70     subklass     = new OopField(type.getOopField("_subklass"), Oop.getHeaderSize());
  71     nextSibling  = new OopField(type.getOopField("_next_sibling"), Oop.getHeaderSize());
  72     allocCount   = new CIntField(type.getCIntegerField("_alloc_count"), Oop.getHeaderSize());
  73 
  74     LH_FLAGS_BITS             = db.lookupIntConstant("LayoutHelper::_flags_bits").intValue();
  75     LH_FLAGS_SHIFT            = db.lookupIntConstant("LayoutHelper::_flags_shift").intValue();
  76     LH_FLAGS_LOW_BITS         = db.lookupIntConstant("LayoutHelper::_flags_low_bits").intValue();
  77     LH_VARIABLE_FLAG            = db.lookupIntConstant("LayoutHelper::_variable_flag").intValue();
  78     LH_ARRAY_FLAG               = db.lookupIntConstant("LayoutHelper::_array_flag").intValue();
  79     LH_FLAGS_EBT_MASK           = db.lookupIntConstant("LayoutHelper::_flags_ebt_mask").intValue();
  80     LH_ELEMENT_SIZE_BITS      = db.lookupIntConstant("LayoutHelper::_element_size_bits").intValue();
  81     LH_ELEMENT_SIZE_SHIFT     = db.lookupIntConstant("LayoutHelper::_element_size_shift").intValue();
  82     LH_ELEMENT_SCALE_BITS       = db.lookupIntConstant("LayoutHelper::_element_scale_bits").intValue();
  83     LH_ELEMENT_SIZEM_BITS       = db.lookupIntConstant("LayoutHelper::_element_sizem_bits").intValue();
  84     LH_ELEMENT_SIZEM_MASK_IP    = db.lookupIntConstant("LayoutHelper::_element_sizem_mask_ip").intValue();
  85     LH_SIZE_LOW_BITS          = db.lookupIntConstant("LayoutHelper::_fixed_size_low_bits").intValue();
  86     LH_SLOW_PATH_LOW_BIT        = db.lookupIntConstant("LayoutHelper::_slow_path_low_bit").intValue();
  87     LH_HEADER_SIZE_BITS       = db.lookupIntConstant("LayoutHelper::_header_size_bits").intValue();
  88     LH_HEADER_SIZE_SHIFT      = db.lookupIntConstant("LayoutHelper::_header_size_shift").intValue();
  89     LH_FIXED_SIZE_BITS        = db.lookupIntConstant("LayoutHelper::_fixed_size_bits").intValue();
  90     LH_FIXED_SIZE_SHIFT       = db.lookupIntConstant("LayoutHelper::_fixed_size_shift").intValue();
  91   }
  92 
  93   Klass(OopHandle handle, ObjectHeap heap) {
  94     super(handle, heap);
  95   }
  96 
  97   // jvmdi support - see also class_status in VM code
  98   public int getClassStatus() {
  99     return 0; // overridden in derived classes
 100   }
 101 
 102   public boolean isKlass()             { return true; }
 103 
 104   // Fields
 105   private static OopField  javaMirror;
 106   private static OopField  superField;
 107   private static IntField layoutHelper;
 108   private static OopField  name;
 109   private static CIntField accessFlags;
 110   private static OopField  subklass;
 111   private static OopField  nextSibling;
 112   private static CIntField allocCount;
 113 
 114   // Accessors for declared fields
 115   public Instance getJavaMirror()       { return (Instance) javaMirror.getValue(this);   }
 116   public Klass    getSuper()            { return (Klass)    superField.getValue(this);   }
 117   public Klass    getJavaSuper()        { return null;  }
 118   public int      getLayoutHelper()     { return (int)           layoutHelper.getValue(this); }
 119   public Symbol   getName()             { return (Symbol)   name.getValue(this);         }
 120   public long     getAccessFlags()      { return            accessFlags.getValue(this);  }
 121   // Convenience routine
 122   public AccessFlags getAccessFlagsObj(){ return new AccessFlags(getAccessFlags());      }
 123   public Klass    getSubklassKlass()    { return (Klass)    subklass.getValue(this);     }
 124   public Klass    getNextSiblingKlass() { return (Klass)    nextSibling.getValue(this);  }
 125   public long     getAllocCount()       { return            allocCount.getValue(this);   }
 126 
 127   public boolean isVariableObject()     { return getLayoutHelper() < 0; }
 128   public boolean isFixedInstance()      { return getLayoutHelper() > 0; }
 129 
 130   public long getHeaderSizeInBytes() {
 131     if (Assert.ASSERTS_ENABLED) {
 132       Assert.that(isVariableObject(), "layout helper initialized for variable class");
 133     }
 134     return Bits.maskBits(getLayoutHelper() >> LH_HEADER_SIZE_SHIFT,
 135                          (Bits.rightNBits(LH_HEADER_SIZE_BITS)
 136                           - Bits.rightNBits(LH_SIZE_LOW_BITS)));
 137   }
 138 
 139   public int getElementSize() {
 140     if (Assert.ASSERTS_ENABLED) {
 141       Assert.that(isVariableObject(), "layout helper initialized for variable class");
 142     }
 143     int lh = getLayoutHelper();
 144     int scale = Bits.maskBits(lh >> LH_ELEMENT_SIZE_SHIFT,
 145                               Bits.rightNBits(LH_ELEMENT_SCALE_BITS));
 146     int sizem = Bits.maskBits(lh >> (LH_ELEMENT_SIZE_SHIFT + LH_ELEMENT_SCALE_BITS),
 147                               Bits.rightNBits(LH_ELEMENT_SIZEM_BITS));
 148     return (sizem + 1) << scale;
 149   }
 150 
 151   public int getElementType() {
 152     if (Assert.ASSERTS_ENABLED) {
 153       Assert.that(isVariableObject(), "layout helper initialized for variable class");
 154     }
 155     return Bits.maskBits(getLayoutHelper() >> LH_FLAGS_SHIFT,
 156                          Bits.rightNBits(LH_FLAGS_EBT_MASK));
 157   }
 158 
 159   // computed access flags - takes care of inner classes etc.
 160   // This is closer to actual source level than getAccessFlags() etc.
 161   public long computeModifierFlags() {
 162     return 0L; // Unless overridden, modifier_flags is 0.
 163   }
 164 
 165   // same as JVM_GetClassModifiers
 166   public final long getClassModifiers() {
 167     // unlike the VM counterpart we never have to deal with primitive type,
 168     // because we operator on Klass and not an instance of java.lang.Class.
 169     long flags = computeModifierFlags();
 170     if (isSuper()) {
 171        flags |= JVM_ACC_SUPER;
 172     }
 173     return flags;
 174   }
 175 
 176   // subclass check
 177   public boolean isSubclassOf(Klass k) {
 178     if (k != null) {