src/share/vm/runtime/thread.cpp

changeset 1137
b9fba36710f2
parent 1104
eca19a8425b5
child 1241
821269eca479
     1.1 --- a/src/share/vm/runtime/thread.cpp	Fri Apr 03 15:59:19 2009 -0700
     1.2 +++ b/src/share/vm/runtime/thread.cpp	Mon Apr 06 15:47:39 2009 -0700
     1.3 @@ -128,7 +128,6 @@
     1.4    debug_only(_allow_allocation_count = 0;)
     1.5    NOT_PRODUCT(_allow_safepoint_count = 0;)
     1.6    CHECK_UNHANDLED_OOPS_ONLY(_gc_locked_out_count = 0;)
     1.7 -  _highest_lock = NULL;
     1.8    _jvmti_env_iteration_count = 0;
     1.9    _vm_operation_started_count = 0;
    1.10    _vm_operation_completed_count = 0;
    1.11 @@ -790,19 +789,6 @@
    1.12  }
    1.13  #endif
    1.14  
    1.15 -bool Thread::lock_is_in_stack(address adr) const {
    1.16 -  assert(Thread::current() == this, "lock_is_in_stack can only be called from current thread");
    1.17 -  // High limit: highest_lock is set during thread execution
    1.18 -  // Low  limit: address of the local variable dummy, rounded to 4K boundary.
    1.19 -  // (The rounding helps finding threads in unsafe mode, even if the particular stack
    1.20 -  // frame has been popped already.  Correct as long as stacks are at least 4K long and aligned.)
    1.21 -  address end = os::current_stack_pointer();
    1.22 -  if (_highest_lock >= adr && adr >= end) return true;
    1.23 -
    1.24 -  return false;
    1.25 -}
    1.26 -
    1.27 -
    1.28  bool Thread::is_in_stack(address adr) const {
    1.29    assert(Thread::current() == this, "is_in_stack can only be called from current thread");
    1.30    address end = os::current_stack_pointer();
    1.31 @@ -818,8 +804,7 @@
    1.32  // should be revisited, and they should be removed if possible.
    1.33  
    1.34  bool Thread::is_lock_owned(address adr) const {
    1.35 -  if (lock_is_in_stack(adr) ) return true;
    1.36 -  return false;
    1.37 +  return (_stack_base >= adr && adr >= (_stack_base - _stack_size));
    1.38  }
    1.39  
    1.40  bool Thread::set_as_starting_thread() {
    1.41 @@ -1664,7 +1649,7 @@
    1.42  }
    1.43  
    1.44  bool JavaThread::is_lock_owned(address adr) const {
    1.45 -  if (lock_is_in_stack(adr)) return true;
    1.46 +  if (Thread::is_lock_owned(adr)) return true;
    1.47  
    1.48    for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
    1.49      if (chunk->contains(adr)) return true;
    1.50 @@ -2443,7 +2428,7 @@
    1.51    if (thread_oop != NULL && java_lang_Thread::is_daemon(thread_oop))  st->print("daemon ");
    1.52    Thread::print_on(st);
    1.53    // print guess for valid stack memory region (assume 4K pages); helps lock debugging
    1.54 -  st->print_cr("[" INTPTR_FORMAT ".." INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12), highest_lock());
    1.55 +  st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
    1.56    if (thread_oop != NULL && JDK_Version::is_gte_jdk15x_version()) {
    1.57      st->print_cr("   java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
    1.58    }
    1.59 @@ -3733,25 +3718,13 @@
    1.60    // heavyweight monitors, then the owner is the stack address of the
    1.61    // Lock Word in the owning Java thread's stack.
    1.62    //
    1.63 -  // We can't use Thread::is_lock_owned() or Thread::lock_is_in_stack() because
    1.64 -  // those routines rely on the "current" stack pointer. That would be our
    1.65 -  // stack pointer which is not relevant to the question. Instead we use the
    1.66 -  // highest lock ever entered by the thread and find the thread that is
    1.67 -  // higher than and closest to our target stack address.
    1.68 -  //
    1.69 -  address    least_diff = 0;
    1.70 -  bool       least_diff_initialized = false;
    1.71    JavaThread* the_owner = NULL;
    1.72    {
    1.73      MutexLockerEx ml(doLock ? Threads_lock : NULL);
    1.74      ALL_JAVA_THREADS(q) {
    1.75 -      address addr = q->highest_lock();
    1.76 -      if (addr == NULL || addr < owner) continue;  // thread has entered no monitors or is too low
    1.77 -      address diff = (address)(addr - owner);
    1.78 -      if (!least_diff_initialized || diff < least_diff) {
    1.79 -        least_diff_initialized = true;
    1.80 -        least_diff = diff;
    1.81 +      if (q->is_lock_owned(owner)) {
    1.82          the_owner = q;
    1.83 +        break;
    1.84        }
    1.85      }
    1.86    }

mercurial