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

查看:284
本文介绍了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.

这个问题已经在较早的主题中进行了讨论(请参阅

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文档.

See the JVMTI docs on local variables.

首先,您需要确保已在功能列表中启用了本地变量访问.然后,使用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-如何从回调获取方法参数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆