[DiSL-user] Handling Array store/load

Lubomír Bulej lubomir.bulej at d3s.mff.cuni.cz
Tue May 2 22:47:41 CEST 2017


Hi Alessio,

when you instrument the array store bytecodes, the information you need is not
directly available, because the array access bytecodes (?ASTORE, ?ALOAD) work
with the array reference on stack -- the reference could have been left there
after a function all, or obtained using the GETFIELD or GETSTATIC bytecodes --
the information on the class is only available those.

To do it properly, you would need to do a simple evaluation of the method's
bytecode to trace how values got on the stack and which array references you
use with the ?ASTORE and ?ALOAD bytecodes.

As a simpler solution, you could try to scan the method bytecode backwards
from the point of the ?ASTORE or ?ALOAD bytecode and try to find the first
GETFIELD or GETSTATIC bytecode that fetches an array (or a method invocation
that returns the array), i.e., the source of the array reference, and then
fetch the owner and the field name from that instruction.

This would be done in a custom static context, i.e., a class that implements
the StaticContext interface.

I would suggest to look at the InstructionStaticContext implementation in the
trunk version, where you will find the getIndex() method, which returns the
index of an instruction's bytecode in a method. It only counts "real" bytecode
instructions (not all ASM's AbstractInsnNode which are also used for labels).

The InstructionStaticContext extends the AbstractStaticContext class (which
does not really do much at the moment, there are plans to make this interface
nicer). Within the getIndex() method, the staticContextData.getRegionStart()
gets you the start of the region the context is related to. The instruction
nodes are linked, so you could try to walk back the list of instructions to
find the field load that got the array reference on top of the stack and
check the FieldAccessStatic context on how to retrieve the owner class and
field name.


Best regards,
Lubomir




On 28/04/17 12:15, Alessio Gambi wrote:
> Hi DiSL-ers,
> 
> I am in the following situation:
> 
> I can capture the array store and load events, but I cannot understand how I can get the following information (if possible):
> 
> - Which field of which class the array store refers to?
> 
> Best
> 
> — Alessio
> _______________________________________________
> Disl-user mailing list
> Disl-user at d3s.mff.cuni.cz
> https://d3s.mff.cuni.cz/mailman/listinfo/disl-user
> 




More information about the Disl-user mailing list