百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 热门文章 > 正文

MacOS下JVM虚拟机编译

bigegpt 2024-09-06 17:56 85 浏览

前面介绍了字节码和类加载。类加载之后是怎么处理的,java命令是怎么启动一个项目并分配内存和空间的。jvm源码中的逻辑是什么样子的。这次主要记录一下JVM源码的编译和调试的过程

1 编译前的准备

OpenJDK源代码由版本控制系统Mercurial维护。首先需要将对应的依赖工具安装好,并将源码拉下来。

安装Mercurial

brew install Mercurial

安装成功以后,将对应的源代码克隆下来。

hg clone http://hg.openjdk.java.net/jdk9/jdk9 YourOpenJDK

要获取完整的OpenJDK Mercurial存储库集,请使用get_source.sh位于根存储库中的脚本

cd YourOpenJDK
bash ./get_source.sh

拉去源码的结果如下:

拉取下来的源码结构介绍

拉取下来的源码结构介绍

构建JVM源码还需要一些基本的配置(对于所有的系统)

1 确保GNU make实用程序为3.81版或更高版本,例如,运行“ make -version”
2 安装 Bootstrap JDK。所有OpenJDK构建都需要访问以前发布的称为引导JDK或引导JDK的JDK。 一般规则是,引导JDK必须是JDK先前主要版本的实例。此外,可能需要使用特定更新级别或更高版本的发行版。如果本地有jdk环境并配置了环境变量,可以可以忽略,编译过程会自动寻找。也可以通过--with-boot-jdk来指定

2 编译源码

构建OpenJDK的第一步是确保系统本身具有完成OpenJDK构建所需的一切。设置系统后,通常无需再次执行。

现在,通过运行configure 脚本来构建OpenJDK,该 脚本将尝试查找并验证您是否拥有所需的一切,然后运行 make,例如

bash ./configure
make all

开始执行构建

(base) xxx@xxxx:/data/study/jvm$ bash configure
Running generated-configure.sh
?
.......
?
====================================================
A new configuration has been successfully created in
/data/study/jvm/build/macosx-x86_64-normal-server-release
using default settings.
?
Configuration summary:
* Debug level: release
* HS debug level: product
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 9-internal+0-adhoc.sunx.jvm (9-internal)
?
Tools summary:
* Boot JDK: java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 8.3.3)
* C Compiler: Version 8.1.0 (at /usr/bin/clang)
* C++ Compiler: Version 8.1.0 (at /usr/bin/clang++)
?
Build performance summary:
* Cores to use: 4
* Memory limit: 8192 MB

开始执行编译

make all

执行过程异常中断,异常信息如下:

ERROR: Build failed for target 'all' in configuration 'macosx-x86_64-normal-server-release' (exit code 2)
Stopping sjavac server
?
=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_objs_compactibleFreeListSpace.o:
In file included from /data/study/jvm/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.cpp:1:
In file included from /data/study/jvm/hotspot/src/share/vm/precompiled/precompiled.hpp:296:
In file included from /data/study/jvm/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.hpp:33:
/data/study/jvm/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:167:12: error: instantiation of variable 'TreeChunk<FreeChunk, AdaptiveFreeList<FreeChunk> >::_min_tree_chunk_size' required here, but no definition is available [-Werror,-Wundefined-var-template]
 return _min_tree_chunk_size;
 ^
/data/study/jvm/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:293:44: note: in instantiation of member function 'TreeChunk<FreeChunk, AdaptiveFreeList<FreeChunk> >::min_size' requested here
 return TreeChunk<Chunk_t, FreeList_t>::min_size();
 ^
/data/study/jvm/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.cpp:2681:67: note: in instantiation of member function 'BinaryTreeDictionary<FreeChunk, AdaptiveFreeList<FreeChunk> >::min_size' requested here
 fc = dictionary()->get_chunk(MAX2(n * word_sz, _dictionary->min_size()),
 ^
 ... (rest of output omitted)
?
* All command lines available in /data/study/jvm/build/macosx-x86_64-normal-server-release/make-support/failure-logs.
=== End of repeated output ===
?
No indication of failed target found.
Hint: Try searching the build log for '] Error'.
Hint: See common/doc/building.html#troubleshooting for assistance.
?
make[1]: *** [main] Error 2
make: *** [all] Error 2

查询资料后,删除build下内容,重新开始构建编译

bash ./configure --with-extra-cflags="-Wno-error=deprecated-declarations -Werror=nonnull -Wno-undefined-var-template -Wno-error=mismatched-parameter-types -Wno-error=shift-negative-value"

执行结果

...........
?
checking if jtreg failure handler should be built... no, missing jtreg
checking if the CDS classlist generation should be enabled... yes
checking for number of cores... 4
checking for memory size... 8192 MB
checking for appropriate number of jobs to run in parallel... 4
checking flags for boot jdk java command ... -Duser.language=en -Duser.country=US
checking flags for boot jdk java command for big workloads... -Xms64M -Xmx1600M -XX:ThreadStackSize=1536
checking flags for bootcycle boot jdk java command for big workloads... -Xms64M -Xmx1600M -XX:ThreadStackSize=1536
checking flags for boot jdk java command for small workloads... -XX:+UseSerialGC -Xms32M -Xmx512M -XX:TieredStopAtLevel=1
checking whether to use sjavac... no
checking whether to use javac server... yes
checking If precompiled header is enabled... yes
checking is ccache enabled... no
checking if build directory is on local disk... yes
checking JVM features for JVM variant 'server'... all-gcs cds compiler1 compiler2 dtrace fprof jni-check jvmci jvmti management nmt services vm-structs
configure: creating /data/study/jvm/build/macosx-x86_64-normal-server-release/configure-support/config.status
config.status: creating /data/study/jvm/build/macosx-x86_64-normal-server-release/spec.gmk
config.status: creating /data/study/jvm/build/macosx-x86_64-normal-server-release/bootcycle-spec.gmk
config.status: creating /data/study/jvm/build/macosx-x86_64-normal-server-release/buildjdk-spec.gmk
config.status: creating /data/study/jvm/build/macosx-x86_64-normal-server-release/compare.sh
config.status: creating /data/study/jvm/build/macosx-x86_64-normal-server-release/Makefile
?
====================================================
A new configuration has been successfully created in
/data/study/jvm/build/macosx-x86_64-normal-server-release
using configure arguments '--with-extra-cflags='-Wno-error=deprecated-declarations -Werror=nonnull -Wno-undefined-var-template -Wno-error=mismatched-parameter-types -Wno-error=shift-negative-value''.
?
Configuration summary:
* Debug level: release
* HS debug level: product
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 9-internal+0-adhoc.sunx.jvm (9-internal)
?
Tools summary:
* Boot JDK: java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 8.3.3)
* C Compiler: Version 8.1.0 (at /usr/bin/clang)
* C++ Compiler: Version 8.1.0 (at /usr/bin/clang++)
?
Build performance summary:
* Cores to use: 4
* Memory limit: 8192 MB

开始编译

(base) xxx@xxxx:/data/study/jvm$ make
Building target 'default (exploded-image)' in configuration 'macosx-x86_64-normal-server-release'
?
...........
?
15 warnings generated.
/data/study/jvm/jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m:397:5: warning: 'objc_registerThreadWithCollector' is deprecated: it does nothing. Define OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily silence this diagnostic. [-Wdeprecated-declarations]
 objc_registerThreadWithCollector();
 ^
/usr/include/objc/objc-auto.h:245:25: note: 'objc_registerThreadWithCollector' has been explicitly marked deprecated here
static OBJC_INLINE void objc_registerThreadWithCollector() { }
 ^
1 warning generated.
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
Compiling 4 files for BUILD_JIGSAW_TOOLS
Stopping sjavac server
Finished building target 'default (exploded-image)' in configuration 'macosx-x86_64-normal-server-release'

编译过程中会偶遇一些warning信息。编译之后的结果在build下。我们看下java对应的版本:

(base) xxxx@xxxx:/data/study/jvm/build/macosx-x86_64-normal-server-release$ ./jdk/bin/java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.sunx.jvm)
OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.sunx.jvm, mixed mode)
(base) xxx@xxx:/data/study/jvm/build/macosx-x86_64-normal-server-release$ pwd
/data/study/jvm/build/macosx-x86_64-normal-server-release
(base) xxx@xxx:/data/study/jvm/build/macosx-x86_64-normal-server-release$

到这里基本编译就已经结束了~

相关推荐

Linux gron 命令使用详解(linux gminer)

简介gron是一个独特的命令行工具,用于将JSON数据转换为离散的、易于grep处理的赋值语句格式。它的名字来源于"grepableon"或"grepable...

【Linux】——从0到1的学习,让你熟练掌握,带你玩转Linu

学习Linux并掌握Java环境配置及SpringBoot项目部署是一个系统化的过程,以下是从零开始的详细指南,帮助你逐步掌握这些技能。一、Linux基础入门1.安装Linux系统选择发行版:推荐...

Linux常用的shell命令汇总(linux中shell的作用)

本文介绍Linux系统下常用的系统级命令,包括软硬件查看、修改命令,有CPU、内存、硬盘、网络、系统管理等命令。说明命令是在Centos6.464位的虚拟机系统进行测试的。本文介绍的命令都会在此C...

零成本搭建个人加密文件保险柜(适用于 Win11 和 Linux)

不依赖收费软件操作简单,小白也能跟着做支持双系统,跨平台使用实现数据加密、防删除、防泄露内容通俗无技术门槛,秒懂秒用使用工具简介我们将使用两个核心工具:工具名用途系统支持Veracrypt创建加密虚...

如何在 Linux 中使用 Gzip 命令?(linux怎么用gzip命令)

gzip(GNUzip)是Linux系统中一个开源的压缩工具,用于压缩和解压缩文件。它基于DEFLATE算法,广泛应用于文件压缩、备份和数据传输。gzip生成的文件通常带有.gz后缀,压缩效率...

Linux 必备的20个核心知识点(linux内核知识点)

学习和使用Linux所必备的20个核心知识点。这些知识点涵盖了从基础操作到系统管理和网络概念,是构建扎实Linux技能的基础。Linux必备的20个知识点1.Linux文件系统层级标...

谷歌 ChromeOS 已支持 7z、iso、tar 文件格式

IT之家6月21日消息,谷歌ChromeOS在管理文件方面进行了改进,新增了对7z、iso和tar等格式的支持。从5月的ChromeOS101更新开始,ChromeOS...

如何在 Linux 中提取 Tar Bz2 文件?

在深入解压方法之前,我们先来了解.tar.bz2文件的本质。.tar.bz2是一种组合文件格式,包含两个步骤:Tar(TapeArchive):tar是一种归档工具,用于将多个文件或目录打包...

如何在 CentOS 7/8 上安装 Kitematic Docker 管理器

Kitematic是一款流行的Docker图形界面管理平台,适用于Ubuntu、macOS和Windows操作系统。然而,其他发行版(如CentOS、OpenSUSE、Fedora、R...

Nacos3.0重磅来袭!全面拥抱AI,单机及集群模式安装详细教程!

之前和大家分享过JDK17的多版本管理及详细安装过程,然后在项目升级完jdk17后又发现之前的注册和配置中心nacos又用不了,原因是之前的nacos1.3版本的,版本太老了,已经无法适配当前新的JD...

爬虫搞崩网站后,程序员自制“Zip炸弹”反击,6刀服务器成功扛住4.6万请求

在这个爬虫横行的时代,越来越多开发者深受其害:有人怒斥OpenAI的爬虫疯狂“偷”数据,7人团队十年心血的网站一夜崩溃;也有人被爬虫逼到极限,最后只好封掉整个巴西的访问才勉强止血。但本文作者却走...

Ubuntu 操作系统常用命令详解(ubuntu必学的60个命令)

UbuntuLinux是一款流行的开源操作系统,广泛应用于服务器、开发、学习等场景。命令行是Ubuntu的灵魂,也是高效、稳定管理系统的利器。本文按照各大常用领域,详细总结Ubuntu必学...

Linux面板8.0.54 测试版-已上线(linux主机面板)

Linux面板8.0.54测试版【增加】[网站]Java项目新增刷新列表按钮【增加】[网站]PHP项目-Apache-服务新增守护进程功能【增加】[网站]Python项目创建/删除网站时新增同时创建...

开源三剑客——构建私有云世界的基石

公共云原生的浪潮正在席卷这个世界,亚马逊AWS、谷歌GCP和微软的Azure年收入增长超过了30%,越来越多的公司和个人开始将自己的服务部署到云环境中,大型数据中心的规模经济带来了成本的降低,可以在保...

2.2k star,一款业界领先的私有云+在线文档管理系统

简介kodbox可道云(原KodExplorer)是业内领先的企业私有云和在线文档管理系统,为个人网站、企业私有云部署、网络存储、在线文档管理、在线办公等提供安全可控,简便易用、可高度定制的私有云产品...