Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java @ 6641:a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
Summary: Added capability to load support classes for other cpus
Reviewed-by: coleenp, bobv, sla
Contributed-by: Bill Pittore <bill.pittore@oracle.com>
author | bpittore |
---|---|
date | Thu, 30 Aug 2012 11:20:01 -0400 |
parents | 78d2ae5ab35b |
children | 5a98bf7d847b |
rev | line source |
---|---|
0 | 1 /* |
6641
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
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:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.runtime; | |
26 | |
27 import java.util.*; | |
28 import sun.jvm.hotspot.debugger.*; | |
29 import sun.jvm.hotspot.types.*; | |
30 import sun.jvm.hotspot.runtime.solaris_sparc.SolarisSPARCJavaThreadPDAccess; | |
31 import sun.jvm.hotspot.runtime.solaris_x86.SolarisX86JavaThreadPDAccess; | |
32 import sun.jvm.hotspot.runtime.solaris_amd64.SolarisAMD64JavaThreadPDAccess; | |
33 import sun.jvm.hotspot.runtime.win32_amd64.Win32AMD64JavaThreadPDAccess; | |
34 import sun.jvm.hotspot.runtime.win32_x86.Win32X86JavaThreadPDAccess; | |
35 import sun.jvm.hotspot.runtime.win32_ia64.Win32IA64JavaThreadPDAccess; | |
36 import sun.jvm.hotspot.runtime.linux_x86.LinuxX86JavaThreadPDAccess; | |
37 import sun.jvm.hotspot.runtime.linux_ia64.LinuxIA64JavaThreadPDAccess; | |
38 import sun.jvm.hotspot.runtime.linux_amd64.LinuxAMD64JavaThreadPDAccess; | |
39 import sun.jvm.hotspot.runtime.linux_sparc.LinuxSPARCJavaThreadPDAccess; | |
3960 | 40 import sun.jvm.hotspot.runtime.bsd_x86.BsdX86JavaThreadPDAccess; |
41 import sun.jvm.hotspot.runtime.bsd_amd64.BsdAMD64JavaThreadPDAccess; | |
0 | 42 import sun.jvm.hotspot.utilities.*; |
43 | |
44 public class Threads { | |
45 private static JavaThreadFactory threadFactory; | |
46 private static AddressField threadListField; | |
47 private static VirtualConstructor virtualConstructor; | |
48 private static JavaThreadPDAccess access; | |
49 | |
50 static { | |
51 VM.registerVMInitializedObserver(new Observer() { | |
52 public void update(Observable o, Object data) { | |
53 initialize(VM.getVM().getTypeDataBase()); | |
54 } | |
55 }); | |
56 } | |
57 | |
58 private static synchronized void initialize(TypeDataBase db) { | |
59 Type type = db.lookupType("Threads"); | |
60 | |
61 threadListField = type.getAddressField("_thread_list"); | |
62 | |
63 // Instantiate appropriate platform-specific JavaThreadFactory | |
64 String os = VM.getVM().getOS(); | |
65 String cpu = VM.getVM().getCPU(); | |
66 | |
67 access = null; | |
68 // FIXME: find the platform specific PD class by reflection? | |
69 if (os.equals("solaris")) { | |
70 if (cpu.equals("sparc")) { | |
71 access = new SolarisSPARCJavaThreadPDAccess(); | |
72 } else if (cpu.equals("x86")) { | |
73 access = new SolarisX86JavaThreadPDAccess(); | |
74 } else if (cpu.equals("amd64")) { | |
75 access = new SolarisAMD64JavaThreadPDAccess(); | |
76 } | |
77 } else if (os.equals("win32")) { | |
78 if (cpu.equals("x86")) { | |
79 access = new Win32X86JavaThreadPDAccess(); | |
80 } else if (cpu.equals("amd64")) { | |
81 access = new Win32AMD64JavaThreadPDAccess(); | |
82 } else if (cpu.equals("ia64")) { | |
83 access = new Win32IA64JavaThreadPDAccess(); | |
84 } | |
85 } else if (os.equals("linux")) { | |
86 if (cpu.equals("x86")) { | |
87 access = new LinuxX86JavaThreadPDAccess(); | |
88 } else if (cpu.equals("ia64")) { | |
89 access = new LinuxIA64JavaThreadPDAccess(); | |
90 } else if (cpu.equals("amd64")) { | |
91 access = new LinuxAMD64JavaThreadPDAccess(); | |
92 } else if (cpu.equals("sparc")) { | |
93 access = new LinuxSPARCJavaThreadPDAccess(); | |
6641
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
94 } else { |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
95 try { |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
96 access = (JavaThreadPDAccess) |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
97 Class.forName("sun.jvm.hotspot.runtime.linux_" + |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
98 cpu.toLowerCase() + ".Linux" + cpu.toUpperCase() + |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
99 "JavaThreadPDAccess").newInstance(); |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
100 } catch (Exception e) { |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
101 throw new RuntimeException("OS/CPU combination " + os + "/" + cpu + |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
102 " not yet supported"); |
a9fed06c01d2
7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents:
6073
diff
changeset
|
103 } |
0 | 104 } |
3960 | 105 } else if (os.equals("bsd")) { |
106 if (cpu.equals("x86")) { | |
107 access = new BsdX86JavaThreadPDAccess(); | |
6073
78d2ae5ab35b
7163117: Agent can't connect to process on Mac OSX
nloodin
parents:
3960
diff
changeset
|
108 } else if (cpu.equals("amd64") || cpu.equals("x86_64")) { |
3960 | 109 access = new BsdAMD64JavaThreadPDAccess(); |
110 } | |
0 | 111 } |
112 | |
113 if (access == null) { | |
114 throw new RuntimeException("OS/CPU combination " + os + "/" + cpu + | |
115 " not yet supported"); | |
116 } | |
117 | |
118 virtualConstructor = new VirtualConstructor(db); | |
119 // Add mappings for all known thread types | |
120 virtualConstructor.addMapping("JavaThread", JavaThread.class); | |
121 if (!VM.getVM().isCore()) { | |
122 virtualConstructor.addMapping("CompilerThread", CompilerThread.class); | |
123 } | |
124 // for now, use JavaThread itself. fix it later with appropriate class if needed | |
125 virtualConstructor.addMapping("SurrogateLockerThread", JavaThread.class); | |
126 virtualConstructor.addMapping("JvmtiAgentThread", JvmtiAgentThread.class); | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
1552
diff
changeset
|
127 virtualConstructor.addMapping("ServiceThread", ServiceThread.class); |
0 | 128 } |
129 | |
130 public Threads() { | |
131 } | |
132 | |
133 /** NOTE: this returns objects of type JavaThread, CompilerThread, | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
1552
diff
changeset
|
134 JvmtiAgentThread, and ServiceThread. |
0 | 135 The latter four are subclasses of the former. Most operations |
136 (fetching the top frame, etc.) are only allowed to be performed on | |
137 a "pure" JavaThread. For this reason, {@link | |
138 sun.jvm.hotspot.runtime.JavaThread#isJavaThread} has been | |
139 changed from the definition in the VM (which returns true for | |
140 all of these thread types) to return true for JavaThreads and | |
141 false for the three subclasses. FIXME: should reconsider the | |
142 inheritance hierarchy; see {@link | |
143 sun.jvm.hotspot.runtime.JavaThread#isJavaThread}. */ | |
144 public JavaThread first() { | |
145 Address threadAddr = threadListField.getValue(); | |
146 if (threadAddr == null) { | |
147 return null; | |
148 } | |
149 | |
150 return createJavaThreadWrapper(threadAddr); | |
151 } | |
152 | |
153 /** Routine for instantiating appropriately-typed wrapper for a | |
154 JavaThread. Currently needs to be public for OopUtilities to | |
155 access it. */ | |
156 public JavaThread createJavaThreadWrapper(Address threadAddr) { | |
157 try { | |
158 JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr); | |
159 thread.setThreadPDAccess(access); | |
160 return thread; | |
161 } catch (Exception e) { | |
162 throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr + | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
1552
diff
changeset
|
163 " (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, or SurrogateLockerThread)", e); |
0 | 164 } |
165 } | |
166 | |
167 /** Memory operations */ | |
168 public void oopsDo(AddressVisitor oopVisitor) { | |
169 // FIXME: add more of VM functionality | |
170 for (JavaThread thread = first(); thread != null; thread = thread.next()) { | |
171 thread.oopsDo(oopVisitor); | |
172 } | |
173 } | |
174 | |
175 // refer to Threads::owning_thread_from_monitor_owner | |
176 public JavaThread owningThreadFromMonitor(Address o) { | |
177 if (o == null) return null; | |
178 for (JavaThread thread = first(); thread != null; thread = thread.next()) { | |
179 if (o.equals(thread.threadObjectAddress())) { | |
180 return thread; | |
181 } | |
182 } | |
183 | |
184 for (JavaThread thread = first(); thread != null; thread = thread.next()) { | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
0
diff
changeset
|
185 if (thread.isLockOwned(o)) |
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
0
diff
changeset
|
186 return thread; |
0 | 187 } |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
0
diff
changeset
|
188 return null; |
0 | 189 } |
190 | |
191 public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) { | |
192 return owningThreadFromMonitor(monitor.owner()); | |
193 } | |
194 | |
195 // refer to Threads::get_pending_threads | |
196 // Get list of Java threads that are waiting to enter the specified monitor. | |
197 public List getPendingThreads(ObjectMonitor monitor) { | |
198 List pendingThreads = new ArrayList(); | |
199 for (JavaThread thread = first(); thread != null; thread = thread.next()) { | |
200 if (thread.isCompilerThread()) { | |
201 continue; | |
202 } | |
203 ObjectMonitor pending = thread.getCurrentPendingMonitor(); | |
204 if (monitor.equals(pending)) { | |
205 pendingThreads.add(thread); | |
206 } | |
207 } | |
208 return pendingThreads; | |
209 } | |
210 | |
211 // Get list of Java threads that have called Object.wait on the specified monitor. | |
212 public List getWaitingThreads(ObjectMonitor monitor) { | |
213 List pendingThreads = new ArrayList(); | |
214 for (JavaThread thread = first(); thread != null; thread = thread.next()) { | |
215 ObjectMonitor waiting = thread.getCurrentWaitingMonitor(); | |
216 if (monitor.equals(waiting)) { | |
217 pendingThreads.add(thread); | |
218 } | |
219 } | |
220 return pendingThreads; | |
221 } | |
222 | |
223 // FIXME: add other accessors | |
224 } |