hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPoolCache.java
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 670 ddf3e9583f2f
equal deleted inserted replaced
357:f4edb0d9f109 360:21d113ecbf6a
    29 import sun.jvm.hotspot.debugger.*;
    29 import sun.jvm.hotspot.debugger.*;
    30 import sun.jvm.hotspot.runtime.*;
    30 import sun.jvm.hotspot.runtime.*;
    31 import sun.jvm.hotspot.types.*;
    31 import sun.jvm.hotspot.types.*;
    32 import sun.jvm.hotspot.utilities.*;
    32 import sun.jvm.hotspot.utilities.*;
    33 
    33 
    34 // A ConstantPool is an array containing class constants
    34 //  ConstantPoolCache : A constant pool cache (constantPoolCacheOopDesc).
    35 // as described in the class file
    35 //  See cpCacheOop.hpp for details about this class.
    36 
    36 //
    37 public class ConstantPoolCache extends Array {
    37 public class ConstantPoolCache extends Oop {
    38   static {
    38   static {
    39     VM.registerVMInitializedObserver(new Observer() {
    39     VM.registerVMInitializedObserver(new Observer() {
    40         public void update(Observable o, Object data) {
    40         public void update(Observable o, Object data) {
    41           initialize(VM.getVM().getTypeDataBase());
    41           initialize(VM.getVM().getTypeDataBase());
    42         }
    42         }
    45 
    45 
    46   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
    46   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
    47     Type type      = db.lookupType("constantPoolCacheOopDesc");
    47     Type type      = db.lookupType("constantPoolCacheOopDesc");
    48     constants      = new OopField(type.getOopField("_constant_pool"), 0);
    48     constants      = new OopField(type.getOopField("_constant_pool"), 0);
    49     baseOffset     = type.getSize();
    49     baseOffset     = type.getSize();
    50 
       
    51     Type elType    = db.lookupType("ConstantPoolCacheEntry");
    50     Type elType    = db.lookupType("ConstantPoolCacheEntry");
    52     elementSize    = elType.getSize();
    51     elementSize    = elType.getSize();
       
    52     length         = new CIntField(type.getCIntegerField("_length"), 0);
    53   }
    53   }
    54 
    54 
    55   ConstantPoolCache(OopHandle handle, ObjectHeap heap) {
    55   ConstantPoolCache(OopHandle handle, ObjectHeap heap) {
    56     super(handle, heap);
    56     super(handle, heap);
    57   }
    57   }
    60 
    60 
    61   private static OopField constants;
    61   private static OopField constants;
    62 
    62 
    63   private static long baseOffset;
    63   private static long baseOffset;
    64   private static long elementSize;
    64   private static long elementSize;
       
    65   private static CIntField length;
       
    66 
    65 
    67 
    66   public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
    68   public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
    67 
    69 
    68   public long getObjectSize() {
    70   public long getObjectSize() {
    69     return alignObjectSize(baseOffset + getLength() * elementSize);
    71     return alignObjectSize(baseOffset + getLength() * elementSize);
    85 
    87 
    86   public void printValueOn(PrintStream tty) {
    88   public void printValueOn(PrintStream tty) {
    87     tty.print("ConstantPoolCache for " + getConstants().getPoolHolder().getName().asString());
    89     tty.print("ConstantPoolCache for " + getConstants().getPoolHolder().getName().asString());
    88   }
    90   }
    89 
    91 
       
    92   public int getLength() {
       
    93     return (int) length.getValue(this);
       
    94   }
       
    95 
    90   public void iterateFields(OopVisitor visitor, boolean doVMFields) {
    96   public void iterateFields(OopVisitor visitor, boolean doVMFields) {
    91     super.iterateFields(visitor, doVMFields);
    97     super.iterateFields(visitor, doVMFields);
    92     if (doVMFields) {
    98     if (doVMFields) {
    93       visitor.doOop(constants, true);
    99       visitor.doOop(constants, true);
    94       for (int i = 0; i < getLength(); i++) {
   100       for (int i = 0; i < getLength(); i++) {