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

Print this page
rev 611 : Merge


  21  * have any 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 
  31 public class Thread extends VMObject {
  32   private static long tlabFieldOffset;
  33 
  34   private static CIntegerField suspendFlagsField;
  35   // Thread::SuspendFlags enum constants
  36   private static int EXTERNAL_SUSPEND;
  37   private static int EXT_SUSPENDED;
  38   private static int HAS_ASYNC_EXCEPTION;
  39 
  40   private static AddressField activeHandlesField;
  41   private static AddressField highestLockField;
  42   private static AddressField currentPendingMonitorField;
  43   private static AddressField currentWaitingMonitorField;
  44 
  45   static {
  46     VM.registerVMInitializedObserver(new Observer() {
  47         public void update(Observable o, Object data) {
  48           initialize(VM.getVM().getTypeDataBase());
  49         }
  50       });
  51   }
  52 
  53   private static synchronized void initialize(TypeDataBase db) {
  54     Type type = db.lookupType("Thread");
  55 
  56     suspendFlagsField = type.getCIntegerField("_suspend_flags");
  57     EXTERNAL_SUSPEND = db.lookupIntConstant("Thread::_external_suspend").intValue();
  58     EXT_SUSPENDED = db.lookupIntConstant("Thread::_ext_suspended").intValue();
  59     HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue();
  60 
  61     tlabFieldOffset    = type.getField("_tlab").getOffset();
  62     activeHandlesField = type.getAddressField("_active_handles");
  63     highestLockField   = type.getAddressField("_highest_lock");
  64     currentPendingMonitorField = type.getAddressField("_current_pending_monitor");
  65     currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor");
  66   }
  67 
  68   public Thread(Address addr) {
  69     super(addr);
  70   }
  71 
  72   public int suspendFlags() {
  73     return (int) suspendFlagsField.getValue(addr);
  74   }
  75 
  76   public boolean isExternalSuspend() {
  77     return (suspendFlags() & EXTERNAL_SUSPEND) != 0;
  78   }
  79 
  80   public boolean isExtSuspended() {
  81     return (suspendFlags() & EXT_SUSPENDED) != 0;
  82   }
  83 


 104       return null;
 105     }
 106     return new JNIHandleBlock(a);
 107   }
 108 
 109   public boolean   isVMThread()                { return false; }
 110   public boolean   isJavaThread()              { return false; }
 111   public boolean   isCompilerThread()          { return false; }
 112   public boolean   isHiddenFromExternalView()  { return false; } 
 113   public boolean   isJvmtiAgentThread()        { return false; }
 114   public boolean   isWatcherThread()           { return false; }
 115   public boolean   isConcurrentMarkSweepThread() { return false; }
 116   public boolean   isLowMemoryDetectorThread() { return false; }
 117 
 118   /** Memory operations */
 119   public void oopsDo(AddressVisitor oopVisitor) {
 120     // FIXME: Empty for now; will later traverse JNI handles and
 121     // pending exception
 122   }
 123 
 124   public Address highestLock() {
 125     return highestLockField.getValue(addr);
 126   }
 127 
 128   public ObjectMonitor getCurrentPendingMonitor() {
 129     Address monitorAddr = currentPendingMonitorField.getValue(addr);
 130     if (monitorAddr == null) {
 131       return null;
 132     }
 133     return new ObjectMonitor(monitorAddr);
 134   }
 135 
 136   public ObjectMonitor getCurrentWaitingMonitor() {
 137     Address monitorAddr = currentWaitingMonitorField.getValue(addr);
 138     if (monitorAddr == null) {
 139       return null;
 140     }
 141     return new ObjectMonitor(monitorAddr);
 142   }
 143 
 144   public boolean isLockOwned(Address lock) {
 145     if (isInStack(lock)) return true;
 146     return false;
 147   }


  21  * have any 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 
  31 public class Thread extends VMObject {
  32   private static long tlabFieldOffset;
  33 
  34   private static CIntegerField suspendFlagsField;
  35   // Thread::SuspendFlags enum constants
  36   private static int EXTERNAL_SUSPEND;
  37   private static int EXT_SUSPENDED;
  38   private static int HAS_ASYNC_EXCEPTION;
  39 
  40   private static AddressField activeHandlesField;

  41   private static AddressField currentPendingMonitorField;
  42   private static AddressField currentWaitingMonitorField;
  43 
  44   static {
  45     VM.registerVMInitializedObserver(new Observer() {
  46         public void update(Observable o, Object data) {
  47           initialize(VM.getVM().getTypeDataBase());
  48         }
  49       });
  50   }
  51 
  52   private static synchronized void initialize(TypeDataBase db) {
  53     Type type = db.lookupType("Thread");
  54 
  55     suspendFlagsField = type.getCIntegerField("_suspend_flags");
  56     EXTERNAL_SUSPEND = db.lookupIntConstant("Thread::_external_suspend").intValue();
  57     EXT_SUSPENDED = db.lookupIntConstant("Thread::_ext_suspended").intValue();
  58     HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue();
  59 
  60     tlabFieldOffset    = type.getField("_tlab").getOffset();
  61     activeHandlesField = type.getAddressField("_active_handles");

  62     currentPendingMonitorField = type.getAddressField("_current_pending_monitor");
  63     currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor");
  64   }
  65 
  66   public Thread(Address addr) {
  67     super(addr);
  68   }
  69 
  70   public int suspendFlags() {
  71     return (int) suspendFlagsField.getValue(addr);
  72   }
  73 
  74   public boolean isExternalSuspend() {
  75     return (suspendFlags() & EXTERNAL_SUSPEND) != 0;
  76   }
  77 
  78   public boolean isExtSuspended() {
  79     return (suspendFlags() & EXT_SUSPENDED) != 0;
  80   }
  81 


 102       return null;
 103     }
 104     return new JNIHandleBlock(a);
 105   }
 106 
 107   public boolean   isVMThread()                { return false; }
 108   public boolean   isJavaThread()              { return false; }
 109   public boolean   isCompilerThread()          { return false; }
 110   public boolean   isHiddenFromExternalView()  { return false; } 
 111   public boolean   isJvmtiAgentThread()        { return false; }
 112   public boolean   isWatcherThread()           { return false; }
 113   public boolean   isConcurrentMarkSweepThread() { return false; }
 114   public boolean   isLowMemoryDetectorThread() { return false; }
 115 
 116   /** Memory operations */
 117   public void oopsDo(AddressVisitor oopVisitor) {
 118     // FIXME: Empty for now; will later traverse JNI handles and
 119     // pending exception
 120   }
 121 




 122   public ObjectMonitor getCurrentPendingMonitor() {
 123     Address monitorAddr = currentPendingMonitorField.getValue(addr);
 124     if (monitorAddr == null) {
 125       return null;
 126     }
 127     return new ObjectMonitor(monitorAddr);
 128   }
 129 
 130   public ObjectMonitor getCurrentWaitingMonitor() {
 131     Address monitorAddr = currentWaitingMonitorField.getValue(addr);
 132     if (monitorAddr == null) {
 133       return null;
 134     }
 135     return new ObjectMonitor(monitorAddr);
 136   }
 137 
 138   public boolean isLockOwned(Address lock) {
 139     if (isInStack(lock)) return true;
 140     return false;
 141   }