comparison agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java @ 8023:758935f7c23f

8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67) Summary: Do not rely on mach thread port names to identify threads from SA Reviewed-by: dholmes, minqi, rbackman
author sla
date Fri, 08 Feb 2013 12:48:24 +0100
parents f08d439fab8c
children 39432a1cefdd
comparison
equal deleted inserted replaced
8021:8d9fc28831cc 8023:758935f7c23f
26 26
27 import sun.jvm.hotspot.debugger.*; 27 import sun.jvm.hotspot.debugger.*;
28 28
29 class BsdThread implements ThreadProxy { 29 class BsdThread implements ThreadProxy {
30 private BsdDebugger debugger; 30 private BsdDebugger debugger;
31 private int lwp_id; 31 private int thread_id;
32 private long unique_thread_id;
32 33
33 /** The address argument must be the address of the _thread_id in the 34 /** The address argument must be the address of the _thread_id in the
34 OSThread. It's value is result ::gettid() call. */ 35 OSThread. It's value is result ::gettid() call. */
35 BsdThread(BsdDebugger debugger, Address addr) { 36 BsdThread(BsdDebugger debugger, Address threadIdAddr, Address uniqueThreadIdAddr) {
36 this.debugger = debugger; 37 this.debugger = debugger;
37 // FIXME: size of data fetched here should be configurable. 38 // FIXME: size of data fetched here should be configurable.
38 // However, making it so would produce a dependency on the "types" 39 // However, making it so would produce a dependency on the "types"
39 // package from the debugger package, which is not desired. 40 // package from the debugger package, which is not desired.
40 this.lwp_id = (int) addr.getCIntegerAt(0, 4, true); 41 this.thread_id = (int) threadIdAddr.getCIntegerAt(0, 4, true);
42 this.unique_thread_id = uniqueThreadIdAddr.getCIntegerAt(0, 8, true);
41 } 43 }
42 44
43 BsdThread(BsdDebugger debugger, long id) { 45 BsdThread(BsdDebugger debugger, long id) {
44 this.debugger = debugger; 46 this.debugger = debugger;
45 this.lwp_id = (int) id; 47 this.thread_id = (int) id;
46 } 48 }
47 49
48 public boolean equals(Object obj) { 50 public boolean equals(Object obj) {
49 if ((obj == null) || !(obj instanceof BsdThread)) { 51 if ((obj == null) || !(obj instanceof BsdThread)) {
50 return false; 52 return false;
51 } 53 }
52 54
53 return (((BsdThread) obj).lwp_id == lwp_id); 55 return (((BsdThread) obj).thread_id == thread_id);
54 } 56 }
55 57
56 public int hashCode() { 58 public int hashCode() {
57 return lwp_id; 59 return thread_id;
58 } 60 }
59 61
60 public String toString() { 62 public String toString() {
61 return Integer.toString(lwp_id); 63 return Integer.toString(thread_id);
62 } 64 }
63 65
64 public ThreadContext getContext() throws IllegalThreadStateException { 66 public ThreadContext getContext() throws IllegalThreadStateException {
65 long[] data = debugger.getThreadIntegerRegisterSet(lwp_id); 67 long[] data = debugger.getThreadIntegerRegisterSet(unique_thread_id);
66 ThreadContext context = BsdThreadContextFactory.createThreadContext(debugger); 68 ThreadContext context = BsdThreadContextFactory.createThreadContext(debugger);
67 for (int i = 0; i < data.length; i++) { 69 for (int i = 0; i < data.length; i++) {
68 context.setRegister(i, data[i]); 70 context.setRegister(i, data[i]);
69 } 71 }
70 return context; 72 return context;