0 Replies Latest reply: Feb 26, 2014 1:30 AM by Alessandro I RSS

How to match the JVM thread id with Linux TOP

Alessandro I Newbie
Currently Being Moderated

For learning purposes I am trying to correlate the native thread id from linux os with a java thread dump taken with jstack utility.

The problem is I cannot find any matching nid into the dump file. I have tried with 2 different JVMs:

  1. JRockit only prints the following header informations

    "RMI TCP Accept-7099" id=17 idx=0x5c tid=6594 prio=5 alive, in native, daemon

  2. While on another standalone Sun JVM process on the same machine I have

    RMI TCP Accept-0" daemon prio=10 tid=0x8f359000 nid=0x16b5 runnable [0x884ad000]

As far as I know the only way to match the thread from a TOP command is to use the nid
Well, in JRockit I'd like to know how to achieve the same goal as I can't see that header, but even with the Sun JVM, if I try to lookup the thread ID in an hexadecimal value I don't always find it, which makes me think the approach is not completely correct.

Here is what I am doing:

  1. take a dump of the java processI am interested.

    jstack 6567 >> /tmp/jstack.example

  2. then I take a look with TOP at which thread is taking majority of the CPU.

    top -Hu myUsr

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    7324 oracle 20 0 2558m 1.4g 3292 S 1 17.6 0:10.21 RMI TCP Connect
    6553 oracle 24 4 1134m 72m 1912 S 1 0.9 0:57.22 (VM Periodic Ta
    6587 oracle 20 0 2558m 1.4g 3292 S 0 17.6 0:05.37 VM JFR Buffer T
    6603 oracle 20 0 2558m 1.4g 3292 S 0 17.6 0:14.87 ExecuteThread: \

  3. I am interested on the first line so I convert the PID id in an hexadecimal value using

    printf "%x\n" 7324

The output is 1c9c

Now if I look at the dump file I cannot find any matching ID. Am I doing any thing wrong here? Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points