JAVA Virtual machine Learning 1---openjdk compilation __java

Source: Internet
Author: User
Tags java web mercurial
-------"C + + programming Ideas" Programming Guidelines 1: First let the program run, and then the pursuit of speed. Even if we make sure that this program is very important and is a bottleneck in our system. Do not optimize, first with the simplest possible design so that the program can run, if the speed does not meet the requirements, and then analyze it. We can always find that "our" bottlenecks are not the problem, saving us time to do something really meaningful.


Compilation of OPENJDK


a OpenJDK

OPENJDK is the open source version of the JDK, the microsystems of the Java language Invention company Sun. An open source project that was set up in INC. Because of the version relationship, the OPENJDK source code is not complete, so its functionality is far less than the sun JDK, does not include: Brower Plugin,java Web Start, and Java Control Panel, these features are not found in openjdk, these can not be bound to the source , as a plug-in to OPENJDK compile-time use, OpenJDK6, the IcedTea project to it these incomplete parts developed the same function of the source code. Start as complete as SUNJDK. Also note that OpenJDK only contains the most streamlined JDK, and if the OpenJDK of the Icetea patch is used, OpenJDK command "java-version" displays not OpenJDK, but Java.
Two installation Environment Preparation This article is selected in the VirtualBox, using the Ubuntu 14.04 32-bit version of the image, the main system is Ubuntu 16.04 64, why I was the real machine is Ubuntu, but also to install a virtual machine. Be idle. This one says back. It's quite handy to build with Linux (Ubuntu), naturally with a variety of tool chains, and if you use Windows, look everywhere for the C + + compiler, as well as the various toolkit and compilation environments that are missing from the compilation, install a common JDK, or openjdk to the system, Configure good Java_home,jre_home,classpath. This is my configuration:

Export JAVA_HOME=/OPT/JDK
 export JRE_HOME=${JAVA_HOME}/JRE
 export Classpath=.:${java_home}/lib:${jre_home }/lib
Why install a new JDK on the machine, the back is said.

three installation stepsThere are two ways to download the source code, a is directly under the whole package source B using OPENJDK official Tools mercurial (Hg) like git to download
A directly under the whole package source code, the advantage is fast and convenient, the bad place is not see the official modification of the release is not. However, it is recommended in this way, because B way, there are many times, is not downloaded, do not know why.
Direct to URL: http://download.java.net/openjdk/jdk8/

B use Mercurial (Hg). Download
OPENJDK's source file version library is based on mercurial (Hg), a distributed version control tool similar to Git. To install mercurial in Ubuntu just execute the command
---Install version management tools
1) $ sudo apt-get install mercurial-y
---download OPENJDK framework
2) $ HG clone http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk8-src
---into the framework directory
3) $ cd JDK8-SRC
----OPENJDK's source code version library actually contains multiple stand-alone versions of the library, you need to execute the following script to download the source codes for each version of the library separately.
4) $ sh get_source.sh
# Repositories:corba Jaxp jaxws langtools jdk hotspot Nashorn
....

Four Build 1 Setting environment variables

First of all, to say that the build openjdk to a narratives, this narratives called the boot JDK, this tool is generally integrated in the common JDK, so install a common JDK to the system, and then configure the environment variables. Then continue to add the following variables to the. BASHRC.

Export use_precompiled_header=true
export skip_debug_build=false  
export skip_fastdebug_build=true  
Export debug_name=debug   
export lang=c   
unset CLASSPATH  
unset java_home

2) Configure the compilation environment$ sh Configure or Bash configure
This process detects if the build environment meets the requirements, and if so, it gives a hint. Like what
Configure:error:Could not find X11 libraries. You are able to fix the by running ' sudo apt-get install Libx11-dev Libxext-dev Libxrender-dev might libxtst-dev '.
Later, most of the missing tools that continue to be installed can be installed by prompting Apt. After each installation, repeat the above configure command again until no error has been returned. Do not use apt to install Ccashe,ubuntu's software library, this software is too old.

3 installation of High speed C + + Compiler tool (CCache)https://ccache.samba.org/
It can take a long time to compile when dealing with some relatively large projects. Sometimes we will often compile the same program over and over again, at this time, with the ccache situation is much better. It will take a few more seconds to compile the first time, but the next step is to multiply (5-10 times) The speed of the compilation.
After downloading the source package, unzip and enter the package. Execute the following command:
$./configure
$make
$make Install
$sudo CP ccache/usr/local/bin/
$sudo ln-s CCACHE/USR/LOCAL/BIN/GCC
$sudo ln-s ccache/usr/local/bin/g++
$sudo ln-s ccache/usr/local/bin/cc
$sudo ln-s ccache/usr/local/bin/c++

4) Return to the OPENJDK source package for construction execute the following command$make All Debug_binaries=true
Next is the slow wait, fast 20 minutes, my due to the virtual machine, the machine CPU is slower, with 40 minutes.

When finished, a build directory is generated under the current path, and the built JDK is there. The specific path of the new JDK is similar to Build/linux-x86-normal-server-release/jdk/bin. You can perform the following command to test this JDK, which I modified the JVM after adding my own name customization, haha.



five postscript: at that time, my machine is Ubuntu 16.04 64, no matter how the construction, are wrong, Google a bit, did not meet the Chinese have said that the problem, only found 2013-2014, a few foreigners posted a mention, One of them was a tester for the Debian system, and today I wrote a letter asking him, "I don't know if this guy left." The following link is the problem in the Debian bug system, and it is the problem I have encountered.
Https://lists.debian.org/debian-java/2014/05/msg00024.html
So, finally, I can only use the virtual machine in Ubuntu, reinstall a 32-bit low version of 14.04, and then no problem. May be g++ too high.


Continued:

After the computer reload Ubuntu 14.04 64, the whole process is no problem. It seems that compiling openjdk is very critical to the environment.




Related Article

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.