< prev index next >

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

Print this page
*** 31,17 ***
--- 31,22 ---
  import sun.jvm.hotspot.utilities.Observer;
  
  public class Thread extends VMObject {
    private static long tlabFieldOffset;
  
+   private static long lockStackCurrentOffset;
+   private static long lockStackBaseOffset;
+ 
    private static CIntegerField suspendFlagsField;
  
    private static AddressField currentPendingMonitorField;
    private static AddressField currentWaitingMonitorField;
  
    private static JLongField allocatedBytesField;
  
+   private static long oopPtrSize;
+ 
    static {
      VM.registerVMInitializedObserver(new Observer() {
          public void update(Observable o, Object data) {
            initialize(VM.getVM().getTypeDataBase());
          }

*** 49,17 ***
--- 54,22 ---
    }
  
    private static synchronized void initialize(TypeDataBase db) {
      Type typeThread = db.lookupType("Thread");
      Type typeJavaThread = db.lookupType("JavaThread");
+     Type typeLockStack = db.lookupType("LockStack");
  
      suspendFlagsField = typeJavaThread.getCIntegerField("_suspend_flags");
  
      tlabFieldOffset    = typeThread.getField("_tlab").getOffset();
      currentPendingMonitorField = typeJavaThread.getAddressField("_current_pending_monitor");
      currentWaitingMonitorField = typeJavaThread.getAddressField("_current_waiting_monitor");
      allocatedBytesField = typeThread.getJLongField("_allocated_bytes");
+ 
+     lockStackCurrentOffset = typeThread.getField("_lock_stack").getOffset() + typeLockStack.getField("_current").getOffset();
+     lockStackBaseOffset = typeThread.getField("_lock_stack").getOffset() + typeLockStack.getField("_base").getOffset();
+     oopPtrSize = VM.getVM().getAddressSize();
    }
  
    public Thread(Address addr) {
      super(addr);
    }

*** 106,12 ***
        return null;
      }
      return new ObjectMonitor(monitorAddr);
    }
  
!   public boolean isLockOwned(Address lock) {
!     if (isInStack(lock)) return true;
      return false;
    }
  
    public boolean isInStack(Address a) {
      // In the Serviceability Agent we need access to the thread's
--- 116,20 ---
        return null;
      }
      return new ObjectMonitor(monitorAddr);
    }
  
!   public boolean isLockOwned(OopHandle obj) {
!     Address current = addr.getAddressAt(lockStackCurrentOffset);
+     Address base = addr.getAddressAt(lockStackBaseOffset);
+     while (base.lessThan(current)) {
+         Address oop = base.getAddressAt(0);
+         if (oop.equals(obj)) {
+             return true;
+         }
+         base = base.addOffsetTo(oopPtrSize);
+     }
      return false;
    }
  
    public boolean isInStack(Address a) {
      // In the Serviceability Agent we need access to the thread's
< prev index next >