57 // threadStatus field is new since 1.5 58 private static IntField threadStatusField; 59 // parkBlocker field is new since 1.6 60 private static OopField threadParkBlockerField; 61 62 // possible values of java_lang_Thread::ThreadStatus 63 private static int THREAD_STATUS_NEW; 64 /* 65 Other enum constants are not needed as of now. Uncomment these as and when needed. 66 67 private static int THREAD_STATUS_RUNNABLE; 68 private static int THREAD_STATUS_SLEEPING; 69 private static int THREAD_STATUS_IN_OBJECT_WAIT; 70 private static int THREAD_STATUS_IN_OBJECT_WAIT_TIMED; 71 private static int THREAD_STATUS_PARKED; 72 private static int THREAD_STATUS_PARKED_TIMED; 73 private static int THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER; 74 private static int THREAD_STATUS_TERMINATED; 75 */ 76 77 // java.lang.Class fields 78 private static OopField hcKlassField; 79 80 // java.util.concurrent.locks.AbstractOwnableSynchronizer fields 81 private static OopField absOwnSyncOwnerThreadField; 82 83 static { 84 VM.registerVMInitializedObserver(new Observer() { 85 public void update(Observable o, Object data) { 86 initialize(VM.getVM().getTypeDataBase()); 87 } 88 }); 89 } 90 91 private static synchronized void initialize(TypeDataBase db) { 92 // FIXME: don't need this observer; however, do need a VM resumed 93 // and suspended observer to refetch fields 94 } 95 96 public static String charArrayToString(TypeArray charArray) { 97 if (charArray == null) { 98 return null; 99 } 251 // enough info for a valid unknown status. 252 JavaThread thr = threadOopGetJavaThread(threadOop); 253 if (thr == null) { 254 // the thread hasn't run yet or is in the process of exiting 255 return THREAD_STATUS_NEW; 256 } else { 257 return JVMTI_THREAD_STATE_ALIVE; 258 } 259 } 260 } 261 262 /** returns value of java.lang.Thread.parkBlocker field */ 263 public static Oop threadOopGetParkBlocker(Oop threadOop) { 264 initThreadFields(); 265 if (threadParkBlockerField != null) { 266 return threadParkBlockerField.getValue(threadOop); 267 } 268 return null; 269 } 270 271 // initialize fields for java.lang.Class 272 private static void initClassFields() { 273 if (hcKlassField == null) { 274 // hc_klass is a HotSpot magic field and hence we can't 275 // find it from InstanceKlass for java.lang.Class. 276 TypeDataBase db = VM.getVM().getTypeDataBase(); 277 int hcKlassOffset = (int) db.lookupType("java_lang_Class").getCIntegerField("klass_offset").getValue(); 278 if (VM.getVM().isCompressedOopsEnabled()) { 279 hcKlassField = new NarrowOopField(new NamedFieldIdentifier("hc_klass"), hcKlassOffset, true); 280 } else { 281 hcKlassField = new OopField(new NamedFieldIdentifier("hc_klass"), hcKlassOffset, true); 282 } 283 } 284 } 285 286 /** get klassOop field at offset hc_klass_offset from a java.lang.Class object */ 287 public static Klass classOopToKlass(Oop aClass) { 288 initClassFields(); 289 return (Klass) hcKlassField.getValue(aClass); 290 } 291 292 // initialize fields for j.u.c.l AbstractOwnableSynchornizer class 293 private static void initAbsOwnSyncFields() { 294 if (absOwnSyncOwnerThreadField == null) { 295 SystemDictionary sysDict = VM.getVM().getSystemDictionary(); 296 InstanceKlass k = sysDict.getAbstractOwnableSynchronizerKlass(); 297 absOwnSyncOwnerThreadField = 298 (OopField) k.findField("exclusiveOwnerThread", 299 "Ljava/lang/Thread;"); 300 } 301 } 302 303 // return exclusiveOwnerThread field of AbstractOwnableSynchronizer class 304 public static Oop abstractOwnableSynchronizerGetOwnerThread(Oop oop) { 305 initAbsOwnSyncFields(); 306 if (absOwnSyncOwnerThreadField == null) { 307 return null; // pre-1.6 VM? 308 } else { 309 return absOwnSyncOwnerThreadField.getValue(oop); 310 } 311 } | 57 // threadStatus field is new since 1.5 58 private static IntField threadStatusField; 59 // parkBlocker field is new since 1.6 60 private static OopField threadParkBlockerField; 61 62 // possible values of java_lang_Thread::ThreadStatus 63 private static int THREAD_STATUS_NEW; 64 /* 65 Other enum constants are not needed as of now. Uncomment these as and when needed. 66 67 private static int THREAD_STATUS_RUNNABLE; 68 private static int THREAD_STATUS_SLEEPING; 69 private static int THREAD_STATUS_IN_OBJECT_WAIT; 70 private static int THREAD_STATUS_IN_OBJECT_WAIT_TIMED; 71 private static int THREAD_STATUS_PARKED; 72 private static int THREAD_STATUS_PARKED_TIMED; 73 private static int THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER; 74 private static int THREAD_STATUS_TERMINATED; 75 */ 76 77 // java.util.concurrent.locks.AbstractOwnableSynchronizer fields 78 private static OopField absOwnSyncOwnerThreadField; 79 80 static { 81 VM.registerVMInitializedObserver(new Observer() { 82 public void update(Observable o, Object data) { 83 initialize(VM.getVM().getTypeDataBase()); 84 } 85 }); 86 } 87 88 private static synchronized void initialize(TypeDataBase db) { 89 // FIXME: don't need this observer; however, do need a VM resumed 90 // and suspended observer to refetch fields 91 } 92 93 public static String charArrayToString(TypeArray charArray) { 94 if (charArray == null) { 95 return null; 96 } 248 // enough info for a valid unknown status. 249 JavaThread thr = threadOopGetJavaThread(threadOop); 250 if (thr == null) { 251 // the thread hasn't run yet or is in the process of exiting 252 return THREAD_STATUS_NEW; 253 } else { 254 return JVMTI_THREAD_STATE_ALIVE; 255 } 256 } 257 } 258 259 /** returns value of java.lang.Thread.parkBlocker field */ 260 public static Oop threadOopGetParkBlocker(Oop threadOop) { 261 initThreadFields(); 262 if (threadParkBlockerField != null) { 263 return threadParkBlockerField.getValue(threadOop); 264 } 265 return null; 266 } 267 268 // initialize fields for j.u.c.l AbstractOwnableSynchornizer class 269 private static void initAbsOwnSyncFields() { 270 if (absOwnSyncOwnerThreadField == null) { 271 SystemDictionary sysDict = VM.getVM().getSystemDictionary(); 272 InstanceKlass k = sysDict.getAbstractOwnableSynchronizerKlass(); 273 absOwnSyncOwnerThreadField = 274 (OopField) k.findField("exclusiveOwnerThread", 275 "Ljava/lang/Thread;"); 276 } 277 } 278 279 // return exclusiveOwnerThread field of AbstractOwnableSynchronizer class 280 public static Oop abstractOwnableSynchronizerGetOwnerThread(Oop oop) { 281 initAbsOwnSyncFields(); 282 if (absOwnSyncOwnerThreadField == null) { 283 return null; // pre-1.6 VM? 284 } else { 285 return absOwnSyncOwnerThreadField.getValue(oop); 286 } 287 } |