openjdk-8u40-src-b25-10_feb_2015.7z openjdk8官方源代码,编译OpenJDK8u的源代码需要先安装JDK。
现在看的资料都是编译 openjdk7 的,openjdk8好像已经 openjdk7 编译方式大一样,按照前辈的文章使用
make sanity
会提示找不到 sanity 规则,然后编译过程其实基本就直接
./configure make all
官方的 README 写的很清楚。
下面记录下过程
下载代码
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8u cd jdk8u bash ./get_source.sh
然后下载代码,进入代码目录:
cd jdk8u
代码目录中有一个 README-builds.html 描述了如何 build 整个系统,一些细节需要自己去寻找。
安装依赖
sudo aptitude build-dep openjdk-7 sudo aptitude install openjdk-7-jdk
配置
环境变量
export export PATH="/usr/lib/jvm/java-7-openjdk/bin:${PATH}"
配置编译选项
bash ./configure
这样生成相应默认配置,如果有需要,比如想编译出调试版本的,可以给 configure 加参数。
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 ./configure --enable-debug
这样会生成 fastdebug 版本的配置信息:
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 了。
--enable-debug 其实相当于--with-debug-level=fastdebug, 可以通过这样的参数选项指定编译级别。一共可以指定三种级别: release, fastdebug, slowdebug, slowdebug 含有最丰富的调试信息,没有这些信息,很多执行可能被优化掉,我们单步执行时,可能看不到一些变量的值。所以最好指定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
140.5M / 09-05
立即下载76.4M / 03-25
立即下载55M / 06-05
立即下载237.9M / 04-13
立即下载900.9M / 03-02
立即下载96.2M / 07-06
立即下载311.2M / 07-06
立即下载335M / 07-06
立即下载200M / 07-06
立即下载413.8M / 07-06
立即下载484.7M / 09-27
立即下载165.4M / 09-05
立即下载353.9M / 06-05
立即下载131.8M / 04-13
立即下载195.6M / 03-03
立即下载45.6M / 09-08
立即下载665.2M / 07-06
立即下载2.84G / 07-06
立即下载93M / 07-06
立即下载338.3M / 07-06
立即下载1.38G / 07-26
立即下载488.3M / 07-16
立即下载109.8M / 06-03
立即下载142M / 01-08
立即下载1.2M / 11-23
立即下载548.8M / 04-13
立即下载1.6M / 04-13
立即下载1.48G / 03-18
立即下载646.6M / 03-03
立即下载133.7M / 03-03
立即下载110.5M / 09-05
立即下载33.4M / 09-05
立即下载325.8M / 08-12
立即下载60M / 04-29
立即下载254M / 04-25
立即下载659M / 04-23
立即下载1M / 12-26
立即下载253.4M / 12-08
立即下载253M / 12-08
立即下载1.19G / 11-16
立即下载369M / 09-22
立即下载181.5M / 09-22
立即下载201.2M / 09-05
立即下载488.3M / 07-16
立即下载248.9M / 12-08
立即下载248.9M / 12-08
立即下载100.6M / 03-06
立即下载148.9M / 03-06
立即下载1.12G / 07-06
立即下载1.25G / 07-06
立即下载1.76G / 09-22
立即下载1.92G / 04-17
立即下载116.2M / 04-10
立即下载201.5M / 04-13
立即下载7.31G / 07-01
立即下载94.3M / 07-06
立即下载2.48G / 07-06
立即下载7.63G / 07-06
立即下载1M / 07-06
立即下载778.1M / 07-06
立即下载561.8M / 07-11
立即下载72M / 07-06
立即下载548.7M / 07-06
立即下载1.00G / 07-06
立即下载9.13G / 07-06
立即下载126.2M / 07-06
立即下载72M / 07-06
立即下载105.1M / 07-06
立即下载132M / 07-06
立即下载132M / 07-06
立即下载