JVM Learning--Compiling OPENJDK

Source: Internet
Author: User

I've been learning more about the second edition of Java Virtual machine. The first part of the book suggests that you compile openjdk yourself. Hold the learning attitude also to compile a play. Let's get down to the chase.

1. Introduction to the compilation environment

Operating system CentOS Linux release 7.1.1503 (Core)
Linux kernel version 3.10.0-229.el7.x86_64
GCC version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)
OPENJDK version Openjdk-7u40

2. Preparatory work

2.1 Downloads OpenJDK

Open Web site https://jdk7.java.net/source.html Copy the link here directly in Linux wget. Wget Http://www.java.net/download/openjdk/jdk7u40/promoted/b43/openjdk-7u40-fcs-src-b43-26_aug_2013.zip Decompress the package, Will get the OpenJDK folder unzip OPENJDK-7U40-FCS-SRC-B43-26_AUG_2013.ZIPCD OpenJDK Here is a build instructions document Readme-builds.html, which is recommended to look under Windows. The next steps depend on it all. 2.2 Download DependenciesSpecific dependency requirements explained in readme-builds.html, here directly to command: # yum install-y glibc*# yum install cups-devel# yum install-y alsa*# Yum Inst All-y fontconfig*# Yum install zip*# yum install libstdc++-static Installing FreeTypeDownload Source # wget http://jaist.dl.sourceforge.net/project/freetype/freetype2/2.3.12/freetype-2.3.12.tar.gz Unzip the source code, compile and install # tar -ZXVF freetype-2.3.12.tar.gz# cd freetype-2.3.12#./configure && make && sudo-u root make Install Download and install AntConfiguring the ANT environment variable # wget http://mirrors.hust.edu.cn/apache//ant/binaries/apache-ant-1.9.6-bin.tar.gz# vi/etc/profile Add the following content:Export ant_home=/opt/openjdkroom/apache-ant-1.9.6export path= $PATH: $ANT _home/bin# Source/etc/profile Download and install cupswget http://www.cups.org/software/2.1.2/cups-2.1.2-source.tar.bz2tar-jxvf cups-2.1.2-source.tar.bz2#./configure && make && make install 2.3 Masking already configured Java_homeThe following post readme-builds.html the central Plains text:
Note that some Linux systems has a habit of pre-populating your environment variables for your, for example java_home< /c1> might get pre-defined for your refer to the JDK installed on your Linux system. You'll need to unset java_home. It's a good idea to run env and verify the environment variables is getting from the default system settings Make sense for building the OpenJDK.
Check first if you have java_home# env configured locally | grep java_home, if any, is shielded. 2.4 Configuring the boot JDKThe following post readme-builds.html the central Plains text:
Bootstrap JDK
All OpenJDK builds require access to the previously released JDK 6, which is often called a bootstrap jdk. The JDK 6 binaries can downloaded from Sun ' s JDK 6 download site. For build performance reasons are very important that this bootstrap JDK being made available on the local disk of the machine Doing the build. You-should always set Alt_bootdir -to-point-the location of the bootstrap JDK installation, which is the Directo Ry pathname that contains a bin, Lib, and include It's also a good idea-to-also place-its bin directory In the PATH environment variable, although it's not required.
Download and install bootstrapDownload the JDK 6 Linux 64-bit jdk-6u45-linux-x64.bin# chmod +x jdk-6u45-linux-x64.bin#./jdk-6u45-linux-x64.bin when the installation is complete, The jdk1.6.0_45 directory is generated under the current directory, and the directory path is configured for the ALT_BOOTDIR environment variable. Add the following configuration to the/etc/profile (whichever is the actual):Export alt_bootdir=/opt/openjdkroom/jdk1.6.0_45# Source/etc/profile 2.5 Configuring environment Variables Alt_cacerts_file
Certificate Authority File (CACert) see http://en.wikipedia.org/wiki/certificate_authority  for a better understanding of the Certificate Authority (CA). A certificates file named "Cacerts" represents a system-wide KeyStore with CA certificates. In JDK and JRE binary bundles, the ' cacerts ' file contains root CA certificates from several public CAs (e.g., VeriSign, T Hawte, and Baltimore). The source contain a cacerts file without CA root certificates. Formal JDK builders would need to secure permission from each public CA and include the certificates into their own custom Cacerts file. Failure to provide a populated cacerts file would result in verification errors of a certificate chain during runtime. The Variable alt_cacerts_file can is used to override the default location of the CACERTS FILE that would get PLA CED in your build. By default a empty Cacerts file is provided and that should are fine for most JDK developers.
Go to the OPENJDK directory and look for files with the name Cacerts: # CD openjdk# find./-name Cacerts The results are as follows: [[email protected] openjdk]# Find/-name cacerts. /jdk/src/share/lib/security/cacerts Open/etc/profile, add the following (specific path according to the actual situation):Export Alt_cacerts_file=/opt/openjdkroom/openjdk/jdk/src/share/lib/security/cacerts 3. Start compilingFinally, we're going to start compiling! >_< Readme-builds.html used is gmake, the actual and make is the same, the following is explained:
Gmake is the abbreviation for GNU make. The Linux system environment makes the GNU make, the reason is gmake, because on other platforms, made is generally occupied, GNU make had to call Gmake.
Go to OpenJDK root directory, compile cd/opt/openjdkroom/openjdkgmake sanitygmake result execution error:gmake[6]: Entering directory '/opt/openjdkroom/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_ Compiler2/product 'Gmake[6]: Stat:libjvm.so:Too Many levels of symbolic linksEnter to/opt/openjdkroom/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/ The following link is available in the product directory: Libjvm.so->libjvm.solibjvm.so.1->libjvm.so is obviously caused by libjvm.so->libjvm.so (you can do an experiment on your own, Do not create a file, directly execute the ln-s file file, and then cat file will report this error) knowing the problem, it is necessary to reference a real so file. Find where the file exists by Find/opt-name libjvm.so command, and point libjvm.so->libjvm.so to the real file location. That # rm-f libjvm.so# ln-sspecific libjvm.so file completion pathLibjvm.so executes gmake again. The results reported the following errors:Error:time is more than-years from present:1136059200000
Java.lang.RuntimeException:time is more than-years from present:1136059200000
At Build.tools.generatecurrencydata.GenerateCurrencyData.makeSpecialCaseEntry (generatecurrencydata.java:285 )
At Build.tools.generatecurrencydata.GenerateCurrencyData.buildMainAndSpecialCaseTables ( generatecurrencydata.java:225)
At Build.tools.generatecurrencydata.GenerateCurrencyData.main (generatecurrencydata.java:154)After the query found this is a bug ..... The following describes the source of the corresponding patches https://bugs.gentoo.org/show_bug.cgi?id=534118#c3 the following related to the cause of the discussion description https://bugs.gentoo.org/show_bug.cgi Id=534118#c7 If you don't want to look closely, you can access the patch URL directly: http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/rev/74a70385c21d# l11.1 copies the contents of the file into the corresponding file. Continue Gmake finally compiled successfully!!! The following prompt shows that the compilation is complete.#--Build Times----------Target All_product_build
Start 2016-01-10 11:18:43
End 2016-01-10 11:52:15
00:00:15 CORBA
00:00:21 hotspot
00:00:11 JAXP
00:00:20 Jaxws
00:32:15 JDK
00:00:10 Langtools
00:33:32 Total------------------------- 4. Run your own compiled virtual machineGo to catalogue/opt/openjdkroom/openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_ Compiler2 There are several compiled versions of the optimization level below: drwxr-xr-x. 2 root root 4096 Jan 9 16:53 Debug
Drwxr-xr-x. 2 root root 4096 Jan 9 16:53 fastdebug
Drwxr-xr-x. 7 root root 4096 Jan 9 16:56 generated
Drwxr-xr-x. 2 root root 4096 Jan 9 16:53 jvmg
Drwxr-xr-x. 2 root root 4096 Jan 9 16:53 optimized
Drwxr-xr-x. 3 root root 20480 Jan 11:19 product
Drwxr-xr-x. 2 root root 4096 Jan 9 16:53 profiled-rw-r--r--. 1 root root 1518 Jan 9 16:53 shared_dirs.lst into the product directory. Here, under the ENV.SH configuration environment variable, point to the shared library

ld_library_path=.:${java_home}/jre/lib/amd64/native_threads:${java_home}/jre/lib/amd64:/opt/openjdkroom/ Openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product
Export Ld_library_path

The full contents of my file are posted below:

# Generated By/opt/openjdkroom/openjdk/hotspot/make/linux/makefiles/buildtree.make
#: ${java_home:=/opt/openjdkroom/jdk1.6.0_45}
Java_home=/opt/openjdkroom/openjdk/build/linux-amd64/j2sdk-image
Classpath=.:${java_home}/jre/lib/rt.jar:${java_home}/jre/lib/i18n.jar
hotspot_build_user= "root in Hotspot"
Export Java_home CLASSPATH Hotspot_build_user

# add

ld_library_path=.:${java_home}/jre/lib/amd64/native_threads:${java_home}/jre/lib/amd64:/opt/openjdkroom/ Openjdk/build/linux-amd64/hotspot/outputdir/linux_amd64_compiler2/product
Export Ld_library_path

Below execution:

# source./env.sh

#./gamma-version

Using Java Runtime at:/opt/openjdkroom/openjdk/build/linux-amd64/j2sdk-image/jre
OPENJDK Version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-root_2016_01_10_00_16-b00)
OpenJDK 64-bit Server VM (build 24.0-b56, Mixed mode)

Run successfully!!

I want to have a reference to a friend who wants to compile openjdk. If you have any questions, please come and study together. >_<

JVM Learning--Compiling OPENJDK

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.