java较新的版本OpenJdk19+GDB
2023-03-07 09:09:19 时间
前言: JVM(HotSpot)比CLR还早,本篇看下较新的版本OpenJdk19.
编译:
#apt-get insatll openjdk-18-jdk //先下一个bootstrap引导后续
#unzip -x jdk-jdk-19-36.zip
#cd jdk-jdk-19-36
#.config
#make all
编译后的源码:jdk-jdk-19-36/src,编译后的地址:jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin,进入查看下版本
#./java --version
openjdk 19-internal 2022-09-20
OpenJDK Runtime Environment (build 19-internal-adhoc.tang.jdk-jdk-19-36)
OpenJDK 64-Bit Server VM (build 19-internal-adhoc.tang.jdk-jdk-19-36, mixed mode)
java示例:
#cd jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin
#vim javahello.java
public class javahello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
#./javac javahello.java
#./java javahello
# ./java javahello
Hello World!
启动GDB
#cd jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin
# gdb --args ./java javahello
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 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.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./java...
Reading symbols from /home/tang/jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin/java.debuginfo...
下断点,然后运行
(gdb) b main
Breakpoint 1 at 0x1180: file src/java.base/share/native/launcher/main.c, line 98.
(gdb) r
Starting program: /home/tang/jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin/java javahello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (argc=2, argv=0x7fffffffdf48) at src/java.base/share/native/launcher/main.c:98
warning: Source file is more recent than executable.
98 {
可以看到 它停在了main.c文件里面,地址在 jdk-jdk-19-36/src/java.base/share/native/launcher/main.c:98。为了在GDB里面看到源码,运行以下命令:
cd jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin
cp -r /home/tang/jdk-jdk-19-36/src/ .
源码 最后看下jvm源码启动main
cd jdk-jdk-19-36/build/linux-x86_64-server-release/jdk/bin/src/java.base/share/native/launcher
vim main.c
main(int argc, char **argv)
{
int margc;
char** margv;
int jargc;
char** jargv;
const jboolean const_javaw = JNI_FALSE;
#endif /* JAVAW */
{
int i, main_jargc, extra_jargc;
JLI_List list;
main_jargc = (sizeof(const_jargs) / sizeof(char *)) > 1
? sizeof(const_jargs) / sizeof(char *)
: 0; // ignore the null terminator index
extra_jargc = (sizeof(const_extra_jargs) / sizeof(char *)) > 1
? sizeof(const_extra_jargs) / sizeof(char *)
: 0; // ignore the null terminator index
if (main_jargc > 0 && extra_jargc > 0) { // combine extra java args
jargc = main_jargc + extra_jargc;
list = JLI_List_new(jargc + 1);
for (i = 0 ; i < extra_jargc; i++) {
JLI_List_add(list, JLI_StringDup(const_extra_jargs[i]));
}
95,1 49%
}
结尾 作者:江湖评谈
相关文章
- Java要抛弃祖宗的基业,Java程序员危险了!
- 十大 Java 语言特性
- JVM 三色标记算法,原来是这么回事!
- 聊聊 Spring 事务控制策略以及 @Transactional 失效问题避坑
- 写给 Java 程序员的前端 Promise 教程
- 写给 Java 程序员的前端 Promise 教程,你学会了吗?
- Java 中为什么不全部使用 Static 方法?
- Java 池化技术你了解多少?
- Java 服务 Docker 容器化优秀实践
- Spring Boot + EasyExcel导入导出,简直太好用了!
- 我们一起聊聊 Java 内存泄漏
- CentOS 下安装 Docker 极简教程
- JDK 19 功能集冻结:Java 19 只有七个新特性
- 关于 CMS 垃圾回收器,你真的懂了吗?
- 为什么会有这么多编程语言?
- 改善Java代码的八个建议
- 接口流量突增,如何做好性能优化?
- Java 以编程方式创建JAR文件
- POJO、Java Bean是如何定义的
- Spring 的 Bean 明明设置了 Scope 为 Prototype,为什么还是只能获取到单例对象?