在Ubuntu 12.04 上編譯調試 OpenJDK8

前言

如今看的資料都是編譯 openjdk7 的,openjdk8好像已經 openjdk7 編譯方式大同樣,按照前輩的文章使用html

make sanity

會提示找不到 sanity 規則,而後編譯過程其實基本就直接java

./configure
make all

官方的 README 寫的很清楚。linux

下面記錄下過程git

下載代碼

hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8u
cd jdk8u 
bash ./get_source.sh

而後下載代碼,進入代碼目錄:github

cd jdk8u

代碼目錄中有一個 README-builds.html 描述瞭如何 build 整個系統,一些細節須要本身去尋找。redis

安裝依賴

sudo aptitude build-dep openjdk-7 
sudo aptitude install openjdk-7-jdk

配置

  • 環境變量
export LANG=C 
export PATH="/usr/lib/jvm/java-7-openjdk/bin:${PATH}"
  • 配置編譯選項
bash ./configure

這樣生成相應默認配置,若是有須要,好比想編譯出調試版本的,能夠給 configure 加參數。ubuntu

A new configuration has been successfully created in
/home/minix/SourceCode/openjdk8/jdk8u/build/linux-x86-normal-server-release
using default settings.

Configuration summary:
* Debug level:    release
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 32

Tools summary:
* Boot JDK:       java version "1.7.0_17" Java(TM) SE Runtime Environment (build 1.7.0_17-b02) Java HotSpot(TM) Server VM (build 23.7-b01, mixed mode)  (at /home/minix/Software/jdk1.7.0_17)
* C Compiler:     gcc-4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (at /usr/bin/gcc-4.6)
* C++ Compiler:   g++-4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (at /usr/bin/g++-4.6)

Build performance summary:
* Cores to use:   3
* Memory limit:   3878 MB
* ccache status:  not installed (consider installing)

Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You do not have ccache installed. Try installing it.
You might be able to fix this by running 'sudo apt-get install ccache'.

能夠看出提示缺乏 ccache 包,按提示安裝就能夠了。從提示能夠看出,編譯級別是 release,另外還有幾種編譯級別,能夠在調試時候提供更多的信息。例如:bash

bash ./configure --enable-debug

這樣會生成 fastdebug 版本的配置信息:jvm

A new configuration has been successfully created in
/home/minix/openjdk8/jdk8u/build/linux-x86-normal-server-fastdebug
using configure arguments '--enable-debug'.

Configuration summary:
* Debug level:    fastdebug
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 32

Tools summary:
* Boot JDK:       java version "1.7.0_17" Java(TM) SE Runtime Environment (build 1.7.0_17-b02) Java HotSpot(TM) Server VM (build 23.7-b01, mixed mode)  (at /home/minix/Software/jdk1.7.0_17)
* C Compiler:     gcc-4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (at /usr/bin/gcc-4.6)
* C++ Compiler:   g++-4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (at /usr/bin/g++-4.6)

Build performance summary:
* Cores to use:   3
* Memory limit:   3878 MB
* ccache status:  installed and in use

注意編譯的級別已經變成 fastdebug 了。ide

--enable-debug 其實至關於 --with-debug-level=fastdebug, 能夠經過這樣的參數選項指定編譯級別。一共能夠指定三種級別: release, fastdebug, slowdebugslowdebug 含有最豐富的調試信息,沒有這些信息,不少執行可能被優化掉,咱們單步執行時,可能看不到一些變量的值。因此最好指定slowdebug 爲編譯級別

編譯

編譯直接

make

就能夠了,若是提示

No CONF given, but more than one configuration found in /home/minix/openjdk8/jdk8u//build.
Available configurations:
* linux-x86-normal-server-fastdebug
* linux-x86-normal-server-release
Please retry building with CONF=<config pattern> (or SPEC=<specfile>)

須要指定使用哪一個編譯配置:

make CONF=linux-x86-normal-server-fastdebug

最後編譯成功後,會提示:

----- Build times -------
Start 2014-08-22 10:56:52
End   2014-08-22 11:16:31
00:00:30 corba
00:13:38 hotspot
00:00:22 jaxp
00:00:30 jaxws
00:04:10 jdk
00:00:29 langtools
00:19:39 TOTAL

查看 build 目錄,能夠看到 linux-x86-normal-server-fastdebug

切換到 jdk/bin 目錄:

cd linux-x86-normal-server-fastdebug/jdk/bin/

運行可執行文件 java

./java -version

會獲得提示

openjdk version "1.8.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.8.0-internal-fastdebug-minix_2014_08_22_10_56-b00)
OpenJDK Server VM (build 25.40-b05-fastdebug, mixed mode)

調試

下面展現一個啓動 GDB, 加斷點,並運行一個 Java 程序的過程。

$ gdb java

GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/minix/openjdk8/jdk8u/build/fastdebug/jdk/bin/java...done.

(gdb) b main
Breakpoint 1 at 0x8048410: file /home/minix/openjdk8/jdk8u/jdk/src/share/bin/main.c, line 94.

(gdb) r -classpath PossibleReordering

Starting program: /home/minix/openjdk8/jdk8u/build/fastdebug/jdk/bin/java -classpath PossibleReordering
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

Breakpoint 1, main (argc=3, argv=0xbfffeca4)
    at /home/minix/openjdk8/jdk8u/jdk/src/share/bin/main.c:94
相關文章
相關標籤/搜索