现在是
加载中...
加载中...

编译环境的准备

JDK源码下载

OpenJDK

http://jdk.java.net/java-se-ri/8

下载地址

https://download.java.net/openjdk/jdk8u40/ri/openjdk-8u40-src-b25-10_feb_2015.zip

dragonwell8

https://github.com/alibaba/dragonwell8

准备编译环境

解压下载的压缩包,进入文件夹,点击README-builds.html,这是官方给的编译指导手册。

支持的环境

https://wiki.openjdk.java.net/display/Build/Supported+Build+Platforms

fedora29

最好选择fedora29

下载地址

https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/9/Fedora/x86_64/iso/

ubuntu14

如果使用图形界面,建议选择 ubuntu-14.04.6-desktop

下载地址

http://releases.ubuntu.com/14.04/ubuntu-14.04.6-desktop-amd64.iso

安装Boot JDK

安装Boot JDK,编译OpenJDK8最好选择jdk1.7

https://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

or

wget https://terwer.oss-cn-qingdao.aliyuncs.com/soft/jdk/jdk-7u80-linux-x64.tar.gz

安装依赖库

sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfreetype6-dev libasound2-dev -y
sudo apt-get install build-essential -y

安装ccache高速编译工具

在处理一些规模相对较大的工程时,编译花费的时间可能会很长。有时候我们会经常一遍一遍地编译相同的程序,此时,有了ccache情况就好多了。它将在第一遍编译时多花几秒钟,但接下来就会使编译成倍(5-10倍)的提速。

ccache 的基本原理是通过将头文件高速缓存到源文件之中而改进了构建性能,因而通过减少每一步编译时添加头文件所需要的时间而提高了构建速度。以下来了解下如何同时使用 ccache 和distcc 来使开发环境达到最佳性能。

sudo apt install ccache -y

wsl

配置gcc为4.8

http://www.terwergreen.com/post-dark/7866.html

开始编译

CentOS/fedora29

./configure --with-boot-jdk=/opt/java/jdk1.7.0_80 --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-jvm-variants=server --with-target-bits=64 --with-num-cores=4

Wlinux/ubuntu14

配置构建

ubuntu14

dragonwell8

./configure --with-boot-jdk=/opt/java/jdk1.7.0_80 --with-freetype-include=/usr/include/freetype2 --with-freetype-lib=/usr/lib/x86_64-linux-gnu --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=3000

openjdk

sudo chmod +x ./configure

./configure --with-boot-jdk=/opt/java/jdk1.7.0_80 --with-freetype-include=/usr/include/freetype2 --with-freetype-lib=/usr/lib/x86_64-linux-gnu --with-debug-level=slowdebug --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=3000

log

====================================================
A new configuration has been successfully created in
/home/terwer/workspace/dragonwell8/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-boot-jdk=/opt/java/jdk1.7.0_80 --with-debug-level=slowdebug --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=3000'.

Configuration summary:
* Debug level:    slowdebug
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK:       java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)  (at /opt/java/jdk1.7.0_80)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 4.8.4 (at /usr/bin/gcc)
* C++ Compiler:   Version 4.8.4 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   2
* Memory limit:   3000 MB
* ccache status:  enabled

build images log

## Finished images (build time 00:03:19)

----- Build times -------
Start 2019-03-29 16:02:40
End   2019-03-29 19:11:11
00:04:57 corba
00:03:48 demos
02:19:09 hotspot
00:03:19 images
00:03:18 jaxp
00:04:15 jaxws
00:23:26 jdk
00:04:34 langtools
00:01:44 nashorn
03:08:31 TOTAL
-------------------------
Finished building OpenJDK for target 'images'

wsl

unset JAVA_HOME

dragonwell8

 ./configure --with-boot-jdk=/opt/java/jdk1.7.0_80 --with-freetype-include=/usr/include/freetype2 --with-freetype-lib=/usr/lib/x86_64-linux-gnu --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-jvm-variants=server --with-target-bits=64

openjdk

sudo chmod +x ./configure

./configure --with-boot-jdk=/opt/java/jdk1.7.0_80 --with-freetype-include=/usr/include/freetype2 --with-freetype-lib=/usr/lib/x86_64-linux-gnu --with-debug-level=slowdebug --with-jvm-variants=server --with-target-bits=64

log

====================================================
A new configuration has been successfully created in
/mnt/c/Users/Terwer/WSLProjects/dragonwell8/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-boot-jdk=/opt/java/jdk1.7.0_80 --with-freetype-include=/usr/include/freetype2 --with-freetype-lib=/usr/lib/x86_64-linux-gnu --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-jvm-variants=server --with-target-bits=64'.

Configuration summary:
* Debug level:    slowdebug
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK:       java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)  (at /opt/java/jdk1.7.0_80)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 4.8.5 (at /usr/bin/gcc)
* C++ Compiler:   Version 4.8.5 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   4
* Memory limit:   8142 MB

WARNING: Your build output directory is not on a local disk.
This will severely degrade build performance!
It is recommended that you create an output directory on a local disk,
and run the configure script again from that directory.

构建

only image

sudo make images

or

terwer@ubuntu-work:~/workspace/dragonwell8$ sudo make images
No CONF given, but more than one configuration found in /home/terwer/workspace/dragonwell8//build.
Available configurations:
* linux-x86_64-normal-server-release
* linux-x86_64-normal-server-slowdebug
Please retry building with CONF=<config pattern> (or SPEC=<specfile>)
Makefile:55: *** Cannot continue.  Stop.
terwer@ubuntu-work:~/workspace/dragonwell8$ sudo make images CONF=linux-x86_64-normal-server-slowdebug

log

Building 'linux-x86_64-normal-server-slowdebug' (matching CONF=linux-x86_64-normal-server-slowdebug)
Building OpenJDK for target 'images' in configuration 'linux-x86_64-normal-server-slowdebug'

build all

sudo build all

问题处理

WSL的WLinux问题

This OS is not supported: Linux WORK 4.4.0-17134-Microsoft #648-Microsoft Tue Mar 05 18:57:00 PST 2019 x86_64 GNU/Linux

解决

# 修改文件 ./hotspot/make/linux/Makefile
# 修改 SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7% 为 
SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7% 3% 4%

configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'. configure exiting with result code 1

解决

./configure --with-freetype-include=/usr/include/freetype2 --with-freetype-lib=/usr/lib/x86_64-linux-gnu

Generating precompiled header precompiled.hpp.gch In file included from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/memory/sharedHeap.hpp:29:0, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelComp act.hpp:34, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/gc_implementation/shared/markSweep.inline.hpp:34, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/oops/oop.inline.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/classfile/classFileParser.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/classfile/classLoader.hpp:28, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/classfile/systemDictionary.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciEnv.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciUtilities.hpp:28, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciNullObject.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciConstant.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciArray.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/precompiled/precompiled.hpp:33: /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/memory/generation.hpp:425:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix] warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, (int64_t)_time_of_last_gc, (int64_t)now); ^ /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/memory/generation.hpp:425:42: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix] warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, (int64_t)_time_of_last_gc, (int64_t)now); ^ In file included from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp:30:0, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/oops/oop.inline.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/classfile/classFileParser.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/classfile/classLoader.hpp:28, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/classfile/systemDictionary.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciEnv.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciUtilities.hpp:28, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciNullObject.hpp:30, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciConstant.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/ci/ciArray.hpp:29, from /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/precompiled/precompiled.hpp:33: /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/memory/threadLocalAllocBuffer.inline.hpp:97:25: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix] gclog_or_tty->print("TLAB: %s thread: "INTPTR_FORMAT" [id: %2d]" ^ /mnt/c/Users/Terwer/WSLProjects/openjdk/hotspot/src/share/vm/memory/threadLocalAllocBuffer.inline.hpp:98:25: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

解决

在文件 ./hotspot/make/linux/makefiles/gcc.make 修改下面的代码

# Compiler warnings are treated as errors
# WARNINGS_ARE_ERRORS = -Werror
WARNINGS_ARE_ERRORS = -Wno-all

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

解决

#add by Kun
CFLAGS += -fpermissive
#end

ubuntu14编译报错

Compiling /home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/jni/jfrGetAllEventClasses.cpp
Compiling /home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/jni/jfrJavaCall.cpp
Compiling /home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/writers/jfrJavaEventWriter.cpp
Compiling /home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp
/home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp: In static member function ‘static void JfrJavaLog::log(jint, jint, jstring, Thread*)’:
/home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp:47:21: error: format not a string literal and no format arguments [-Werror=format-security]
     log_trace(jfr)(s);
                     ^
/home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp:50:21: error: format not a string literal and no format arguments [-Werror=format-security]
     log_debug(jfr)(s);
                     ^
/home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp:53:20: error: format not a string literal and no format arguments [-Werror=format-security]
     log_info(jfr)(s);
                    ^
/home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp:56:23: error: format not a string literal and no format arguments [-Werror=format-security]
     log_warning(jfr)(s);
                       ^
/home/terwer/workspace/dragonwell8/hotspot/src/share/vm/jfr/utilities/jfrJavaLog.cpp:59:21: error: format not a string literal and no format arguments [-Werror=format-security]
     log_error(jfr)(s);
                     ^
cc1plus: all warnings being treated as errors
make[6]: *** [jfrJavaLog.o] Error 1
make[5]: *** [the_vm] Error 2
make[4]: *** [product] Error 2
make[3]: *** [generic_build2] Error 2
make[2]: *** [product] Error 2
make[1]: *** [/home/terwer/workspace/dragonwell8/build/linux-x86_64-normal-server-release/hotspot/_hotspot.timestamp] Error 2
make: *** [hotspot-only] Error 2
terwer@ubuntu:~/workspace/dragonwell8$ 

解决

在文件 ./hotspot/make/linux/makefiles/gcc.make 修改下面的代码

# Compiler warnings are treated as errors
# WARNINGS_ARE_ERRORS = -Werror
WARNINGS_ARE_ERRORS = -Wno-all

构建成功

----- Build times -------
Start 2019-03-29 10:55:48
End   2019-03-29 12:31:27
00:03:25 corba
00:03:20 demos
00:18:37 docs
00:35:29 hotspot
00:03:31 images
00:02:21 jaxp
00:04:19 jaxws
00:22:28 jdk
00:00:00 langtools
00:02:08 nashorn
01:35:39 TOTAL
-------------------------
Finished building OpenJDK for target 'all'

验证

ubuntu 14 右键打开终端

sudo apt-get install nautilus-open-terminal -y
nautilis -q

验证java编译结果

terwer@ubuntu-work:~/workspace/dragonwell8/build/linux-x86_64-normal-server-release/jdk/bin$ ./java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment ( ) (build 1.8.0-internal-root_2019_03_29_09_33-b00)
OpenJDK 64-Bit Server VM ( ) (build 25.71-b00, mixed mode)

Java SE规范

https://docs.oracle.com/javase/specs/index.html

作者:Terwer

首发:浅海拾贝

原创内容,转载请注明出处!

评论