编译及单步调试JVM

环境

腾讯云:4核8G ubuntu 20.04 STL

编译OpenJDK 8

下载jdk源码:

git clone https://ghproxy.com/https://github.com/openjdk/jdk8u.git

安装编译的jdk

sudo apt-get install openjdk-8-jdk 1

安装编译依赖

sudo apt-get install build-essential cmake sudo apt-get install --no-install-recommends libfreetype6-dev libcups2-dev libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev libasound2-dev libffi-dev autoconf

进行编译配置

bash configure --with-debug-level=slowdebug --with-jvm-variants=server --with-boot-jdk=/usr/lib/jvm/java-1.8.0-openjdk-amd64 --with-native-debug-symbols=internal

配置的含义

--with-debug-level 选择debug的等级

--with-jvm-variants 编译特定模式的Hotspot虚拟机,我这里选择server模式

--with-boot-jdk 指定Boot-JDK的根目录

--with-native-debug-symbols 符号信息的编译方式,我们选择internal

配置成功:

====================================================
A new configuration has been successfully created in
/root/jdk8u/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-debug-level=slowdebug --with-jvm-variants=server --with-boot-jdk=/usr/lib/jvm/java-1.8.0-openjdk-amd64 --with-native-debug-symbols=internal'.

Configuration summary:
* Debug level:    slowdebug
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK:       openjdk version "1.8.0_342" OpenJDK Runtime Environment (build 1.8.0_342-8u342-b07-0ubuntu1~22.04-b07) OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)  (at /usr/lib/jvm/java-1.8.0-openjdk-amd64)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 9.5.0 (at /usr/bin/gcc)
* C++ Compiler:   Version 9.5.0 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   1
* Memory limit:   1982 MB

WARNING: The result of this configuration has overridden an older
configuration. You *should* run 'make clean' to make sure you get a
proper build. Failure to do so might result in strange build problems.

注意gcc的大版本要gcc-9,如果不是,百度ubuntu切换gcc版本

开始编译

make images

如果编译失败,需要重新编译:

make clean make images

编译成功:

----- Build times -------
Start 2022-11-12 21:57:06
End   2022-11-12 22:03:23
00:00:15 corba
00:00:14 demos
00:02:57 hotspot
00:00:16 images
00:00:09 jaxp
00:00:12 jaxws
00:01:49 jdk
00:00:17 langtools
00:00:06 nashorn
00:06:17 TOTAL
-------------------------
Finished building OpenJDK for target 'clean make images'

单步调试配置

vscode

安装插件

  • Remote - SSH
  • c/c++
  • cmake
  • Cmake tools

image

连接远端服务器

image

远端服务器安装vscode service 及相关插件

image

下载过程卡住,手动下载并上传到服务器手动安装

调试配置

新建.vscode下新建launch.json文件

image

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java",
            "args": [
                "-cp",
                "/root/jdk8u/test/ylctest/",
                "MainClass"
            ],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    "name": "JAVA_HOME",
                    "value": "${workspaceFolder}/build/linux-x86_64-normal-server-slowdebug/jdk/bin"
                },
                {
                    "name": "LD_LIBRARY_PATH",
                    "value": "${workspaceFolder}/build/linux-x86_64-normal-server-slowdebug/jdk/lib/amd64"
                }
            ],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

单步调试

安装gdb

apt install gdb

调试

image

服务迁移

腾讯云4核8G每小时0.5块太贵了,将配置好的环境迁移到本地可长期使用

  1. 实例 - 镜像 - 制作镜像 - 制作完成后缀后缀为raw的文件
  2. 导出到cos(腾讯云的对象存储服务)
  3. 从cos下载到本地
  4. 下载转换工具:https://qemu.weilnetz.de/w64/
  5. 进行转换:qemu-img.exe convert -p -f raw ${raw文件的地址} -O vmdk test.vmdk
  6. vmwera安装虚拟机
  7. 通本地调试本地虚拟机
posted @ 2023-04-23 18:07  ylc0x01  阅读(146)  评论(0)    收藏  举报