package sun.jvm.hotspot.runtime;
import java.util.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.Observable;
import sun.jvm.hotspot.utilities.Observer;
public class ObjectMonitor extends VMObject {
static {
VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) {
initialize(VM.getVM().getTypeDataBase());
}
});
}
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
heap = VM.getVM().getObjectHeap();
Type type = db.lookupType("ObjectMonitor");
sun.jvm.hotspot.types.Field f = type.getField("_header");
headerFieldOffset = f.getOffset();
f = type.getField("_object");
objectFieldOffset = f.getOffset();
f = type.getField("_owner");
ownerFieldOffset = f.getOffset();
f = type.getField("_next_om");
nextOMFieldOffset = f.getOffset();
contentionsField = type.getJIntField("_contentions");
waitersField = type.getJIntField("_waiters");
recursionsField = type.getCIntegerField("_recursions");
}
public ObjectMonitor(Address addr) {
super(addr);
}
public Mark () {
return new Mark(addr.addOffsetTo(headerFieldOffset));
}
public boolean isEntered(sun.jvm.hotspot.runtime.Thread current) {
Address o = owner();
if (current.threadObjectAddress().equals(o) ||
current.isLockOwned(o)) {
return true;
}
return false;
}
public Address owner() { return addr.getAddressAt(ownerFieldOffset); }
public int waiters() { return waitersField.getValue(addr); }
public Address nextOM() { return addr.getAddressAt(nextOMFieldOffset); }
public long recursions() { return recursionsField.getValue(addr); }
public OopHandle object() {
Address objAddr = addr.getAddressAt(objectFieldOffset);
if (objAddr == null) {
return null;
}
return objAddr.getOopHandleAt(0);
}
public int contentions() {
return contentionsField.getValue(addr);
}
private static ObjectHeap heap;
private static long ;
private static long objectFieldOffset;
private static long ownerFieldOffset;
private static long nextOMFieldOffset;
private static JIntField contentionsField;
private static JIntField waitersField;
private static CIntegerField recursionsField;
}