MacOS-10.15.6 編譯 OpenJdk 16.15 源碼及 Clion 調試

MacOS-10.15.6 編譯 OpenJdk 16.15 源碼及 Clion 調試

1. 下載最新版本源碼

2. 源碼編譯

# 主流程
Get the complete source code:
bash get_source.sh

Run configure:
bash configure

If configure fails due to missing dependencies (to either the toolchain, external libraries or the boot JDK), most of the time it prints a suggestion on how to resolve the situation on your platform. Follow the instructions, and try running bash configure again.

Run make:
make images

Verify your newly built JDK:
./build/*/images/jdk/bin/java -version

Run basic tests:
make run-test-tier1

# 實際操作
1. 安裝依賴工具
brew install autoconf
2. 配置
bash ./configure  --enable-dtrace --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home --with-debug-level=slowdebug --with-target-bits=64  --with-native-debug-symbols=internal --disable-warnings-as-errors  --with-jvm-variants=server
3. 編譯
make images
4. 驗證編譯后的 jdk
./build/*/images/jdk/bin/java -version
./build/macosx-x86_64-server-slowdebug/jdk/bin/java -version

openjdk version "16-internal" 2021-03-16
OpenJDK Runtime Environment (slowdebug build 16-internal+0-adhoc.Tao.jdk-jdk-16-15)
OpenJDK 64-Bit Server VM (slowdebug build 16-internal+0-adhoc.Tao.jdk-jdk-16-15, mixed mode)

3. 過程日志

## 部分日志
## 配置
1. bash ./configure  --enable-dtrace --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home --with-debug-level=slowdebug --with-target-bits=64  --with-native-debug-symbols=internal --disable-warnings-as-errors  --with-jvm-variants=server

Configuration summary:
* Debug level:    slowdebug
* HS debug level: debug
* JVM variants:   server
* JVM features:   server: 'aot cds compiler1 compiler2 dtrace epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc'
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 16-internal+0-adhoc.Tao.jdk-jdk-16-15 (16-internal)

Tools summary:
* Boot JDK:       java version "14.0.2" 2020-07-14 Java(TM) SE Runtime Environment (build 14.0.2+12-46) Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)  (at /Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home)
* Toolchain:      clang (clang/LLVM from Xcode 11.7)
* C Compiler:     Version 11.0.3 (at /usr/bin/clang)
* C++ Compiler:   Version 11.0.3 (at /usr/bin/clang++)

Build performance summary:
* Cores to use:   8
* Memory limit:   16384 MB

## 生成鏡像
2. make images

Updating support/demos/image/jfc/TransparentRuler/src.zip
Creating support/demos/image/jfc/CodePointIM/CodePointIM.jar
Creating support/demos/image/jfc/FileChooserDemo/FileChooserDemo.jar
Creating support/demos/image/jfc/SwingSet2/SwingSet2.jar
Creating support/demos/image/jfc/Font2DTest/Font2DTest.jar
Creating support/demos/image/jfc/J2Ddemo/J2Ddemo.jar
Creating support/demos/image/jfc/Metalworks/Metalworks.jar
Creating support/demos/image/jfc/Notepad/Notepad.jar
Creating support/demos/image/jfc/Stylepad/Stylepad.jar
Creating support/demos/image/jfc/SampleTree/SampleTree.jar
Creating support/demos/image/jfc/TableExample/TableExample.jar
Creating support/demos/image/jfc/TransparentRuler/TransparentRuler.jar
Creating jdk image
Creating CDS archive for jdk image
Creating CDS-NOCOOPS archive for jdk image
Stopping sjavac server
Finished building target 'images' in configuration 'macosx-x86_64-server-slowdebug'

## 查看 jdk 版本信息
3. ./build/macosx-x86_64-server-slowdebug/jdk/bin/java -version

openjdk version "16-internal" 2021-03-16
OpenJDK Runtime Environment (slowdebug build 16-internal+0-adhoc.Tao.jdk-jdk-16-15)
OpenJDK 64-Bit Server VM (slowdebug build 16-internal+0-adhoc.Tao.jdk-jdk-16-15, mixed mode)


4. Clion Debug class

4.1 編譯器忽略錯誤退出

# Works once enabled through the ~/.lldbinit in the home directory.
echo 'settings set target.load-cwd-lldbinit true' > ~/.lldbinit

4.2 Clion 打開 openjdk 源碼并在 java main 函數打斷點

main 函數路徑(src/java.base/share/native/launcher/main.c)

EYOKDT

4.3 Custom build targets for OpenJDK

4.3.1 編寫 java 測試代碼并生成 class 文件

// Hello.java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World !!!\nWow! Hotspot debug mode !!!");
    }
}
// 編譯 
javac Hello.java
// 測試 Hello.class
java Hello
// 輸出結果
Hello World !!!
Wow! Hotspot debug mode !!!

4.3.2 配置 openjdk 調試 Hello.class 字節(jié)碼

  • 創(chuàng)建啟動配置項

    UC8ZUI
  • 自定義構建應用

    xwSMsB

    說明:

    1. 創(chuàng)建 Custom Build Application

    2. 參考下面 Configure Custom Build Target

    3. 編譯后 openjdk java 命令(./build/macosx-x86_64-server-slowdebug/jdk/bin/java)

    4. Hello.class 文件名稱

    5. Hello.class 文件所在路徑(必須使用 class 文件所在的絕對路徑

    6. 移除 Before launch 中的 build ,我們的 openjdk 源碼是編譯完成的,不需要 build

  • Configure Custom Build Target

    1. 點擊箭頭位置

      mqDiBm
  1. 配置參數

    QZunmZ
    1. 創(chuàng)建 External tools
    2. name 與 description 可以寫 openjdk 編譯后的文件夾名稱 (macosx-x86_64-server-slowdebug)
    3. make 命令
    4. CONF 參數
    5. openjdk 源碼的根路徑

5. 問題及建議

5.1 autoconf 異常

# 問題
Autoconf is not found on the PATH, and AUTOCONF is not set.
You need autoconf to be able to generate a runnable configure script.
You might be able to fix this by running 'brew install autoconf'.
Error: Cannot find autoconf
# 解決方案
brew install autoconf

5.2 jdk 版本問題

## 問題
configure: Potential Boot JDK found at /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home is incorrect JDK version (java version "10.0.2" 2018-07-17); ignoring
configure: (Your Boot JDK version must be one of: 14 15 16)
configure: Could not find a valid Boot JDK. OpenJDK distributions are available at http://jdk.java.net/.
configure: This might be fixed by explicitly setting --with-boot-jdk

## 解決方案
添加 --with-boot-jdk灵再,指定高版本 JDK 路徑尘分,JDK 版本必須為 14,15婴噩,16,可以去 oracle 官網下載對應版本的 jdk
bash ./configure  --enable-dtrace --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home --with-debug-level=slowdebug --with-target-bits=64  --with-native-debug-symbols=internal --disable-warnings-as-errors  --with-jvm-variants=server

5.3 Tips

編譯配置參數(--enable-dtrace 等)參考OpenJdk GitHub 官方編譯文檔說明

5.4 java 運行命令

## 啟動方式
jar     : java -jar hello.jar
class   : java Hello

6. 參考文檔

https://github.com/openjdk/jdk/blob/master/doc/building.md

https://blog.jetbrains.com/clion/2020/03/openjdk-with-clion/

http://www.txazo.com/jvm/jvm-startup.html

https://www.cnblogs.com/bolingcavalry/p/11495456.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末吨掌,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌率翅,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,110評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件袖迎,死亡現場離奇詭異冕臭,居然都是意外死亡腺晾,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 93,443評論 3 395
  • 文/潘曉璐 我一進店門辜贵,熙熙樓的掌柜王于貴愁眉苦臉地迎上來悯蝉,“玉大人,你說我怎么就攤上這事托慨”怯桑” “怎么了?”我有些...
    開封第一講書人閱讀 165,474評論 0 356
  • 文/不壞的土叔 我叫張陵厚棵,是天一觀的道長蕉世。 經常有香客問我,道長婆硬,這世上最難降的妖魔是什么狠轻? 我笑而不...
    開封第一講書人閱讀 58,881評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮柿祈,結果婚禮上哈误,老公的妹妹穿的比我還像新娘哩至。我一直安慰自己躏嚎,他們只是感情好,可當我...
    茶點故事閱讀 67,902評論 6 392
  • 文/花漫 我一把揭開白布菩貌。 她就那樣靜靜地躺著卢佣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪箭阶。 梳的紋絲不亂的頭發(fā)上虚茶,一...
    開封第一講書人閱讀 51,698評論 1 305
  • 那天,我揣著相機與錄音仇参,去河邊找鬼嘹叫。 笑死,一個胖子當著我的面吹牛诈乒,可吹牛的內容都是我干的罩扇。 我是一名探鬼主播,決...
    沈念sama閱讀 40,418評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼怕磨,長吁一口氣:“原來是場噩夢啊……” “哼喂饥!你這毒婦竟也來了?” 一聲冷哼從身側響起肠鲫,我...
    開封第一講書人閱讀 39,332評論 0 276
  • 序言:老撾萬榮一對情侶失蹤员帮,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后导饲,有當地人在樹林里發(fā)現了一具尸體捞高,經...
    沈念sama閱讀 45,796評論 1 316
  • 正文 獨居荒郊野嶺守林人離奇死亡氯材,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,968評論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現自己被綠了棠枉。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片浓体。...
    茶點故事閱讀 40,110評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖辈讶,靈堂內的尸體忽然破棺而出命浴,到底是詐尸還是另有隱情,我是刑警寧澤贱除,帶...
    沈念sama閱讀 35,792評論 5 346
  • 正文 年R本政府宣布生闲,位于F島的核電站,受9級特大地震影響月幌,放射性物質發(fā)生泄漏碍讯。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,455評論 3 331
  • 文/蒙蒙 一扯躺、第九天 我趴在偏房一處隱蔽的房頂上張望捉兴。 院中可真熱鬧,春花似錦录语、人聲如沸倍啥。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽虽缕。三九已至,卻和暖如春蒲稳,著一層夾襖步出監(jiān)牢的瞬間氮趋,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評論 1 272
  • 我被黑心中介騙來泰國打工江耀, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留剩胁,地道東北人。 一個月前我還...
    沈念sama閱讀 48,348評論 3 373
  • 正文 我出身青樓祥国,卻偏偏與公主長得像昵观,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子系宫,可洞房花燭夜當晚...
    茶點故事閱讀 45,047評論 2 355

推薦閱讀更多精彩內容