为什么jstack dump 出来的线程的线程为什么都是000结尾的。

xgj1988 2015-08-06
比如dump线程后。
"Thread-0" prio=6 tid=0x000000000c17a000 nid=0x2fc4 waiting for monitor entry [[color=red]0x000000000cfbf000[/color]]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at Test$1.run(Test.java:12)
        - waiting to lock <0x00000007d5fccc50> (a java.lang.Object)


0x000000000cfbf000这个是线程的起始地址。而且发现所有线程都是000结尾。然而。我用hsdb查看线程线程信息。得到的结果如下。
Thread Info: Thread-0
State: BLOCKED
Stack in use by Java:[color=red] 0x000000000cfbf2a0 .. 0x000000000cfbf300[/color]
Base of Stack: null
Last_Java_SP: 0x000000000cfbf2a0
Last_Java_FP: 0x000000000cfbf2f0
Last_Java_PC: null


为什么这里的起始地址又是 0x000000000cfbf2a0呢。求解释!
liuxinglanyue 2015-08-06

起始地址是 0x000000000cfbf2a0

 

但是print的时候会进行处理,代码见 thread.cpp:

 

// Called by Threads::print() for VM_PrintThreads operation
void JavaThread::print_on(outputStream *st) const {
  st->print("\"%s\" ", get_thread_name());
  oop thread_oop = threadObj();
  if (thread_oop != NULL) {
    st->print("#" INT64_FORMAT " ", java_lang_Thread::thread_id(thread_oop));
    if (java_lang_Thread::is_daemon(thread_oop))  st->print("daemon ");
    st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
  }
  Thread::print_on(st);
  // print guess for valid stack memory region (assume 4K pages); helps lock debugging
  st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
  if (thread_oop != NULL) {
    st->print_cr("   java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
  }
#ifndef PRODUCT
  print_thread_state_on(st);
  _safepoint_state->print_on(st);
#endif // PRODUCT
}

 

 

last_Java_sp()  得到的就是 0x000000000cfbf2a0 ,再经过位运算后 就是 0x000000000cfbf000

217838240 & ~((1<<12) - 1)

 

xgj1988 2015-08-07
liuxinglanyue  3Q
Global site tag (gtag.js) - Google Analytics