前置
环境依赖:
- 安装一个 JDK21
- Autogen
- Autoconf
- Python 2
- Libffi
- Freetype
- Ccache
- XCode Version 14.3.1 (14E300c) macOS Version 13.4.1 (22F82)
- Binutils
- texinfo
获得源码
git clone --recurse-submodules --depth 1 https://github.com/openjdk/jdk.git
libffi
git clone --depth 1 git@github.com:libffi/libffi.git
cd libffi
./autogen.sh && \
python ./generate-darwin-source-and-headers.py && \
./configure --enable-debug --enable-purify-safety --prefix=${LOCAL_DIR} && \
make -j4 && make install
生成Makefile
Zero Slowdebug
make clean ; make dist-clean;
sh ./configure --enable-dtrace \
--with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/ \
--with-toolchain-path=/Applications/Xcode.app/Contents/Developer/usr/bin \
--disable-warnings-as-errors \
--with-boot-jdk-jvmargs="-XX:+UseG1GC -Xms8G -Xmx8G" \
--with-toolchain-type=clang \
--with-debug-level=slowdebug \
--with-native-debug-symbols=internal \
--with-jvm-variants=zero \
--with-hsdis=binutils \
--with-binutils-src=/Volumes/sm/github/jdk/jdkbuild/src/utils/hsdis/binutils-2.42 \
--with-target-bits=64 \
--with-libffi=/opt/homebrew/brew/opt/libffi \
--with-num-cores=12 \
--with-jobs=12
Server & Client Fastdebug
make clean ; make dist-clean;
sh ./configure --enable-dtrace \
--with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home/ \
--with-toolchain-path=/Applications/Xcode.app/Contents/Developer/usr/bin \
--disable-warnings-as-errors \
--with-boot-jdk-jvmargs="-XX:+UseG1GC -Xms8G -Xmx8G" \
--with-toolchain-type=clang \
--with-debug-level=slowdebug \
--with-native-debug-symbols=internal \
--with-jvm-variants=server,client \
--with-hsdis=binutils \
--with-binutils-src=/Volumes/sm/github/jdk/jdkbuild/src/utils/hsdis/binutils-2.37 \
--with-target-bits=64 \
--with-libffi=/Users/yakir/local/brew/opt/libffi \
--with-num-cores=12 \
--with-jobs=12
--enable-ccache
选项看着加😁
Zero Slowdebug configure
成功输出
====================================================
A new configuration has been successfully created in
/Volumes/sm/github/jdk/jdkbuild/build/macosx-aarch64-zero-slowdebug
using configure arguments '--enable-dtrace --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home/ --with-toolchain-path=/Applications/Xcode.app/Contents/Developer/usr/bin --disable-warnings-as-errors --with-boot-jdk-jvmargs='-XX:+UseG1GC -Xms8G -Xmx8G' --with-toolchain-type=clang --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-jvm-variants=zero --with-hsdis=binutils --with-binutils-src=/Volumes/sm/github/jdk/jdkbuild/src/utils/hsdis/binutils-2.42 --with-target-bits=64 --with-libffi=/opt/homebrew/opt/libffi/ --with-num-cores=14 --with-jobs=14'.
Configuration summary:
* Name: macosx-aarch64-zero-slowdebug
* Debug level: slowdebug
* HS debug level: debug
* JVM variants: zero
* JVM features: zero: 'cds dtrace epsilongc g1gc jni-check jvmti management parallelgc serialgc services shenandoahgc vm-structs zero'
* OpenJDK target: OS: macosx, CPU architecture: aarch64, address length: 64
* Version string: 24-internal-adhoc.yakir.jdkbuild (24-internal)
* Source date: 1719382331 (2024-06-26T06:12:11Z)
Tools summary:
* Boot JDK: java version "22.0.1" 2024-04-16 Java(TM) SE Runtime Environment (build 22.0.1+8-16) Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 15.4)
* Sysroot: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
* C Compiler: Version 15.0.0 (at /usr/bin/clang)
* C++ Compiler: Version 15.0.0 (at /usr/bin/clang++)
Build performance summary:
* Build jobs: 14
* Memory limit: 36864 MB
The following warnings were produced. Repeated here for convenience:
WARNING: pandoc is version 3.2.1, not the recommended version 2.19.2
Server & Client Fastdebug configure
成功输出
====================================================
A new configuration has been successfully created in
/Volumes/sm/github/jdk/jdkbuild/build/macosx-x86_64-serverANDclient-fastdebug
using configure arguments '--enable-dtrace --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/ --with-toolchain-path=/Applications/Xcode.app/Contents/Developer/usr/bin --disable-warnings-as-errors --with-boot-jdk-jvmargs='-XX:+UseG1GC -Xms8G -Xmx8G' --with-toolchain-type=clang --with-debug-level=fastdebug --with-native-debug-symbols=internal --with-jvm-variants=server,client --with-target-bits=64 --with-libffi=/Users/yakir/local/brew/opt/libffi --with-num-cores=12 --with-jobs=12'.
Configuration summary:
* Name: macosx-x86_64-serverANDclient-fastdebug
* Debug level: fastdebug
* HS debug level: fastdebug
* JVM variants: server client
* JVM features: server: 'cds compiler1 compiler2 dtrace epsilongc g1gc jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc' client: 'cds compiler1 dtrace epsilongc g1gc jfr jni-check jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc'
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 18-internal+0-adhoc.yakir.jdkbuild (18-internal)
Tools summary:
* Boot JDK: java version "16.0.2" 2021-07-20 Java(TM) SE Runtime Environment (build 16.0.2+7-67) Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 12.5.1)
* C Compiler: Version 12.0.5 (at /usr/bin/clang)
* C++ Compiler: Version 12.0.5 (at /usr/bin/clang++)
Build performance summary:
* Build jobs: 12
* Memory limit: 32768 MB
NOTE: You have requested to build more than one version of the JVM, which
will result in longer build times.
The following warnings were produced. Repeated here for convenience:
WARNING: libffi not used, so --with-libffi[-*] is ignored
Make
make JOBS=12 all && make images
# 增量编译
make hotspot
make java.desktop
make jdk.compiler
验证(进build
目录)
% time ./build/macosx-x86_64-zero-slowdebug/jdk/bin/java -version
openjdk version "21-internal" 2023-09-19
OpenJDK Runtime Environment (slowdebug build 21-internal-adhoc.yakir.jdkbuild)
OpenJDK 64-Bit Zero VM (slowdebug build 21-internal-adhoc.yakir.jdkbuild, interpreted mode)
./build/macosx-x86_64-zero-slowdebug/jdk/bin/java -version 3.95s user 0.07s system 99% cpu 4.052 total
% time /Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin/java -version
java version "17.0.3.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3.1+2-LTS-6, mixed mode, sharing)
/Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin/java 0.03s user 0.04s system 46% cpu 0.145 total
% time ./build/macosx-x86_64-zero-slowdebug/jdk/bin/java /Volumes/sm/Hello.java
Hello World
./build/macosx-x86_64-zero-slowdebug/jdk/bin/java /Volumes/sm/Hello.java 34.09s user 0.78s system 107% cpu 32.567 total
对比OpenJDK Java 17
% time /Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin/java /Volumes/sm/Hello.java
Hello World
/Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin/java 0.65s user 0.05s system 182% cpu 0.386 total
// Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
hsdis
cd src/utils/hsdis &&
make ARCH=amd64 BINUTILS=binutils-2.37 CFLAGS="-Wno-error=logical-not-parentheses -Wno-error=string-plus-int -fbracket-depth=512" && \
cp build/macosx-amd64/hsdis-amd64.dylib <JDK Home>/Contents/Home/lib/server/
使用: java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
IdealGraphVisualizer
Clion/IDEA 调试
make compile-commands
make compile-commands-hotspot
sh bin/idea.sh
生成compile_commands.json
文件, 位于${SRC}/build/macosx-x86_64-zero-slowdebug/
目录中
同一目录下创建.lldbinit
文件,内容如下
settings set target.load-cwd-lldbinit true
br set -n main -o true -G true -C "pro hand -p true -s false SIGSEGV SIGBUS"
在Clion
中 Open
compile_commands.json
文件,选择 open as project
References
Tips & Tricks: Develop OpenJDK in CLion with Pleasure Jetbrains: Tips & Tricks: Develop OpenJDK in CLion with Pleasure