< prev index next >

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

Print this page
@@ -209,10 +209,11 @@
          }
      }
  
      // refer to Threads::owning_thread_from_monitor_owner
      public JavaThread owningThreadFromMonitor(Address o) {
+         assert(VM.getVM().getCommandLineFlag("LockingMode").getInt() != LockingMode.getLightweight());
          if (o == null) return null;
          for (int i = 0; i < getNumberOfThreads(); i++) {
              JavaThread thread = getJavaThreadAt(i);
              if (o.equals(thread.threadObjectAddress())) {
                  return thread;

@@ -226,11 +227,28 @@
          }
          return null;
      }
  
      public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
-         return owningThreadFromMonitor(monitor.owner());
+         if (VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLightweight()) {
+             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");
+             }
+             // 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());
+         }
      }
  
      // 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) {
< prev index next >