JVM进阶3--Centos7编译OpenJDK8

启动Centos操作系统

1.下载openjdk8源码 

 http://jdk.java.net/java-se-ri/8

2.安装jdk1.7版本以上

[root@hadoop-01 ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
[root@hadoop-01 ~]# whereis java
java: /home/jdk1.7.0_79/bin/java

3.检查GNU make版本大于3.81

[root@hadoop-01 ~]# make -version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010  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.

4.进入到openjdk目录下执行编译环境检查指令

安装必须的软件

yum install -y zip
yum groupinstall -y "Development Tools"
yum install -y libbXtst-devel libXt-devel libXrender-devel
yum install -y cups-devel
yum install -y alsa-lib-devel
yum install -y freetype-devel

执行编译检查命令

bash ./configure --with-target-bits=64 --with-boot-jdk=/home/jdk1.7.0_79/ --with-debug-level=slowdebug --enable-debug-symbols ZIP_DEBUGINFO_FILES=0

--with-boot-jdk:指定引导JDK所在目录;

--with-target-bits:指定编译64位系统的JDK;

为可以进行源码调试,再指定下面三个参数:

--with-debug-level=slowdebug:指定可以生成最多的调试信息;

--enable-debug-symbols ZIP_DEBUGINFO_FILES=0:生成调试的符号信息,并且不压缩;

在此过程中会提示缺少系统需要的软件,根据日志信息来安装相应软件。

编译检查通过显示如下:

====================================================
A new configuration has been successfully created in
/openjdk/openjdk/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-target-bits=64 --with-boot-jdk=/home/jdk1.7.0_79/ --with-debug-level=slowdebug --enable-debug-symbols ZIP_DEBUGINFO_FILES=0'.

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

Tools summary:
* Boot JDK:       java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)  (at /home/jdk1.7.0_79)
* C Compiler:     gcc (GCC) 4.8.5 20150623 (Red Hat-36) version 4.8.5-36) (at /usr/bin/gcc)
* C++ Compiler:   g++ (GCC) 4.8.5 20150623 (Red Hat-36) version 4.8.5-36) (at /usr/bin/g++)

Build performance summary:
* Cores to use:   3
* Memory limit:   3774 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 yum install ccache'.

5.执行编译指令

make all ZIP_DEBUGINFO_FILES=0

编译完成,显示如下:

----- Build times -------
Start 2019-04-17 21:54:03
End   2019-04-17 22:08:15
00:00:42 corba
00:00:23 demos
00:02:18 docs
00:04:03 hotspot
00:00:55 images
00:00:21 jaxp
00:00:28 jaxws
00:03:59 jdk
00:00:44 langtools
00:00:18 nashorn
00:14:12 TOTAL
-------------------------
Finished building OpenJDK for target 'all'

编译文件位置:/openjdk/build/linux-x86_64-normal-server-slowdebug

查看一下java版本信息

[root@hadoop-01 bin]# pwd
/openjdk/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin
[root@hadoop-01 bin]# ./java -version
openjdk version "1.8.0-internal-debug"
OpenJDK Runtime Environment (build 1.8.0-internal-debug-root_2019_04_17_21_50-b00)
OpenJDK 64-Bit Server VM (build 25.40-b25-debug, mixed mode)

6.gdb调试源代码

编辑测试类Test.java

[root@hadoop-01 build]# cat Test.java 
public class Test{
    public static void main(String[] args){
        System.out.println("hello world !");
    }
}

编译执行

[root@hadoop-01 build]# ./linux-x86_64-normal-server-slowdebug/jdk/bin/javac Test.java
[root@hadoop-01 build]# ./linux-x86_64-normal-server-slowdebug/jdk/bin/java Test
hello world !

利用gdb进行调试

gdb --args /openjdk/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java Test
[root@hadoop-01 build]# gdb --args /openjdk/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java Test
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /openjdk/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java...done.
(gdb) break init.cpp:95
No source file named init.cpp.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (init.cpp:95) pending.
(gdb) run
Starting program: /openjdk/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java Test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff7fcd700 (LWP 55943)]
[Switching to Thread 0x7ffff7fcd700 (LWP 55943)]

Breakpoint 1, init_globals () at /openjdk/openjdk/hotspot/src/share/vm/runtime/init.cpp:96
96	  HandleMark hm;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7_6.3.x86_64 libgcc-4.8.5-36.el7_6.1.x86_64 libstdc++-4.8.5-36.el7_6.1.x86_64
(gdb) l
91	  perfMemory_init();
92	}
93	
94	
95	jint init_globals() {
96	  HandleMark hm;
97	  management_init();
98	  bytecodes_init();
99	  classLoader_init();
100	  codeCache_init();

gdb指令总结:https://www.cnblogs.com/HKUI/p/8955443.html

启动方式:

1.GDB yourpram

2.先输入GDB
然后输入 file yourpram

参数列表

 命令

命令缩写

命令说明

list

l

显示多行源代码

break

b

设置断点,程序运行到断点的位置会停下来

info

i

描述程序的状态

run

r

开始运行程序

display

disp

跟踪查看某个变量,每次停下来都显示它的值

step

s

执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句

next

n

执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)

print

p

打印内部变量值

continue

c

继续程序的运行,直到遇到下一个断点

set var name=v

 

设置变量的值

start

st

开始执行程序,在main函数的第一条语句前面停下来

file

 

装入需要调试的程序

kill

k

终止正在调试的程序

watch

 

监视变量值的变化

backtrace

bt

查看函数调用信息(堆栈)

frame

f

查看栈帧  f n 切换到编号为n的栈

quit

q

退出GDB环境

参考地址:

https://www.linuxidc.com/Linux/2017-06/144713.htm

https://www.cnblogs.com/HKUI/p/8955443.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值