mac下編譯OpenJDK10

OpenJDK是與Oracle JDK最接近的開源jdk,周志明老師在《深入理解JAVA虛擬機(jī)》第一章就建議大家自己編譯下OpenJDK的源碼,最近遇到JVM相關(guān)的一些問題,又心血來潮的想試試。
如果是第一次編譯的話真的是很難一次成功的,由于操作系統(tǒng)、軟件環(huán)境、OpenJDK版本不同各種千奇百怪的問題都有。雖然項(xiàng)目中用的是java8,但因?yàn)樽约菏褂胢acOS 10.13.6操作系統(tǒng),看了下網(wǎng)上的一些文章對jdk8編譯支持不是很好,因此選擇了不少人編譯成功的jdk9進(jìn)行下手。
但是jdk9到我這里也行不通,遇到的問題在openjdk官網(wǎng)和stackoverflow上都有人反映,但沒人回答, 因此不得不放棄。接下來試jdk9u遇到相同錯(cuò)誤,換到j(luò)dk10卻異常順利,無需像jdk9一樣改源碼啥的,一次成功。因此如果你打算在mac上嘗試編譯的話,建議直接編譯jdk10吧。

1. 工具準(zhǔn)備

  • homebrew,mac下的包管理工具
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • mercurial, openjdk源碼版本管理工具
    sudo easy_install mercurial
  • ccache, freetype, 編譯以及加速編譯時(shí)所要用到的
    brew install ccache
    brew install freetype

2. 下載源碼

  • hg clone
    hg clone http://hg.openjdk.java.net/jdk10/jdk10/
  • 修改get_source.sh最后幾行如下以防止中斷
# Get clones of all absent nested repositories (harmless if already exist)
sh ./common/bin/hgforest.sh clone "$@"

while [ $? -ne 0 ]
do
    sh ./common/bin/hgforest.sh clone "$@"
done

# Update all existing repositories to the latest sources
sh ./common/bin/hgforest.sh pull -u

while [ $? -ne 0 ]
do
    sh ./common/bin/hgforest.sh pull -u
done
  • 執(zhí)行以下命令以獲取全部資源:
    sh ./get_source.sh

3. 執(zhí)行configure

`sh ./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-zip-debug-info --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log`

注意:freetype版本要和自己使用的對應(yīng)

4. 執(zhí)行make

export LANG=C
make all LOG=debug 2>&1 | tee make_mac_x64.log

5. 驗(yàn)證

執(zhí)行./java -version打印如下表示編譯成功。

openjdk version "10-internal"
OpenJDK Runtime Environment (slowdebug build 10-internal+0-adhoc.baohuahe.jdk10)
OpenJDK 64-Bit Server VM (slowdebug build 10-internal+0-adhoc.baohuahe.jdk10, mixed mode)

接下來就可以愉快的看jvm源碼和進(jìn)行本地調(diào)試了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容