Centos compile JDK8 source code

The configuration of the development machine is as follows: Linux kernel is 2.6, Centos version is 6.9, there should be little difference.

1、 Prepare the environment

Because the kernel is written in C++, GCC is required, and the version of my development machine is 8.1.0;

The make is 3.8.1, and a newer version of 4.2 was originally installed, but it doesn't work, just change to 3.8.1;

JDK

You may need to pay attention to this, because the entire JDK source code only the core code such as JVM is written in C/C++, and some class libraries are written in Java, and finally need to be compiled into class files. This part of the work needs another JDK to compile; To compile 8 JDK, you need to use 1.7, I can also compile with 1.8, and the version I use is 1.8.0_231.

There are a lot of other libraries, you can use yum to install

yum -y install libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel

yum -y install cups-devel

yum -y install alsa-lib-devel

2、 Download source code

There are two download methods, one is github, the address is:

https://github.com/openjdk/jdk

The other is to download with hg, I recommend you to use hg, I used the code downloaded by gitlab to compile a bunch of errors, changed to hg to download and compile and it passed.

hg download command

hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8u

3、 Compile

3.1、 First enter the source code root directory

 cd jdk8u

3.2、 Then download the source code, some codes are not downloaded by default

bash ./get_source.sh

3.3、 Then configure the compilation parameters

bash ./configure --with-target-bits=64--with-debug-level=slowdebug --enable-debug-symbols --with-native-debug-symbols=internal --with-extra-ldflags=-liconv

Pay attention to several parameters

with-debug-level=slowdebug: With debugging information, there are several options: none means no debugging information, and there is a fastdebug, which has limited debugging information. It is recommended to use slowdebug, which has the most debugging information.

enable-debug-symbols and with-native-debug-symbols: both enable debugging information. Only enable-debug-symbols is enabled during the first compilation. There is no breakpoint information when debugging JVM related functions, so bring with -native-debug-symbols will do.

with-extra-ldflags=-liconv: This is because I reported that iconv related functions could not be found when compiling, and the error was reported as follows:

utf_md.c:(.text+0xb6): undefined reference to `libiconv_open'
utf_md.c:(.text+0xf8): undefined reference to `libiconv_open'

This is added according to your own situation.

3.4 Start compiling

make CONF=linux-x86_64-normal-server-slowdebug

The CONF parameter is a compilation configuration, we can configure different compilation parameters, such as one for production without debugging information, the other with debugging information; after configuration, the corresponding folder will be generated in the build directory.

4、 Common compilation errors

4.1、 invalid suffix on literal; C++11 requires a space between literal and string macro [-Werror=literal-suffix]

This is because the compiler warning level is too high, the solution:

Modification: hotspot/make/linux/makefiles/gcc.make

# WARNINGS_ARE_ERRORS =-Werror
WARNINGS_ARE_ERRORS =-Wno-all

4.2、 error: left operand of shift expression ‘(-1 << 28)’ is negative [-fpermissive]

Solution: modify: hotspot/make/linux/makefiles/gcc.make

Add the following content:

CFLAGS +=-fpermissive

Other errors depend on the situation under Baidu. Generally speaking, it is a lack of libraries or something, just install it with yum; there is also a compilation parameter, just modify the relevant Makefile.

5、 debugging

After the above compilation, we can compile with GDB. The GDB version of my development machine is 9.1.

First write a HelloWorld Java code and save it as Hello.java:

publicclassHello{publicstaticvoidmain(String[] args){
 System.out.println("hello world");}}

Then compile with javac, the path of javac is:

. /build/linux-x86_64-normal-server-slowdebug/jdk/bin/javac

Start debugging Java:

gdb ./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java

Set the debugging parameters after running gdb:

set args Hello

Then set a breakpoint in the main function of the entry:

break jdk/src/share/bin/main.c:97

Then you can start to roam in the jdk source code.

Some key functions are as follows:

JNI_CreateJavaVM
JNI_GetDefaultJavaVMInitArgs
JNI_GetCreatedJavaVMs

JavaMain
create_vm

Recommended Posts

Centos compile JDK8 source code
Compile FFMPEG source code under CentOS7
CentOS7.5 source code compile and install mysql5.7.29
CentOS7.4 source code compile and install MySQL8.0
Ubuntu 18.04 source code compile and install ffmpeg4.1
CentOS install jdk
Centos7 configure JDK
How to install openssh from centos 7 source code
Install MySQL 8.x from source code under CentOS7
Compile Hadoop-2.7.6 under CentOS7.4
Linux Centos7 install jdk1.8
CentOS7 install JDK8, tomcat8
CentOS 5 to CentOS 5.8 YUM source
Centos 7 install JDK (Linux install jdk)
Compile and install OpenJDK8 from source code under Ubuntu 18.04.1
Compile and install the open source EDA tool-Surelog on CentOS8
CentOS 7 install JAVA environment (JDK 1.8)
CentOs7.3 compile and install Nginx 1.9.9
Centos compile and install Git
Tencent Cloud Centos install jdk8
Install Java JDK8 under CentOS6
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS 6 compile and install python 3
5.1. CentOS@ install JDK1.8 graphic tutorial
Centos 7 install jdk and package service service
How to install jdk1.8 on centOS7
Install JDK8 in rpm on CentOS7
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
Minimal install JDK 1.8 tutorial in CentOS 7
CentOS8 install jdk8 / java8 tutorial (recommended)
Linux CentOS 7 install JDK detailed steps
CentOS 6.x compile and install Nginx
CentOS7 compile and install L(A|N)MP environment
Android source code compilation (ubuntu16.04 64-bit)
Centos7 uninstall openJdk, and install JDK1.8
CentOS 7 install gogs git code server
Linux CentOS6 compile and install Pyt
How to compile and install xdebug from source code in Ubuntu environment