hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java
changeset 2526 39a58a50be35
parent 1 489c9b5090e2
child 3261 c7d5aae8d3f7
equal deleted inserted replaced
2364:7c9f46e9d37c 2526:39a58a50be35
   162             if (o.equals(thread.threadObjectAddress())) {
   162             if (o.equals(thread.threadObjectAddress())) {
   163                 return thread;
   163                 return thread;
   164             }
   164             }
   165         }
   165         }
   166 
   166 
   167         long leastDiff = 0;
   167         for (JavaThread thread = first(); thread != null; thread = thread.next()) {
   168         boolean leastDiffInitialized = false;
   168           if (thread.isLockOwned(o))
   169         JavaThread theOwner = null;
   169             return thread;
   170         for (JavaThread thread = first(); thread != null; thread = thread.next()) {
   170         }
   171             Address addr = thread.highestLock();
   171         return null;
   172             if (addr == null || addr.lessThan(o)) continue;
       
   173             long diff = addr.minus(o);
       
   174             if (!leastDiffInitialized || diff < leastDiff) {
       
   175                 leastDiffInitialized = true;
       
   176                 leastDiff = diff;
       
   177                 theOwner = thread;
       
   178             }
       
   179         }
       
   180         return theOwner;
       
   181     }
   172     }
   182 
   173 
   183     public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
   174     public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
   184         return owningThreadFromMonitor(monitor.owner());
   175         return owningThreadFromMonitor(monitor.owner());
   185     }
   176     }