daikon
Class DynamicConstants

Object
  extended by DynamicConstants
All Implemented Interfaces:
Serializable

public class DynamicConstants
extends Object
implements Serializable

Class that implements dynamic constants optimization. This optimization doesn't instantiate invariants over constant variables (i.e., that that have only seen one value). When the variable receives a second value, invariants are instantiated and are given the sample representing the previous constant value. Each DynamicConstants object is associated with a single program point, ppt.

See Also:
Serialized Form

Nested Class Summary
static class DynamicConstants.ConIndexComparator
          Compares two constants based on the vi_index of their variable.
static class DynamicConstants.Constant
          Class used to indicate, for each variable, whether it is constant (see boolean field "constant").
 
Field Summary
static Logger debug
          Debug tracer.
static boolean dkconfig_OneOf_only
          Boolean.
 
Constructor Summary
DynamicConstants(PptTopLevel ppt)
          Create an initial list of constants and missing variables for the specified ppt.
 
Method Summary
 void add(ValueTuple vt, int count)
          Checks each current constant to see if it is still a constant.
 int constant_leader_cnt()
          Returns the number of constants that are leaders.
 Object constant_value(VarInfo vi)
          Returns the constant value of the specified variable, or null if the variable is not constant or prev_constant.
 List<PptSlice> create_constant_invs()
          Create unary and binary constant invariants.
 DynamicConstants.Constant getConstant(VarInfo vi)
          Returns the Constant for the specified variable.
 void instantiate_constant_suppressions(List<DynamicConstants.Constant> new_noncons, List<DynamicConstants.Constant> all)
           
 void instantiate_new_views(List<DynamicConstants.Constant> noncons, List<DynamicConstants.Constant> non_missing)
          Creates all new views required for the newly non constants (noncons) and the newly non-missing (non_missing).
 void instantiate_oneof(DynamicConstants.Constant con)
          Creates OneOf invariants for each constant
 boolean is_constant(VarInfo vi)
          Returns whether the specified variable is currently a constant.
 boolean is_missing(VarInfo vi)
          Returns whether the specified variable missing for all values so far.
 boolean is_prev_constant(VarInfo vi)
          returns whether the specified variable is currently a constant OR was a constant at the beginning of constants processing.
 boolean is_prev_missing(VarInfo vi)
          returns whether the specified variable is currently missing OR was missing at the beginning of constants processing.
 void merge()
          Merge dynamic constants from the children of this ppt.
 void post_process()
          Create invariants for any remaining constants.
 void print_missing(PrintWriter out)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dkconfig_OneOf_only

public static boolean dkconfig_OneOf_only
Boolean. If true only create OneOf invariants for variables that are constant for the entire run. If false, all possible invariants are created between constants. Note that setting this to true only fails to create invariants between constants. Invariants between constants and non-constants are created regardless. A problem occurs with merging when this is turned on. If a var_info is constant at one child slice, but not constant at the other child slice, interesting invariants may not be merged because they won't exist on the slice with the constant. This is thus currently defaulted to false.


debug

public static final Logger debug
Debug tracer.

Constructor Detail

DynamicConstants

public DynamicConstants(PptTopLevel ppt)
Create an initial list of constants and missing variables for the specified ppt.

Method Detail

add

public void add(ValueTuple vt,
                int count)
Checks each current constant to see if it is still a constant. Constants must have the same value and cannot be missing. In the long run a better job of dealing with missing might be helpful. Also checks each variable that has always been missing to date to insure that it is still missing. Creates all new views required for the newly non constants (noncons) and the newly non-missing (non_missing)


getConstant

public DynamicConstants.Constant getConstant(VarInfo vi)
Returns the Constant for the specified variable.


is_constant

public boolean is_constant(VarInfo vi)
Returns whether the specified variable is currently a constant.


is_prev_constant

public boolean is_prev_constant(VarInfo vi)
returns whether the specified variable is currently a constant OR was a constant at the beginning of constants processing.


constant_value

public Object constant_value(VarInfo vi)
Returns the constant value of the specified variable, or null if the variable is not constant or prev_constant. But, it is apparently only called on constants with a value.


is_missing

public boolean is_missing(VarInfo vi)
Returns whether the specified variable missing for all values so far.


is_prev_missing

public boolean is_prev_missing(VarInfo vi)
returns whether the specified variable is currently missing OR was missing at the beginning of constants processing.


constant_leader_cnt

public int constant_leader_cnt()
Returns the number of constants that are leaders.


instantiate_new_views

public void instantiate_new_views(List<DynamicConstants.Constant> noncons,
                                  List<DynamicConstants.Constant> non_missing)
Creates all new views required for the newly non constants (noncons) and the newly non-missing (non_missing).


instantiate_constant_suppressions

public void instantiate_constant_suppressions(List<DynamicConstants.Constant> new_noncons,
                                              List<DynamicConstants.Constant> all)

post_process

public void post_process()
Create invariants for any remaining constants. Right now, this looks for invariants between all of the constants. Its not clear that between constants are interesting, but to match previous behavior, this is what we will do for now.


create_constant_invs

public List<PptSlice> create_constant_invs()
Create unary and binary constant invariants. The slices and invariants are created and returned, but not added to the ppt. Note that when NIS.dkconfig_suppressor_list is turned on (default is on), only unary and binary invariants that can be suppressors in NIS suppressions are created.


print_missing

public void print_missing(PrintWriter out)

merge

public void merge()
Merge dynamic constants from the children of this ppt. Only missing is merged since constants are not used after we are done processing samples.


instantiate_oneof

public void instantiate_oneof(DynamicConstants.Constant con)
Creates OneOf invariants for each constant