27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.oops.*;
31 import sun.jvm.hotspot.types.*;
32 import sun.jvm.hotspot.utilities.*;
33 import sun.jvm.hotspot.utilities.Observable;
34 import sun.jvm.hotspot.utilities.Observer;
35
36 /** This is an abstract class because there are certain OS- and
37 CPU-specific operations (like the setting and getting of the last
38 Java frame pointer) which need to be factored out. These
39 operations are implemented by, for example,
40 SolarisSPARCJavaThread, and the concrete subclasses are
41 instantiated by the JavaThreadFactory in the Threads class. */
42
43 public class JavaThread extends Thread {
44 private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.runtime.JavaThread.DEBUG") != null;
45
46 private static long threadObjFieldOffset;
47 private static AddressField anchorField;
48 private static AddressField lastJavaSPField;
49 private static AddressField lastJavaPCField;
50 private static CIntegerField threadStateField;
51 private static AddressField osThreadField;
52 private static AddressField stackBaseField;
53 private static CIntegerField stackSizeField;
54 private static CIntegerField terminatedField;
55
56 private static JavaThreadPDAccess access;
57
58 // JavaThreadStates read from underlying process
59 private static int UNINITIALIZED;
60 private static int NEW;
61 private static int NEW_TRANS;
62 private static int IN_NATIVE;
63 private static int IN_NATIVE_TRANS;
64 private static int IN_VM;
65 private static int IN_VM_TRANS;
66 private static int IN_JAVA;
67 private static int IN_JAVA_TRANS;
68 private static int BLOCKED;
69 private static int BLOCKED_TRANS;
70
71 private static int NOT_TERMINATED;
72 private static int EXITING;
73
74 private static final String ADDRESS_FORMAT = VM.getVM().isLP64() ? "0x%016x" : "0x%08x";
75
76 static {
77 VM.registerVMInitializedObserver(new Observer() {
78 public void update(Observable o, Object data) {
79 initialize(VM.getVM().getTypeDataBase());
80 }
81 });
82 }
83
84 private static synchronized void initialize(TypeDataBase db) {
85 Type type = db.lookupType("JavaThread");
86 Type anchorType = db.lookupType("JavaFrameAnchor");
87
88 threadObjFieldOffset = type.getField("_threadObj").getOffset();
89
90 anchorField = type.getAddressField("_anchor");
91 lastJavaSPField = anchorType.getAddressField("_last_Java_sp");
92 lastJavaPCField = anchorType.getAddressField("_last_Java_pc");
93 threadStateField = type.getCIntegerField("_thread_state");
94 osThreadField = type.getAddressField("_osthread");
95 stackBaseField = type.getAddressField("_stack_base");
96 stackSizeField = type.getCIntegerField("_stack_size");
97 terminatedField = type.getCIntegerField("_terminated");
98
99 UNINITIALIZED = db.lookupIntConstant("_thread_uninitialized").intValue();
100 NEW = db.lookupIntConstant("_thread_new").intValue();
101 NEW_TRANS = db.lookupIntConstant("_thread_new_trans").intValue();
102 IN_NATIVE = db.lookupIntConstant("_thread_in_native").intValue();
103 IN_NATIVE_TRANS = db.lookupIntConstant("_thread_in_native_trans").intValue();
104 IN_VM = db.lookupIntConstant("_thread_in_vm").intValue();
105 IN_VM_TRANS = db.lookupIntConstant("_thread_in_vm_trans").intValue();
106 IN_JAVA = db.lookupIntConstant("_thread_in_Java").intValue();
107 IN_JAVA_TRANS = db.lookupIntConstant("_thread_in_Java_trans").intValue();
108 BLOCKED = db.lookupIntConstant("_thread_blocked").intValue();
109 BLOCKED_TRANS = db.lookupIntConstant("_thread_blocked_trans").intValue();
110
111 NOT_TERMINATED = db.lookupIntConstant("JavaThread::_not_terminated").intValue();
112 EXITING = db.lookupIntConstant("JavaThread::_thread_exiting").intValue();
113
114 }
115
116 public JavaThread(Address addr) {
117 super(addr);
118 }
375
376 // FIXME: add in the rest of the routine from the VM
377
378 // Traverse the execution stack
379 for(StackFrameStream fst = new StackFrameStream(this); !fst.isDone(); fst.next()) {
380 fst.getCurrent().oopsDo(oopVisitor, fst.getRegisterMap());
381 }
382 }
383
384 public boolean isInStack(Address a) {
385 if (Assert.ASSERTS_ENABLED) {
386 Assert.that(VM.getVM().isDebugging(), "Not yet implemented for non-debugging system");
387 }
388 Address sp = lastSPDbg();
389 Address stackBase = getStackBase();
390 // Be robust
391 if (sp == null) return false;
392 return stackBase.greaterThan(a) && sp.lessThanOrEqual(a);
393 }
394
395 public boolean isLockOwned(Address a) {
396 Address stackBase = getStackBase();
397 Address stackLimit = stackBase.addOffsetTo(-getStackSize());
398
399 return stackBase.greaterThan(a) && stackLimit.lessThanOrEqual(a);
400
401 // FIXME: should traverse MonitorArray/MonitorChunks as in VM
402 }
403
404 public Oop getCurrentParkBlocker() {
405 Oop threadObj = getThreadObj();
406 if (threadObj != null) {
407 return OopUtilities.threadOopGetParkBlocker(threadObj);
408 }
409 return null;
410 }
411
412 public void printInfoOn(PrintStream tty) {
413
414 tty.println("State: " + getThreadState().toString());
|
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.oops.*;
31 import sun.jvm.hotspot.types.*;
32 import sun.jvm.hotspot.utilities.*;
33 import sun.jvm.hotspot.utilities.Observable;
34 import sun.jvm.hotspot.utilities.Observer;
35
36 /** This is an abstract class because there are certain OS- and
37 CPU-specific operations (like the setting and getting of the last
38 Java frame pointer) which need to be factored out. These
39 operations are implemented by, for example,
40 SolarisSPARCJavaThread, and the concrete subclasses are
41 instantiated by the JavaThreadFactory in the Threads class. */
42
43 public class JavaThread extends Thread {
44 private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.runtime.JavaThread.DEBUG") != null;
45
46 private static long threadObjFieldOffset;
47 private static long lockStackTopOffset;
48 private static long lockStackBaseOffset;
49 private static AddressField anchorField;
50 private static AddressField lastJavaSPField;
51 private static AddressField lastJavaPCField;
52 private static CIntegerField threadStateField;
53 private static AddressField osThreadField;
54 private static AddressField stackBaseField;
55 private static CIntegerField stackSizeField;
56 private static CIntegerField terminatedField;
57 private static long oopPtrSize;
58
59 private static JavaThreadPDAccess access;
60
61 // JavaThreadStates read from underlying process
62 private static int UNINITIALIZED;
63 private static int NEW;
64 private static int NEW_TRANS;
65 private static int IN_NATIVE;
66 private static int IN_NATIVE_TRANS;
67 private static int IN_VM;
68 private static int IN_VM_TRANS;
69 private static int IN_JAVA;
70 private static int IN_JAVA_TRANS;
71 private static int BLOCKED;
72 private static int BLOCKED_TRANS;
73
74 private static int NOT_TERMINATED;
75 private static int EXITING;
76
77 private static final String ADDRESS_FORMAT = VM.getVM().isLP64() ? "0x%016x" : "0x%08x";
78
79 static {
80 VM.registerVMInitializedObserver(new Observer() {
81 public void update(Observable o, Object data) {
82 initialize(VM.getVM().getTypeDataBase());
83 }
84 });
85 }
86
87 private static synchronized void initialize(TypeDataBase db) {
88 Type type = db.lookupType("JavaThread");
89 Type anchorType = db.lookupType("JavaFrameAnchor");
90 Type typeLockStack = db.lookupType("LockStack");
91
92 threadObjFieldOffset = type.getField("_threadObj").getOffset();
93
94 anchorField = type.getAddressField("_anchor");
95 lastJavaSPField = anchorType.getAddressField("_last_Java_sp");
96 lastJavaPCField = anchorType.getAddressField("_last_Java_pc");
97 threadStateField = type.getCIntegerField("_thread_state");
98 osThreadField = type.getAddressField("_osthread");
99 stackBaseField = type.getAddressField("_stack_base");
100 stackSizeField = type.getCIntegerField("_stack_size");
101 terminatedField = type.getCIntegerField("_terminated");
102
103 lockStackTopOffset = type.getField("_lock_stack").getOffset() + typeLockStack.getField("_top").getOffset();
104 lockStackBaseOffset = type.getField("_lock_stack").getOffset() + typeLockStack.getField("_base[0]").getOffset();
105 oopPtrSize = VM.getVM().getAddressSize();
106
107 UNINITIALIZED = db.lookupIntConstant("_thread_uninitialized").intValue();
108 NEW = db.lookupIntConstant("_thread_new").intValue();
109 NEW_TRANS = db.lookupIntConstant("_thread_new_trans").intValue();
110 IN_NATIVE = db.lookupIntConstant("_thread_in_native").intValue();
111 IN_NATIVE_TRANS = db.lookupIntConstant("_thread_in_native_trans").intValue();
112 IN_VM = db.lookupIntConstant("_thread_in_vm").intValue();
113 IN_VM_TRANS = db.lookupIntConstant("_thread_in_vm_trans").intValue();
114 IN_JAVA = db.lookupIntConstant("_thread_in_Java").intValue();
115 IN_JAVA_TRANS = db.lookupIntConstant("_thread_in_Java_trans").intValue();
116 BLOCKED = db.lookupIntConstant("_thread_blocked").intValue();
117 BLOCKED_TRANS = db.lookupIntConstant("_thread_blocked_trans").intValue();
118
119 NOT_TERMINATED = db.lookupIntConstant("JavaThread::_not_terminated").intValue();
120 EXITING = db.lookupIntConstant("JavaThread::_thread_exiting").intValue();
121
122 }
123
124 public JavaThread(Address addr) {
125 super(addr);
126 }
383
384 // FIXME: add in the rest of the routine from the VM
385
386 // Traverse the execution stack
387 for(StackFrameStream fst = new StackFrameStream(this); !fst.isDone(); fst.next()) {
388 fst.getCurrent().oopsDo(oopVisitor, fst.getRegisterMap());
389 }
390 }
391
392 public boolean isInStack(Address a) {
393 if (Assert.ASSERTS_ENABLED) {
394 Assert.that(VM.getVM().isDebugging(), "Not yet implemented for non-debugging system");
395 }
396 Address sp = lastSPDbg();
397 Address stackBase = getStackBase();
398 // Be robust
399 if (sp == null) return false;
400 return stackBase.greaterThan(a) && sp.lessThanOrEqual(a);
401 }
402
403 public boolean isLockOwned(OopHandle obj) {
404 long current = lockStackBaseOffset;
405 long end = addr.getJIntAt(lockStackTopOffset);
406 if (Assert.ASSERTS_ENABLED) {
407 Assert.that(current <= end, "current stack offset must be above base offset");
408 }
409
410 while (current < end) {
411 Address oop = addr.getAddressAt(current);
412 if (oop.equals(obj)) {
413 return true;
414 }
415 current += oopPtrSize;
416 }
417 return false;
418 }
419
420 public boolean isLockOwned(Address a) {
421 Address stackBase = getStackBase();
422 Address stackLimit = stackBase.addOffsetTo(-getStackSize());
423
424 return stackBase.greaterThan(a) && stackLimit.lessThanOrEqual(a);
425
426 // FIXME: should traverse MonitorArray/MonitorChunks as in VM
427 }
428
429 public Oop getCurrentParkBlocker() {
430 Oop threadObj = getThreadObj();
431 if (threadObj != null) {
432 return OopUtilities.threadOopGetParkBlocker(threadObj);
433 }
434 return null;
435 }
436
437 public void printInfoOn(PrintStream tty) {
438
439 tty.println("State: " + getThreadState().toString());
|