annotate agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java @ 2468:6c97c830fb6f

Merge
author jrose
date Sat, 09 Apr 2011 21:16:12 -0700
parents 63997f575155
children f6f3bb0ee072
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.TypeDataBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.jdi.JVMTIThreadState;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /** A utility class encapsulating useful oop operations */
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public class OopUtilities implements /* imports */ JVMTIThreadState {
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // FIXME: access should be synchronized and cleared when VM is
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // resumed
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // String fields
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static IntField offsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private static IntField countField;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static OopField valueField;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // ThreadGroup fields
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private static OopField threadGroupParentField;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private static OopField threadGroupNameField;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static IntField threadGroupNThreadsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static OopField threadGroupThreadsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private static IntField threadGroupNGroupsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private static OopField threadGroupGroupsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // Thread fields
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private static OopField threadNameField;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private static OopField threadGroupField;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private static LongField threadEETopField;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // threadStatus field is new since 1.5
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private static IntField threadStatusField;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // parkBlocker field is new since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private static OopField threadParkBlockerField;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // possible values of java_lang_Thread::ThreadStatus
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private static int THREAD_STATUS_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Other enum constants are not needed as of now. Uncomment these as and when needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private static int THREAD_STATUS_RUNNABLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 private static int THREAD_STATUS_SLEEPING;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private static int THREAD_STATUS_IN_OBJECT_WAIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 private static int THREAD_STATUS_IN_OBJECT_WAIT_TIMED;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private static int THREAD_STATUS_PARKED;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private static int THREAD_STATUS_PARKED_TIMED;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private static int THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private static int THREAD_STATUS_TERMINATED;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 */
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // java.util.concurrent.locks.AbstractOwnableSynchronizer fields
a61af66fc99e Initial load
duke
parents:
diff changeset
78 private static OopField absOwnSyncOwnerThreadField;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 });
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // FIXME: don't need this observer; however, do need a VM resumed
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // and suspended observer to refetch fields
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public static String charArrayToString(TypeArray charArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (charArray == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return charArrayToString(charArray, 0, (int) charArray.getLength());
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public static String charArrayToString(TypeArray charArray, int offset, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (charArray == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 final int limit = offset + length;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 Assert.that(offset >= 0 && limit <= charArray.getLength(), "out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 StringBuffer buf = new StringBuffer(length);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 for (int i = offset; i < limit; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 buf.append(charArray.getCharAt(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public static String stringOopToString(Oop stringOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (offsetField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 InstanceKlass k = (InstanceKlass) stringOop.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 offsetField = (IntField) k.findField("offset", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 countField = (IntField) k.findField("count", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 valueField = (OopField) k.findField("value", "[C");
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 Assert.that(offsetField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
123 countField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
124 valueField != null, "must find all java.lang.String fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return charArrayToString((TypeArray) valueField.getValue(stringOop),
a61af66fc99e Initial load
duke
parents:
diff changeset
128 offsetField.getValue(stringOop),
a61af66fc99e Initial load
duke
parents:
diff changeset
129 countField.getValue(stringOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 private static void initThreadGroupFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 if (threadGroupParentField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 InstanceKlass k = sysDict.getThreadGroupKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 threadGroupParentField = (OopField) k.findField("parent", "Ljava/lang/ThreadGroup;");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 threadGroupNameField = (OopField) k.findField("name", "Ljava/lang/String;");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 threadGroupNThreadsField = (IntField) k.findField("nthreads", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 threadGroupThreadsField = (OopField) k.findField("threads", "[Ljava/lang/Thread;");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 threadGroupNGroupsField = (IntField) k.findField("ngroups", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 threadGroupGroupsField = (OopField) k.findField("groups", "[Ljava/lang/ThreadGroup;");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Assert.that(threadGroupParentField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
144 threadGroupNameField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
145 threadGroupNThreadsField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
146 threadGroupThreadsField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
147 threadGroupNGroupsField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
148 threadGroupGroupsField != null, "must find all java.lang.ThreadGroup fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public static Oop threadGroupOopGetParent(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return threadGroupParentField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public static String threadGroupOopGetName(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return stringOopToString(threadGroupNameField.getValue(threadGroupOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public static Oop[] threadGroupOopGetThreads(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int nthreads = threadGroupNThreadsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 Oop[] result = new Oop[nthreads];
a61af66fc99e Initial load
duke
parents:
diff changeset
167 ObjArray threads = (ObjArray) threadGroupThreadsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 for (int i = 0; i < nthreads; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 result[i] = threads.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public static Oop[] threadGroupOopGetGroups(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 int ngroups = threadGroupNGroupsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 Oop[] result = new Oop[ngroups];
a61af66fc99e Initial load
duke
parents:
diff changeset
178 ObjArray groups = (ObjArray) threadGroupGroupsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 for (int i = 0; i < ngroups; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 result[i] = groups.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 private static void initThreadFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 if (threadNameField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 InstanceKlass k = sysDict.getThreadKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 threadNameField = (OopField) k.findField("name", "[C");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 threadGroupField = (OopField) k.findField("group", "Ljava/lang/ThreadGroup;");
a61af66fc99e Initial load
duke
parents:
diff changeset
191 threadEETopField = (LongField) k.findField("eetop", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 threadStatusField = (IntField) k.findField("threadStatus", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 threadParkBlockerField = (OopField) k.findField("parkBlocker",
a61af66fc99e Initial load
duke
parents:
diff changeset
194 "Ljava/lang/Object;");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 TypeDataBase db = VM.getVM().getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 THREAD_STATUS_NEW = db.lookupIntConstant("java_lang_Thread::NEW").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
198 Other enum constants are not needed as of now. Uncomment these as and when needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 THREAD_STATUS_RUNNABLE = db.lookupIntConstant("java_lang_Thread::RUNNABLE").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 THREAD_STATUS_SLEEPING = db.lookupIntConstant("java_lang_Thread::SLEEPING").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 THREAD_STATUS_IN_OBJECT_WAIT = db.lookupIntConstant("java_lang_Thread::IN_OBJECT_WAIT").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 THREAD_STATUS_IN_OBJECT_WAIT_TIMED = db.lookupIntConstant("java_lang_Thread::IN_OBJECT_WAIT_TIMED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 THREAD_STATUS_PARKED = db.lookupIntConstant("java_lang_Thread::PARKED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 THREAD_STATUS_PARKED_TIMED = db.lookupIntConstant("java_lang_Thread::PARKED_TIMED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER = db.lookupIntConstant("java_lang_Thread::BLOCKED_ON_MONITOR_ENTER").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 THREAD_STATUS_TERMINATED = db.lookupIntConstant("java_lang_Thread::TERMINATED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 */
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // it is okay to miss threadStatusField, because this was
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // introduced only in 1.5 JDK.
a61af66fc99e Initial load
duke
parents:
diff changeset
213 Assert.that(threadNameField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
214 threadGroupField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
215 threadEETopField != null, "must find all java.lang.Thread fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 public static Oop threadOopGetThreadGroup(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return threadGroupField.getValue(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 public static String threadOopGetName(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 return charArrayToString((TypeArray) threadNameField.getValue(threadOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 /** May return null if, e.g., thread was not started */
a61af66fc99e Initial load
duke
parents:
diff changeset
231 public static JavaThread threadOopGetJavaThread(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 Address addr = threadOop.getHandle().getAddressAt(threadEETopField.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
234 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 return VM.getVM().getThreads().createJavaThreadWrapper(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 /** returns value of java.lang.Thread.threadStatus field */
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public static int threadOopGetThreadStatus(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // The threadStatus is only present starting in 1.5
a61af66fc99e Initial load
duke
parents:
diff changeset
244 if (threadStatusField != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 return (int) threadStatusField.getValue(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // All we can easily figure out is if it is alive, but that is
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // enough info for a valid unknown status.
a61af66fc99e Initial load
duke
parents:
diff changeset
249 JavaThread thr = threadOopGetJavaThread(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if (thr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // the thread hasn't run yet or is in the process of exiting
a61af66fc99e Initial load
duke
parents:
diff changeset
252 return THREAD_STATUS_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 return JVMTI_THREAD_STATE_ALIVE;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 /** returns value of java.lang.Thread.parkBlocker field */
a61af66fc99e Initial load
duke
parents:
diff changeset
260 public static Oop threadOopGetParkBlocker(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (threadParkBlockerField != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 return threadParkBlockerField.getValue(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // initialize fields for j.u.c.l AbstractOwnableSynchornizer class
a61af66fc99e Initial load
duke
parents:
diff changeset
269 private static void initAbsOwnSyncFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 if (absOwnSyncOwnerThreadField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
272 InstanceKlass k = sysDict.getAbstractOwnableSynchronizerKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
273 absOwnSyncOwnerThreadField =
a61af66fc99e Initial load
duke
parents:
diff changeset
274 (OopField) k.findField("exclusiveOwnerThread",
a61af66fc99e Initial load
duke
parents:
diff changeset
275 "Ljava/lang/Thread;");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // return exclusiveOwnerThread field of AbstractOwnableSynchronizer class
a61af66fc99e Initial load
duke
parents:
diff changeset
280 public static Oop abstractOwnableSynchronizerGetOwnerThread(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 initAbsOwnSyncFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 if (absOwnSyncOwnerThreadField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 return null; // pre-1.6 VM?
a61af66fc99e Initial load
duke
parents:
diff changeset
284 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 return absOwnSyncOwnerThreadField.getValue(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }