< prev index next >

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

Print this page
@@ -210,32 +210,24 @@
              JavaThread thread = threads.getJavaThreadAt(i);
              thread.oopsDo(oopVisitor);
          }
      }
  
-     // refer to Threads::owning_thread_from_monitor_owner
-     public JavaThread owningThreadFromMonitor(Address o) {
-         assert(VM.getVM().getCommandLineFlag("LockingMode").getInt() != LockingMode.getLightweight());
+     private 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())) {
+             if (o.equals(thread.getLockId())) {
                  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) {
-         if (VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLightweight()) {
-             if (monitor.isOwnedAnonymous()) {
+         if (monitor.isOwnedAnonymous()) {
+             if (VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLightweight()) {
                  OopHandle object = monitor.object();
                  for (int i = 0; i < getNumberOfThreads(); i++) {
                      JavaThread thread = getJavaThreadAt(i);
                      if (thread.isLockOwned(object)) {
                          return thread;

@@ -244,15 +236,20 @@
                  // We should have found the owner, however, as the VM could be in any state, including the middle
                  // of performing GC, it is not always possible to do so. Just return null if we can't locate it.
                  System.out.println("Warning: We failed to find a thread that owns an anonymous lock. This is likely");
                  System.out.println("due to the JVM currently running a GC. Locking information may not be accurate.");
                  return null;
+             } else {
+                 assert(VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLegacy());
+                 Address o = (Address)monitor.stackLocker();
+                 for (int i = 0; i < getNumberOfThreads(); i++) {
+                     JavaThread thread = getJavaThreadAt(i);
+                     if (thread.isLockOwned(o))
+                         return thread;
+                 }
+                 return null;
              }
-             // Owner can only be threads at this point.
-             Address o = monitor.owner();
-             if (o == null) return null;
-             return new JavaThread(o);
          } else {
              return owningThreadFromMonitor(monitor.owner());
          }
      }
  
< prev index next >