While reading Understanding the JVM – Advanced Features and Best Practices, Second Edition (in Chinese) recently, there is a guide in chapter one to build JVM from source. It is based on OpenJDK7, which only works when using a Java6/Java7 VM as build bootstrap. Java8 bootstrap has more strict code checks and will finally fail the build. So, I just switched to a more recent OpenJDK8 code. The file name is openjdk-8u40-src-b25-10_feb_2015.zip
.
The code provides a better build experience, and compiles on my Linux box almost out of box. But remember, do not use a gcc compiler >= gcc-6. It defaults to C++14 and breaks the build. On macOS, the build scripts seem only support gcc. Actually, a clang compiler is required to build the objc code.
1. So the first step after downloading and unzipping the code, modify the configure script:
Comment out the lines(2 appearances):
2. Now install freetype and run configure:
A slowdebug
build disables optimization and helps a lot when debugging. The summary output looks like:
3. Apply the following patch to fix build errors. Partially picked from an official OpenJDK10 changeset:
4. Start the build:
Lots of warnings, but the build should finish successfully:
5. Debugging with lldb:
The output binary lie in openjdk/build/macosx-x86_64-normal-server-slowdebug/jdk
. The output of java -version
:
Never used lldb
before, seems to be compatible with gdb
:
Hi there, I use the way of how to debug openjdk. It Work, but there is a problem! I can’t step into any method I want check out. For example, JLI_Launch. Is there any other way for me to keep going. Thx.