MacOS編譯openjdk9

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)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末署辉,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子岩四,更是在濱河造成了極大的恐慌哭尝,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件剖煌,死亡現(xiàn)場離奇詭異材鹦,居然都是意外死亡逝淹,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進(jìn)店門桶唐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來栅葡,“玉大人,你說我怎么就攤上這事尤泽⌒来兀” “怎么了?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵坯约,是天一觀的道長醉蚁。 經(jīng)常有香客問我,道長鬼店,這世上最難降的妖魔是什么网棍? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮妇智,結(jié)果婚禮上滥玷,老公的妹妹穿的比我還像新娘。我一直安慰自己巍棱,他們只是感情好惑畴,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著航徙,像睡著了一般如贷。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上到踏,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天杠袱,我揣著相機(jī)與錄音,去河邊找鬼窝稿。 笑死楣富,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的伴榔。 我是一名探鬼主播纹蝴,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼踪少!你這毒婦竟也來了塘安?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤援奢,失蹤者是張志新(化名)和其女友劉穎兼犯,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡免都,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年锉罐,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片绕娘。...
    茶點(diǎn)故事閱讀 38,137評論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡脓规,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出险领,到底是詐尸還是另有隱情侨舆,我是刑警寧澤,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布绢陌,位于F島的核電站挨下,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏脐湾。R本人自食惡果不足惜臭笆,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望秤掌。 院中可真熱鬧愁铺,春花似錦、人聲如沸闻鉴。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽孟岛。三九已至瓶竭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間渠羞,已是汗流浹背斤贰。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留堵未,地道東北人腋舌。 一個(gè)月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像渗蟹,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子赞辩,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評論 2 345

推薦閱讀更多精彩內(nèi)容