194 thread.setThreadPDAccess(access);
195 return thread;
196 } catch (Exception e) {
197 throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
198 " (expected type JavaThread, CompilerThread, MonitorDeflationThread, ServiceThread, JvmtiAgentThread or CodeCacheSweeperThread)", e);
199 }
200 }
201
202 /** Memory operations */
203 public void oopsDo(AddressVisitor oopVisitor) {
204 // FIXME: add more of VM functionality
205 Threads threads = VM.getVM().getThreads();
206 for (int i = 0; i < threads.getNumberOfThreads(); i++) {
207 JavaThread thread = threads.getJavaThreadAt(i);
208 thread.oopsDo(oopVisitor);
209 }
210 }
211
212 // refer to Threads::owning_thread_from_monitor_owner
213 public JavaThread owningThreadFromMonitor(Address o) {
214 if (o == null) return null;
215 for (int i = 0; i < getNumberOfThreads(); i++) {
216 JavaThread thread = getJavaThreadAt(i);
217 if (o.equals(thread.threadObjectAddress())) {
218 return thread;
219 }
220 }
221
222 for (int i = 0; i < getNumberOfThreads(); i++) {
223 JavaThread thread = getJavaThreadAt(i);
224 if (thread.isLockOwned(o))
225 return thread;
226 }
227 return null;
228 }
229
230 public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
231 return owningThreadFromMonitor(monitor.owner());
232 }
233
234 // refer to Threads::get_pending_threads
235 // Get list of Java threads that are waiting to enter the specified monitor.
236 public List<JavaThread> getPendingThreads(ObjectMonitor monitor) {
237 List<JavaThread> pendingThreads = new ArrayList<>();
238 for (int i = 0; i < getNumberOfThreads(); i++) {
239 JavaThread thread = getJavaThreadAt(i);
240 if (thread.isCompilerThread() || thread.isCodeCacheSweeperThread()) {
241 continue;
242 }
243 ObjectMonitor pending = thread.getCurrentPendingMonitor();
244 if (monitor.equals(pending)) {
245 pendingThreads.add(thread);
246 }
247 }
248 return pendingThreads;
249 }
250
251 // Get list of Java threads that have called Object.wait on the specified monitor.
|
194 thread.setThreadPDAccess(access);
195 return thread;
196 } catch (Exception e) {
197 throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
198 " (expected type JavaThread, CompilerThread, MonitorDeflationThread, ServiceThread, JvmtiAgentThread or CodeCacheSweeperThread)", e);
199 }
200 }
201
202 /** Memory operations */
203 public void oopsDo(AddressVisitor oopVisitor) {
204 // FIXME: add more of VM functionality
205 Threads threads = VM.getVM().getThreads();
206 for (int i = 0; i < threads.getNumberOfThreads(); i++) {
207 JavaThread thread = threads.getJavaThreadAt(i);
208 thread.oopsDo(oopVisitor);
209 }
210 }
211
212 // refer to Threads::owning_thread_from_monitor_owner
213 public JavaThread owningThreadFromMonitor(Address o) {
214 assert(VM.getVM().getCommandLineFlag("LockingMode").getInt() != LockingMode.getLightweight());
215 if (o == null) return null;
216 for (int i = 0; i < getNumberOfThreads(); i++) {
217 JavaThread thread = getJavaThreadAt(i);
218 if (o.equals(thread.threadObjectAddress())) {
219 return thread;
220 }
221 }
222
223 for (int i = 0; i < getNumberOfThreads(); i++) {
224 JavaThread thread = getJavaThreadAt(i);
225 if (thread.isLockOwned(o))
226 return thread;
227 }
228 return null;
229 }
230
231 public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
232 if (VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLightweight()) {
233 if (monitor.isOwnedAnonymous()) {
234 OopHandle object = monitor.object();
235 for (int i = 0; i < getNumberOfThreads(); i++) {
236 JavaThread thread = getJavaThreadAt(i);
237 if (thread.isLockOwned(object)) {
238 return thread;
239 }
240 }
241 throw new InternalError("We should have found a thread that owns the anonymous lock");
242 }
243 // Owner can only be threads at this point.
244 Address o = monitor.owner();
245 if (o == null) return null;
246 return new JavaThread(o);
247 } else {
248 return owningThreadFromMonitor(monitor.owner());
249 }
250 }
251
252 // refer to Threads::get_pending_threads
253 // Get list of Java threads that are waiting to enter the specified monitor.
254 public List<JavaThread> getPendingThreads(ObjectMonitor monitor) {
255 List<JavaThread> pendingThreads = new ArrayList<>();
256 for (int i = 0; i < getNumberOfThreads(); i++) {
257 JavaThread thread = getJavaThreadAt(i);
258 if (thread.isCompilerThread() || thread.isCodeCacheSweeperThread()) {
259 continue;
260 }
261 ObjectMonitor pending = thread.getCurrentPendingMonitor();
262 if (monitor.equals(pending)) {
263 pendingThreads.add(thread);
264 }
265 }
266 return pendingThreads;
267 }
268
269 // Get list of Java threads that have called Object.wait on the specified monitor.
|