Class VolatileMethodSummary

java.lang.Object
com.ibm.wala.ipa.summaries.VolatileMethodSummary

public class VolatileMethodSummary extends Object
Instructions can be added in a non-ascending manner.

The later position of the instruction is determined by it's iindex. Additionally this Summary may be instructed to prune unnecessary instructions.

However don't go berserk with the iindex as this will consume loads of memory.

You can get an ordinary MethodSummary using the getMethodSummary()-Method.

It extends the MethodSummarys capabilities by the functions: * getStatementAt(int) * reserveProgramCounters(int) * allowReserved(boolean)

Since:
2013-09-08
Author:
Tobias Blaschke <code@tobiasblaschke.de>
See Also:
  • Constructor Details

    • VolatileMethodSummary

      public VolatileMethodSummary(MethodSummary summary)
      Parameters:
      summary - a "real" summary methods get added to.
      Throws:
      IllegalArgumentException - if this summary is null or not empty
  • Method Details

    • getStatementAt

      public SSAInstruction getStatementAt(int programCounter)
      Parameters:
      programCounter - the ProgramCounter to retrieve the Instruction from
      Returns:
      The instruction or null if there is none
      Throws:
      IllegalArgumentException - if the ProgramCounter is negative
    • reserveProgramCounters

      public void reserveProgramCounters(int count)
      Reserves an amount of ProgramCounters for later use.

      This method reserves a count of ProgramCounters and thus affects the value returned by getNextProgramCounter. It also marks these ProgramCounters as reserved so you can't use them unless you explicitly allow it by allowReserved(boolean).

      Parameters:
      count - The amount of ProgramCounters to reserve ongoing from the current ProgramCounter
      Throws:
      IllegalArgumentException - if the count is negative (a count of zero is however ok)
    • allowReserved

      public boolean allowReserved(boolean enable)
      (Dis-)allows the usage of reserved ProgramCounters.

      The setting of this function defaults to disallow upon class creation

      Parameters:
      enable - A value of true allows the usage of all reserved ProgramCounters
      Returns:
      the previous value of allowReserved
    • isReserved

      public boolean isReserved(int programCounter)
      Returns if the ProgramCounter is reserved.
      Parameters:
      programCounter - the ProgramCounter in question
      Returns:
      true if the position is reserved
      Throws:
      IllegalArgumentException - if the ProgramCounter is negative
    • isFree

      public boolean isFree(int programCounter)
      Returns if the ProgramCounter is writable.

      The ProgramCounter is not writable if there is already an instruction located at that ProgramCounter or if the reserved ProgramCounters forbid usage. Thus the answer may depend on the setting of allowReserved(boolean).

      Parameters:
      programCounter - the ProgramCounter in question
      Returns:
      true if you may write to the location
      Throws:
      IllegalArgumentException - if the ProgramCounter is negative
    • isUsed

      public boolean isUsed(int programCounter)
      Not exactly dual to isFree(int).

      Returns whether an instruction is located at ProgramCounter. Thus it is a shortcut to getStatementAt(int) != null.

      It is not the exact dual to isFree(int) as it does not consider reserved ProgramCounters.

      Parameters:
      programCounter - the ProgramCounter in question
      Returns:
      true if there's an instruction at that program counter
      Throws:
      IllegalArgumentException - if the ProgramCounter is negative
    • overwriteStatement

      public boolean overwriteStatement(SSAInstruction statement)
      Like addStatement(SSAInstruction) but may replace an existing one.
      Parameters:
      statement - The statement to add without care of overwriting
      Returns:
      true if a statement has actually been overwritten
      Throws:
      IllegalStateException - if you may not write to the ProgramCounter due to the setting of allowReserved(boolean) or getMethodSummary() has been called and thus this summary got locked.
      NullPointerException - if statement is null
      IllegalArgumentException - if the statement has set an invalid ProgramCounter
    • getMethodSummary

      public MethodSummary getMethodSummary()
      Generates the MethodSummary and locks class.
      Returns:
      the finished MethodSummary
      Throws:
      IllegalStateException - if you altered the referenced (by constructor) summary
    • addStatement

      public void addStatement(SSAInstruction statement)
      Adds a statement to the MethodSummary.
      Parameters:
      statement - The statement to be added
      Throws:
      IllegalStateException - if you may not write to the ProgramCounter due to the setting of allowReserved(boolean) or getMethodSummary() has been called and thus this summary got locked.
      NullPointerException - if statement is null
      IllegalArgumentException - if the statement has set an invalid ProgramCounter or if there is already a statement at the statements iindex. In this case you can use overwriteStatement(SSAInstruction).
    • setLocalName

      public void setLocalName(int number, String name)
      Optionally add a name for a local variable.
    • setLocalNames

      public void setLocalNames(Map<Integer,Atom> merge)
      Set localNames merges with existing names.

      If a key in merge exists the value is overwritten if not the value is kept (it's a putAll on the internal map).

    • getLocalNames

      public Map<Integer,Atom> getLocalNames()
      A mapping from SSA-Values to Variable-names.
    • addConstant

      public void addConstant(Integer vn, ConstantValue value)
      Assigns a new Constant to a SSA-Value.
      Throws:
      IllegalStateException - if you redefine a constant or use the number of an existent SSA-Variable
      IllegalArgumentException - if value is null or negative
    • addPoison

      public void addPoison(String reason)
      Adds posion to the function.

      This call gets passed directly to the internal MethodSummary.

    • getConstants

      public Map<Integer,ConstantValue> getConstants()
      Retrieves a mapping from SSA-Number to a constant.

      You can add Constants using the function addConstant(java.lang.Integer, ConstantValue). A call to this function gets passed directly to the internal MethodSummary.

      Returns:
      a mapping from SSA-Number to assigned ConstantValue
    • getMethod

      public MemberReference getMethod()
      Retrieve the Method this Summary implements.

      You'll get a MemberReference which contains the declaring class (which should be the FakeRootClass in most cases) and the signature of the method.

      This call gets passed directly to the internal MethodSummary.

      Returns:
      the implemented method as stated above
    • getNextProgramCounter

      public int getNextProgramCounter()
      Gets you a non-reserved ProgramCounter you can write to.

      This function returns the next ProgramCounter for which not(isUsed(int)) holds. Thus it will _not_ give you a ProgramCounter which is reserved even if you enabled writing to reserved ProgramCounters using allowReserved(boolean)! You'll have to keep track of them on your own.

      Returns:
      A non-reserved writable ProgramCounter
    • getNumberOfParameters

      public int getNumberOfParameters()
      Get the count of parameters of the Method this Summary implements.

      This call gets passed directly to the internal MethodSummary.

      Returns:
      Number of parameters
    • getParameterType

      public TypeReference getParameterType(int i)
      Gets you the TypeReference of a parameter.

      This call gets passed directly to the internal MethodSummary after some checks.

      Returns:
      the TypeReference of the i-th parameter.
      Throws:
      IllegalArgumentException - if the parameter is zero or negative
      ArrayIndexOutOfBoundsException - if the parameter is to large
    • getPoison

      public String getPoison()
      Retrieves the poison set using addPoison(java.lang.String)
      Returns:
      The poison-String
    • getPoisonLevel

      public byte getPoisonLevel()
      Retrieves the value of Poison-Level.

      This call gets passed directly to the internal MethodSummary.

      Returns:
      the poison level
    • getReturnType

      public TypeReference getReturnType()
      Retrieves the return-type of the Function whose body this Summary implements.

      This call gets passed directly to the internal MethodSummary.

    • getStatements

      public SSAInstruction[] getStatements()
      Get all statements added to the Summary.

      This builds a copy of the internal list and may contain 'null'-values if no instruction has been placed at a particular pc.

      Returns:
      The statements of the summary
    • hasPoison

      public boolean hasPoison()
      Returns if Poison has been added using addPoison(java.lang.String).

      This call gets passed directly to the internal MethodSummary.

      Returns:
      true if poison has been added
    • isFactory

      public boolean isFactory()
      Returns if the implemented method is a factory.

      This call gets passed directly to the internal MethodSummary.

      Returns:
      true if it's a factory
    • isNative

      public boolean isNative()
      Return if the implemented method is a native one (which it shouldn't be).

      This call gets passed directly to the internal MethodSummary.

      Returns:
      almost always false
    • isStatic

      public boolean isStatic()
      Return if the implemented method is static.

      A static method may not access non-static (and thus instance-specific) content.

      Returns:
      true if the method is static.
    • setFactory

      public void setFactory(boolean b)
      Set the value returned by isFactory()
      Throws:
      IllegalStateException - if summary was locked
    • setPoisonLevel

      public void setPoisonLevel(byte b)
      Set the value returned by getPoisonLevel()
      Throws:
      IllegalStateException - if summary was locked
    • setStatic

      public void setStatic(boolean b)
      Set the value returned by isStatic()
      Throws:
      IllegalStateException - if summary was locked
    • toString

      public String toString()
      Generates a String-Representation of an instance of the class.
      Overrides:
      toString in class Object