SandMark version 3.0


sandmark.watermark.util
Class StaticWriteParityMarker

java.lang.Object
  |
  +--sandmark.watermark.util.BasicBlockMarker
        |
        +--sandmark.watermark.util.StaticWriteParityMarker
Direct Known Subclasses:
InsnCountMarker, PutstaticCountMarker

public abstract class StaticWriteParityMarker
extends BasicBlockMarker

This class encodes one-bit values in basic blocks. It does so using parity which can be toggled by inserting one of the following instruction sequences into the basic block:

 getstatic dummyfield
 ineg
 putstatic dummyfield
 
or
 getstatic dummyfield
 iconst_1
 iadd
 putstatic dummyfield
 
where dummyfield is a field added to the program during marking, and is hence not used anywhere by the program. For blocks from instance methods, an instance field is used, so the first and last instructions would be getfield and putfield, respectively.

Note that this approach will only work if getstatic, putstatic, getfield, and putfield instructions do not end basic blocks. Because of that, classed derived from this one should only be used to mark basic blocks from a MethodCFG where the possibility of a thrown exception does not end a basic block.

See Also:
MethodCFG.MethodCFG(de.fub.bytecode.generic.MethodGen, boolean), MethodCFG.MethodCFG(de.fub.bytecode.generic.MethodGen, de.fub.bytecode.generic.ConstantPoolGen, boolean)

Constructor Summary
protected StaticWriteParityMarker(de.fub.bytecode.generic.ClassGen cg, boolean _increment)
          Constructs a new marker which will create a new static field in the given class if necessary.
 
Method Summary
(package private)  boolean capacityIsConstant()
          Returns true if this class returns the same capacity for any basic block, including null.
 void embed(BasicBlock b, de.fub.bytecode.generic.ClassGen cg, java.math.BigInteger value)
          Attempts to encode the given value in the given basic block.
 int getCapacity(BasicBlock b)
          Returns the number of bits that can be encoded into the given basic block.
protected abstract  int getParity(BasicBlock b)
          Returns either 0 or 1, based on what the parity of the given basic block currently is.
(package private) static de.fub.bytecode.generic.MethodGen methodGen(BasicBlock b)
           
 java.util.Iterator recognize(BasicBlock b)
          Returns an Iterator over all values found to be embedded in the given basic block.
 
Methods inherited from class sandmark.watermark.util.BasicBlockMarker
embed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticWriteParityMarker

protected StaticWriteParityMarker(de.fub.bytecode.generic.ClassGen cg,
                                  boolean _increment)
Constructs a new marker which will create a new static field in the given class if necessary. The field is not added until an attempt is made to mark a basic block from a static method. When a basic block from an instance method is marked, an instance field is added to the class the basic block came from instead.

Parameters:
cg - class to create a new dummy static field in
_increment - If this argument is true, each added piece of code will increment a new field by 1. If it is false, each piece will negate the new field. Note that the negating instruction sequence consists of 3 instructions, while the incrementing instruction sequence consists of 4.
Method Detail

getParity

protected abstract int getParity(BasicBlock b)
Returns either 0 or 1, based on what the parity of the given basic block currently is. How exactly that parity is computed is determined by each subclass


embed

public final void embed(BasicBlock b,
                        de.fub.bytecode.generic.ClassGen cg,
                        java.math.BigInteger value)
Attempts to encode the given value in the given basic block. The basic block is modified in place. If the given value is something other than 0 or 1, an IllegalArgumentException will be thrown.

Specified by:
embed in class BasicBlockMarker
Parameters:
b - basic block to encode data in
cg - class the basic block comes from
value - data to encode
Throws:
java.lang.IllegalArgumentException - if value is neither 0 nor 1
See Also:
getCapacity(sandmark.util.controlflowgraph.BasicBlock)

recognize

public final java.util.Iterator recognize(BasicBlock b)
Returns an Iterator over all values found to be embedded in the given basic block. Only values embedded using the marking scheme used by this marker will be reported.

The Iterator will iterate over exactly one value, and that value will be either 0 or 1.

Specified by:
recognize in class BasicBlockMarker
Parameters:
b - basic block to search for a mark in

getCapacity

public final int getCapacity(BasicBlock b)
Returns the number of bits that can be encoded into the given basic block. This method always returns 1.

Specified by:
getCapacity in class BasicBlockMarker
Parameters:
b - basic block to report the bit capacity of
See Also:
embed(sandmark.util.controlflowgraph.BasicBlock, de.fub.bytecode.generic.ClassGen, java.math.BigInteger), BasicBlockMarker.embed(sandmark.util.controlflowgraph.BasicBlock, de.fub.bytecode.generic.ClassGen, long)

capacityIsConstant

final boolean capacityIsConstant()
Returns true if this class returns the same capacity for any basic block, including null. Since the capacity of each basic block under this marker is exactly one bit, this method returns true.

Overrides:
capacityIsConstant in class BasicBlockMarker
See Also:
getCapacity(sandmark.util.controlflowgraph.BasicBlock)

methodGen

static de.fub.bytecode.generic.MethodGen methodGen(BasicBlock b)

SandMark version 3.0

Wed Jan 29 10:30:05 MST 2003