OpenJDK9 Hotspot Mac OSX 編譯和調試

Intellij CLion CPU 佔用率過高,還出各類奇怪問題,轉投 Xcode 調試 hotspotjava

安裝 hg

# brew install hg

下載 open jdk 9 源代碼

# hg clone http://hg.openjdk.java.net/jdk9/dev

漫長等待,中間無數次中斷c++

安裝 freetype

# brew install freetype

安裝 libffi(可選)

若是要使用 zero 解釋器,須要安裝 libffimacos

# brew install libffi

configure

# bash configure --with-debug-level=slowdebug \
--with-freetype=/usr/local/opt/freetype \
--disable-warnings-as-errors \
--with-jvm-features=zero \
--with-jvm-variants=zero \
--with-libffi=/usr/local/opt/libffi \
--with-libffi-include=/usr/local/Cellar/libffi/3.0.13/lib/libffi-3.0.13/include

--with-debug-level

設置調試級別,設成 slow debug 能夠提供更多的調試信息bash

--with-free-type

設置 free type 路徑jvm

--disable-warnings-as-errors

忽略警告工具

--with-jvm-features

設置使用 c++ 實現的 zero 解釋器,比基於模版的解釋器更容易調試(若是彙編功力不夠的話)ui

--with-jvm-variants

配合 --with-jvm-features 使用spa

--with-libffi

配合 --with-jvm-features 使用.net

--with-libffi-include

設置 libffi include 文件夾路徑命令行

make

# make

構建成功後:
jdk -> build/macosx-x86_64-normal-server-slowdebug/jdk
hotspot -> build/macosx-x86_64-normal-server-slowdebug/hotspot

Xcode 調試

新建 command line 工程

新建一個 command line(命令行工具)工程,新建後刪除 XCode 自動生成的代碼

編輯 hotspot scheme

首先去掉 IDE build 配置,由於咱們沒法(也不須要)在IDE中構建 hotspot,其次將運行目標修改成: <jdk源代碼目錄>/build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java(在編譯源代碼階段已經生成)

添加 hotspot src 到工程

右擊 hotspot 工程,選擇 "add files to project" 添加 <jdk源代碼目錄>/hotspot/src 到工程中

在 jni.cpp 的 JNI_CreateJavaVM 方法中設置斷點, goooooo

若是出現 sigsegv 信號中斷,能夠在 lldb 中設置

(lldb) process handle SIGSEGV --stop=false

上圖

圖片描述

相關文章
相關標籤/搜索