1、安装homebrew ,打开命令行工具:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安装必备工具:
brew install mercurial
brew install ccache
brew install freetype
3、下载jdk源码,注意提前创建好文件夹哦:
git clone https://github.com/dmlloyd/openjdk.git
cd openjdk
git checkout -b jdk9 origin/jdk9/jdk9
我们先进行编译前的配置(检查):
./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.8.1 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" --disable-zip-debug-info --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log
有日志,出问题查问题也很方便!
注意,上面的freetype,需要替换成本机实际安装的版本,把上面的 --with-freetype=/usr/local/Cellar/freetype/2.8.1换成你实际安装的版本和目录就可以啦。
如果出现如下的提示,那么恭喜你,接下来就可以执行编译了:
====================================================
The existing configuration has been successfully updated in
/Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug
using configure arguments '--with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.0 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs='-Xlint:deprecation -Xlint:unchecked' --disable-warnings-as-errors --with-debug-level=slowdebug'.
Configuration summary:
* Debug level: slowdebug
* HS debug level: debug
* JDK variant: normal
* JVM variants: server client
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 9-internal+0-adhoc.rex.openjdk (9-internal)
Tools summary:
* Boot JDK: java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 9.4.1)
* C Compiler: Version 9.1.0 (at /usr/bin/clang)
* C++ Compiler: Version 9.1.0 (at /usr/bin/clang++)
Build performance summary:
* Cores to use: 4
* Memory limit: 8192 MB
* ccache status: Active (3.6)
NOTE: You have requested to build more than one version of the JVM, which
will result in longer build times.
WARNING: The result of this configuration has overridden an older
configuration. You *should* run 'make clean' to make sure you get a
proper build. Failure to do so might result in strange build problems.
我们执行下面的操作:
export LANG=C
make all LOG=debug 2>&1 | tee make_mac_x64.log
如果出现如下的提示,那么恭喜你,你的运气太好了!!!
----- Build times -------
Start 2019-04-25 18:55:19
End 2019-04-25 19:00:57
00:05:38 TOTAL
-------------------------
if test -f /Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/exit-with-error ; then \
exit 1 ; \
fi
/usr/bin/printf "Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug'\n" > >(/usr/bin/tee -a /Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log) 2> >(/usr/bin/tee -a /Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log >&2) && wait
Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-s
最后,验证一下
cd build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin
./java -version
出现下面的提示就完美了:
openjdk version "9-internal"
OpenJDK Runtime Environment (slowdebug build 9-internal+0-adhoc.rex.openjdk)
OpenJDK 64-Bit Server VM (slowdebug build 9-internal+0-adhoc.rex.openjdk, mixed mode)
XCode升级到10之后, 删除了底层目录下的libstdc++文件。导致在JDK的Make时会报错, 无法识别
打开报错的文件,将 base() > 0 改为 base() != NULL
说明是编译的jvm库出了问题,打开 hotspot/src/share/vm/runtime/perfData.cpp这个文件。把所有的"delete p;"注释掉可以正常停止了。或者参考 Building OpenJDK 9 on Mac os
妥妥的~