Package com.ibm.wala.ipa.summaries
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 thegetMethodSummary()
-Method. It extends the MethodSummarys capabilities by the functions: *getStatementAt(int)
*#getStatementsAfter(int)
*reserveProgramCounters(int)
*allowReserved(boolean)
- Since:
- 2013-09-08
- See Also:
com.ibm.wala.dalvik.ssa.AndroidModelInstructionFectory
,DexFakeRootMethod
,MethodSummary
-
-
Constructor Summary
Constructors Constructor Description VolatileMethodSummary(MethodSummary summary)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConstant(Integer vn, ConstantValue value)
Assigns a new Constant to a SSA-Value.void
addPoison(String reason)
Adds posion to the function.void
addStatement(SSAInstruction statement)
Adds a statement to the MethodSummary.boolean
allowReserved(boolean enable)
(Dis-)allows the usage of reserved ProgramCounters.Map<Integer,ConstantValue>
getConstants()
Retrieves a mapping from SSA-Number to a constant.Map<Integer,Atom>
getLocalNames()
A mapping from SSA-Values to Variable-names.MemberReference
getMethod()
Retrieve the Method this Summary implements.MethodSummary
getMethodSummary()
Generates the MethodSummary and locks class.int
getNextProgramCounter()
Gets you a non-reserved ProgramCounter you can write to.int
getNumberOfParameters()
Get the count of parameters of the Method this Summary implements.TypeReference
getParameterType(int i)
Gets you the TypeReference of a parameter.String
getPoison()
Retrieves the poison set usingaddPoison(java.lang.String)
byte
getPoisonLevel()
Retrieves the value of Poison-Level.TypeReference
getReturnType()
Retrieves the return-type of the Function whose body this Summary implements.SSAInstruction
getStatementAt(int programCounter)
SSAInstruction[]
getStatements()
Get all statements added to the Summary.boolean
hasPoison()
Returns if Poison has been added usingaddPoison(java.lang.String)
.boolean
isFactory()
Returns if the implemented method is a factory.boolean
isFree(int programCounter)
Returns if the ProgramCounter is writable.boolean
isNative()
Return if the implemented method is a native one (which it shouldn't be).boolean
isReserved(int programCounter)
Returns if the ProgramCounter is reserved.boolean
isStatic()
Return if the implemented method is static.boolean
isUsed(int programCounter)
Not exactly dual to#isFree(boolean)
.boolean
overwriteStatement(SSAInstruction statement)
Likebut may replace an existing one.
void
reserveProgramCounters(int count)
Reserves an amount of ProgramCounters for later use.void
setFactory(boolean b)
Set the value returned by#getFactory()
void
setLocalName(int number, String name)
Optionally add a name for a local variable.void
setLocalNames(Map<Integer,Atom> merge)
Set localNames merges with existing names.void
setPoisonLevel(byte b)
Set the value returned bygetPoisonLevel()
void
setStatic(boolean b)
Set the value returned by#getStatic()
String
toString()
Generates a String-Representation of an instance of the class.
-
-
-
Constructor Detail
-
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 Detail
-
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 byallowReserved(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 ofallowReserved(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(boolean)
. Returns whether an instruction is located at ProgramCounter. Thus it is a shortcut togetStatementAt(int)
!= null.It is not the exact dual to
#isFree(boolean)
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)
Likebut 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 ofallowReserved(boolean)
orgetMethodSummary()
has been called and thus this summary got locked.NullPointerException
- if statement is nullIllegalArgumentException
- 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 ofallowReserved(boolean)
orgetMethodSummary()
has been called and thus this summary got locked.NullPointerException
- if statement is nullIllegalArgumentException
- 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#overwritetatement(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-VariableIllegalArgumentException
- 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 functionaddConstant(java.lang.Integer,com.ibm.wala.ssa.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(ProgramCounter)
) holds. Thus it will _not_ give you a ProgramCounter which is reserved even if you enabled writing to reserved ProgramCounters usingallowReserved(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 negativeArrayIndexOutOfBoundsException
- if the parameter is to large
-
getPoison
public String getPoison()
Retrieves the poison set usingaddPoison(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 usingaddPoison(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#getFactory()
- Throws:
IllegalStateException
- if summary was locked
-
setPoisonLevel
public void setPoisonLevel(byte b)
Set the value returned bygetPoisonLevel()
- Throws:
IllegalStateException
- if summary was locked
-
setStatic
public void setStatic(boolean b)
Set the value returned by#getStatic()
- Throws:
IllegalStateException
- if summary was locked
-
-