< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ObjectMonitor.java

Print this page

 28 
 29 import sun.jvm.hotspot.debugger.*;
 30 import sun.jvm.hotspot.oops.*;
 31 import sun.jvm.hotspot.types.*;
 32 import sun.jvm.hotspot.utilities.Observable;
 33 import sun.jvm.hotspot.utilities.Observer;
 34 
 35 public class ObjectMonitor extends VMObject {
 36   static {
 37     VM.registerVMInitializedObserver(new Observer() {
 38         public void update(Observable o, Object data) {
 39           initialize(VM.getVM().getTypeDataBase());
 40         }
 41       });
 42   }
 43 
 44   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
 45     heap = VM.getVM().getObjectHeap();
 46     Type type  = db.lookupType("ObjectMonitor");
 47 
 48     sun.jvm.hotspot.types.Field f = type.getField("_header");
 49     headerFieldOffset = f.getOffset();
 50     f = type.getField("_object");
 51     objectFieldOffset = f.getOffset();
 52     f = type.getField("_owner");
 53     ownerFieldOffset = f.getOffset();
 54     f = type.getField("_next_om");
 55     nextOMFieldOffset = f.getOffset();
 56     contentionsField  = new CIntField(type.getCIntegerField("_contentions"), 0);
 57     waitersField      = new CIntField(type.getCIntegerField("_waiters"), 0);
 58     recursionsField   = type.getCIntegerField("_recursions");
 59 
 60     ANONYMOUS_OWNER = db.lookupLongConstant("ObjectMonitor::ANONYMOUS_OWNER").longValue();
 61   }
 62 
 63   public ObjectMonitor(Address addr) {
 64     super(addr);
 65   }
 66 
 67   public Mark header() {
 68     return new Mark(addr.addOffsetTo(headerFieldOffset));
 69   }
 70 
 71   // FIXME
 72   //  void      set_header(markWord hdr);
 73 
 74   // FIXME: must implement and delegate to platform-dependent implementation
 75   //  public boolean isBusy();
 76   public boolean isEntered(sun.jvm.hotspot.runtime.Thread current) {
 77     Address o = owner();
 78     if (current.threadObjectAddress().equals(o) ||
 79         current.isLockOwned(o)) {
 80       return true;
 81     }
 82     return false;
 83   }
 84 
 85   public boolean isOwnedAnonymous() {
 86     return addr.getAddressAt(ownerFieldOffset).asLongValue() == ANONYMOUS_OWNER;
 87   }
 88 

 97   //  void      set_queue(void* owner);
 98 
 99   public long recursions() { return recursionsField.getValue(addr); }
100 
101   public OopHandle object() {
102     Address objAddr = addr.getAddressAt(objectFieldOffset);
103     if (objAddr == null) {
104       return null;
105     }
106     return objAddr.getOopHandleAt(0);
107   }
108 
109   public int contentions() {
110       return (int)contentionsField.getValue(this);
111   }
112 
113   // The following four either aren't expressed as typed fields in
114   // vmStructs.cpp because they aren't strongly typed in the VM, or
115   // would confuse the SA's type system.
116   private static ObjectHeap    heap;
117   private static long          headerFieldOffset;
118   private static long          objectFieldOffset;
119   private static long          ownerFieldOffset;
120   private static long          nextOMFieldOffset;
121   private static CIntField     contentionsField;
122   private static CIntField     waitersField;
123   private static CIntegerField recursionsField;
124   private static long          ANONYMOUS_OWNER;
125 
126   // FIXME: expose platform-dependent stuff
127 }

 28 
 29 import sun.jvm.hotspot.debugger.*;
 30 import sun.jvm.hotspot.oops.*;
 31 import sun.jvm.hotspot.types.*;
 32 import sun.jvm.hotspot.utilities.Observable;
 33 import sun.jvm.hotspot.utilities.Observer;
 34 
 35 public class ObjectMonitor extends VMObject {
 36   static {
 37     VM.registerVMInitializedObserver(new Observer() {
 38         public void update(Observable o, Object data) {
 39           initialize(VM.getVM().getTypeDataBase());
 40         }
 41       });
 42   }
 43 
 44   private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
 45     heap = VM.getVM().getObjectHeap();
 46     Type type  = db.lookupType("ObjectMonitor");
 47 
 48     sun.jvm.hotspot.types.Field f = type.getField("_metadata");
 49     metadataFieldOffset = f.getOffset();
 50     f = type.getField("_object");
 51     objectFieldOffset = f.getOffset();
 52     f = type.getField("_owner");
 53     ownerFieldOffset = f.getOffset();
 54     f = type.getField("_next_om");
 55     nextOMFieldOffset = f.getOffset();
 56     contentionsField  = new CIntField(type.getCIntegerField("_contentions"), 0);
 57     waitersField      = new CIntField(type.getCIntegerField("_waiters"), 0);
 58     recursionsField   = type.getCIntegerField("_recursions");
 59 
 60     ANONYMOUS_OWNER = db.lookupLongConstant("ObjectMonitor::ANONYMOUS_OWNER").longValue();
 61   }
 62 
 63   public ObjectMonitor(Address addr) {
 64     super(addr);
 65   }
 66 
 67   public Mark header() {
 68     return new Mark(addr.addOffsetTo(metadataFieldOffset));
 69   }
 70 
 71   // FIXME
 72   //  void      set_header(markWord hdr);
 73 
 74   // FIXME: must implement and delegate to platform-dependent implementation
 75   //  public boolean isBusy();
 76   public boolean isEntered(sun.jvm.hotspot.runtime.Thread current) {
 77     Address o = owner();
 78     if (current.threadObjectAddress().equals(o) ||
 79         current.isLockOwned(o)) {
 80       return true;
 81     }
 82     return false;
 83   }
 84 
 85   public boolean isOwnedAnonymous() {
 86     return addr.getAddressAt(ownerFieldOffset).asLongValue() == ANONYMOUS_OWNER;
 87   }
 88 

 97   //  void      set_queue(void* owner);
 98 
 99   public long recursions() { return recursionsField.getValue(addr); }
100 
101   public OopHandle object() {
102     Address objAddr = addr.getAddressAt(objectFieldOffset);
103     if (objAddr == null) {
104       return null;
105     }
106     return objAddr.getOopHandleAt(0);
107   }
108 
109   public int contentions() {
110       return (int)contentionsField.getValue(this);
111   }
112 
113   // The following four either aren't expressed as typed fields in
114   // vmStructs.cpp because they aren't strongly typed in the VM, or
115   // would confuse the SA's type system.
116   private static ObjectHeap    heap;
117   private static long          metadataFieldOffset;
118   private static long          objectFieldOffset;
119   private static long          ownerFieldOffset;
120   private static long          nextOMFieldOffset;
121   private static CIntField     contentionsField;
122   private static CIntField     waitersField;
123   private static CIntegerField recursionsField;
124   private static long          ANONYMOUS_OWNER;
125 
126   // FIXME: expose platform-dependent stuff
127 }
< prev index next >