Personal tech blog: www.zhenganwen.top

The author environment

  • 64bit/Windows10 / I5-7200U / 4 core CPU, on the VMCentos7(can connect to the Internet) on the compilationOpenJDK7u75

You are advised to use Centos or debain, or change yum to Centos. I compiled on Rhel at first. Step on a lot of pit, finally change to centos to compile successfully. No way, Linux is a real dish, but through this pit also learned a lot of Linux compiler source routines, this article will be interspersed with mentioned).

Environment to prepare

Its source

Openjdk7u75, main character, download to compile.

Bootstrap JDK

BOOTSTRAP JDK (JDK6 Update14 or later); BOOTSTRAP JDK (BOOTSTRAP JDK); We recommend that you download the JDK – 7U4-linux-x64 from Oracle’s official website

Compile environment

Compilation needs to rely on GCC, C++ and other environments, one-click download:

yum -y install build-essential gawk m4 openjdk6-jdk libasound2-print-dev binutils libmotif3 libmotif-dev ant
Copy the code

Xcode-related libraries:

yum install libX*
Copy the code

Checking the compilation environment

/usr/local/java = /usr/local/java = /usr/local/java

[root@pinyoyougou-docker Java]# ls jdk1.7.0_04 JDK-7u4-linux-x64.tar. gz openJDK openJDK-7U75-src-b13-18_dec_2014.zipCopy the code

The openJDK directory above is the directory in which the openJDK source package was unzipped.

Enter the OpenJDK and check the compilation environment:

[root@pinyoyougou-docker java]# cd openjdk [root@pinyoyougou-docker java]# make sanity WARNING: LANG has been set to zh_CN.UTF-8, this can cause build failures. Try setting LANG to 'C'. WARNING: The version of zip being used is older than The required version of '2.2'. The version of zip found was ". ERROR: The Compiler version is undefined. ERROR: Your CLASSPATH environment variable is set. This will most likely cause the build to fail. Please unset it and start your build again. ERROR: Your JAVA_HOME environment variable is set. This will most likely cause the build to fail. Please unset it and start your build again. ERROR: You seem to not have installed ALSA 0.9.1 or higher. Please install ALSA (drivers and lib) distribution from http://www.alsa-project.org or go to http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. ERROR: FreeType version 2.3.0 or higher is required. Make [2]: Enter the directory "/ usr/local/Java/its/JDK/make/tools/freetypecheck"/bin/mkdir -p /usr/local/java/openjdk/build/linux-amd64/btbins rm -f /usr/local/java/openjdk/build/linux-amd64/btbins/freetype_versioncheck make[2]: Leave the directory "/ usr/local/Java/its/JDK/make/tools/freetypecheck" Failed to build freetypecheck. ERROR: You do not have access to valid Cups header files. Please check your access to /usr/include/cups/cups.h and/or check your value of ALT_CUPS_HEADERS_PATH, CUPS is frequently pre-installed on many systems, or may be downloaded from http://www.cups.orgCopy the code

There are two warnings and five exceptions that we need to resolve one by one. (Skip this step if you are exporting check pass to make sanity)

  1. Set the environment variable LANG=C

    WARNING: LANG has been set to zh_CN.UTF-8, this can cause build failures.
             Try setting LANG to 'C'.
    Copy the code

    Solutions:

    [root@pinyoyougou-docker java]# export LANG=C
    Copy the code
  2. The zip version is early and needs to be updated

    WARNING: The version of zip being used is older than The required version of '2.2'. The version of zip found was ".Copy the code

    Solutions:

    yum install zip
    Copy the code
  3. Lack of compile dependencies

    ERROR: The Compiler version is undefined.
    Copy the code

    Solution:

    [root@pinyoyougou-docker openjdk]# yum install gcc gcc-c++
    Copy the code
  4. Cancels existing JDK environment variables

    ERROR: Your CLASSPATH environment variable is set.  This will
           most likely cause the build to fail.  Please unset it
           and start your build again.
    Copy the code

    Since I have installed JDK on centos and configured JAVA_HOME and CLASS_PATH in /etc/profile, I am advised to temporarily cancel these two Settings, otherwise unknown errors may occur. Solution:

    [root@pinyoyougou-docker openjdk]# unset JAVA_HOME
    [root@pinyoyougou-docker openjdk]# unset CLASS_PATH
    Copy the code
  5. The lack of a sound card dependency on ALSA, which is a common sound device dependency on Linux and is required by java.awt.

    ERROR: You seem to not have installed ALSA 0.9.1 or higher. Please install ALSA (drivers and lib) distribution from http://www.alsa-project.org or go to http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages.Copy the code

    To solve

    [root@pinyoyougou-docker openJDK]# yum Search alsa fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.shu.edu.cn * updates: mirrors.aliyun.com ======================================== N/S matched: alsa ======================================== alsa-firmware.noarch : Firmware for several ALSA-supported sound cards alsa-lib.x86_64 : The Advanced Linux Sound Architecture (ALSA) library alsa-lib.i686 : The Advanced Linux Sound Architecture (ALSA) library alsa-lib-devel.i686 : Development files from the ALSA library alsa-lib-devel.x86_64 : Development files from the ALSA library alsa-plugins-arcamav.i686 : Arcam AV amplifier plugin for ALSA alsa-plugins-arcamav.x86_64 : Arcam AV amplifier plugin for ALSA alsa-plugins-maemo.i686 : Maemo plugin for ALSA alsa-plugins-maemo.x86_64 : Maemo plugin for ALSA alsa-plugins-oss.i686 : Oss PCM output plugin for ALSA alsa-plugins-oss.x86_64 : Oss PCM output plugin for ALSA alsa-plugins-pulseaudio.i686 : Alsa to PulseAudio backend alsa-plugins-pulseaudio.x86_64 : Alsa to PulseAudio backend alsa-plugins-samplerate.i686 : External rate converter plugin for ALSA alsa-plugins-samplerate.x86_64 : External rate converter plugin for ALSA alsa-plugins-upmix.i686 : Upmixer channel expander plugin for ALSA alsa-plugins-upmix.x86_64 : Upmixer channel expander plugin for ALSA alsa-plugins-usbstream.i686 : USB stream plugin for ALSA alsa-plugins-usbstream.x86_64 : USB stream plugin for ALSA alsa-plugins-vdownmix.i686 : Downmixer to stereo plugin for ALSA alsa-plugins-vdownmix.x86_64 : Downmixer to stereo plugin for ALSA alsa-tools.x86_64 : Specialist tools for ALSA alsa-tools-firmware.x86_64 : ALSA tools for uploading firmware to some soundcards alsa-utils.x86_64 : Advanced Linux Sound Architecture (ALSA) utilities alsa-plugins-speex.i686 : Rate Converter Plugin Using Speex Resampler alsa-plugins-speex.x86_64 : Rate Converter Plugin Using Speex Resampler [root@pinyoyougou-docker openjdk]# yum -y install alsa-lib* alsa-util*Copy the code

    You can search yum Search for dependencies that have the same prefix and use the suffix wildcard to download them in one click.

  6. Lack of FreeType dependencies

    ERROR: FreeType version  2.3.0  or higher is required.
    Copy the code

    Solution:

    root@pinyoyougou-docker openJDK]# yum Search freetype fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.shu.edu.cn * updates: mirrors.aliyun.com ====================================== N/S matched: freetype ====================================== freetype-demos.x86_64 : A collection of FreeType demos freetype-devel.i686 : FreeType development libraries and header files freetype-devel.x86_64 : FreeType development libraries and header files freetype.x86_64 : A free and portable font rendering engine freetype.i686 : A free and portable Font rendering engine Matches only, use "Search all". [root@pinyoyougou-docker openjdk]# yum install freetype-devel.x86_64Copy the code

    # yum install install -y (-y)

  7. Then I applied to Sanity and found another problem

    ERROR: You do not have access to valid Cups header files.
           Please check your access to
               /usr/include/cups/cups.h
           and/or check your value of ALT_CUPS_HEADERS_PATH,
           CUPS is frequently pre-installed on many systems,
           or may be downloaded from http://www.cups.org
    Copy the code

    Missing cups printing framework, resolved:

    [root@pinyoyougou-docker openjdk]# yum Search cups fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.shu.edu.cn * updates: mirrors.aliyun.com ======================================== N/S matched: cups ======================================== bluez-cups.x86_64 : CUPS printer backend for Bluetooth printers cups.x86_64 : CUPS printing system cups-client.x86_64 : CUPS printing system - client programs cups-devel.i686 : CUPS printing system - development environment cups-devel.x86_64 : CUPS printing system - development environment cups-filesystem.noarch : CUPS printing system - directory layout cups-filters.x86_64 : OpenPrinting CUPS filters and backends cups-filters-devel.i686 : OpenPrinting CUPS filters and backends - development environment cups-filters-devel.x86_64 : OpenPrinting CUPS filters and backends - development environment cups-filters-libs.i686 : OpenPrinting CUPS filters and backends - cupsfilters and fontembed : libraries cups-filters-libs.x86_64 : OpenPrinting CUPS filters and backends - cupsfilters and fontembed : libraries cups-ipptool.x86_64 : CUPS printing system - tool for performing IPP requests cups-libs.x86_64 : CUPS printing system - libraries cups-libs.i686 : CUPS printing system - libraries cups-lpd.x86_64 : CUPS printing system - lpd emulation ghostscript-cups.x86_64 : CUPS filter for interpreting PostScript and PDF gutenprint-cups.x86_64 : CUPS drivers for Canon, Epson, HP and compatible printers python-cups.x86_64 : Python bindings for CUPS python-cups-doc.x86_64 : Documentation for python-cups cups-pk-helper.x86_64 : A helper that makes system-config-printer use PolicyKit foomatic-filters.x86_64 : CUPS print filters for the foomatic package samba-krb5-printing.x86_64 : Samba CUPS backend for printing with Kerberos name and description match only, use "search all" to try. [root@pinyoyougou-docker openjdk]# yum install cups-devel.x86_64Copy the code
  8. Have you passed my sanity exam?

    Sanity check passed.
    Copy the code

Write the compile startup script

After the previous effort, the compilation environment is basically ready, and you can make the compilation. However, before compiling, you need to set some environment variables, such as the root directory of the Boostrap JDK, which needs to be compiled, and the number of parallel compilation threads.

Create compile. Sh under openJDK/and type the following (see Understanding the Java Virtual Machine in Depth) :

#Language option, this must be set, otherwise it will compile a HashTable NPE error
export LANG=C

#Bootstrap Specifies the JDK installation path. This parameter must be set.Export ALT_BOOTDIR = / usr/local/Java/jdk1.7.0 _04
#Allow automatic downloading of dependencies
export ALLOW_DOWNLOADS=true

#The number of concurrent compilation threads is set to the same as the number of CPU cores
export HOTSPOT_BUILD_JOBS=4
export ALT_PARALLEL_COMPILE_JOBS=4

#Compare the image produced by this build with the previous version. This doesn't make sense to us, we have to set it tofalseOtherwise, the Sanity check will report a missing image of the previous JDK. If dev or DEV_ONLY= is settrueYou can do this without explicitly setting it.
export SKIP_COMPARE_IMAGES=true

#Use a precompiled header file, which compiles more slowly without it
export USE_PRECOMPILED_HEADER=true

#What to compile
export BUILD_LANGTOOLS=true 
#export BUILD_JAXP=false
#export BUILD_JAXWS=false 
#export BUILD_CORBA=false
export BUILD_HOTSPOT=true 
export BUILD_JDK=true

#The version to compile
#export SKIP_DEBUG_BUILD=false
#export SKIP_FASTDEBUG_BUILD=true
#export DEBUG_NAME=debug

#Set it tofalseYou can avoid parts of builds like Javaws and browser Java plug-ins.
BUILD_DEPLOY=false

#Set it tofalseYou won't build the installation package. There are some strange dependencies in the installation package, but you can already get a full JDK image without building it, so don't build it.
BUILD_INSTALL=false

#These two environment variables must be removed, otherwise something really weird will happen (I didn't specifically check for these "weird things", and the Makefile script will warn if it checks for these two variables).
unset JAVA_HOME
unset CLASSPATH

make 2>&1 | tee $ALT_OUTPUTDIR/build.log
Copy the code

The following points need attention:

  1. You must set upLANG=CWill,ALT_BOOTDIRSet toboostrap jdkThe root directory of the
  2. If your system has been configured previouslyjdkThe environment variable, it has to be hereunsetBelow (the no40 9Line)
  3. The above parallel thread count with yourscpuThe number of cores is the same

You can do it in other places.

Begin to compile

Start compiling using the compile startup script written above:

[root@pinyoyougou-docker openjdk]# chmod +x compile.sh
[root@pinyoyougou-docker openjdk]# ./compile.sh
Copy the code

This process usually takes a few dozen minutes, and if all goes well, the compile start and end times are displayed at the end. (Of course, most of the time, the road to frustration is pretty tortuous.)

## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
##### Leaving jdk for target(s) sanity all docs images #####
## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
##### Build time 00:10:12 jdk for target(s) sanity all docs images #####
## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#-- Build times ----------Target all_product_build Start 2019-01-23 16:37:02 End 2019-01-23 16:48:00 00:00:23 corba 00:00:09 hotspot 00:00:03 jaxp  00:00:06 jaxws 00:10:12 jdk 00:00:03 langtools 00:10:58 TOTAL ------------------------- make[1]: Leaving directory `/usr/local/java/openjdk' [root@pinyoyougou-docker openjdk]#Copy the code

So here’s a list of my frustrations… If an error occurs during make, continue making after the exception is resolved. I started being so stupid that I solved every exception, and then made clean, and then made again.

Resolving compilation errors

  1. cannot find -lstdc++

    -l indicates the library. Cannot find -lxxx usually indicates the absence of the libXXX library. Yum search libstdc++-static install yum search libstdc++-static install yum search libstdc++-static install yum

  2. Libjvm. so soft connection is dead loop

    /usr/bin/ld: cannot open output file libjvm.so: Too many levels of symbolic links
    collect2: error: ld returned 1 exit status
    ln: failed to access 'libjvm.so': Too many levels of symbolic links
    ln: failed to access 'libjvm.so.1': Too many levels of symbolic links
    /usr/bin/objcopy --only-keep-debug libjvm.so libjvm.debuginfo
    /usr/bin/objcopy: Warning: could not locate 'libjvm.so'.  reason: Too many levels of symbolic links
    Copy the code

    I don’t want to make clean and sanity

  3. More than ten years problem

    Error: time is more than 10 years from present: 1136059200000
    java.lang.RuntimeException: time is more than 10 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)
    Copy the code

    Modify its / / JDK/SRC/share/classes/Java/util/CurrencyData properties, said one year places to distance in no more than 10 this year, the year:

    • Modify line 108 AZ=AZM. The 2015-12-31-20-00-00; AZN
    • Modify line 381 MZ=MZM; The 2015-06-30-22-00-00; MZN
    • Modify line 443 RO=ROL; The 2015-06-30-21-00-00; RON
    • Modify line 535 TR=TRL; The 2015-12-31-22-00-00; TRY
    • Modify line 561 VE=VEB; The 2015-01-01-04-00-00; VEF
  4. The C header file is missing

     fatal error: X11/Intrinsic.h: No such file or directory
     # include <X11/Intrinsic.h>
    Copy the code
    /usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory compilation terminated. make: *** [bitmap.o] Error 1
    Copy the code

    If you are missing XXX /xxx.h, you can use yum provides */ xx.h to check which library the header file is contained in, and then download the full name of the library as a parameter of yum install

I wanted to post all the pits I stepped on, but the compiler output information is too much to find traces of pit mining. In short, either the dependencies are missing or the existing dependencies are incompatible (in which case you need to download both the 32-bit and 64-bit versions)

Use the compiled JDK

Openjdk /build/linux-amd64/ j2SDK-image is the compiled JDK root directory:

[root@pinyoyougou-docker j2SDK-image]# bin/ Java -version openJDK version "1.7.0-internal" OpenJDK Runtime Environment (Build 1.7.0-internal root_2019_01_23_14_04-b00) OpenJDK 64-bit Server VM (build 24.75-b04, mixed mode)Copy the code

Refer to the link

  • In-depth Understanding of the Java Virtual Machine (Version 2)
  • Github.com/xiongzhengg…