< prev index next >

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

Print this page
*** 207,31 ***
              thread.oopsDo(oopVisitor);
          }
      }
  
      // refer to Threads::owning_thread_from_monitor_owner
!     public JavaThread owningThreadFromMonitor(Address o) {
          if (o == null) return null;
          for (int i = 0; i < getNumberOfThreads(); i++) {
              JavaThread thread = getJavaThreadAt(i);
              if (o.equals(thread.threadObjectAddress())) {
                  return thread;
              }
          }
- 
-         for (int i = 0; i < getNumberOfThreads(); i++) {
-             JavaThread thread = getJavaThreadAt(i);
-             if (thread.isLockOwned(o))
-                 return thread;
-         }
          return null;
      }
  
-     public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
-         return owningThreadFromMonitor(monitor.owner());
-     }
- 
      // refer to Threads::get_pending_threads
      // Get list of Java threads that are waiting to enter the specified monitor.
      public List<JavaThread> getPendingThreads(ObjectMonitor monitor) {
          List<JavaThread> pendingThreads = new ArrayList<>();
          for (int i = 0; i < getNumberOfThreads(); i++) {
--- 207,32 ---
              thread.oopsDo(oopVisitor);
          }
      }
  
      // refer to Threads::owning_thread_from_monitor_owner
!     public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
+         if (monitor.isOwnedAnonymous()) {
+             OopHandle object = monitor.object();
+             for (int i = 0; i < getNumberOfThreads(); i++) {
+                 JavaThread thread = getJavaThreadAt(i);
+                 if (thread.isLockOwned(object)) {
+                     return thread;
+                 }
+             }
+             throw new InternalError("We should have found a thread that owns the anonymous lock");
+         }
+         Address o = monitor.owner();
          if (o == null) return null;
          for (int i = 0; i < getNumberOfThreads(); i++) {
              JavaThread thread = getJavaThreadAt(i);
              if (o.equals(thread.threadObjectAddress())) {
                  return thread;
              }
          }
          return null;
      }
  
      // refer to Threads::get_pending_threads
      // Get list of Java threads that are waiting to enter the specified monitor.
      public List<JavaThread> getPendingThreads(ObjectMonitor monitor) {
          List<JavaThread> pendingThreads = new ArrayList<>();
          for (int i = 0; i < getNumberOfThreads(); i++) {
< prev index next >