< prev index next >

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

Print this page

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

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

















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

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