JVM (i) OpenJDK1.8 source code under the Ubuntu16.04 of the compilation

Source: Internet
Author: User

I recently in the study Zhou Zhiming teacher wrote "in-depth understanding of Java Virtual Machine" book, the first chapter of the actual combat part is "self-compiled JDK", but the book refers to the compilation of OpenJDK 7. Since the Java development mainstream JDK is basically 1.8 version, so the author of the OpenJDK 8 compiled.

(This article for Bo Master original article, reproduced please specify the source)

First, the Environment preparation

1. Operating system

The author uses Ubuntu 16.04.2 LTS (gnu/linux 4.8.0-36-generic x86_64), and of course other Debian Linux operating systems, theoretically also possible;

2. Installing the bootstrap JDK

Since we compiled the OPENJDK 8, the Bootstrap JDK is best used in the OpenJDK 1.7 version, the author installs the

" 1.7.0_95 "  2.6. 4) (7u95-2.6.  4-324.95-b01, Mixed mode)

The way to install OpenJDK7 under Ubuntu is simple

Run the following command directly:

sudo Install openjdk-7-JREsudoinstall openjdk-7-jdk

If there is no package openjdk-7-jdk available, it is referenced by other packages. This may mean that the missing package may have been discarded, or can only be found in other publishing sources, E: Package OPENJDK-7-JDK has no installable candidate ", you can install the 1.7.X version by following the operation

sudo add-apt-repository ppa:openjdk-r/ppa  sudo apt-get update   sudo  Install openjdk-7-JREsudoinstall openjdk-7- Jdk

3. Download the source code download for OPENJDK 8

I try to download from the official website, but, but did not find the place to download (find the relevant links can not be downloaded, only through the HG from the code base check out, but this is too time-consuming, because the code base in foreign countries), and finally on the csdn someone to provide the source of the download, If you do not want to find the source of energy, I provide a link to Baidu network, students who need to download.

Links: http://pan.baidu.com/s/1hr9IV3m

Password: 2VB5

4. Installation of dependent packages

Since the JDK relies on some external packages during compilation, it is best to install them before compiling. Of course, If you do not install before compiling, the script will check the environment when you run the./configure, and when it fails, it can be installed, but it is time-consuming.

The following is a package that I found missing and installed during the installation, for reference only, and may not be the same for different OS missing packages:

sudo Install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-devsudoinstall libcups2-Devsudoinstall libfreetype6-devsudoinstall Libasound2-dev

Second, compile

OK, now that the environment for compiling the JDK is ready, we can start compiling.

1. Upload the OPENJDK 8 source package to any directory on the OS

2. Enter the root directory of OPENJDK 8

ls a.out               Build   Configure  Get_source. SH   jaxp   jdk        LICENSE  Makefile  README              testassembly_exception  Common  CORBA      hotspot        jaxws  langtools  make     nashorn   readme-builds.html  Third_party_readme

3. Run the Configure script under the root directory

[email protected]:openjdk$ bash Configure Running generated-configure.SHConfigure:configuration created at Wed Sep6  to: the: GenevaPdt .. Configure:configure script generated at timestamp1416326200. Checking for basename.../usr/bin/basenamechecking forBash .../bin/bashchecking for Cat.../bin/Catchecking for chmod.../bin/chmod.............................. Omitted====================================================A New configuration has been successfully createdinch/home/lxy/jdk-src/openjdk/build/linux-x86_64-normal-server-releaseusing default settings. Configuration Summary:*Debug level:release*JDK Variant:normal*JVM Variants:server* OpenJDK Target:OS:linux, CPU architecture:x86, address length: -Tools Summary:* Boot Jdk:java version"1.7.0_95"OpenJDK Runtime Environment (IcedTea2.6.4) (7u95-2.6.4-3) OpenJDK --bit Server VM (build24.95-B01, Mixed mode) (at/usr/lib/jvm/java-7-openjdk-AMD64)* C Compiler:GCC-5(Ubuntu5.4.0-6ubuntu1~16.04.4)5.4.0Version20160609(at/usr/bin/GCC-5)* C + + compiler:g++-5(Ubuntu5.4.0-6ubuntu1~16.04.4)5.4.0Version20160609(at/usr/bin/g++-5) Build Performance Summary:* Cores to use:1* Memory Limit:1981MB* CCache Status:not installed (consider installing)

4. Run Make all

If everything goes well, after about 40 minutes, the entire compilation of the JDK will be completed and you will see the following message.

-----Build times-------Start .- the- to  the: -:GenevaEnd .- the- to  the: the: -xx: on: toCORBAxx: on:TenDemosxx: to: theDocsxx: -: ,hotspotxx: on: -Imagesxx:xx: $Jaxpxx:xx: theJaxwsxx: the: atJDKxx:xx:xxLangtoolsxx:xx: +Nashornxx: $: - Total-------------------------

5. Verify the JDK after compilation

The compiled JDK executable files are stored in the Build/linux-x86_64-normal-server-release directory of the JDK root directory and into the directory./build/linux-x86_64- Normal-server-release/jdk/bin

Run the following command

[Email protected]:bin$./java-"1.8.0-internal"1.8. 0-internal-lxy_2017_09_05_08_49-25.40-b25, Mixed mode)

Well, congratulations, your JDK compiles and runs, and of course you can write a simple Java Hello world to run the ^~^.

Iii. problems encountered and solutions

1. When running bash./configure, you encounter an error similar to the following

As I mentioned in "Environment preparation", according to the prompts to install the relevant package can be;

2. Running make all encountered an unsupported error from the operating system

It is easy to see from the error that the kernel version is inconsistent with the kernel version required by the JDK. According to the error, find the corresponding makefile (

/home/lxy/jdk-src/openjdk/hotspot/make/linux/makefile) file, line 259

See here, because my current connotation is 4 beginning, so here error. My solution is to change the Supported_os_version = 2.4% 2.5% 2.6% 3% here directly to Supported_os_version = 2.4% 2.5% 2.6% 3% 4%, which adds support for the version beginning with 4. After you have modified and run make all, no more error has occurred.

Iv. Summary

The entire OPENJDK 8 compilation process is much simpler than I imagined. If something is wrong or there is a problem, please ask to discuss it together.

Reference:

Readme-builds.html--This document is OPENJDK in the source code, more comprehensive

http://blog.csdn.net/u010856630/article/details/51660012

"In-depth understanding of Java virtual machines"

JVM (i) OpenJDK1.8 source code under the Ubuntu16.04 of the compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.