JVMTI - 如何从回调中获取方法参数的值

JVMTI - how to get the value of a method parameter from callback(JVMTI - 如何从回调中获取方法参数的值)

本文介绍了JVMTI - 如何从回调中获取方法参数的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢 JVMTI 代理,我正在记录我的 Java 应用程序中的所有方法条目.目前,我能够获取每个方法的名称,但我希望能够获取该方法接收到的参数的值.

I am recording all method entries from my Java app thanks to a JVMTI Agent. For now, I am able to get the name of each method, but I'd want to be able to get the value of the parameters that method received.

这个问题已经在较早的主题中讨论过(请参阅 如何在 MethodEntry 回调中获取参数值);它完全符合我的要求,所以我知道我必须使用 GetLocalObject 函数,但我不知道如何使用(主题中给出的示例已损坏).

This problem has already been discussed in an older topic (see How to get parameter values in a MethodEntry callback); it fits perfectly what I'm looking for, so I know I have to use GetLocalObject function, but I can't figure out how to (the example given in the topic is broken).

谁能帮我找出如何做到这一点?谢谢.

Can anyone help me finding out how to do this? Thanks.

推荐答案

我认为您想在不知道其内容的情况下访问任意方法参数,如果不是,您能否澄清您的问题?

I think you want to access arbitrary method parameters without foreknowledge of their content, if not could you clarify your question?

请参阅 JVMTI 本地变量文档.

首先,您需要确保已在功能列表中启用局部变量访问.然后,使用 GetLocalVariableTable 找出可用的参数.返回的表将包含方法中每个局部变量的描述,包括参数.完成后不要忘记Deallocate它.

First, you need to ensure you have enabled local variable access in your capabilities list. Then, find out what parameters are available using GetLocalVariableTable. The returned table will contain a description of each local variable in the method, including the parameters. Don't forget to Deallocate it when you're done.

您需要确定哪些变量是参数.您可以通过查找当前的 jlocation 并消除尚不可用的局部变量来做到这一点.这不会告诉您参数顺序,但会告诉您哪些局部变量是参数.你大概可以假设槽号是正确的顺序.

You'll need to work out which variables are parameters. You can do that by finding the current jlocation and eliminating local variables which are not yet available. This won't tell you the parameter order, but it'll tell you which locals are parameters. You can probably assume that the slot number is the correct order.

使用GetFrameLocation找到当前的jlocation,遍历局部变量表,对每个start_location小于等于的局部变量到您当前的位置,将插槽号和类型添加到您的参数列表中.

Find the current jlocation using GetFrameLocation, iterate over the local variable table, and for each local variable whose start_location is less than or equal to your current location, add the slot number and type to your list of parameters.

对于每个参数,根据其类型调用相应的 GetLocal{X} 方法.您需要当前帧的深度,您已经从 GetFrameLocation 获得.

For each parameter, call the appropriate GetLocal{X} method based on its type. You'll need the depth of your current frame, which you already have from GetFrameLocation.

这应该会为您提供参数,但实施起来会很慢而且很棘手.您最好遵循指南的建议,即避免 MethodEntry 回调并改用字节码检测 (BCI).

That should get you your parameters, but it'll be slow and tricky to implement. You'd be far better off following the guide's recommendation of avoiding MethodEntry callbacks and use bytecode instrumentation (BCI) instead.

这篇关于JVMTI - 如何从回调中获取方法参数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:JVMTI - 如何从回调中获取方法参数的值

基础教程推荐