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 字节码

  • 创建启动配置项

    UC8ZUI
  • 自定义构建应用

    xwSMsB

    说明:

    1. 创建 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. 创建 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阅读 217,277评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,689评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,624评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,356评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,402评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,292评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,135评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,992评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,429评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,636评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,785评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,492评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,092评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,723评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,858评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,891评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,713评论 2 354

推荐阅读更多精彩内容