< prev index next >

src/hotspot/share/runtime/threads.cpp

Print this page
@@ -66,10 +66,11 @@
  #include "runtime/java.hpp"
  #include "runtime/javaCalls.hpp"
  #include "runtime/javaThread.inline.hpp"
  #include "runtime/jniHandles.inline.hpp"
  #include "runtime/jniPeriodicChecker.hpp"
+ #include "runtime/lockStack.inline.hpp"
  #include "runtime/monitorDeflationThread.hpp"
  #include "runtime/mutexLocker.hpp"
  #include "runtime/nonJavaThread.hpp"
  #include "runtime/objectMonitor.inline.hpp"
  #include "runtime/osThread.hpp"

@@ -1386,10 +1387,11 @@
  }
  
  
  JavaThread *Threads::owning_thread_from_monitor_owner(ThreadsList * t_list,
                                                        address owner) {
+   assert(!UseFastLocking, "only with stack-locking");
    // null owner means not locked so we can skip the search
    if (owner == nullptr) return nullptr;
  
    for (JavaThread* p : *t_list) {
      // first, see if owner is the address of a Java thread

@@ -1415,13 +1417,33 @@
  
    // cannot assert on lack of success here; see above comment
    return the_owner;
  }
  
+ JavaThread* Threads::owning_thread_from_object(ThreadsList * t_list, oop obj) {
+   assert(UseFastLocking, "Only with fast-locking");
+   for (JavaThread* q : *t_list) {
+     if (q->lock_stack().contains(obj)) {
+       return q;
+     }
+   }
+   return nullptr;
+ }
+ 
  JavaThread* Threads::owning_thread_from_monitor(ThreadsList* t_list, ObjectMonitor* monitor) {
-   address owner = (address)monitor->owner();
-   return owning_thread_from_monitor_owner(t_list, owner);
+   if (UseFastLocking) {
+     if (monitor->is_owner_anonymous()) {
+       return owning_thread_from_object(t_list, monitor->object());
+     } else {
+       Thread* owner = reinterpret_cast<Thread*>(monitor->owner());
+       assert(owner == nullptr || owner->is_Java_thread(), "only JavaThreads own monitors");
+       return reinterpret_cast<JavaThread*>(owner);
+     }
+   } else {
+     address owner = (address)monitor->owner();
+     return owning_thread_from_monitor_owner(t_list, owner);
+   }
  }
  
  class PrintOnClosure : public ThreadClosure {
  private:
    outputStream* _st;
< prev index next >