hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java
changeset 8076 96d498ec7ae1
parent 5547 f4b087cbb361
child 8725 8c1e3dd5fe1b
equal deleted inserted replaced
8075:582dd25571b2 8076:96d498ec7ae1
    80     fields               = new OopField(type.getOopField("_fields"), Oop.getHeaderSize());
    80     fields               = new OopField(type.getOopField("_fields"), Oop.getHeaderSize());
    81     constants            = new OopField(type.getOopField("_constants"), Oop.getHeaderSize());
    81     constants            = new OopField(type.getOopField("_constants"), Oop.getHeaderSize());
    82     classLoader          = new OopField(type.getOopField("_class_loader"), Oop.getHeaderSize());
    82     classLoader          = new OopField(type.getOopField("_class_loader"), Oop.getHeaderSize());
    83     protectionDomain     = new OopField(type.getOopField("_protection_domain"), Oop.getHeaderSize());
    83     protectionDomain     = new OopField(type.getOopField("_protection_domain"), Oop.getHeaderSize());
    84     signers              = new OopField(type.getOopField("_signers"), Oop.getHeaderSize());
    84     signers              = new OopField(type.getOopField("_signers"), Oop.getHeaderSize());
    85     sourceFileName       = new OopField(type.getOopField("_source_file_name"), Oop.getHeaderSize());
    85     sourceFileName       = type.getAddressField("_source_file_name");
    86     sourceDebugExtension = new OopField(type.getOopField("_source_debug_extension"), Oop.getHeaderSize());
    86     sourceDebugExtension = type.getAddressField("_source_debug_extension");
    87     innerClasses         = new OopField(type.getOopField("_inner_classes"), Oop.getHeaderSize());
    87     innerClasses         = new OopField(type.getOopField("_inner_classes"), Oop.getHeaderSize());
    88     nonstaticFieldSize   = new CIntField(type.getCIntegerField("_nonstatic_field_size"), Oop.getHeaderSize());
    88     nonstaticFieldSize   = new CIntField(type.getCIntegerField("_nonstatic_field_size"), Oop.getHeaderSize());
    89     staticFieldSize      = new CIntField(type.getCIntegerField("_static_field_size"), Oop.getHeaderSize());
    89     staticFieldSize      = new CIntField(type.getCIntegerField("_static_field_size"), Oop.getHeaderSize());
    90     staticOopFieldSize   = new CIntField(type.getCIntegerField("_static_oop_field_size"), Oop.getHeaderSize());
    90     staticOopFieldSize   = new CIntField(type.getCIntegerField("_static_oop_field_size"), Oop.getHeaderSize());
    91     nonstaticOopMapSize  = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), Oop.getHeaderSize());
    91     nonstaticOopMapSize  = new CIntField(type.getCIntegerField("_nonstatic_oop_map_size"), Oop.getHeaderSize());
    92     isMarkedDependent    = new CIntField(type.getCIntegerField("_is_marked_dependent"), Oop.getHeaderSize());
    92     isMarkedDependent    = new CIntField(type.getCIntegerField("_is_marked_dependent"), Oop.getHeaderSize());
    93     initState            = new CIntField(type.getCIntegerField("_init_state"), Oop.getHeaderSize());
    93     initState            = new CIntField(type.getCIntegerField("_init_state"), Oop.getHeaderSize());
    94     vtableLen            = new CIntField(type.getCIntegerField("_vtable_len"), Oop.getHeaderSize());
    94     vtableLen            = new CIntField(type.getCIntegerField("_vtable_len"), Oop.getHeaderSize());
    95     itableLen            = new CIntField(type.getCIntegerField("_itable_len"), Oop.getHeaderSize());
    95     itableLen            = new CIntField(type.getCIntegerField("_itable_len"), Oop.getHeaderSize());
    96     breakpoints          = type.getAddressField("_breakpoints");
    96     breakpoints          = type.getAddressField("_breakpoints");
    97     genericSignature     = new OopField(type.getOopField("_generic_signature"), Oop.getHeaderSize());
    97     genericSignature     = type.getAddressField("_generic_signature");
    98     majorVersion         = new CIntField(type.getCIntegerField("_major_version"), Oop.getHeaderSize());
    98     majorVersion         = new CIntField(type.getCIntegerField("_major_version"), Oop.getHeaderSize());
    99     minorVersion         = new CIntField(type.getCIntegerField("_minor_version"), Oop.getHeaderSize());
    99     minorVersion         = new CIntField(type.getCIntegerField("_minor_version"), Oop.getHeaderSize());
   100     headerSize           = alignObjectOffset(Oop.getHeaderSize() + type.getSize());
   100     headerSize           = alignObjectOffset(Oop.getHeaderSize() + type.getSize());
   101 
   101 
   102     // read field offset constants
   102     // read field offset constants
   133   private static OopField  fields;
   133   private static OopField  fields;
   134   private static OopField  constants;
   134   private static OopField  constants;
   135   private static OopField  classLoader;
   135   private static OopField  classLoader;
   136   private static OopField  protectionDomain;
   136   private static OopField  protectionDomain;
   137   private static OopField  signers;
   137   private static OopField  signers;
   138   private static OopField  sourceFileName;
   138   private static AddressField  sourceFileName;
   139   private static OopField  sourceDebugExtension;
   139   private static AddressField  sourceDebugExtension;
   140   private static OopField  innerClasses;
   140   private static OopField  innerClasses;
   141   private static CIntField nonstaticFieldSize;
   141   private static CIntField nonstaticFieldSize;
   142   private static CIntField staticFieldSize;
   142   private static CIntField staticFieldSize;
   143   private static CIntField staticOopFieldSize;
   143   private static CIntField staticOopFieldSize;
   144   private static CIntField nonstaticOopMapSize;
   144   private static CIntField nonstaticOopMapSize;
   145   private static CIntField isMarkedDependent;
   145   private static CIntField isMarkedDependent;
   146   private static CIntField initState;
   146   private static CIntField initState;
   147   private static CIntField vtableLen;
   147   private static CIntField vtableLen;
   148   private static CIntField itableLen;
   148   private static CIntField itableLen;
   149   private static AddressField breakpoints;
   149   private static AddressField breakpoints;
   150   private static OopField  genericSignature;
   150   private static AddressField  genericSignature;
   151   private static CIntField majorVersion;
   151   private static CIntField majorVersion;
   152   private static CIntField minorVersion;
   152   private static CIntField minorVersion;
   153 
   153 
   154   // type safe enum for ClassState from instanceKlass.hpp
   154   // type safe enum for ClassState from instanceKlass.hpp
   155   public static class ClassState {
   155   public static class ClassState {
   255   public TypeArray getFields()              { return (TypeArray)    fields.getValue(this); }
   255   public TypeArray getFields()              { return (TypeArray)    fields.getValue(this); }
   256   public ConstantPool getConstants()        { return (ConstantPool) constants.getValue(this); }
   256   public ConstantPool getConstants()        { return (ConstantPool) constants.getValue(this); }
   257   public Oop       getClassLoader()         { return                classLoader.getValue(this); }
   257   public Oop       getClassLoader()         { return                classLoader.getValue(this); }
   258   public Oop       getProtectionDomain()    { return                protectionDomain.getValue(this); }
   258   public Oop       getProtectionDomain()    { return                protectionDomain.getValue(this); }
   259   public ObjArray  getSigners()             { return (ObjArray)     signers.getValue(this); }
   259   public ObjArray  getSigners()             { return (ObjArray)     signers.getValue(this); }
   260   public Symbol    getSourceFileName()      { return (Symbol)       sourceFileName.getValue(this); }
   260   public Symbol    getSourceFileName()      { return getSymbol(sourceFileName); }
   261   public Symbol    getSourceDebugExtension(){ return (Symbol)       sourceDebugExtension.getValue(this); }
   261   public Symbol    getSourceDebugExtension(){ return getSymbol(sourceDebugExtension); }
   262   public TypeArray getInnerClasses()        { return (TypeArray)    innerClasses.getValue(this); }
   262   public TypeArray getInnerClasses()        { return (TypeArray)    innerClasses.getValue(this); }
   263   public long      getNonstaticFieldSize()  { return                nonstaticFieldSize.getValue(this); }
   263   public long      getNonstaticFieldSize()  { return                nonstaticFieldSize.getValue(this); }
   264   public long      getStaticFieldSize()     { return                staticFieldSize.getValue(this); }
   264   public long      getStaticFieldSize()     { return                staticFieldSize.getValue(this); }
   265   public long      getStaticOopFieldSize()  { return                staticOopFieldSize.getValue(this); }
   265   public long      getStaticOopFieldSize()  { return                staticOopFieldSize.getValue(this); }
   266   public long      getNonstaticOopMapSize() { return                nonstaticOopMapSize.getValue(this); }
   266   public long      getNonstaticOopMapSize() { return                nonstaticOopMapSize.getValue(this); }
   267   public boolean   getIsMarkedDependent()   { return                isMarkedDependent.getValue(this) != 0; }
   267   public boolean   getIsMarkedDependent()   { return                isMarkedDependent.getValue(this) != 0; }
   268   public long      getVtableLen()           { return                vtableLen.getValue(this); }
   268   public long      getVtableLen()           { return                vtableLen.getValue(this); }
   269   public long      getItableLen()           { return                itableLen.getValue(this); }
   269   public long      getItableLen()           { return                itableLen.getValue(this); }
   270   public Symbol    getGenericSignature()    { return (Symbol)       genericSignature.getValue(this); }
   270   public Symbol    getGenericSignature()    { return getSymbol(genericSignature); }
   271   public long      majorVersion()           { return                majorVersion.getValue(this); }
   271   public long      majorVersion()           { return                majorVersion.getValue(this); }
   272   public long      minorVersion()           { return                minorVersion.getValue(this); }
   272   public long      minorVersion()           { return                minorVersion.getValue(this); }
   273 
   273 
   274   // "size helper" == instance size in words
   274   // "size helper" == instance size in words
   275   public long getSizeHelper() {
   275   public long getSizeHelper() {
   306           // 'ioff' can be zero.
   306           // 'ioff' can be zero.
   307           // refer to JVM spec. section 4.7.5.
   307           // refer to JVM spec. section 4.7.5.
   308           if (ioff != 0) {
   308           if (ioff != 0) {
   309              // only look at classes that are already loaded
   309              // only look at classes that are already loaded
   310              // since we are looking for the flags for our self.
   310              // since we are looking for the flags for our self.
   311              Oop classInfo = getConstants().getObjAt(ioff);
   311              ConstantPool.CPSlot classInfo = getConstants().getSlotAt(ioff);
   312              Symbol name = null;
   312              Symbol name = null;
   313              if (classInfo instanceof Klass) {
   313              if (classInfo.isOop()) {
   314                 name = ((Klass) classInfo).getName();
   314                name = ((Klass) classInfo.getOop()).getName();
   315              } else if (classInfo instanceof Symbol) {
   315              } else if (classInfo.isMetaData()) {
   316                 name = (Symbol) classInfo;
   316                name = classInfo.getSymbol();
   317              } else {
   317              } else {
   318                 throw new RuntimeException("should not reach here");
   318                 throw new RuntimeException("should not reach here");
   319              }
   319              }
   320 
   320 
   321              if (name.equals(getName())) {
   321              if (name.equals(getName())) {
   356          int ioff = innerClassList.getShortAt(i +
   356          int ioff = innerClassList.getShortAt(i +
   357                         InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
   357                         InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
   358          // 'ioff' can be zero.
   358          // 'ioff' can be zero.
   359          // refer to JVM spec. section 4.7.5.
   359          // refer to JVM spec. section 4.7.5.
   360          if (ioff != 0) {
   360          if (ioff != 0) {
   361             Oop iclassInfo = getConstants().getObjAt(ioff);
   361             ConstantPool.CPSlot iclassInfo = getConstants().getSlotAt(ioff);
   362             Symbol innerName = null;
   362             Symbol innerName = null;
   363             if (iclassInfo instanceof Klass) {
   363             if (iclassInfo.isOop()) {
   364                innerName = ((Klass) iclassInfo).getName();
   364               innerName = ((Klass) iclassInfo.getOop()).getName();
   365             } else if (iclassInfo instanceof Symbol) {
   365             } else if (iclassInfo.isMetaData()) {
   366                innerName = (Symbol) iclassInfo;
   366               innerName = iclassInfo.getSymbol();
   367             } else {
   367             } else {
   368                throw new RuntimeException("should not reach here");
   368                throw new RuntimeException("should not reach here");
   369             }
   369             }
   370 
   370 
   371             Symbol myname = getName();
   371             Symbol myname = getName();
   385                      // exclude anonymous classes.
   385                      // exclude anonymous classes.
   386                      return (innerNameIndex != 0);
   386                      return (innerNameIndex != 0);
   387                   }
   387                   }
   388                }
   388                }
   389             } else {
   389             } else {
   390                Oop oclassInfo = getConstants().getObjAt(ooff);
   390                ConstantPool.CPSlot oclassInfo = getConstants().getSlotAt(ooff);
   391                Symbol outerName = null;
   391                Symbol outerName = null;
   392                if (oclassInfo instanceof Klass) {
   392                if (oclassInfo.isOop()) {
   393                   outerName = ((Klass) oclassInfo).getName();
   393                  outerName = ((Klass) oclassInfo.getOop()).getName();
   394                } else if (oclassInfo instanceof Symbol) {
   394                } else if (oclassInfo.isMetaData()) {
   395                   outerName = (Symbol) oclassInfo;
   395                  outerName = oclassInfo.getSymbol();
   396                } else {
   396                } else {
   397                   throw new RuntimeException("should not reach here");
   397                   throw new RuntimeException("should not reach here");
   398                }
   398                }
   399 
   399 
   400                // include only if current class is outer class.
   400                // include only if current class is outer class.
   448       visitor.doOop(fields, true);
   448       visitor.doOop(fields, true);
   449       visitor.doOop(constants, true);
   449       visitor.doOop(constants, true);
   450       visitor.doOop(classLoader, true);
   450       visitor.doOop(classLoader, true);
   451       visitor.doOop(protectionDomain, true);
   451       visitor.doOop(protectionDomain, true);
   452       visitor.doOop(signers, true);
   452       visitor.doOop(signers, true);
   453       visitor.doOop(sourceFileName, true);
       
   454       visitor.doOop(innerClasses, true);
   453       visitor.doOop(innerClasses, true);
   455       visitor.doCInt(nonstaticFieldSize, true);
   454       visitor.doCInt(nonstaticFieldSize, true);
   456       visitor.doCInt(staticFieldSize, true);
   455       visitor.doCInt(staticFieldSize, true);
   457       visitor.doCInt(staticOopFieldSize, true);
   456       visitor.doCInt(staticOopFieldSize, true);
   458       visitor.doCInt(nonstaticOopMapSize, true);
   457       visitor.doCInt(nonstaticOopMapSize, true);
   465     TypeArray fields = getFields();
   464     TypeArray fields = getFields();
   466     int length = (int) fields.getLength();
   465     int length = (int) fields.getLength();
   467     for (int index = 0; index < length; index += NEXT_OFFSET) {
   466     for (int index = 0; index < length; index += NEXT_OFFSET) {
   468       short accessFlags    = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
   467       short accessFlags    = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
   469       short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   468       short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   470       FieldType   type   = new FieldType((Symbol) getConstants().getObjAt(signatureIndex));
   469       FieldType   type   = new FieldType(getConstants().getSymbolAt(signatureIndex));
   471       AccessFlags access = new AccessFlags(accessFlags);
   470       AccessFlags access = new AccessFlags(accessFlags);
   472       if (access.isStatic()) {
   471       if (access.isStatic()) {
   473         visitField(visitor, type, index);
   472         visitField(visitor, type, index);
   474       }
   473       }
   475     }
   474     }
   488     int length = (int) fields.getLength();
   487     int length = (int) fields.getLength();
   489     for (int index = 0; index < length; index += NEXT_OFFSET) {
   488     for (int index = 0; index < length; index += NEXT_OFFSET) {
   490       short accessFlags    = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
   489       short accessFlags    = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
   491       short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   490       short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   492 
   491 
   493       FieldType   type   = new FieldType((Symbol) getConstants().getObjAt(signatureIndex));
   492       FieldType   type   = new FieldType(getConstants().getSymbolAt(signatureIndex));
   494       AccessFlags access = new AccessFlags(accessFlags);
   493       AccessFlags access = new AccessFlags(accessFlags);
   495       if (!access.isStatic()) {
   494       if (!access.isStatic()) {
   496         visitField(visitor, type, index);
   495         visitField(visitor, type, index);
   497       }
   496       }
   498     }
   497     }
   785 
   784 
   786   // Creates new field from index in fields TypeArray
   785   // Creates new field from index in fields TypeArray
   787   private Field newField(int index) {
   786   private Field newField(int index) {
   788     TypeArray fields = getFields();
   787     TypeArray fields = getFields();
   789     short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   788     short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   790     FieldType type = new FieldType((Symbol) getConstants().getObjAt(signatureIndex));
   789     FieldType type = new FieldType(getConstants().getSymbolAt(signatureIndex));
   791     if (type.isOop()) {
   790     if (type.isOop()) {
   792      if (VM.getVM().isCompressedOopsEnabled()) {
   791      if (VM.getVM().isCompressedOopsEnabled()) {
   793         return new NarrowOopField(this, index);
   792         return new NarrowOopField(this, index);
   794      } else {
   793      } else {
   795         return new OopField(this, index);
   794         return new OopField(this, index);