zzyandzzy / jdk11

JDK编译,JVM、GC、java.util、java.lang源码学习

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jdk11

Welcome to the JDK!

For information about building the JDK, including how to retrieve all of the source code, please see either of these files:

  • doc/building.html (html version)
  • doc/building.md (markdown version)

See http://openjdk.java.net/ for more information about the OpenJDK Community and the JDK.

导航

编译jdk11需要boot jdk,也就是另外一个JDK来编译这个JDK...(经典套娃)。

  • JDK版本必须大于等于10
  • make版本最好是4.2.1
  • gcc版本最好gcc-9

build

参数

--with-debug-level=slowdebug 启用slowdebug级别调试

--enable-dtrace 启用dtrace

--with-jvm-variants=server 编译server类型JVM

--with-target-bits=64 指定JVM为64位

--enable-ccache 启用ccache,加快编译

--with-num-cores=8 编译使用CPU核心数

--with-memory-size=8000 编译使用内存

--disable-warnings-as-errors 忽略警告 , mac 使用 xcode 编译, 官方要求加上这个参数.

--with-freetype 设置freetype的路径

linux

  1. 首先安装JDK11

gentoo

sudo emerge -av dev-java/openjdk freetype
  1. 工具链版本

确保make版本是4.2.1,不能是4.3

make -v
GNU Make 4.2.1
为 x86_64-pc-linux-gnu 编译
Copyright (C) 1988-2016 Free Software Foundation, Inc.
许可证:GPLv3+:GNU 通用公共许可证第 3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本软件是自由软件:您可以自由修改和重新发布它。
在法律允许的范围内没有其他保证。

如果执意要在4.3编译JDK11请做以下操作。

修复教程

diff -r e7c4199e4d32 make/common/MakeBase.gmk
--- a/make/common/MakeBase.gmk
+++ b/make/common/MakeBase.gmk
@@ -532,7 +532,9 @@
               $(info NewVariable $1: >$(strip $($1))<) \
               $(info OldVariable $1: >$(strip $($1_old))<)) \
           $(call WriteFile, $1_old:=$(call DoubleDollar,$(call EscapeHash,$($1))), \
- $(call DependOnVariableFileName, $1, $2))) \
+ $(call DependOnVariableFileName, $1, $2) ) \
+ $(eval $(call DependOnVariableFileName, $1, $2): ) \
+ ) \
         $(call DependOnVariableFileName, $1, $2) \
     )

确保gcc版本是gcc-9

~ git:(master) ✗ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.4.0/lto-wrapper
目标:x86_64-pc-linux-gnu
配置为:/var/tmp/portage/sys-devel/gcc-9.4.0/work/gcc-9.4.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/9.4.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.4.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.4.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.4.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.4.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.4.0/include/g++-v9 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/9.4.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.4.0 p1' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --disable-systemtap --enable-vtable-verify --enable-lto --without-isl --enable-default-pie --enable-default-ssp
线程模型:posix
gcc 版本 9.4.0 (Gentoo 9.4.0 p1)
  1. 编译
./configure --with-debug-level=fastdebug --with-jvm-variants=server --with-target-bits=64 --with-num-cores=8 --with-memory-size=16384 --disable-warnings-as-errors --with-freetype=system --with-boot-jdk=/usr/lib64/openjdk-11

make images

macOS

# 安装freetype
brew install freetype

chmod +x ./configure

./configure --with-debug-level=slowdebug --enable-dtrace --with-jvm-variants=server --with-target-bits=64 --with-num-cores=8 --with-memory-size=16384 --disable-warnings-as-errors --with-freetype=bundled --with-boot-jdk=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
# 编译
make images
# 因为make版本太新导致的错误参考用~ make --version 
GNU Make 4.2.1 
Built for x86_64-pc-linux-gnu 
Copyright (C) 1988-2016 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. 

gcc-9 (Homebrew GCC 9.3.0_2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# 因为gcc10太新导致的错误,建议用gcc 9
# https://bugs.openjdk.java.net/browse/JDK-8235903

# 清理
make clean && make dist-clean

# 快速编译jdk
make jdk

参考

About

JDK编译,JVM、GC、java.util、java.lang源码学习

License:GNU General Public License v2.0


Languages

Language:Java 77.6%Language:C++ 11.5%Language:C 7.5%Language:JavaScript 1.1%Language:Roff 0.8%Language:HTML 0.4%Language:Shell 0.3%Language:Objective-C 0.3%Language:XSLT 0.2%Language:CMake 0.1%Language:M4 0.1%Language:Python 0.1%Language:Assembly 0.0%Language:Hack 0.0%Language:Makefile 0.0%Language:DTrace 0.0%Language:Awk 0.0%Language:CSS 0.0%Language:GDB 0.0%Language:Perl 0.0%Language:Batchfile 0.0%Language:sed 0.0%Language:Red 0.0%Language:SourcePawn 0.0%