wiki:JavaDtrace
Last modified 10 years ago Last modified on 02/08/09 20:19:29

DTrace and Java 6.0

Requarments:

  • Solaris >= 10
  • Sun JVM >= 1.6 You have to use java installed from java.sun.com. The JVM included into standard Solaris distribution do not include DTrace hotspot provider. ( don't ask ). Run following command to test:
    # dtrace  -ln 'hotspot*:::'
    

Enable DTrace on runnign system:

jinfo -flag +ExtendedDTraceProbes <jvm pid>

Disable DTrace:

jinfo -flag -ExtendedDTraceProbes <jvm pid>

Simples

trace method entry:

#!/usr/sbin/dtrace -s

hotspot$1:::method-entry
/ copyinstr(arg1,arg2) == "diskCacheV111/util/PnfsId" /
{
        printf("Method called: %s
", copyinstr(arg3,arg4) );
}

to run:

dtrace -s method.d <jvm pid>

Object allocation:

#!/usr/sbin/dtrace -s

hotspot$1:::object-alloc
{

  printf("allocating object %s, %d bytes
", copyinstr(arg1,arg2), args[3]);

}

Profiling

#!/usr/sbin/dtrace -s


hotspot$1:::method-entry
/ copyinstr(arg1,arg2) == $2 /
{
        self->timestamp = timestamp;
}


hotspot$1:::method-return
/ copyinstr(arg1,arg2) == $2 /
{
        printf("Method called: %s %d ns
", copyinstr(arg3,arg4), timestamp - self->timestamp );
}

where $1 jvm pid, $2 class to profile

Real issues

Here is a simple dtrace script to trace source of non closed pipes in dCache prioir version 1.7.0-42 ( beta-1.8.0-15 ):

#!/usr/sbin/dtrace -s


syscall::pipe:entry
/ pid == $1 /
{
   ustack(50, 500);
}

Output:

dcache44# /tmp/pipe.d 24844
dtrace: script '/tmp/pipe.d' matched 1 probe
dtrace: 4 jstack()/ustack() string table overflows
CPU     ID                    FUNCTION:NAME
  1  55399                       pipe:entry
              libc.so.1`pipe+0x7
              java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I
              java/lang/UNIXProcess.<init>([B[BI[BI[BZ)V
              java/lang/ProcessImpl.start([Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Z)Ljava/lang/Process;
              java/lang/ProcessBuilder.start()Ljava/lang/Process;
              java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
              java/lang/Runtime.exec(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/
              0xfb202d67
              0xfb202d67
              0xfb202ecd
              0xfb2033a9
              0xfb2033a9
              0xfb200202
              libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x1a3
              libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v2468_v_+0x27
              libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x2f
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nLKlassHandle_nMsymbolHandle_4pnRJavaCallArguments_pnGThread__v_+0xc1
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nGHandle_nLKlassHandle_nMsymbolHandle_5pnGThread__v_+0x7e
              libjvm.so`__1cMthread_entry6FpnKJavaThread_pnGThread__v_+0xd2
              libjvm.so`__1cKJavaThreadRthread_main_inner6M_v_+0x4c
              libjvm.so`__1cKJavaThreadDrun6M_v_+0x196
              libjvm.so`java_start+0xd3
              libc.so.1`_thr_setup+0x52
              libc.so.1`_lwp_start

  1  55399                       pipe:entry
              libc.so.1`pipe+0x7
              java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I
              java/lang/UNIXProcess.<init>([B[BI[BI[BZ)V
              java/lang/ProcessImpl.start([Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Z)Ljava/lang/Process;
              java/lang/ProcessBuilder.start()Ljava/lang/Process;
              java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
              java/lang/Runtime.exec(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)java
              0xfb202d67
              0xfb202d67
              0xfb202ecd
              0xfb2033a9
              0xfb2033a9
              0xfb200202
              libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x1a3
              libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v2468_v_+0x27
              libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x2f
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nLKlassHandle_nMsymbolHandle_4pnRJavaCallArguments_pnGThread__v_+0xc1
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nGHandle_nLKlassHandle_nMsymbolHandle_5pnGThread__v_+0x7e
              libjvm.so`__1cMthread_entry6FpnKJavaThread_pnGThread__v_+0xd2
              libjvm.so`__1cKJavaThreadRthread_main_inner6M_v_+0x4c
              libjvm.so`__1cKJavaThreadDrun6M_v_+0x196
              libjvm.so`java_start+0xd3
              libc.so.1`_thr_setup+0x52
              libc.so.1`_lwp_start

  1  55399                       pipe:entry
              libc.so.1`pipe+0x7
              java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I
              java/lang/UNIXProcess.<init>([B[BI[BI[BZ)V
              java/lang/ProcessImpl.start([Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Z)Ljava/lang/Process;
              java/lang/ProcessBuilder.start()Ljava/lang/Process;
              java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
              java/lang/Runtime.exec(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)java
              0xfb202d67
              0xfb202d67
              0xfb202ecd
              0xfb2033a9
              0xfb2033a9
              0xfb200202
              libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x1a3
              libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v2468_v_+0x27
              libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x2f
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nLKlassHandle_nMsymbolHandle_4pnRJavaCallArguments_pnGThread__v_+0xc1
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nGHandle_nLKlassHandle_nMsymbolHandle_5pnGThread__v_+0x7e
              libjvm.so`__1cMthread_entry6FpnKJavaThread_pnGThread__v_+0xd2
              libjvm.so`__1cKJavaThreadRthread_main_inner6M_v_+0x4c
              libjvm.so`__1cKJavaThreadDrun6M_v_+0x196
              libjvm.so`java_start+0xd3
              libc.so.1`_thr_setup+0x52
              libc.so.1`_lwp_start

  1  55399                       pipe:entry
              libc.so.1`pipe+0x7
              java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I
              java/lang/UNIXProcess.<init>([B[BI[BI[BZ)V
              java/lang/ProcessImpl.start([Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Z)Ljava/lang/Process;
              java/lang/ProcessBuilder.start()Ljava/lang/Process;
              java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
              java/lang/Runtime.exec(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)java
              0xfb202d67
              0xfb202d67
              0xfb202ecd
              0xfb2033a9
              0xfb2033a9
              0xfb200202
              libjvm.so`__1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x1a3
              libjvm.so`__1cCosUos_exception_wrapper6FpFpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v2468_v_+0x27
              libjvm.so`__1cJJavaCallsEcall6FpnJJavaValue_nMmethodHandle_pnRJavaCallArguments_pnGThread__v_+0x2f
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nLKlassHandle_nMsymbolHandle_4pnRJavaCallArguments_pnGThread__v_+0xc1
              libjvm.so`__1cJJavaCallsMcall_virtual6FpnJJavaValue_nGHandle_nLKlassHandle_nMsymbolHandle_5pnGThread__v_+0x7e
              libjvm.so`__1cMthread_entry6FpnKJavaThread_pnGThread__v_+0xd2
              libjvm.so`__1cKJavaThreadRthread_main_inner6M_v_+0x4c
              libjvm.so`__1cKJavaThreadDrun6M_v_+0x196
              libjvm.so`java_start+0xd3
              libc.so.1`_thr_setup+0x52
              libc.so.1`_lwp_start

Links:

http://java.sun.com/javase/6/docs/technotes/guides/vm/dtrace.html Java Built in probes

http://docs.sun.com/app/docs/doc/817-6223 Sun Dynamic Traceing Guide

http://www.sun.com/software/solaris/howtoguides/dtracehowto.jsp DTrace HOWTO


Last update: Sun Nov 18 23:29:27 2018