环境准备
macOS High Sierra,版本 10.13.6
安装brew
如果没有安装,参考这里,命令:
1 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
安装mercurial
openjdk
代码由hg管理,命令:
1 | brew install mercurial |
安装ccache
ccache
可以提高编译速度,命令:
1 | brew install ccache |
安装freetype
freetype
编译需要,命令:
1 | brew install freetype |
编译
源码下载
1 | clone到指定目录 |
编译配置
1 | bash configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.9.1 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log |
注意需要修改命令中的freetype
版本号
编译参数简介:
1 | --with-target-bits:设置32位/64位编译 |
编译配置创建完成后控制台输出:
1 | A new configuration has been successfully created in |
编译
1 | 设定语言选项 |
编译完成后控制台输出:
1 | Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug' |
编译错误
问题一
1 | === Output from failing command(s) repeated here === |
错误1指向文件../src/share/vm/memory/virtualspace.cpp
第584行,调整为:
1 | // if (base() > 0) { |
错误2指向文件../src/share/vm/opto/lcm.cpp
第42行,调整为:
1 | // if (Universe::narrow_oop_base() > 0) { // Implies UseCompressedOops. |
解决方案:https://bugs.openjdk.java.net/browse/JDK-8187787
问题二
1 | === Output from failing command(s) repeated here === |
错误指向../src/share/vm/opto/loopPredicate.cpp
第903行,调整为:
1 | //assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be"); |
解决方案:https://bugs.openjdk.java.net/browse/JDK-8187787
问题三
1 | # |
注释文件hotspot/src/share/vm/runtime/perfMemory.cpp
第75~77行:
1 | // if (SafepointSynchronize::is_at_safepoint() && !StatSampler::is_active()) { |
解决方案:https://stackoverflow.com/questions/50678467/building-openjdk-9-on-mac-os/54954805
但是这样处理后,使用jstat
监控JVM时可能会导致 内存泄露
测试验证
1 | $ cd build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin/ |
控制台输出:
1 | openjdk version "9-internal" |
参考
Mac OSX 10.12.1 编译 Openjdk 9
macOS 编译 OpenJDK 10
在 macOS 上编译 OpenJDK 8