hotspot8编译

参照xiaguang的博客,帮我踩了很多坑,虽然编译过程中还是遇到了一点小问题.

修改 ubuntu18 adp 源

1
sudo vi /etc/apt/sources.list

最好搜索一下最新的国内源

1
2
3
4
5
6
7
8
9
10
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
1
apt-get update

安装相关依赖

1
2
sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8
1
2
3
4
sudo apt-get install  libxext-dev libxrender-dev libxtst-dev libxt-dev
sudo apt-get install libcups2-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libasound2-dev

clone hostspot 代码

原文是通过 hg clone http://hg.openjdk.java.net/jdk8/jdk8 下载,但是官网速度太慢了.fan了也很慢.

后来找了个github上的镜像,总是下载一半就出问题:
https://github.com/unofficial-openjdk/openjdk

最后用gitee里的这个镜像,速度很快,tag 也比较全
https://gitee.com/solie/openjdk.git

1
2
3
4
5
6
7
// clone
git clone https://gitee.com/solie/openjdk.git

// 切分支
git checkout jdk8-b120

git checkout -b jdk8-b120-zc jdk8-b120

代码路径
/home/flyingzc/java/workspace/01opensource/openjdk

下载并编译 make 3.82

1.下载地址: ftp://ftp.gnu.org/gnu/make/make-3.82.tar.gz

2.解压
flyingzc@ubuntu:~/java/downloads$ tar -zxvf make-3.82.tar.gz -C .

3.vim glob/glob.c

将 第 211行, 232行 注释掉,注释后如下

1
2
#// #if !defined __alloca && !defined __GNU_LIBRARY__
#// #endif

准备编译 make3.82

chmod +x configure
./configure
make
./make –version
make编译成功

将系统的默认 make 链接成 3.82 版本

1
2
3
4
5
6
7
8
9
10
cd /usr/bin/

sudo ln -s /home/flyingzc/java/soft/make-3.82/make make-3.82

sudo rm make

sudo ln -s make-3.82 make

make --version
输出: GNU Make 3.82

确认 gcc 和 g++ 是4.8版本

gcc

1
2
3
cd /usr/bin
sudo rm gcc
sudo ln -s gcc-4.8 gcc

g++

1
2
3
cd /usr/bin
sudo rm g++
sudo ln -s g++-4.8 g++

输出

1
2
3
4
5
6
7
8
9
10
flyingzc@ubuntu:/usr/bin$ gcc --version
gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 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.

flyingzc@ubuntu:/usr/bin$ g++ --version
g++ (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

修改支持的os版本检查

1
2
3
查看内核版本
uname -a
Linux ubuntu 5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
1
2
hotspot/make/linux/Makefile
修改 SUPPORTED_OS_VERSION =... 加上4%,不然4.x的内核不支持.我的ubuntu内核是5.x,需要加上 5%

如果存在build目录则删除

1
2
3
4
5
rm -rf build/

chmod +x configure

./configure --with-debug-level=slowdebug

编译

1
nohup make all & tail -f nohup.out

报错解决

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Running nasgen
Exception in thread "main" java.lang.VerifyError: class jdk.nashorn.internal.objects.ScriptFunctionImpl overrides final method setPrototype.(Ljava/lang/Object;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at jdk.nashorn.internal.tools.nasgen.StringConstants.<clinit>(StringConstants.java:85)
at jdk.nashorn.internal.tools.nasgen.MemberInfo.verify(MemberInfo.java:250)
at jdk.nashorn.internal.tools.nasgen.ScriptClassInfo.verify(ScriptClassInfo.java:227)
at jdk.nashorn.internal.tools.nasgen.Main.process(Main.java:108)
at jdk.nashorn.internal.tools.nasgen.Main.processAll(Main.java:88)
at jdk.nashorn.internal.tools.nasgen.Main.main(Main.java:62)
make[1]: *** [/home/flyingzc/java/workspace/01opensource/openjdk/build/linux-x86_64-normal-server-slowdebug/nashorn/classes/_the.nasgen.run] Error 1
make: *** [nashorn-only] Error 2



修改:vim nashorn/make/BuildNashorn.gmk
第80行 -cp "$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)
第80行将原来的 -cp 修改为 -Xbootclasspath/p:

问题的解决方案来自这里

编译成功输出的信息

编译成功

解压调试符号包

1
2
openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/lib/amd64/server 目录下
unzip libjvm.diz

解压出来的是 libjvm.debuginfo 调试信息文件