annotate agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents d1605aabd0a1
children c7f3d0b4570f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
2 * Copyright (c) 2000, 2008, 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.lang.Class fields
a61af66fc99e Initial load
duke
parents:
diff changeset
78 private static OopField hcKlassField;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // java.util.concurrent.locks.AbstractOwnableSynchronizer fields
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private static OopField absOwnSyncOwnerThreadField;
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 });
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // FIXME: don't need this observer; however, do need a VM resumed
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // and suspended observer to refetch fields
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public static String charArrayToString(TypeArray charArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (charArray == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return charArrayToString(charArray, 0, (int) charArray.getLength());
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public static String charArrayToString(TypeArray charArray, int offset, int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (charArray == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 final int limit = offset + length;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 Assert.that(offset >= 0 && limit <= charArray.getLength(), "out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 StringBuffer buf = new StringBuffer(length);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 for (int i = offset; i < limit; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 buf.append(charArray.getCharAt(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public static String stringOopToString(Oop stringOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (offsetField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 InstanceKlass k = (InstanceKlass) stringOop.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 offsetField = (IntField) k.findField("offset", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 countField = (IntField) k.findField("count", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
123 valueField = (OopField) k.findField("value", "[C");
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 Assert.that(offsetField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
126 countField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
127 valueField != null, "must find all java.lang.String fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return charArrayToString((TypeArray) valueField.getValue(stringOop),
a61af66fc99e Initial load
duke
parents:
diff changeset
131 offsetField.getValue(stringOop),
a61af66fc99e Initial load
duke
parents:
diff changeset
132 countField.getValue(stringOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 private static void initThreadGroupFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (threadGroupParentField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 InstanceKlass k = sysDict.getThreadGroupKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 threadGroupParentField = (OopField) k.findField("parent", "Ljava/lang/ThreadGroup;");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 threadGroupNameField = (OopField) k.findField("name", "Ljava/lang/String;");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 threadGroupNThreadsField = (IntField) k.findField("nthreads", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 threadGroupThreadsField = (OopField) k.findField("threads", "[Ljava/lang/Thread;");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 threadGroupNGroupsField = (IntField) k.findField("ngroups", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
144 threadGroupGroupsField = (OopField) k.findField("groups", "[Ljava/lang/ThreadGroup;");
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 Assert.that(threadGroupParentField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
147 threadGroupNameField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
148 threadGroupNThreadsField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
149 threadGroupThreadsField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
150 threadGroupNGroupsField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
151 threadGroupGroupsField != null, "must find all java.lang.ThreadGroup fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public static Oop threadGroupOopGetParent(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return threadGroupParentField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public static String threadGroupOopGetName(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return stringOopToString(threadGroupNameField.getValue(threadGroupOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 public static Oop[] threadGroupOopGetThreads(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 int nthreads = threadGroupNThreadsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 Oop[] result = new Oop[nthreads];
a61af66fc99e Initial load
duke
parents:
diff changeset
170 ObjArray threads = (ObjArray) threadGroupThreadsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 for (int i = 0; i < nthreads; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 result[i] = threads.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public static Oop[] threadGroupOopGetGroups(Oop threadGroupOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 initThreadGroupFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 int ngroups = threadGroupNGroupsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 Oop[] result = new Oop[ngroups];
a61af66fc99e Initial load
duke
parents:
diff changeset
181 ObjArray groups = (ObjArray) threadGroupGroupsField.getValue(threadGroupOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 for (int i = 0; i < ngroups; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 result[i] = groups.getObjAt(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 private static void initThreadFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (threadNameField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 InstanceKlass k = sysDict.getThreadKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 threadNameField = (OopField) k.findField("name", "[C");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 threadGroupField = (OopField) k.findField("group", "Ljava/lang/ThreadGroup;");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 threadEETopField = (LongField) k.findField("eetop", "J");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 threadStatusField = (IntField) k.findField("threadStatus", "I");
a61af66fc99e Initial load
duke
parents:
diff changeset
196 threadParkBlockerField = (OopField) k.findField("parkBlocker",
a61af66fc99e Initial load
duke
parents:
diff changeset
197 "Ljava/lang/Object;");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 TypeDataBase db = VM.getVM().getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 THREAD_STATUS_NEW = db.lookupIntConstant("java_lang_Thread::NEW").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Other enum constants are not needed as of now. Uncomment these as and when needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 THREAD_STATUS_RUNNABLE = db.lookupIntConstant("java_lang_Thread::RUNNABLE").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 THREAD_STATUS_SLEEPING = db.lookupIntConstant("java_lang_Thread::SLEEPING").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 THREAD_STATUS_IN_OBJECT_WAIT = db.lookupIntConstant("java_lang_Thread::IN_OBJECT_WAIT").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 THREAD_STATUS_IN_OBJECT_WAIT_TIMED = db.lookupIntConstant("java_lang_Thread::IN_OBJECT_WAIT_TIMED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 THREAD_STATUS_PARKED = db.lookupIntConstant("java_lang_Thread::PARKED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 THREAD_STATUS_PARKED_TIMED = db.lookupIntConstant("java_lang_Thread::PARKED_TIMED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
209 THREAD_STATUS_BLOCKED_ON_MONITOR_ENTER = db.lookupIntConstant("java_lang_Thread::BLOCKED_ON_MONITOR_ENTER").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 THREAD_STATUS_TERMINATED = db.lookupIntConstant("java_lang_Thread::TERMINATED").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 */
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // it is okay to miss threadStatusField, because this was
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // introduced only in 1.5 JDK.
a61af66fc99e Initial load
duke
parents:
diff changeset
216 Assert.that(threadNameField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
217 threadGroupField != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
218 threadEETopField != null, "must find all java.lang.Thread fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public static Oop threadOopGetThreadGroup(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 return threadGroupField.getValue(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 public static String threadOopGetName(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 return charArrayToString((TypeArray) threadNameField.getValue(threadOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 /** May return null if, e.g., thread was not started */
a61af66fc99e Initial load
duke
parents:
diff changeset
234 public static JavaThread threadOopGetJavaThread(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 Address addr = threadOop.getHandle().getAddressAt(threadEETopField.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
237 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 return VM.getVM().getThreads().createJavaThreadWrapper(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 /** returns value of java.lang.Thread.threadStatus field */
a61af66fc99e Initial load
duke
parents:
diff changeset
244 public static int threadOopGetThreadStatus(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // The threadStatus is only present starting in 1.5
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (threadStatusField != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return (int) threadStatusField.getValue(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // All we can easily figure out is if it is alive, but that is
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // enough info for a valid unknown status.
a61af66fc99e Initial load
duke
parents:
diff changeset
252 JavaThread thr = threadOopGetJavaThread(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (thr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // the thread hasn't run yet or is in the process of exiting
a61af66fc99e Initial load
duke
parents:
diff changeset
255 return THREAD_STATUS_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 return JVMTI_THREAD_STATE_ALIVE;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 /** returns value of java.lang.Thread.parkBlocker field */
a61af66fc99e Initial load
duke
parents:
diff changeset
263 public static Oop threadOopGetParkBlocker(Oop threadOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 initThreadFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (threadParkBlockerField != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return threadParkBlockerField.getValue(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // initialize fields for java.lang.Class
a61af66fc99e Initial load
duke
parents:
diff changeset
272 private static void initClassFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (hcKlassField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // hc_klass is a HotSpot magic field and hence we can't
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // find it from InstanceKlass for java.lang.Class.
a61af66fc99e Initial load
duke
parents:
diff changeset
276 TypeDataBase db = VM.getVM().getTypeDataBase();
180
b9ebd46331d2 6710654: SAJDI failures with Compressed Oops
kvn
parents: 113
diff changeset
277 int hcKlassOffset = (int) Instance.getHeaderSize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
278 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 hcKlassOffset += (db.lookupIntConstant("java_lang_Class::hc_klass_offset").intValue() *
180
b9ebd46331d2 6710654: SAJDI failures with Compressed Oops
kvn
parents: 113
diff changeset
280 VM.getVM().getHeapOopSize());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
281 } catch (RuntimeException re) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // ignore, currently java_lang_Class::hc_klass_offset is zero
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
284 if (VM.getVM().isCompressedOopsEnabled()) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
285 hcKlassField = new NarrowOopField(new NamedFieldIdentifier("hc_klass"), hcKlassOffset, true);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
286 } else {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
287 hcKlassField = new OopField(new NamedFieldIdentifier("hc_klass"), hcKlassOffset, true);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
288 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 /** get klassOop field at offset hc_klass_offset from a java.lang.Class object */
a61af66fc99e Initial load
duke
parents:
diff changeset
293 public static Klass classOopToKlass(Oop aClass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 initClassFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 return (Klass) hcKlassField.getValue(aClass);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // initialize fields for j.u.c.l AbstractOwnableSynchornizer class
a61af66fc99e Initial load
duke
parents:
diff changeset
299 private static void initAbsOwnSyncFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 if (absOwnSyncOwnerThreadField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 InstanceKlass k = sysDict.getAbstractOwnableSynchronizerKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 absOwnSyncOwnerThreadField =
a61af66fc99e Initial load
duke
parents:
diff changeset
304 (OopField) k.findField("exclusiveOwnerThread",
a61af66fc99e Initial load
duke
parents:
diff changeset
305 "Ljava/lang/Thread;");
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // return exclusiveOwnerThread field of AbstractOwnableSynchronizer class
a61af66fc99e Initial load
duke
parents:
diff changeset
310 public static Oop abstractOwnableSynchronizerGetOwnerThread(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 initAbsOwnSyncFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (absOwnSyncOwnerThreadField == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 return null; // pre-1.6 VM?
a61af66fc99e Initial load
duke
parents:
diff changeset
314 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 return absOwnSyncOwnerThreadField.getValue(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }