< prev index next >

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

Print this page

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 package sun.jvm.hotspot.runtime;
 26 
 27 import java.util.*;
 28 import sun.jvm.hotspot.debugger.*;
 29 import sun.jvm.hotspot.types.*;
 30 import sun.jvm.hotspot.utilities.Observable;
 31 import sun.jvm.hotspot.utilities.Observer;
 32 
 33 public class Thread extends VMObject {
 34   private static long tlabFieldOffset;
 35 



 36   private static CIntegerField suspendFlagsField;
 37 
 38   private static AddressField currentPendingMonitorField;
 39   private static AddressField currentWaitingMonitorField;
 40 
 41   private static JLongField allocatedBytesField;
 42 


 43   static {
 44     VM.registerVMInitializedObserver(new Observer() {
 45         public void update(Observable o, Object data) {
 46           initialize(VM.getVM().getTypeDataBase());
 47         }
 48       });
 49   }
 50 
 51   private static synchronized void initialize(TypeDataBase db) {
 52     Type typeThread = db.lookupType("Thread");
 53     Type typeJavaThread = db.lookupType("JavaThread");

 54 
 55     suspendFlagsField = typeJavaThread.getCIntegerField("_suspend_flags");
 56 
 57     tlabFieldOffset    = typeThread.getField("_tlab").getOffset();
 58     currentPendingMonitorField = typeJavaThread.getAddressField("_current_pending_monitor");
 59     currentWaitingMonitorField = typeJavaThread.getAddressField("_current_waiting_monitor");
 60     allocatedBytesField = typeThread.getJLongField("_allocated_bytes");




 61   }
 62 
 63   public Thread(Address addr) {
 64     super(addr);
 65   }
 66 
 67   public int suspendFlags() {
 68     return (int) suspendFlagsField.getValue(addr);
 69   }
 70 
 71   public ThreadLocalAllocBuffer tlab() {
 72     return new ThreadLocalAllocBuffer(addr.addOffsetTo(tlabFieldOffset));
 73   }
 74 
 75   public long allocatedBytes() {
 76     return allocatedBytesField.getValue(addr);
 77   }
 78 
 79   public boolean   isVMThread()                  { return false; }
 80   public boolean   isJavaThread()                { return false; }

 91     // FIXME: Empty for now; will later traverse JNI handles and
 92     // pending exception
 93   }
 94 
 95   public ObjectMonitor getCurrentPendingMonitor() {
 96     Address monitorAddr = currentPendingMonitorField.getValue(addr);
 97     if (monitorAddr == null) {
 98       return null;
 99     }
100     return new ObjectMonitor(monitorAddr);
101   }
102 
103   public ObjectMonitor getCurrentWaitingMonitor() {
104     Address monitorAddr = currentWaitingMonitorField.getValue(addr);
105     if (monitorAddr == null) {
106       return null;
107     }
108     return new ObjectMonitor(monitorAddr);
109   }
110 
111   public boolean isLockOwned(Address lock) {
112     if (isInStack(lock)) return true;








113     return false;
114   }
115 
116   public boolean isInStack(Address a) {
117     // In the Serviceability Agent we need access to the thread's
118     // stack pointer to be able to answer this question. Since it is
119     // only a debugging system at the moment we need access to the
120     // underlying thread, which is only present for Java threads; see
121     // JavaThread.java.
122     return false;
123   }
124 
125   /** Assistance for ObjectMonitor implementation */
126   Address threadObjectAddress() { return addr; }
127 }

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 package sun.jvm.hotspot.runtime;
 26 
 27 import java.util.*;
 28 import sun.jvm.hotspot.debugger.*;
 29 import sun.jvm.hotspot.types.*;
 30 import sun.jvm.hotspot.utilities.Observable;
 31 import sun.jvm.hotspot.utilities.Observer;
 32 
 33 public class Thread extends VMObject {
 34   private static long tlabFieldOffset;
 35 
 36   private static long lockStackCurrentOffset;
 37   private static long lockStackBaseOffset;
 38 
 39   private static CIntegerField suspendFlagsField;
 40 
 41   private static AddressField currentPendingMonitorField;
 42   private static AddressField currentWaitingMonitorField;
 43 
 44   private static JLongField allocatedBytesField;
 45 
 46   private static long oopPtrSize;
 47 
 48   static {
 49     VM.registerVMInitializedObserver(new Observer() {
 50         public void update(Observable o, Object data) {
 51           initialize(VM.getVM().getTypeDataBase());
 52         }
 53       });
 54   }
 55 
 56   private static synchronized void initialize(TypeDataBase db) {
 57     Type typeThread = db.lookupType("Thread");
 58     Type typeJavaThread = db.lookupType("JavaThread");
 59     Type typeLockStack = db.lookupType("LockStack");
 60 
 61     suspendFlagsField = typeJavaThread.getCIntegerField("_suspend_flags");
 62 
 63     tlabFieldOffset    = typeThread.getField("_tlab").getOffset();
 64     currentPendingMonitorField = typeJavaThread.getAddressField("_current_pending_monitor");
 65     currentWaitingMonitorField = typeJavaThread.getAddressField("_current_waiting_monitor");
 66     allocatedBytesField = typeThread.getJLongField("_allocated_bytes");
 67 
 68     lockStackCurrentOffset = typeThread.getField("_lock_stack").getOffset() + typeLockStack.getField("_current").getOffset();
 69     lockStackBaseOffset = typeThread.getField("_lock_stack").getOffset() + typeLockStack.getField("_base").getOffset();
 70     oopPtrSize = VM.getVM().getAddressSize();
 71   }
 72 
 73   public Thread(Address addr) {
 74     super(addr);
 75   }
 76 
 77   public int suspendFlags() {
 78     return (int) suspendFlagsField.getValue(addr);
 79   }
 80 
 81   public ThreadLocalAllocBuffer tlab() {
 82     return new ThreadLocalAllocBuffer(addr.addOffsetTo(tlabFieldOffset));
 83   }
 84 
 85   public long allocatedBytes() {
 86     return allocatedBytesField.getValue(addr);
 87   }
 88 
 89   public boolean   isVMThread()                  { return false; }
 90   public boolean   isJavaThread()                { return false; }

101     // FIXME: Empty for now; will later traverse JNI handles and
102     // pending exception
103   }
104 
105   public ObjectMonitor getCurrentPendingMonitor() {
106     Address monitorAddr = currentPendingMonitorField.getValue(addr);
107     if (monitorAddr == null) {
108       return null;
109     }
110     return new ObjectMonitor(monitorAddr);
111   }
112 
113   public ObjectMonitor getCurrentWaitingMonitor() {
114     Address monitorAddr = currentWaitingMonitorField.getValue(addr);
115     if (monitorAddr == null) {
116       return null;
117     }
118     return new ObjectMonitor(monitorAddr);
119   }
120 
121   public boolean isLockOwned(OopHandle obj) {
122     Address current = addr.getAddressAt(lockStackCurrentOffset);
123     Address base = addr.getAddressAt(lockStackBaseOffset);
124     while (base.lessThan(current)) {
125         Address oop = base.getAddressAt(0);
126         if (oop.equals(obj)) {
127             return true;
128         }
129         base = base.addOffsetTo(oopPtrSize);
130     }
131     return false;
132   }
133 
134   public boolean isInStack(Address a) {
135     // In the Serviceability Agent we need access to the thread's
136     // stack pointer to be able to answer this question. Since it is
137     // only a debugging system at the moment we need access to the
138     // underlying thread, which is only present for Java threads; see
139     // JavaThread.java.
140     return false;
141   }
142 
143   /** Assistance for ObjectMonitor implementation */
144   Address threadObjectAddress() { return addr; }
145 }
< prev index next >