Skip to content

aristotle0x01/centos7_build_openjdk8

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1.原作者readme

centos7_build_openjdk8 Build and compile openjdk8 src at centos7

  1. docker build -t bolingcavalryopenjdk:0.0.1 .
  2. docker run --name=jdk001 -idt bolingcavalryopenjdk:0.0.1
  3. docker exec -it jdk001 /bin/bash
  4. cd /usr/local/openjdk
  5. ./start_make.sh
  6. Waiting for the building complete, then goto build/, you will find linux-xxxxx path, new jdk is in here.
  7. If you have question, try send email to : zq2599@gmail.com

2.改造

  • 使用volume映射源代码

    • 不必加载源文件,可灵活选择版本
    • 本地变更后易于容器内再次编译
  • 使用vscode可视化debug


2.1 编译改造

  • Dockerfile变更见源文件
  • docker build -t bolingcavalryopenjdk:0.0.2 .
  • docker run --name=jdk002 --security-opt seccomp=unconfined -v /path to/openjdk:/var/shared/jdk8u -idt bolingcavalryopenjdk:0.0.2
    • docker exec -it jdk002 /bin/bash
    • cd /var/shared/jdk8u
    • chmod a+x configure && ./configure --with-debug-level=slowdebug --with-native-debug-symbols=internal --enable-debug-symbols
    • make all ZIP_DEBUGINFO_FILES=0 ENABLE_FULL_DEBUG_SYMBOLS=1 DISABLE_HOTSPOT_OS_VERSION_CHECK=OK CONF=linux-x86_64-normal-server-slowdebug
    • 提示缺少的可以通过yum install xx安装即可
    • 验证:cd build/linux-x86_64-normal-server-release/jdk/bin && ./java -version
  • docker commit 47b978003035 bolingcavalryopenjdk:0.0.2_ok (可将上述编译后容器commit),停止并删除该容器
  • docker run --name=jdk002 --security-opt seccomp=unconfined -p 1234:1234 -v /path to/jdk8u:/var/shared/jdk8u -idt bolingcavalryopenjdk:0.0.2_ok

2.2 本地debug

gdb --args ./java -version

但是gdb调试在打断点时比如xxx.cpp:method时,会提示:No source file named xxx.cpp。有几篇文章探讨这个问题,但是没有很好的解决方案1 2 3。解决方法有二:

  • 可以改用lldb调试,绕过去

  • 从openjdk-8u分支切换到8b分支则无此问题(Make breakpoint pending on future即可)

  • 进入gdb之后,执行:directory /var/shared/jdk8u明确告诉gdb源码路径。之后再打断点break classFileParser.cpp:3735,会出现类似:

    No source file named classFileParser.cpp. Make breakpoint pending on future shared library load? (y or [n])

    选择: Y

    Breakpoint 1 (classFileParser.cpp:3735) pending. // 表示未来会在此处断点


2.3 vscode远程debug

容器:

  • docker run --name=jdk002 --security-opt seccomp=unconfined -p 1234:1234 -v /path to/jdk8u:/var/shared/jdk8u -idt bolingcavalryopenjdk:0.0.2_ok

  • yum install gdb-gdbserver

  • gdbserver :1234 /var/shared/jdk8u/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java -version

    注意java完整路径,影响断点同步

本地:

  • 安装gdb

  • vscode安装插件: Native Debug (WebFreak)

    配置文件launch.json如下:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "gdb",
                "request": "attach",
                "name": "Attach to gdbserver",
                "executable": "/var/shared/jdk8u/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java",
                "target": "localhost:1234",
                "remote": true,
                "printCalls": true,
                "cwd": "${workspaceRoot}",
                "valuesFormatting": "parseText",
            }
        ]
    }
    
  • vscode与容器源代码映射:本地建立软连接,这样本地和容器都有了/var/shared/jdk8u路径,即可启动本地单步调试

    ln -s /path to/jdk8u /var/shared。当然这是一种取巧的方式,也可以通过sourceFileMap解决

  • 本地vscode: Run / Start Debugging

  • 打断点无效问题,无论在什么路径测试java程序,注意gdbserver使用编译后完整路径/var/shared/jdk8u/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java,仅仅./java不行


2.4 hsdis编译

cd hotspot/src/share/tools/hsdis
wget http://ftp.heanet.ie/mirrors/ftp.gnu.org/gnu/binutils/binutils-2.29.tar.gz
tar -xzf binutils-2.29.tar.gz
sed -ri 's/development=.*/development=false/' ./binutils-2.29/bfd/development.sh # set development to false
make BINUTILS=binutils-2.29 ARCH=amd64

// 成功后拷贝到相关目录
sudo cp build/linux-amd64/hsdis-amd64.so ...
./linux-x86_64-normal-server-slowdebug/jdk/lib/amd64/server/hsdis-amd64.so
./linux-x86_64-normal-server-slowdebug/jdk/lib/amd64/hsdis-amd64.so
./linux-x86_64-normal-server-slowdebug/hotspot/dist/jre/lib/amd64/server/hsdis-amd64.so
./linux-x86_64-normal-server-slowdebug/hotspot/dist/jre/lib/amd64/hsdis-amd64.so

如果遇到下面错误:

hsdis.c:314:3: error: incompatible type for argument 1 of 'disassembler'

可参考hsdis disassembler plugin does not compile with binutils 2.29+ 按照**CUSTOMER SUBMITTED WORKAROUND :**部分修改hsdis.c代码即可

Build hsdis for JDK 1.8 on Ubuntu

Developers disassemble! Use Java and hsdis to see it all


3.reference

在docker上编译openjdk8

修改,编译,GDB调试openjdk8源码(docker环境下)

Debugging C/C++ Programs Remotely Using Visual Studio Code and gdbserver

How to Remote Debugging with Visual Studio Code

Configure C/C++ debugging

VS Code Remote Development

Pipe transport

Remote Development using SSH

MacOS 编译 openjdk8 并导入 Clion 调试

搭建 JVM(HotSpot) 源码调试环境(OpenJDK8)

gdb breakpoint issue:

Footnotes

  1. Could not step in cpp file when debug Openjdk8 hotspot in mac

  2. [讨论] HotSpot gdb调试, No source file named ...

  3. GDB: Debug native part of java application (C/C++ libraries and JDK)

About

build and compile openjdk8 src at centos7

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Dockerfile 60.7%
  • Shell 39.3%