Shark and Java on Snow Leopard

February 24th, 2010

Filed under: Mac Development | Be the first to comment!

In my research for the Shark chapter of the new edition of the Xcode book, I had a difficult time getting Shark to profile a Java program in Snow Leopard. I’m writing this post to spare others my pain.

For Java profiling to work with Shark, you must link Shark with the Java virtual machine. To link Shark with the Java virtual machine, you must add the following flag to the virtual machine:

-agentlib:Shark

Profiling with Shark on Snow Leopard is complicated by the fact that Snow Leopard initially uses the 64-bit version of the Java virtual machine. Shark does not work with 64-bit Java applications. You must use the 32-bit version of the Java virtual machine to profile with Shark. Add the following flag to the virtual machine

-d32

If you’re using Xcode 3.2 to write your Java applications, you must add the flags to the build.xml file Xcode includes when you create a Java project. Search build.xml for the </java> tag and add the flags before that tag.

<jvmarg value="-d32"/>
<jvmarg value="-agentlib:Shark"/>

At this point you’ll be able to use the Java Time Profile and Java Call Trace profiles. You won’t be able to use the Java Alloc Trace profile because Snow Leopard uses JVM 1.6, and the Java Alloc Trace profile doesn’t work with it. You will have to install JVM 1.5 to use Java Alloc Trace.

Tags: , ,


Leave a Reply

Your email address will not be published. Required fields are marked *