daikon.chicory
Class DaikonVariableInfo

Object
  extended by DaikonVariableInfo
All Implemented Interfaces:
Comparable<DaikonVariableInfo>, Iterable<DaikonVariableInfo>
Direct Known Subclasses:
ArrayInfo, DaikonClassInfo, FieldInfo, ListInfo, ParameterInfo, PureMethodInfo, ReturnInfo, RootInfo, StaticObjInfo, StringInfo, ThisObjInfo

public abstract class DaikonVariableInfo
extends Object
implements Iterable<DaikonVariableInfo>, Comparable<DaikonVariableInfo>

Each DaikonVariableInfo object is a node in the tree structure of the variables in the target application. The tree structure is built in the DeclWriter and traversed in the DTraceWriter. There is such a tree structure associated with every program point. This architecture makes it possible to avoid the issue of "traversal pattern duplication" in which both the DeclWriter and DTraceWriter must traverse the target application's variables identically. In general, the variable a will be the parent of the variables a.b and a.c in the tree, where b and c are fields in a's class. Each node can have any non-negative number of child nodes. DaikonVariableInfo is an abstract class. Its subtypes are designed to represent specific types of variables, such as arguments, arrays, etc.


Field Summary
 List<DaikonVariableInfo> children
          The child nodes
static String class_suffix
          Suffix for "typeOf" variables that represent a class, eg, "foo.getClass()".
protected static String classClassName
           
protected  String compareInfoString
           
protected  boolean declShouldPrint
          True iff the DeclWriter should print this variable
static boolean dkconfig_constant_infer
          Enable experimental techniques on static constants.
protected  boolean dtraceShouldPrint
          True iff the DTraceWriter should print this variable
protected  boolean dtraceShouldPrintChildren
          True iff the DTraceWriter should print the children of this variable
protected  boolean isArray
          True iff this variable is an array
protected static Set<String> ppt_statics
          Set of fully qualified static variable names for this ppt.
protected  String repTypeName
           
static boolean std_visibility
          If false, use standard dfej behavior (any field in an instrumented class is visible) If true, use standard java behavior (if the field is in a class in a different package, it is only visible if public, etc.)
protected static String stringClassName
           
protected  String typeName
          The three strings needed for the .decls info, in addition to the variable name are typeName, repTypeName, and compareInfoString.
 
Constructor Summary
DaikonVariableInfo(String theName)
          Constructs a non-array type DaikonVariableInfo object
DaikonVariableInfo(String theName, boolean arr)
          Constructs a DaikonVariableInfo object
 
Method Summary
protected  void addChild(DaikonVariableInfo info)
          Add a child to this node.
protected  void addChildNodes(ClassInfo cinfo, Class<?> type, String theName, String offset, int depthRemaining)
          Explores the tree one level deeper (see DaikonVariableInfo).
protected  void addClassVars(ClassInfo cinfo, boolean dontPrintInstanceVars, Class<?> type, String offset, int depth)
          Adds class variables (i.e., the fields) for the given type and attach new nodes as children of this node.
protected  DaikonVariableInfo addDeclVar(ClassInfo cinfo, Class<?> type, String name, String offset, int depth, int argNum, int param_offset)
          Adds the decl info for a single parameter as a child of this node.
protected  DaikonVariableInfo addDeclVar(Field field, String offset, StringBuffer buf)
          Adds the decl info for a single class variable (a field) as a child of this node.
protected  void addParameters(ClassInfo cinfo, Member method, List<String> argnames, String offset, int depth)
          Add the parameters of the given method to this node.
protected  DaikonVariableInfo addPureMethodDecl(ClassInfo curClass, MethodInfo minfo, String offset, int depth, StringBuffer buf)
          Adds the decl info for a pure method.
 DaikonVariableInfo array_child()
          Returns the direct child that is an array, null if one does not exist
protected  void checkForDerivedVariables(Class<?> type, String theName, String offset)
          Checks for "derived" Chicory variables: .class, .tostring, and java.util.List implementors and adds appropriate children to this node.
protected  void checkForListDecl(Class<?> type, String theName, String offset)
          Determines if type implements list and prints associated decls, if necessary
protected  void checkForRuntimeClass(Class<?> type, String theName, String offset)
          Checks the given type to see if it requires a .class addition to the decls file.
 int compareTo(DaikonVariableInfo dv)
          Compares based on the name of the variable
 boolean declShouldPrint()
          Return true iff the DeclWriter should print this node.
 boolean dTraceShouldPrint()
          Return true iff the DTraceWriter should print this node.
 boolean dTraceShouldPrintChildren()
           
 String get_const_val()
          Returns the constant value of the variable.
 String get_relative_name()
          Returns the name of this variable relative to its enclosing variable.
 EnumSet<VarFlags> get_var_flags()
          Returns the variable flags for this variable.
abstract  VarKind get_var_kind()
          Returns the kind of the variable (array, field, function, etc)
 String getCompareString()
          Returns the comparability information for this variable.
 String getDTraceValueString(Object val)
          Returns a String representation of this object suitable for a .dtrace file
abstract  Object getMyValFromParentVal(Object parentVal)
          Given an object value corresponding to the parent of this DaikonVariableInfo variable, return the value (of the corresponding value in the target application) of this DaikonVariableInfo variable.
 String getName()
          Returns the name of this variable.
static String getRepName(Class<?> type, boolean asArray)
          Given a type, gets the representation type to be used in Daikon.
 String getRepTypeName()
          Returns the representation type name of this variable.
 String getRepTypeNameOnly()
          Return the rep type name without the constant value
 String getTypeName()
          Returns the declared type name of this variable.
 String getTypeNameOnly()
          Return the type name without aux information
protected  String getValueStringOfList(List<Object> theValues)
          Returns a string representation of the values of a list of values as if it were an array.
protected  String getValueStringOfObjectWithMod(Object theValue, boolean hashArray)
          Gets the value of an object and concatenates the associated "modified" integer.
static boolean implementsList(Class<?> type)
          Returns true iff type implements the List interface.
 boolean isArray()
          Returns whether or not this variable is an array
static boolean isFieldVisible(Class<?> current, Field field)
          Returns whether or not the specified field is visible from the Class current.
 boolean isHashcode()
          Returns whether or not this variable has a rep type of hashcode
 boolean isHashcodeArray()
           
 boolean isInt()
          Returns whether or not the declared type of this variable is int
 boolean isStatic()
          Returns true iff the variable is static.
 Iterator<DaikonVariableInfo> iterator()
          Return an iterator over all the node's children.
protected static boolean shouldAddRuntimeClass(Class<?> type)
          Determines if type needs a corresponding .class runtime class variable
static String stdClassName(Class<?> type)
          Returns the class name of the specified class in 'Java' format (i.e., as the class would have been declared in Java source code)
static boolean systemClass(Class<?> type)
          Returns whether or not the fields of the specified class should be included, based on whether the Class type is a system class or not.
 String toString()
          Returns a string representation of this node.
 List<DaikonVariableInfo> tree_as_list()
          Returns the complete tree of variables as a list
 String treeString()
          Returns a string representative of this node and its children
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dkconfig_constant_infer

public static boolean dkconfig_constant_infer
Enable experimental techniques on static constants.


children

public List<DaikonVariableInfo> children
The child nodes


isArray

protected final boolean isArray
True iff this variable is an array


classClassName

protected static final String classClassName
See Also:
Constant Field Values

stringClassName

protected static final String stringClassName
See Also:
Constant Field Values

class_suffix

public static final String class_suffix
Suffix for "typeOf" variables that represent a class, eg, "foo.getClass()".

See Also:
Constant Field Values

typeName

protected String typeName
The three strings needed for the .decls info, in addition to the variable name are typeName, repTypeName, and compareInfoString.


repTypeName

protected String repTypeName

compareInfoString

protected String compareInfoString

declShouldPrint

protected boolean declShouldPrint
True iff the DeclWriter should print this variable


dtraceShouldPrint

protected boolean dtraceShouldPrint
True iff the DTraceWriter should print this variable


dtraceShouldPrintChildren

protected boolean dtraceShouldPrintChildren
True iff the DTraceWriter should print the children of this variable


std_visibility

public static boolean std_visibility
If false, use standard dfej behavior (any field in an instrumented class is visible) If true, use standard java behavior (if the field is in a class in a different package, it is only visible if public, etc.)


ppt_statics

protected static Set<String> ppt_statics
Set of fully qualified static variable names for this ppt. Used to ensure that each static is only included once (regardless of how many other variables may include its declaring class).

Constructor Detail

DaikonVariableInfo

public DaikonVariableInfo(String theName)
Constructs a non-array type DaikonVariableInfo object

Parameters:
theName - The name of the variable

DaikonVariableInfo

public DaikonVariableInfo(String theName,
                          boolean arr)
Constructs a DaikonVariableInfo object

Parameters:
theName - The variable's name
arr - True iff the variable is an array
Method Detail

getName

public String getName()
Returns the name of this variable.


addChild

protected void addChild(DaikonVariableInfo info)
Add a child to this node. Should only be called while the tree is being constructed.

Parameters:
info - The child object, must be non-null. The child's fields name, typeName, repTypeName, and compareInofString should also be non-null.

toString

public String toString()
Returns a string representation of this node.

Overrides:
toString in class Object

treeString

public String treeString()
Returns a string representative of this node and its children


iterator

public Iterator<DaikonVariableInfo> iterator()
Return an iterator over all the node's children. Don't modify the list of children through the iterator, as an unmodifiable list is used to generate the iterator.

Specified by:
iterator in interface Iterable<DaikonVariableInfo>

tree_as_list

public List<DaikonVariableInfo> tree_as_list()
Returns the complete tree of variables as a list


getMyValFromParentVal

public abstract Object getMyValFromParentVal(Object parentVal)
Given an object value corresponding to the parent of this DaikonVariableInfo variable, return the value (of the corresponding value in the target application) of this DaikonVariableInfo variable. For instance, if the variable a has a field b, then calling getMyValParentVal(val_of_a) will return the value of a.b

Parameters:
parentVal - The parent object. Can be null for static fields. (Are there any other circumstances where it can be null?)

getDTraceValueString

public String getDTraceValueString(Object val)
Returns a String representation of this object suitable for a .dtrace file

Parameters:
val - The object whose value to print

getValueStringOfObjectWithMod

protected String getValueStringOfObjectWithMod(Object theValue,
                                               boolean hashArray)
Gets the value of an object and concatenates the associated "modified" integer.


getValueStringOfList

protected String getValueStringOfList(List<Object> theValues)
Returns a string representation of the values of a list of values as if it were an array.

Parameters:
theValues - The values to print out

addParameters

protected void addParameters(ClassInfo cinfo,
                             Member method,
                             List<String> argnames,
                             String offset,
                             int depth)
Add the parameters of the given method to this node.


addClassVars

protected void addClassVars(ClassInfo cinfo,
                            boolean dontPrintInstanceVars,
                            Class<?> type,
                            String offset,
                            int depth)
Adds class variables (i.e., the fields) for the given type and attach new nodes as children of this node.


addDeclVar

protected DaikonVariableInfo addDeclVar(ClassInfo cinfo,
                                        Class<?> type,
                                        String name,
                                        String offset,
                                        int depth,
                                        int argNum,
                                        int param_offset)
Adds the decl info for a single parameter as a child of this node. Also adds "derived" variables such as the runtime .class variable.

Returns:
The newly created DaikonVariableInfo object, whose parent is this.

addPureMethodDecl

protected DaikonVariableInfo addPureMethodDecl(ClassInfo curClass,
                                               MethodInfo minfo,
                                               String offset,
                                               int depth,
                                               StringBuffer buf)
Adds the decl info for a pure method.


addDeclVar

protected DaikonVariableInfo addDeclVar(Field field,
                                        String offset,
                                        StringBuffer buf)
Adds the decl info for a single class variable (a field) as a child of this node. Also adds "derived" variables such as the runtime .class variable.

Returns:
The newly created DaikonVariableInfo object, whose parent is this.

stdClassName

public static String stdClassName(Class<?> type)
Returns the class name of the specified class in 'Java' format (i.e., as the class would have been declared in Java source code)


getRepName

public static String getRepName(Class<?> type,
                                boolean asArray)
Given a type, gets the representation type to be used in Daikon. For example, the representation type of a class object is "hashcode."

Parameters:
type - The type of the variable
asArray - Whether the variable is being output as an array (true) or as a pointer (false).
Returns:
The representation type as a string

shouldAddRuntimeClass

protected static boolean shouldAddRuntimeClass(Class<?> type)
Determines if type needs a corresponding .class runtime class variable

Parameters:
type - The variable's Type

isFieldVisible

public static boolean isFieldVisible(Class<?> current,
                                     Field field)
Returns whether or not the specified field is visible from the Class current. All fields within instrumented classes are considered visible from everywhere (to match dfej behavior)


checkForDerivedVariables

protected void checkForDerivedVariables(Class<?> type,
                                        String theName,
                                        String offset)
Checks for "derived" Chicory variables: .class, .tostring, and java.util.List implementors and adds appropriate children to this node.


checkForListDecl

protected void checkForListDecl(Class<?> type,
                                String theName,
                                String offset)
Determines if type implements list and prints associated decls, if necessary


checkForRuntimeClass

protected void checkForRuntimeClass(Class<?> type,
                                    String theName,
                                    String offset)
Checks the given type to see if it requires a .class addition to the decls file. If so, it adds the correct child to this node.


implementsList

public static boolean implementsList(Class<?> type)
Returns true iff type implements the List interface.

Parameters:
type -
Returns:
true iff type implements the List interface

addChildNodes

protected void addChildNodes(ClassInfo cinfo,
                             Class<?> type,
                             String theName,
                             String offset,
                             int depthRemaining)
Explores the tree one level deeper (see DaikonVariableInfo). This method adds child nodes to this node. For example: "recurse" on a hashcode array object to print the actual array of values or recurse on hashcode variable to print its fields. Also accounts for derived variables (.class, .tostring) and "recurses" on arrays (that is, adds a variable to print out the arrays's elements as opposed to just the hashcode of the array).

Parameters:
theName - The name of the variable currently being examined, such as "ballCount"
offset - The representation of the variables we have previously examined. For examples, offset could be "this." in which case offset + name would be "this.ballCount."

systemClass

public static boolean systemClass(Class<?> type)
Returns whether or not the fields of the specified class should be included, based on whether the Class type is a system class or not. Right now, any system classes are excluded, but a better way of determining this is probably necessary


getTypeName

public String getTypeName()
Returns the declared type name of this variable.


getTypeNameOnly

public String getTypeNameOnly()
Return the type name without aux information


getRepTypeName

public String getRepTypeName()
Returns the representation type name of this variable.


getRepTypeNameOnly

public String getRepTypeNameOnly()
Return the rep type name without the constant value


get_const_val

public String get_const_val()
Returns the constant value of the variable. If the variable is not static and final, or if the constant value is not available in the class file, returns null.


getCompareString

public String getCompareString()
Returns the comparability information for this variable.


declShouldPrint

public boolean declShouldPrint()
Return true iff the DeclWriter should print this node.


dTraceShouldPrint

public boolean dTraceShouldPrint()
Return true iff the DTraceWriter should print this node.


dTraceShouldPrintChildren

public boolean dTraceShouldPrintChildren()

compareTo

public int compareTo(DaikonVariableInfo dv)
Compares based on the name of the variable

Specified by:
compareTo in interface Comparable<DaikonVariableInfo>

isArray

public boolean isArray()
Returns whether or not this variable is an array


array_child

public DaikonVariableInfo array_child()
Returns the direct child that is an array, null if one does not exist


isHashcode

public boolean isHashcode()
Returns whether or not this variable has a rep type of hashcode


isHashcodeArray

public boolean isHashcodeArray()

isInt

public boolean isInt()
Returns whether or not the declared type of this variable is int


get_var_kind

public abstract VarKind get_var_kind()
Returns the kind of the variable (array, field, function, etc)


get_relative_name

public String get_relative_name()
Returns the name of this variable relative to its enclosing variable. For example the relative name for 'this.a' is 'a'.


get_var_flags

public EnumSet<VarFlags> get_var_flags()
Returns the variable flags for this variable. Subclasses should call super() and or in any flags that they add


isStatic

public boolean isStatic()
Returns true iff the variable is static. Overridden by subclasses that can be static