I am trying to profile a Java application using DTrace on macOS Sierra 10.12. I am using the JDK8:
⋊> ~ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
⋊> ~ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
My ultimate goal is to trace all Java method entries and exits for specific packages.
DTrace Probes in HotSpot VM and Mac OS X Port Using HotSpot DTrace Probes seem to suggest that this should in fact be supported on macOS. However, even when my Java application is running, there are no hotspot
probes available and jstack()
appears to fail:
⋊> ~ pgrep java
24564
⋊> ~ sudo dtrace -ln 'hotspot*:::'
dtrace: system integrity protection is on, some features will not be available
ID PROVIDER MODULE FUNCTION NAME
dtrace: failed to match hotspot*:::: No probe matches description
⋊> ~ sudo dtrace -n 'syscall::read:entry /execname == "java"/ { jstack(); }'
dtrace: system integrity protection is on, some features will not be available
dtrace: description 'syscall::read:entry ' matched 1 probe
dtrace: error on enabled probe ID 1 (ID 153: syscall::read:entry): invalid address (0xe2e3275e) in action #1
dtrace: error on enabled probe ID 1 (ID 153: syscall::read:entry): invalid address (0xe2e3275e) in action #1
dtrace: error on enabled probe ID 1 (ID 153: syscall::read:entry): invalid address (0xe2e3275e) in action #1
…
Providing the path to libjvm.dylib
to the dtrace
command does not seem to help:
⋊> ~ ll "$JAVA_HOME/jre/lib/server/"
total 31616
-rw-rw-r-- 1 root wheel 1.4K Jun 22 15:02 Xusage.txt
-rwxrwxr-x 1 root wheel 15K Jun 22 15:01 libjsig.dylib
-rwxrwxr-x 1 root wheel 15M Jun 22 15:02 libjvm.dylib
⋊> ~ sudo dtrace -L "$JAVA_HOME/jre/lib/server/" -ln 'hotspot*:::'
dtrace: system integrity protection is on, some features will not be available
ID PROVIDER MODULE FUNCTION NAME
dtrace: failed to match hotspot*:::: No probe matches description
So what am I missing? How do I profile a Java application using the DTrace facilities?