Getting arrayref for stack operand in Java bytecode

I work with the ASM API to create Java bytecode, and I would like to be able to determine which array is accessed (by array name) in every access to any array.

I have two problems: - take, for example, iastore instrution. arrayref is pushed onto the operand stack under two other variables - value and index. How to get an array without destroying the stack (I cannot duplicate more than two top variables in the stack)? I thought about the pop index and value from the stack and saved them somewhere, and then to get arrayref and finally push the index and value back onto the stack, but I really don't know how to do this ...

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

early.

+4
source share
1 answer

dup2_x1, pop2, dup_x2 , and now you have arrayref at the top of the stack. But in general, it is easier to use local variables, and the final result after JIT should not differ.

As others have noted, your second part of the question does not make much sense. Objects are not needed in variables, and you can select and use an array without storing it in any variable.

But I suspect that you intend to track access, for example x[0]=1 , and assign it to x, and this can be achieved by analyzing the data stream. You will track aload and where these values ​​will be used, and if your arrayref is directly from aload, you know that the array came from a variable.

0
source

Source: https://habr.com/ru/post/1335271/


All Articles