Skip to content

Trace Variables

Yun Lin edited this page Dec 8, 2020 · 1 revision

In Microbat, we use the following ID naming convention to uniquely identity a variable. We use different ID naming convention for primitive and object variable.

Object Variable

Given an object o, JVM maintains a heap ID and programmers can get it by calling System.identityHashCode(o). Note that, a variable can be written multiple times. Thus, the id of an object (non-primitive type) is its heap address + the order of trace node defining it, e.g., 100:33.

Primitive Variable

A variable of primitive type cannot have a heap address by calling System.identityHashCode(o). Thus, we have the following convention:

  • non-static field: its id is: its parent's object id + field name + the order of trace node defining it,e.g., 100.a:33;
  • static field: its id is: its field name + the order of trace node defining it,e.g., Class.a:33;
  • array element: its id is: its parent's object id + index + the order of trace node defining it,e.g., 100[1]:33 ;
  • local variable: its id is: its scope (i.e., class[startLine, endLine]) + variable name+ invocation_layer + the order of trace node defining it, invocation_layer is for distinguish recursive methods, e.g., com/Main{12, 21}a-3:33;
  • return variable: its id is: "virtualVar" + the order of the relevant return-trace-node.

Note that, an object variable can have ID following ID naming convention of primitive variable, however, not vice versa. Thus, we can track dynamic data flow, we may need to check two IDs if a variable is an object variable.

API

If the user want to concanate a variable ID, such as local variable ID, field ID, etc. Users should use the following three static method:

  • Variable.concanateFieldVarID()
  • Variable.concanateArrayElementVarID()
  • Variable.concanateLocalVarID()