构建编译环境
下载openjdk12的的源码
链接
zip下载
安装GCC
sudo apt-get install build-essential
安装OpenJDK的编译依赖库
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
想要编译OpenJDK12就要安装至少OpenJDK11
sudo apt-get install openjdk-11-jdk
bash configure --help
打印出configure命令的帮助
编译FastDebug版、仅含Server模式的HotSpot虚拟机
bash configure --enable-debug --with-jvm-variants=server
编译成功的话
====================================================
A new configuration has been successfully created in
/home/amazong-xyb/Desktop/JVM-Lreaned/jdk12-06222165c35f/build/linux-x86_64-server-fastdebug
using configure arguments '--enable-debug --with-jvm-variants=server'.
Configuration summary:
* Debug level: fastdebug
* HS debug level: fastdebug
* JVM variants: server
* JVM features: server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc'
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 12-internal+0-adhoc.amazongxyb.jdk12-06222165c35f (12-internal)
Tools summary:
* Boot JDK: openjdk version "11.0.14" 2022-01-18 OpenJDK Runtime Environment (build 11.0.14+9-Ubuntu-0ubuntu2.18.04) OpenJDK 64-Bit Server VM (build 11.0.14+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing) (at /usr/lib/jvm/java-11-openjdk-amd64)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 7.5.0 (at /usr/bin/gcc)
* C++ Compiler: Version 7.5.0 (at /usr/bin/g++)
Build performance summary:
* Cores to use: 4
* Memory limit: 7927 MB
并且在build目录下出现一个
输入make images
编译整个OpenJDK后这个目录下就有
bootcycle-spec.gmk
buildtools
configure-support
jdk
spec.gmk
buildjdk-spec.gmk
compare.sh
hotspot
Makefile
support
build.log
configure.log
images
make-support
make
的命令
···
在build/机器名/jdk/bin/jdk/bin/下运行java -version
可以看
openjdk version "11.0.14" 2022-01-18
OpenJDK Runtime Environment (build 11.0.14+9-Ubuntu-0ubuntu2.18.04)
OpenJDK 64-Bit Server VM (build 11.0.14+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing)
配置jdk环境变量
sudo gedit ~/.bashrc //配置JAVA_HOME路径
bashrc文件中添加:
export JAVA_HOME=/home/aaron/jvm/jdk12/build/linux-x86_64-server-fastdebug/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source ~/.bashrc //使文件立即生效
然后再任意路径下都可以用java -version
查看
在jdk的源码编译目录下新建CMakeLists.txt
CMakeLists.txt:
cmake_minimum_required(VERSION 3.7)
project(hotspot)
include_directories(
src/hotspot/cpu
src/hotspot/os
src/hotspot/os_cpu
src/hotspot/share
src/hotspot/share/precompiled
src/hotspot/share/include
src/java.base/unix/native/include
src/java.base/share/native/include
src/java.base/share/native/libjli
)
file(GLOB_RECURSE SOURCE_FILES "*.cpp" "*.hpp" "*.c" "*.h")
add_executable(hotspot ${SOURCE_FILES})
通过CLion打开CMakeLists.txt
就可以把jdk12导入项目了
项目构建完了之后就可以编写Java代码测试一下了
编写Java代码放到/home/aaron/jvm/jdk12/build/linux-x86_64-server-fastdebug/jdk/bin/下
。具体编写的Java代码如下:
public class Test{
public static void main(String[] args){
System.out.println("Hello world!");
}
}
将此代码编译成.class文件
配置Clion中运行配置
打断点调试
q08b6K)
打断点调试
[外链图片转存中…(img-Gi4J8ery-1648366609311)]
[外链图片转存中…(img-2645h0H3-1648366609311)]
搞完了还是啥也看不懂