Installing Eclipse Memory Analyzer on My Mac
While digging into some potential memory issues in a Lucee container, I found myself needing to analyze a JVM heap dump. A little research indicated that Eclipse Memory Analyzer (MAT) was the way to go. But I had to jump through a few hoops to get it working on my M2 Mac.
I went to the MAT download page and installed the Mac OSX (Mac/Cocoa/AArch64) version, and then read the documentation that said:
The minimum Java version required to run the stand-alone version of Memory Analyzer is Java 17.
Back in the terminal, I ran java -version
only to discover that I was... very far behind, running version 11.0.11.
jabba Updates
I wrote a few years back about how I use jabba and jEnv to manage Java versions, but it's been a while since I've needed to use them. When I went to use jabba to download a newer version of Java, I found that the project isn't being actively maintained, but that there is an active fork: https://github.com/Jabba-Team/jabba
Updating from the old project to the latest version of the fork (0.14.0) was surprisingly, refreshingly easy:
export JABBA_VERSION=0.14.0
curl -sL https://github.com/Jabba-Team/jabba/raw/main/install.sh | bash && . ~/.jabba/jabba.sh
With jabba set, I moved on to updating the version of Java I was using.
Java Updates
I initially tried installing and using openjdk@1.17.0
, only to encounter a strange error: "The JVM shared library does not contain the JNI_CreateJavaVM symbol".
Some searching let me to this discussion, which indicated that the actual JRE distribution could be the culprit. Sure enough, using Eclipse Temurin resolved the issue, as I lay out below.
I installed Java 17 with jabba:
jabba install temurin@17.0.12
Set it up as my global Java version with jEnv:
jenv add /Users/me/.jabba/jdk/temurin@17.0.12/Contents/Home/
jenv global 17.0.12
Correcting the MAT's JVM Location
Just updating Java wasn't enough to resolve the "JNI_CreateJavaVM" - there was one more issue.
After a little more digging, I found out that I needed to point Memory Analyzer to the correct JVM location (thanks to this post)
I did this by editting /Applications/MemoryAnalyzer.app/Contents/Info.plist
. In the section below, I needed to add the -vm
key-value pair, pointing to where Java was actually installed.
<key>Eclipse</key>
<array>
<string>-keyring</string>
<string>~/.eclipse_keyring</string>
<string>-vm</string>
<string>/Users/matthew/.jabba/jdk/temurin@17.0.12/Contents/Home/bin/java</string>
</array>
Once that was set, I was finally able to use MAT to analyze the heap dump. And I will say - it's a very powerful, very impressive piece of software. Worth the hassle I went through installing it, in order to have it available to use when needed.