本文介绍了如何通过汇编代码从JVM核心转储中检查jitted Java方法参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取jitted代码的汇编代码来获取基于Java调用约定的参数值。
假设JVM是热点,平台是Linux 64位,并且我们有以下调用者和调用者,并且我想检查从JVM核心转储传递给调用者的参数。

  protected void caller(){
callee(1,123,123,1);


$ b protected void callee(int a,String b,Integer c,Object d){
Thread.sleep(11111111);



$ b基于以下Java调用约定,我们知道我们可以从寄存器,例如最多6个第一个整数参数在寄存器中传递:rsi,rdx,rcx,r8,r9,rdi



对于c / c ++方法,我们可以通过方式使用gdb通过命令backtrace打印调用堆栈,然后写入N(N是线程号),然后用x / 20i $ pc-64得到汇编代码,我们可以从相关的帧上下文寄存器中获得值。
然而,Java方法调用堆栈无法从gdb打印,并且我们不知道帧编号,因此我们不能使用像c / c ++一样的方法来获取汇编代码,因此如何检查汇编来自核心转储的Java jitted方法的代码?

PS,
有人提到了PrintOptoAssembly,但是我需要汇编代码通过调用约定从寄存器获取参数值(例如通过backtrace,然后帧N,然后x / 20i $ pc-64通过gdb)不只是汇编代码而已。 你不会使用gdb backtrace 命令查看Java框架。但是,您无需手动从coredump中提取VM结构 - 有更好的选择。



1。 HotSpot Serviceability Agent



是专门用于分析Java进程或coredump的内存的工具。它的可在 sa-jdi.jar 提供了一个标准的JDK包。



这是一个,打印带有局部变量信息的扩展Java堆栈跟踪。它也可以解析coredumps。

2。 HotSpot调试功能



HotSpot JVM的调试版本包含可以从gdb调用的特殊调试功能。例如


  • psf()打印堆栈帧;
  • pfl()打印框架布局;
  • disnm(intptr_t addr)在给定地址反汇编已编译的Java方法;
  • pp(intptr_t addr)打印指定地址的Java对象;
  • >
  • 等。请参阅。



这些函数在调试活动进程时工作;虽然不适合coredumps。

顺便说一句,以自行构建JVM的调试版本。


I want to get the Assembly code for the jitted code to get the parameters value based on the Java calling convention. Suppose the JVM is hotspot, the platform is Linux 64 bit , and we have the following caller and calle, and I want to check the parameters passed to callee from the JVM core dump.

protected void caller( ) {
callee(1,"123", 123,1);

}

protected void callee(int a,String b, Integer c,Object d) {
 Thread.sleep(11111111);
}

Based on the following Java calling convention, we know we can get the parameters from the Registers, such as up to 6 first integer arguments are passed in registers: rsi, rdx, rcx, r8, r9, rdihttp://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/file/b4bdf3484720/src/cpu/x86/vm/assembler_x86.hpp#l91

For the c/c++ method, and we can use the gdb just through the way by printting call stack by the command backtrace , then frame N(N is the thread number), then x/20i $pc-64 to get the assembly code, and we can get the value from the related frame context Register. However the Java method call stack can not be printed from gdb, and we don't know the frame number, then we cannot use the same way like c/c++ to get the assembly code,so how to check the assembly code for the Java jitted method from the core dump?

PS,Someone mentioned the PrintOptoAssembly, however I need the Assembly code to get the parameters value from the registers by calling convention(such as by backtrace , then frame N , then x/20i $pc-64 through gdb) not just the Assembly code only.

解决方案

You won't see Java frames with gdb backtrace command. However, you don't need to extract VM structures from a coredump manually - there are better options.

1. HotSpot Serviceability Agent

Serviceability Agent is an instrument designed specially for analyzing memory of a Java process or a coredump. It has Java API available in sa-jdi.jar supplied with a standard JDK package.

Here is an example that prints extended Java stacktraces wtih local variable info. It can also parse coredumps.

2. HotSpot debug functions

Debug builds of HotSpot JVM include special debugging functions that can be called from gdb. E.g.

  • psf() print stack frames;
  • pfl() print frame layout;
  • disnm(intptr_t addr) disassemble compiled Java method at given address;
  • pp(intptr_t addr) print Java object at given address;
  • etc. See other commands in debug.cpp.

These functions work while debugging an active process; not suitable for coredumps though.

BTW, a quick guide to building debug version of JVM by yourself.

这篇关于如何通过汇编代码从JVM核心转储中检查jitted Java方法参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:13