前置
环境依赖:
- 安装一个 JDK16
- Autogen
- Autoconf
- Python 2
- Libffi
- Freetype
- Ccache
- XCode Version 12.5 (12E262) macOS Version 11.4 (20F71)
- Binutils
获得源码
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-16.0.1.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-target-bits=64 \
--with-libffi=/Users/yakir/local/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-16.0.1.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
--enable-ccache
选项看着加😁
Zero Slowdebug configure
成功输出
====================================================
A new configuration has been successfully created in
/Volumes/sm/github/jdk/jdkbuild/build/macosx-x86_64-zero-slowdebug
using configure arguments '--enable-dtrace --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home/ --with-toolchain-path=/Applications/Xcode.app/Contents/Developer/usr/bin --disable-warnings-as-errors --with-boot-jdk-jvmargs='-XX:+UseG1GC -Xms4G -Xmx4G' --with-toolchain-type=clang --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-jvm-variants=zero --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-zero-slowdebug
* Debug level: slowdebug
* HS debug level: debug
* JVM variants: zero
* JVM features: zero: 'dtrace epsilongc g1gc jni-check jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zero'
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 17-internal+0-adhoc.yakir.jdkbuild (17-internal)
Tools summary:
* Boot JDK: java version "16.0.1" 2021-04-20 Java(TM) SE Runtime Environment (build 16.0.1+9-24) Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 12.5)
* C Compiler: Version 12.0.5 (at /usr/bin/clang)
* C++ Compiler: Version 12.0.5 (at /usr/bin/clang++)
Build performance summary:
* Cores to use: 12
* Memory limit: 32768 MB
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.1.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: 17-internal+0-adhoc.yakir.jdkbuild (17-internal)
Tools summary:
* Boot JDK: java version "16.0.1" 2021-04-20 Java(TM) SE Runtime Environment (build 16.0.1+9-24) Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 12.5)
* C Compiler: Version 12.0.5 (at /usr/bin/clang)
* C++ Compiler: Version 12.0.5 (at /usr/bin/clang++)
Build performance summary:
* Cores to use: 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
# 增量编译hotspot
make hotspot
验证(进build
目录)
% time /Users/yakir/local/jdk/jdk-17.jdk/Contents/Home/bin/java -version
openjdk version "17-internal" 2021-09-14
OpenJDK Runtime Environment (slowdebug build 17-internal+0-adhoc.yakir.jdkbuild)
OpenJDK 64-Bit Zero VM (slowdebug build 17-internal+0-adhoc.yakir.jdkbuild, interpreted mode)
/Users/yakir/local/jdk/jdk-17.jdk/Contents/Home/bin/java -version 0.61s user 0.02s system 22% cpu 2.800 total
% time /Users/yakir/local/jdk/jdk-17.jdk/Contents/Home/bin/javac -version
javac 17-internal
/Users/yakir/local/jdk/jdk-17.jdk/Contents/Home/bin/javac -version 3.71s user 0.04s system 99% cpu 3.766 total
% time /Users/yakir/local/jdk/jdk-17.jdk/Contents/Home/bin/java /Volumes/sm/Hello.java
Hello
/Users/yakir/local/jdk/jdk-17.jdk/Contents/Home/bin/java 20.35s user 0.10s system 99% cpu 20.497 total
对比Oracle Java 11
% time java /Volumes/sm/Hello.java
Hello
java /Volumes/sm/Hello.java 1.00s user 0.12s system 108% cpu 1.032 total
对比OpenJDK Java 16
% time java /Volumes/sm/Hello.java
Hello
java /Volumes/sm/Hello.java 0.89s user 0.07s system 219% cpu 0.439 total
// Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
hsdis
cd src/utils/hsdis &&
make ARCH=amd64 BINUTILS=binutils-2.34 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