Class DaikonVariableInfo
- Object
-
- 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. 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. There is such a tree structure associated with every program point.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.
The tree structure is built in the DeclWriter and traversed in the DTraceWriter.
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.
-
-
Field Summary
Fields Modifier and Type Field Description List<DaikonVariableInfo>
children
The child nodes.static String
class_suffix
static String
class_suffix_relative_name
protected static String
classClassName
protected String
compareInfoString
The printed comparability information that will appear in the .decls declaration.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 String
isNonNullParamString
Indicates that a given variable is non-null and a parameter.protected static String
isNonNullString
Indicates that a given variable is non-null.protected static String
isParamString
Indicates that a given variable is a parameter to a method.protected static Set<String>
ppt_statics
Set of fully qualified static variable names for this ppt.protected String
repTypeName
The printed representation type that will appear in the .decls declaration.static boolean
std_visibility
If false, every field in an instrumented class is visible.protected static String
stringClassName
protected String
typeName
The printed type that will appear in the .decls declaration.
-
Constructor Summary
Constructors Modifier Constructor Description protected
DaikonVariableInfo(String theName, String typeName, String repTypeName)
Constructs a non-array-type DaikonVariableInfo object.protected
DaikonVariableInfo(String theName, String typeName, String repTypeName, boolean arr)
Constructs a DaikonVariableInfo object.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 (seeDaikonVariableInfo
).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(Field field, String offset, StringBuilder buf)
Adds the decl info for a single class variable (a field) as a child of this node.protected DaikonVariableInfo
addParamDeclVar(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 void
addParameters(ClassInfo cinfo, Member method, List<String> argnames, int depth)
Add the parameters of the given method to this node.protected DaikonVariableInfo
addPureMethodDecl(ClassInfo curClass, MethodInfo minfo, DaikonVariableInfo[] args, String offset, int depth, StringBuilder buf)
Adds the decl info for a pure method.@Nullable 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()
@Nullable String
get_const_val()
Returns the constant value of the variable.@Nullable String
get_function_args()
Returns the function args of the variable.@Nullable 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 @Nullable Object
getMyValFromParentVal(Object parentVal)
Given a value corresponding to the parent of this, return the value of this.@Nullable 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.@BinaryName 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()
Returns 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 @BinaryName String
stdClassName(Class<?> type)
Returns the class name of the specified class as a binary name (i.e., as the class would have been declared in Java source code, except with '$' instead of '.' separating outer and inner classes).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 representation of this node and its descandants.-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface Iterable
forEach, spliterator
-
-
-
-
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.
-
isNonNullString
protected static final String isNonNullString
Indicates that a given variable is non-null.- See Also:
- Constant Field Values
-
isParamString
protected static final String isParamString
Indicates that a given variable is a parameter to a method.- See Also:
- Constant Field Values
-
isNonNullParamString
protected static final String isNonNullParamString
Indicates that a given variable is non-null and a parameter.- See Also:
- Constant Field Values
-
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
- See Also:
- Constant Field Values
-
class_suffix_relative_name
public static final String class_suffix_relative_name
-
typeName
protected String typeName
The printed type that will appear in the .decls declaration. May include aux information at the end, such as isParamString.- See Also:
getTypeName()
,getTypeNameOnly()
-
repTypeName
protected String repTypeName
The printed representation type that will appear in the .decls declaration.
-
compareInfoString
protected String compareInfoString
The printed comparability information that will appear in the .decls declaration.
-
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, every 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
protected DaikonVariableInfo(String theName, String typeName, String repTypeName)
Constructs a non-array-type DaikonVariableInfo object.- Parameters:
theName
- the name of the variabletypeName
- the name of the typerepTypeName
- the name of the representation type
-
DaikonVariableInfo
protected DaikonVariableInfo(String theName, String typeName, String repTypeName, boolean arr)
Constructs a DaikonVariableInfo object.- Parameters:
theName
- the variable's namearr
- true iff the variable is an array
-
-
Method Detail
-
getName
public @Nullable String getName(@GuardSatisfied DaikonVariableInfo this)
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 compareInfoString should also be non-null.
-
toString
@SideEffectFree public String toString(@GuardSatisfied DaikonVariableInfo this)
Returns a string representation of this node.
-
treeString
public String treeString()
Returns a string representation of this node and its descandants.- Returns:
- a string representation of this node and its descandants
-
iterator
public Iterator<DaikonVariableInfo> iterator()
Returns 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 interfaceIterable<DaikonVariableInfo>
- Returns:
- an iterator over all the node's children
-
tree_as_list
public List<DaikonVariableInfo> tree_as_list()
Returns the complete tree of variables as a list.
-
getMyValFromParentVal
public abstract @Nullable Object getMyValFromParentVal(Object parentVal)
Given a value corresponding to the parent of this, return the value of this.For instance, if the variable a has a field b, then calling getMyValFromParentVal(val_of_a) will return the value of a.b .
- Parameters:
parentVal
- the parent object. Can be null for static fields.- Returns:
- the value for this, computed from
parentVal
-
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, int depth)
Add the parameters of the given method to this node.- Parameters:
cinfo
- the method's classmethod
- the methodargnames
- the method's argumentsdepth
- the remaining depth to print variables to
-
addClassVars
@RequiresNonNull("#1.clazz") 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.- Parameters:
type
- the class whose fields should all be added to this nodeoffset
- the prefix for variables -- that is, the expression whose fields are being printeddepth
- the remaining depth to print variables to
-
addParamDeclVar
protected DaikonVariableInfo addParamDeclVar(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, DaikonVariableInfo[] args, String offset, int depth, StringBuilder buf)
Adds the decl info for a pure method.
-
addDeclVar
protected DaikonVariableInfo addDeclVar(Field field, String offset, StringBuilder 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 @BinaryName String stdClassName(Class<?> type)
Returns the class name of the specified class as a binary name (i.e., as the class would have been declared in Java source code, except with '$' instead of '.' separating outer and inner classes).
-
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 variableasArray
- 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.The .class variable is printed for interfaces, abstract classes, and Object. For these types, the run-time class is always (or, for Object, usually) different than the declared type. An alternate, and possibly more useful, heuristic would be to print the .class variable for any type that has subtypes.
- 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.- Returns:
- true iff type implements the List interface
-
addChildNodes
@RequiresNonNull("#1.clazz") protected void addChildNodes(ClassInfo cinfo, Class<?> type, String theName, String offset, int depthRemaining)
Explores the tree one level deeper (seeDaikonVariableInfo
). 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. May include auxiliary information (represented as a suffix starting with "#").- See Also:
getTypeNameOnly()
-
getTypeNameOnly
public @BinaryName String getTypeNameOnly()
Return the type name without aux information.- See Also:
getTypeName()
-
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 @Nullable 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.
-
get_function_args
public @Nullable String get_function_args()
Returns the function args of the variable. If the variable is not a function, or does not have any arguments, 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
@Pure public int compareTo(@GuardSatisfied DaikonVariableInfo this, DaikonVariableInfo dv)
Compares based on the name of the variable.- Specified by:
compareTo
in interfaceComparable<DaikonVariableInfo>
-
isArray
public boolean isArray()
Returns whether or not this variable is an array.
-
array_child
public @Nullable 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 @Nullable 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(), then add in any flags that they add.
-
isStatic
@Pure public boolean isStatic()
Returns true iff the variable is static. Overridden by subclasses that can be static.
-
-