< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/OopUtilities.java

Print this page

208     }
209     return result;
210   }
211 
212   public static Oop[] threadGroupOopGetGroups(Oop threadGroupOop) {
213     initThreadGroupFields();
214     int ngroups = threadGroupNGroupsField.getValue(threadGroupOop);
215     Oop[] result = new Oop[ngroups];
216     ObjArray groups = (ObjArray) threadGroupGroupsField.getValue(threadGroupOop);
217     for (int i = 0; i < ngroups; i++) {
218       result[i] = groups.getObjAt(i);
219     }
220     return result;
221   }
222 
223   private static void initThreadFields() {
224     if (threadNameField == null) {
225       SystemDictionary sysDict = VM.getVM().getSystemDictionary();
226       InstanceKlass k = sysDict.getThreadKlass();
227       threadNameField  = (OopField) k.findField("name", "Ljava/lang/String;");
228       threadGroupField = (OopField) k.findField("group", "Ljava/lang/ThreadGroup;");
229       threadEETopField = (LongField) k.findField("eetop", "J");
230       threadTIDField = (LongField) k.findField("tid", "J");
231       threadStatusField = (IntField) k.findField("threadStatus", "I");
232       threadParkBlockerField = (OopField) k.findField("parkBlocker",
233                                      "Ljava/lang/Object;");
234       threadPriorityField = (IntField) k.findField("priority", "I");
235       threadDaemonField = (BooleanField) k.findField("daemon", "Z");
236       TypeDataBase db = VM.getVM().getTypeDataBase();
237       THREAD_STATUS_NEW = db.lookupIntConstant("JavaThreadStatus::NEW").intValue();
238 
239       THREAD_STATUS_RUNNABLE = db.lookupIntConstant("JavaThreadStatus::RUNNABLE").intValue();
240       THREAD_STATUS_SLEEPING = db.lookupIntConstant("JavaThreadStatus::SLEEPING").intValue();
241       THREAD_STATUS_IN_OBJECT_WAIT = db.lookupIntConstant("JavaThreadStatus::IN_OBJECT_WAIT").intValue();
242       THREAD_STATUS_IN_OBJECT_WAIT_TIMED = db.lookupIntConstant("JavaThreadStatus::IN_OBJECT_WAIT_TIMED").intValue();
243       THREAD_STATUS_PARKED = db.lookupIntConstant("JavaThreadStatus::PARKED").intValue();
244       THREAD_STATUS_PARKED_TIMED = db.lookupIntConstant("JavaThreadStatus::PARKED_TIMED").intValue();
245       THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER = db.lookupIntConstant("JavaThreadStatus::BLOCKED_ON_MONITOR_ENTER").intValue();
246       THREAD_STATUS_TERMINATED = db.lookupIntConstant("JavaThreadStatus::TERMINATED").intValue();
247 
248       if (Assert.ASSERTS_ENABLED) {
249         // it is okay to miss threadStatusField, because this was
250         // introduced only in 1.5 JDK.
251         Assert.that(threadNameField   != null &&
252                     threadGroupField  != null &&
253                     threadEETopField  != null, "must find all java.lang.Thread fields");
254       }
255     }
256   }
257 
258   public static Oop threadOopGetThreadGroup(Oop threadOop) {
259     initThreadFields();
260     return threadGroupField.getValue(threadOop);
261   }
262 
263   public static String threadOopGetName(Oop threadOop) {
264     initThreadFields();
265     return stringOopToString(threadNameField.getValue(threadOop));
266   }
267 
268   /** May return null if, e.g., thread was not started */
269   public static JavaThread threadOopGetJavaThread(Oop threadOop) {
270     initThreadFields();
271     Address addr = threadOop.getHandle().getAddressAt(threadEETopField.getOffset());
272     if (addr == null) {
273       return null;
274     }
275     return VM.getVM().getThreads().createJavaThreadWrapper(addr);
276   }
277 
278   public static long threadOopGetTID(Oop threadOop) {
279     initThreadFields();
280     if (threadTIDField != null) {
281       return threadTIDField.getValue(threadOop);
282     } else {

208     }
209     return result;
210   }
211 
212   public static Oop[] threadGroupOopGetGroups(Oop threadGroupOop) {
213     initThreadGroupFields();
214     int ngroups = threadGroupNGroupsField.getValue(threadGroupOop);
215     Oop[] result = new Oop[ngroups];
216     ObjArray groups = (ObjArray) threadGroupGroupsField.getValue(threadGroupOop);
217     for (int i = 0; i < ngroups; i++) {
218       result[i] = groups.getObjAt(i);
219     }
220     return result;
221   }
222 
223   private static void initThreadFields() {
224     if (threadNameField == null) {
225       SystemDictionary sysDict = VM.getVM().getSystemDictionary();
226       InstanceKlass k = sysDict.getThreadKlass();
227       threadNameField  = (OopField) k.findField("name", "Ljava/lang/String;");

228       threadEETopField = (LongField) k.findField("eetop", "J");
229       threadTIDField = (LongField) k.findField("tid", "J");
230       threadStatusField = (IntField) k.findField("threadStatus", "I");
231       threadParkBlockerField = (OopField) k.findField("parkBlocker",
232                                      "Ljava/lang/Object;");
233       threadPriorityField = (IntField) k.findField("priority", "I");
234       threadDaemonField = (BooleanField) k.findField("daemon", "Z");
235       TypeDataBase db = VM.getVM().getTypeDataBase();
236       THREAD_STATUS_NEW = db.lookupIntConstant("JavaThreadStatus::NEW").intValue();
237 
238       THREAD_STATUS_RUNNABLE = db.lookupIntConstant("JavaThreadStatus::RUNNABLE").intValue();
239       THREAD_STATUS_SLEEPING = db.lookupIntConstant("JavaThreadStatus::SLEEPING").intValue();
240       THREAD_STATUS_IN_OBJECT_WAIT = db.lookupIntConstant("JavaThreadStatus::IN_OBJECT_WAIT").intValue();
241       THREAD_STATUS_IN_OBJECT_WAIT_TIMED = db.lookupIntConstant("JavaThreadStatus::IN_OBJECT_WAIT_TIMED").intValue();
242       THREAD_STATUS_PARKED = db.lookupIntConstant("JavaThreadStatus::PARKED").intValue();
243       THREAD_STATUS_PARKED_TIMED = db.lookupIntConstant("JavaThreadStatus::PARKED_TIMED").intValue();
244       THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER = db.lookupIntConstant("JavaThreadStatus::BLOCKED_ON_MONITOR_ENTER").intValue();
245       THREAD_STATUS_TERMINATED = db.lookupIntConstant("JavaThreadStatus::TERMINATED").intValue();
246 
247       if (Assert.ASSERTS_ENABLED) {
248         // it is okay to miss threadStatusField, because this was
249         // introduced only in 1.5 JDK.
250         Assert.that(threadNameField   != null &&

251                     threadEETopField  != null, "must find all java.lang.Thread fields");
252       }
253     }
254   }
255 





256   public static String threadOopGetName(Oop threadOop) {
257     initThreadFields();
258     return stringOopToString(threadNameField.getValue(threadOop));
259   }
260 
261   /** May return null if, e.g., thread was not started */
262   public static JavaThread threadOopGetJavaThread(Oop threadOop) {
263     initThreadFields();
264     Address addr = threadOop.getHandle().getAddressAt(threadEETopField.getOffset());
265     if (addr == null) {
266       return null;
267     }
268     return VM.getVM().getThreads().createJavaThreadWrapper(addr);
269   }
270 
271   public static long threadOopGetTID(Oop threadOop) {
272     initThreadFields();
273     if (threadTIDField != null) {
274       return threadTIDField.getValue(threadOop);
275     } else {
< prev index next >