How to install HotSpot Disassembler (hsdis) on macOS

Ondrej Kvasnovsky
4 min readJan 13, 2025

--

The simplest way to install hsdis is using Homebrew with Capstone as the backend.

Before you start

For Apple Silicon

If running macOS on Apple Silicon, make sure you have arm64 homebrew installed. If not, remove and install homebrew.

# Remove Intel Homebrew first
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

# Install ARM64 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Otherwise, you might see errors like:

ERROR: Build failed for target 'build-hsdis' in configuration 
'macosx-aarch64-server-release' (exit code 2)

Installation steps

First, install Capstone using Homebrew:

brew install capstone

Clone the OpenJDK, find your Java version, and checkout the proper tag:

➜ git clone git@github.com:openjdk/jdk.git


➜ java -version
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)


➜ git tag | grep jdk-21+2
jdk-21+2
jdk-21+20
jdk-21+21
jdk-21+22
jdk-21+23
jdk-21+24
jdk-21+25
jdk-21+26
jdk-21+27
jdk-21+28
jdk-21+29

➜ git checkout jdk-21+2

Then, you’ll need to go to your JDK directory and run the configure command to enable hsdis with Capstone:

bash configure \
--with-hsdis=capstone \
--with-capstone=/opt/homebrew \
--with-boot-jdk=$JAVA_HOME \
--disable-warnings-as-errors

After configuration, build hsdis:

➜ make build-hsdis

Building target 'build-hsdis' in configuration 'macosx-aarch64-server-release'
Finished building target 'build-hsdis' in configuration 'macosx-aarch64-server-release'

# Verify the build is there, search for "support/hsdis/libhsdis.dylib"
➜ ls -1 build/macosx-aarch64-server-release/support/hsdis/
BUILD_HSDIS.d
BUILD_HSDIS.d.old
BUILD_HSDIS_link.cmdline
BUILD_HSDIS_link.log
_build-info.marker
hsdis-aarch64.dylib
hsdis-capstone.d
hsdis-capstone.d.targets
hsdis-capstone.o
hsdis-capstone.o.cmdline
hsdis-capstone.o.log
libhsdis.comp.vardeps
libhsdis.dylib. <------- hsdis library
libhsdis.dylib.dSYM
libhsdis.vardeps

Now, we should be able to install hsdis:

➜ make install-hsdis

If it fails, like its failing for me, I found we can simply copy/paste the library to the JDK folder:

➜ sudo cp build/macosx-aarch64-server-release/support/hsdis/libhsdis.dylib $JAVA_HOME/lib/server/
➜ sudo cp build/macosx-aarch64-server-release/support/hsdis/hsdis-aarch64.dylib $JAVA_HOME/lib/server/

➜ sudo chmod 755 $JAVA_HOME/lib/server/libhsdis.dylib
➜ sudo chmod 755 $JAVA_HOME/lib/server/hsdis-aarch64.dylib

Once installed, you can verify it’s working by running a Java program:

# Create Java file
➜ cat << 'EOF' > PerformanceExample.java
public class PerformanceExample {
private static final int LOOPS = 1000_000;
private static final int MULTIPLIER = 7;

public long test() {
long sum = 0;
for (int i = 0; i < LOOPS; i++) {
// Constants will be propagated
sum += i * MULTIPLIER;
}
return sum;
}

public static void main(String[] args) {
new PerformanceExample().test();
}
}
EOF

# Compile it
➜ javac PerformanceExample.java

# Run it
➜ java -XX:+PrintCompilation \
-XX:+UnlockDiagnosticVMOptions \
-XX:+PrintInlining \
-XX:CompileCommand=print,*PerformanceExample.test \
PerformanceExample

Failing install

The make install-hsdis is actually failing for me, if you find how to make it work, please let me know. Here is what is going on:

➜ make install-hsdis
Building target 'install-hsdis' in configuration 'macosx-aarch64-server-release'
Compiling up to 8 files for BUILD_TOOLS_LANGTOOLS
Compiling up to 1 files for BUILD_TOOLS_HOTSPOT
Creating hotspot/variant-server/tools/adlc/adlc from 13 file(s)
Compiling 9 properties into resource bundles for jdk.jshell
Generating classes for compiler.properties launcher.properties
Compiling 17 properties into resource bundles for jdk.javadoc
Compiling 15 properties into resource bundles for jdk.jdeps
Compiling up to 2 files for BUILD_JVMTI_TOOLS
Compiling 20 properties into resource bundles for jdk.compiler
Compiling up to 349 files for BUILD_jdk.compiler.interim
Compiling up to 245 files for BUILD_jdk.javadoc.interim
Compiling up to 17 files for BUILD_JAVAC_SERVER
Compiling up to 127 files for BUILD_java.compiler.interim
warning: unknown enum constant Feature.UNNAMED_CLASSES
error: warnings found and -Werror specified
Creating support/modules_libs/java.base/server/libjvm.dylib from 1094 file(s)
1 error
1 warning
make[3]: *** [/Users/ondrej/hsdis-build/jdk/build/macosx-aarch64-server-release/buildtools/interim_langtools_modules/java.compiler.interim/_the.BUILD_java.compiler.interim_batch] Error 1
make[2]: *** [interim-langtools] Error 2
make[2]: *** Waiting for unfinished jobs....
/Users/ondrej/hsdis-build/jdk/src/hotspot/share/runtime/notificationThread.cpp:69:15: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
69 | while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... more lines ....
/Users/ondrej/hsdis-build/jdk/src/hotspot/share/runtime/serviceThread.cpp:114:15: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
114 | while (((sensors_changed = (!UseNotificationThread && LowMemoryDetector::has_pending_requests())) |
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ||
115 | (has_jvmti_events = _jvmti_service_queue.has_events()) |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/ondrej/hsdis-build/jdk/src/hotspot/share/runtime/serviceThread.cpp:114:15: note: cast one or both operands to int to silence this warning
13 warnings generated.
ERROR: Build failed for target 'install-hsdis' in configuration 'macosx-aarch64-server-release' (exit code 2)
=== Output from failing command(s) repeated here ===
* For target buildtools_interim_langtools_modules_java.compiler.interim__the.BUILD_java.compiler.interim_batch:
warning: unknown enum constant Feature.UNNAMED_CLASSES
error: warnings found and -Werror specified
1 error
1 warning
* All command lines available in /Users/ondrej/hsdis-build/jdk/build/macosx-aarch64-server-release/make-support/failure-logs.
=== End of repeated output ===
No indication of failed target found.
HELP: Try searching the build log for '] Error'.
HELP: Run 'make doctor' to diagnose build problems.
make[1]: *** [main] Error 2
make: *** [install-hsdis] Error 2

Resources

--

--

No responses yet