< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Threads.java

Print this page

193             thread.setThreadPDAccess(access);
194             return thread;
195         } catch (Exception e) {
196             throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
197             " (expected type JavaThread, CompilerThread, MonitorDeflationThread, ServiceThread or JvmtiAgentThread)", e);
198         }
199     }
200 
201     /** Memory operations */
202     public void oopsDo(AddressVisitor oopVisitor) {
203         // FIXME: add more of VM functionality
204         Threads threads = VM.getVM().getThreads();
205         for (int i = 0; i < threads.getNumberOfThreads(); i++) {
206             JavaThread thread = threads.getJavaThreadAt(i);
207             thread.oopsDo(oopVisitor);
208         }
209     }
210 
211     // refer to Threads::owning_thread_from_monitor_owner
212     public JavaThread owningThreadFromMonitor(Address o) {

213         if (o == null) return null;
214         for (int i = 0; i < getNumberOfThreads(); i++) {
215             JavaThread thread = getJavaThreadAt(i);
216             if (o.equals(thread.threadObjectAddress())) {
217                 return thread;
218             }
219         }
220 
221         for (int i = 0; i < getNumberOfThreads(); i++) {
222             JavaThread thread = getJavaThreadAt(i);
223             if (thread.isLockOwned(o))
224                 return thread;
225         }
226         return null;
227     }
228 
229     public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
230         return owningThreadFromMonitor(monitor.owner());

















231     }
232 
233     // refer to Threads::get_pending_threads
234     // Get list of Java threads that are waiting to enter the specified monitor.
235     public List<JavaThread> getPendingThreads(ObjectMonitor monitor) {
236         List<JavaThread> pendingThreads = new ArrayList<>();
237         for (int i = 0; i < getNumberOfThreads(); i++) {
238             JavaThread thread = getJavaThreadAt(i);
239             if (thread.isCompilerThread() || thread.isCodeCacheSweeperThread()) {
240                 continue;
241             }
242             ObjectMonitor pending = thread.getCurrentPendingMonitor();
243             if (monitor.equals(pending)) {
244                 pendingThreads.add(thread);
245             }
246         }
247         return pendingThreads;
248     }
249 
250     // Get list of Java threads that have called Object.wait on the specified monitor.

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