开发者

Getting the arrayref for stack operand in Java bytecode

开发者 https://www.devze.com 2023-02-03 16:55 出处:网络
I work with ASM API for Java bytecode instrumantation, and I\'d like to be able to determine which array is accessed (by the array\'s name) in each access to any array.

I work with ASM API for Java bytecode instrumantation, and I'd like to be able to determine which array is accessed (by the array's name) in each access to any array.

I have two problems with it: - let's take for example 开发者_开发百科the iastore instrution. the arrayref is placed in the operand stack under two other variables - value and index. How do I get the arrayref without ruining the stack (I can't duplicate more than two top variables in the stack)? I thought of pop index and value from the stack and save them somewhere and then to get the arrayref and finally push index and value back to the stack but I don't really know how to do this...

  • I would like to get from the arrayref (once I have it) the name of the array (the name that the user declared that array called it).

thanks in advance.


dup2_x1, pop2, dup_x2 and you now have arrayref at the top of the stack. But in general it's simpler to use local variables and the end result after JIT should be no different.

As others commented, your 2nd part of the question doesn't make much sense. Objects aren't necessary in variables, and you can allocate and use an array without ever storing it into any variable.

But I suspect your intent is to track access like x[0]=1 and attribute that to x, and that can be achieved by the dataflow analysis. You'll track aload and where those values are used, and if your arrayref turns out to be straight from aload, you know that array came from a variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消