MacOS編譯openjdk9
下載JDK
源碼文件:
方式一,Git clone:https://github.com/campolake/openjdk9.git
方式二轧拄,官方下載jdk
源碼zip
包:http://jdk.java.net/
各個(gè)版本JDK
下載地址匯總:https://blog.csdn.net/qq_23091073/article/details/83178848
以下命令均在openjdk9
的路徑下執(zhí)行:
1热凹、首先安裝必要依賴:
brew install ccache
brew install freetype
brew install ant
brew install autoconf
brew install llvm
brew install binutils
2柄延、配置configure
權(quán)限:
chmod u+x configure
3肃廓、進(jìn)行檢查配置:
注意:參數(shù)--with-freetype=/usr/local/Cellar/freetype/2.11.0
中的路徑一定是你自己的安裝路徑。
sudo bash ./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.11.0 --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
配置xcode丟失的文件(Xcode 10以后刪除了libstdc++庫晤柄,轉(zhuǎn)而使用libc++)擦剑,
解決方法就是從github上下載庫妖胀,然后設(shè)置環(huán)境變量后解決芥颈,此方法我編譯過兩次都通過。
克隆倉庫:git clone https://github.com/imkiwa/xcode-missing-libstdc-.git
赚抡,
執(zhí)行倉庫下的install.sh
進(jìn)行安裝爬坑。
接下來進(jìn)行環(huán)境變量的配置:
export CFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
export CXXFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
export LDFLAGS=-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
export LIBRARY_PATH=$LIBRARY_PATH:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
4、執(zhí)行make
進(jìn)行編譯
sudo make all JOBS=8 ZIP_DEBUGINFO_FILES=0 COMPILER_WARNINGS_FATAL=false CC=clang USE_CLANG=true LP64=1 LOG=debug 2>&1 | tee make_mac_x64.log
5涂臣、錯(cuò)誤匯總
參考博客盾计,這里有些常見的錯(cuò)誤對應(yīng)的解決方法:https://blog.csdn.net/lizhengjava/article/details/105629780
此博客也有一些需要更改cpp代碼的錯(cuò)誤的解決方法:https://blog.csdn.net/qq_25905629/article/details/107485000
其他有關(guān)問題解決方案的博客:https://super2bai.github.io/JVM/build.html
其他錯(cuò)誤1:
Building target 'default (exploded-image)' in configuration 'macosx- x86_64-normal-server-slowdebug' Warning: No mercurial configuration present and no .src-rev
其他錯(cuò)誤1---解決方法博客地址:
https://stackoverflow.com/questions/50678467/building-openjdk-9-on-mac-os/54954805#54954805
其他錯(cuò)誤2:
[error occurred during error reporting (), id 0x4]
make[3]: *** [/Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/_packages_attribute.done] Abort trap: 6
make[2]: *** [exploded-image-optimize] Error 2
ERROR: Build failed for target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug' (exit code 2)
[ -f /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/javacservers/server.port ] && /bin/echo Stopping sjavac server && /usr/bin/touch /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/javacservers/server.port.stop; true
/bin/date '+%Y %m %d %H %M %S' | /usr/bin/awk '{ print $1,$2,$3,$4,$5,$6,($4*3600+$5*60+$6) }' > /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_end_TOTAL
/bin/date '+%Y-%m-%d %H:%M:%S' > /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_end_TOTAL_human_readable
/bin/echo `/bin/cat /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_start_TOTAL` `/bin/cat /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_end_TOTAL` TOTAL | /usr/bin/awk '{ F=$7; T=$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$15); }' > /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_diff_TOTAL
/usr/bin/printf -- "----- Build times -------\nStart %s\nEnd %s\n%s\n%s\n-------------------------\n" "`/bin/cat /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_start_TOTAL_human_readable`" "`/bin/cat /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_end_TOTAL_human_readable`" "`/bin/ls /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_diff_* | /usr/bin/grep -v _TOTAL | /usr/bin/xargs /bin/cat | /usr/bin/sort -k 2`" "`/bin/cat /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/build-times/build_time_diff_TOTAL`" > >(/usr/bin/tee -a /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log) 2> >(/usr/bin/tee -a /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log >&2) && wait
if /usr/bin/grep -q "recipe for target .* failed" /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log 2> /dev/null; then /usr/bin/printf "\n=== Make failed targets repeated here ===\n" ; /usr/bin/grep "recipe for target .* failed" /Users/yier/Documents/openjdk/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log ; /usr/bin/printf "=== End of repeated output ===\n" ; /usr/bin/printf "\nHint: Try searching the build log for the name of the first failed target.\n" ; else /usr/bin/printf "\nNo indication of failed target found.\n" ; /usr/bin/printf "Hint: Try searching the build log for '] Error'.\n" ; fi
----- Build times -------
Start 2019-10-16 20:52:13
End 2019-10-16 20:52:28
00:00:15 TOTAL
-------------------------
No indication of failed target found.
Hint: Try searching the build log for '] Error'.
/usr/bin/printf "Hint: See common/doc/building.html#troubleshooting for assistance.\n\n"
Hint: See common/doc/building.html#troubleshooting for assistance.
make[1]: *** [main] Error 2
make: *** [all] Error 2
其他錯(cuò)誤2----解決方法:
注釋文件hotspot/src/share/vm/runtime/perfMemory.cpp
第75~77行:
// if (SafepointSynchronize::is_at_safepoint() && !StatSampler::is_active()) {
// PerfDataManager::destroy();
// }
解決方案:https://stackoverflow.com/questions/50678467/building-openjdk-9-on-mac-os/54954805
但是這樣處理后,使用jstat
監(jiān)控JVM時(shí)可能會(huì)導(dǎo)致 內(nèi)存泄露
6赁遗、編譯成功結(jié)果
----- Build times -------
Start 2021-09-28 09:05:02
End 2021-09-28 09:17:43
00:12:41 TOTAL
-------------------------
/usr/bin/printf "Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug'\n" > >(/usr/bin/tee -a /Users/ellisonpei/Desktop/apache/sourceCode/java/openjdk9-master/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log) 2> >(/usr/bin/tee -a /Users/ellisonpei/Desktop/apache/sourceCode/java/openjdk9-master/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log >&2) && wait
Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug'
測試驗(yàn)證
ellisonpei@peimacbookpro bin % cd build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin
ellisonpei@peimacbookpro bin % ./java -version
控制臺輸出:
openjdk version "9-internal"
OpenJDK Runtime Environment (slowdebug build 9-internal+0-2021-09-28-085320.root.openjdk9-master)
OpenJDK 64-Bit Server VM (slowdebug build 9-internal+0-2021-09-28-085320.root.openjdk9-master, mixed mode)