< prev index next >

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

Print this page

192             JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
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.
251     public List<JavaThread> getWaitingThreads(ObjectMonitor monitor) {
252         List<JavaThread> pendingThreads = new ArrayList<>();

192             JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
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(ObjectMonitor monitor) {
213         if (monitor.isOwnedAnonymous()) {
214             OopHandle object = monitor.object();
215             for (int i = 0; i < getNumberOfThreads(); i++) {
216                 JavaThread thread = getJavaThreadAt(i);
217                 if (thread.isLockOwned(object)) {
218                     return thread;
219                 }
220             }
221             throw new InternalError("We should have found a thread that owns the anonymous lock");
222         }
223         Address o = monitor.owner();
224         if (o == null) return null;
225         for (int i = 0; i < getNumberOfThreads(); i++) {
226             JavaThread thread = getJavaThreadAt(i);
227             if (o.equals(thread.threadObjectAddress())) {
228                 return thread;
229             }
230         }






231         return null;
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.
252     public List<JavaThread> getWaitingThreads(ObjectMonitor monitor) {
253         List<JavaThread> pendingThreads = new ArrayList<>();
< prev index next >