title: Profiling Java applications with DTrace on macOS
body: <p>I am trying to profile a Java application using DTrace on macOS Sierra 10.12. I am using the JDK8:</p>
  
  <pre><code>⋊&gt; ~ 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)
  
  ⋊&gt; ~ echo $JAVA_HOME
  /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
  </code></pre>
  
  <p>My ultimate goal is to trace all Java method entries and exits for specific packages.</p>
  
  <p><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/vm/dtrace.html" rel="noreferrer">DTrace Probes in HotSpot VM</a> and <a href="https://wiki.openjdk.java.net/display/MacOSXPort/Mac+OS+X+Port+Using+HotSpot+DTrace+Probes" rel="noreferrer">Mac OS X Port Using HotSpot DTrace Probes</a> seem to suggest that this should in fact be supported on macOS. However, even when my Java application is running, there are no <code>hotspot</code> probes available and <code>jstack()</code> appears to fail:</p>
  
  <pre><code>⋊&gt; ~ pgrep java
  24564
  
  ⋊&gt; ~ 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
  
  ⋊&gt; ~ 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
  …
  </code></pre>
  
  <p>Providing the path to <code>libjvm.dylib</code> to the <code>dtrace</code> command does not seem to help:</p>
  
  <pre><code>⋊&gt; ~ 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
  
  ⋊&gt; ~ 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
  </code></pre>
  
  <p>So what am I missing?
  How do I profile a Java application using the DTrace facilities?</p>