2

I am trying to record the arguments passed to a method before it is called using bytecode instrumentation.

Currently while instrumenting using java code I have to first pop all the args into a locals, then push them again twice (once for my method which will record and in this case all primitive types have to be converted to their boxed types, and once for the actual method call).

What I would ideally like to do is just duplicate the entire stack for the num of args pushed for the method call. However the jvm bytecode's dup() instruction only allows duplicating the topmost value of the stack. Is it possible using JNI to somehow duplicate the entire stack in one go?

4

1 回答 1

1

不,当编译方法时堆栈有效地消失了。JVM 无法编译本机代码。因此,即使您确实尝试直接操作堆栈,它也会即时更改格式(并使用寄存器)。

您可以相当容易地复制堆栈的前四个插槽(使用 dup2_x2),但如果再进一步,您可能需要使用局部变量。

于 2008-12-04T14:09:33.893 回答