若是使用 hg 下載源代碼會很漫長並且常常掉線,能夠使用 github 上的源代碼鏡像html
# git clone https://github.com/dmlloyd/openjdk
在構建以前建議仔細閱讀源代碼目錄下的 README-builds.html or README-builds.md 文件java
# bash ./configure
configure 錯誤輸出很 nice,若是缺乏庫,使用 apt install 便可,例如:linux
configure: error: Could not find alsa! You might be able to fix this by running 'sudo apt-get install libasound2-dev'. configure exiting with result code 1
配置完成後會有個 summary:git
==================================================== A new configuration has been successfully created in /home/xingpingz/studies/openjdk/build/linux-x86_64-normal-server-slowdebug using configure arguments '--with-debug-level=slowdebug'. Configuration summary: * Debug level: slowdebug * HS debug level: debug * JDK variant: normal * JVM variants: server * OpenJDK target: OS: linux, CPU architecture: x86, address length: 64 * Version string: 9-internal+0-adhoc.xingpingz.openjdk (9-internal) Tools summary: * Boot JDK: java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode) (at /opt/jdk1.8.0) * Toolchain: gcc (GNU Compiler Collection) * C Compiler: Version 5.4.0 (at /usr/bin/gcc) * C++ Compiler: Version 5.4.0 (at /usr/bin/g++) Build performance summary: * Cores to use: 4 * Memory limit: 11963 MB
# make
構建完成後在源代碼 build 目錄下會生成 linux-x86_64-normal-server-slowdebug,裏面包含生成的 jdk,hotspot .etcgithub
$ ll 總用量 120K -rw-rw-r-- 1 xingpingz xingpingz 2.7K 2月 14 13:56 bootcycle-spec.gmk -rw-rw-r-- 1 xingpingz xingpingz 7.0K 2月 14 13:56 buildjdk-spec.gmk -rw-rw-r-- 1 xingpingz xingpingz 17K 2月 14 14:02 build.log drwxrwxr-x 17 xingpingz xingpingz 4.0K 2月 14 14:02 buildtools -rwxrwxr-x 1 xingpingz xingpingz 3.6K 2月 14 13:56 compare.sh -rw-rw-r-- 1 xingpingz xingpingz 13K 2月 14 13:56 configure.log drwxrwxr-x 2 xingpingz xingpingz 4.0K 2月 14 13:56 configure-support drwxrwxr-x 4 xingpingz xingpingz 4.0K 2月 14 13:57 hotspot drwxrwxr-x 2 xingpingz xingpingz 4.0K 2月 14 13:59 images drwxrwxr-x 7 xingpingz xingpingz 4.0K 2月 14 14:02 jdk -rw-rw-r-- 1 xingpingz xingpingz 1.3K 2月 14 13:56 Makefile drwxrwxr-x 6 xingpingz xingpingz 4.0K 2月 14 13:57 make-support -rw-rw-r-- 1 xingpingz xingpingz 33K 2月 14 13:56 spec.gmk drwxrwxr-x 13 xingpingz xingpingz 4.0K 2月 14 14:01 support
下載和安裝 CLion IDEbash
以源代碼方式新建一個工程,將 hotspot 相關的源代碼導入 IDE工具
CLion 集成 CMake(Java 界的 Maven)進行構建,編輯 CMakeLists.txt 裏面的 set 語句塊,刪除 x86 之外的源代碼,減小 IDE 要索引的文件,加快速度ui
set(SOURCE_FILES cpu/x86/vm/... ...
編輯 "運行&調試" configuration,將 executable(要運行的目標程序)修改爲 在 make 階段生成的 jdk/bin/javathis
去掉 Before launch 裏面的 build 動做,在 IDE 裏面咱們沒法進行構建spa
打開 jni.cpp 文件,找到 JNI_CreateJavaVM,設置斷點,點擊工具欄上那個"小臭蟲"開始調試