记录下在
Ubuntu20.04下编译调试Zero-Assembler OpenJDK的过程和指令。
Zero-Assembler OpenJDK指的是不使用汇编代码来构建的openjdk。因为OpenJDK一般是使用TemplateInterpreter,代码中除了 C++ 代码之外还包含许多汇编代码。Zero项目旨在通过移除OpenJDK项目代码中的与平台相关的汇编代码,使用纯C++来替代,从而可以在任何 Linux 系统上构建,而无需进一步进行移植工作。
Zero-Assembler OpenJDK只包含一个纯C++解释器,无JIT, 目前已集成到了openjdk的主分支中,只要在配置OpenJDK的时候指定参数--with-jvm-variants=zero重新编译即可。
简要介绍看:Zero-Assembler Project
稍微详细点的中文介绍看:如何编译"零汇编(Zero-Assembler)"的OpenJDK(上面的介绍都是从这里copy的)
本文主要参考如何编译"零汇编(Zero-Assembler)"的OpenJDK和Building the JDK11
环境: Ubuntu 20.04, OpenJDK11
1. 下载源码
git clone git@github.com:openjdk/jdk11u-dev.git
#切换到所需要的发行版本
git checkout jdk-11.0.12+6
2. 环境依赖
在编译过程中需要依赖FreeType、CUPS等若干第三方库。
sudo apt-get install build-essential
# 下载安装依赖包
# FreeType
sudo apt-get install libfreetype6-dev
# CUPS
sudo apt-get install libcups2-dev
# X11
sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev
#ALSA
sudo apt-get install libasound2-dev
# libffi
sudo apt-get install libffi-dev
#autoconf
sudo apt-get install autoconf
sudo apt-get install libfontconfig1-dev
3. Running Configure
/bin/bash configure --with-jvm-variants=zero --with-debug-level=slowdebug --with-native-debug-symbols=internal --with-target-bits=64 --with-num-cores=8 --with-boot-jdk=/home/xx/Downloads/jdk-10.0.2
比较搞笑的是,编译版本号为
N的jdk是需要有一个已经存在的版本号最少为N-1的已编译好的jdk的,一般称这个jdk为"boot JDK"。所以编译jdk11需要一个jdk10以上版本的jdk。使用--with-boot-jdk来指定一个jdk来使用。
--with-jvm-variants : 编译特定版本的hotSpot虚拟机,可以多个模式并存--with-debug-level : 设置编译级别,可选值release, fastdebug, slowdebug or optimized 。区别就在于优化措施的多少,slowdebug是不带优化的,可以得到的调试信息是最多的。推荐fastdebug,slowdebugoptimized is variant of release with additional Hotspot debug code.--with-native-debug-symbols 确定调试符号信息的编译方式。Available methods are none, internal, external, zipped. Native libraries 和可执行程序可以具有与它们关联的调试符号(和其他调试信息)。不同的参数表示如何处理调试符号的不同方法。--with-target-bits :选择编译32位还是64位的java虚拟机--with-num-cores :number of cores in the build system,跟它相类似的还有--with-memory-size,如果不指定的话,默认是系统所能提供的最大数目。make images
使用这个指令就可以编译出整个JDK镜像,当然除此之外还有其他选项:
hotspot - Build all of hotspot (but only hotspot)hotspot- - Build just the specified jvm variantimages or product-images - Build the JDK imagedocs or docs-image - Build the documentation imagetest-image - Build the test imageall or all-images - Build all images (product, docs and test)bootcycle-images - Build images twice, second time with newly built JDK (good for testing)clean - Remove all files generated by make, but not those generated by configuredist-clean - Remove all files, including configurationmake compile-commands
暂时不考虑使用了,实测了一下Zero-Assembler OpenJDK,速度太慢了,比espresso还要慢。