Class FastHierarchy
- java.lang.Object
-
- soot.FastHierarchy
-
public class FastHierarchy extends Object
Represents the class hierarchy. It is closely linked to a Scene, and must be recreated if the Scene changes.This version supercedes the old soot.Hierarchy class.
- Author:
- Ondrej Lhotak, Manuel Benz 22.10.19 - Fixed concrete/abstract dispatch methods to car for default interface methods and account for overwritten return types
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFastHierarchy.Interval
-
Field Summary
Fields Modifier and Type Field Description protected RefTypecilArrayprotected RefTypecilIcomparableprotected RefTypecilIcomparable1protected RefTypecilIconvertibleprotected RefTypecilIequatable1protected RefTypecilIformattableprotected Map<SootClass,FastHierarchy.Interval>classToIntervalFor each class (NOT interface), this map contains a Interval, which is a pair of numbers giving a preorder and postorder ordering of classes in the inheritance tree.protected MultiMap<SootClass,SootClass>classToSubclassesThis map holds all key,value pairs such that value.getSuperclass() == key.protected MultiMap<SootClass,SootClass>interfaceToAllImplementersThis map gives, for an interface, all concrete classes that implement that interface and all its subinterfaces, but NOT their subclasses.protected MultiMap<SootClass,SootClass>interfaceToAllSubinterfacesThis map is a transitive closure of interfaceToSubinterfaces, and each set contains its superinterface itself.protected MultiMap<SootClass,SootClass>interfaceToImplementersThis map holds all key,value pairs such that value is a class (NOT an interface) and key is in value.getInterfaces().protected MultiMap<SootClass,SootClass>interfaceToSubinterfacesThis map holds all key,value pairs such that value is an interface and key is in value.getInterfaces().protected RefTypertCloneableprotected RefTypertObjectprotected RefTypertSerializableprotected Scenescprotected com.google.common.collect.Table<SootClass,NumberedString,SootMethod>typeToVtblprotected static intUSE_INTERVALS_BOUNDARY
-
Constructor Summary
Constructors Constructor Description FastHierarchy()Constructs a hierarchy from the current scene.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildInverseMaps()booleancanStoreClass(SootClass child, SootClass parent)Given an object of declared type child, returns true if the object can be stored in a variable of type parent.protected booleancanStoreClassClassic(SootClass child, SootClass parent)"Classic" implementation using the intuitive approach (without usingFastHierarchy.Interval) to check whetherchildcan be stored in a type ofparent:booleancanStoreType(Type child, Type parent)Given an object of declared type child, returns true if the object can be stored in a variable of type parent.Iterable<Type>canStoreTypeList(Type nt)Returns a list of types which can be used to store the given typeprotected intdfsVisit(int start, SootClass c)Set<SootClass>getAllImplementersOfInterface(SootClass parent)For an interface parent (MUST be an interface), returns set of all implementers of it but NOT their subclasses.Set<SootClass>getAllSubinterfaces(SootClass parent)For an interface parent (MUST be an interface), returns set of all subinterfaces includingparent.Collection<SootClass>getSubclassesOf(SootClass c)Gets the direct subclasses of a given class.protected booleanisHandleDefaultMethods()booleanisSubclass(SootClass child, SootClass parent)Return true if class child is a subclass of class parent, neither of them being allowed to be interfaces.Set<SootMethod>resolveAbstractDispatch(SootClass baseType, SootMethod m)Given an object of declared type C, returns the methods which could be called on an o.f() invocation.Set<SootMethod>resolveAbstractDispatch(SootClass baseType, SootMethodRef m)Given an object of declared type C, returns the methods which could be called on an o.f() invocation.Collection<SootMethod>resolveConcreteDispatch(Collection<Type> concreteTypes, SootMethod m, RefType declaredTypeOfBase)SootMethodresolveConcreteDispatch(SootClass baseType, SootMethod m)Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.SootMethodresolveConcreteDispatch(SootClass baseType, SootMethodRef m)Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.Collection<SootMethod>resolveConcreteDispatchWithoutFailing(Collection<Type> concreteTypes, SootMethod m, RefType declaredTypeOfBase)SootMethodresolveMethod(SootClass baseType, SootClass declaringClass, String name, List<Type> parameterTypes, Type returnType, boolean allowAbstract)Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.SootMethodresolveMethod(SootClass baseType, SootClass declaringClass, String name, List<Type> parameterTypes, Type returnType, boolean allowAbstract, NumberedString subsignature)Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.SootMethodresolveMethod(SootClass baseType, SootMethod m, boolean allowAbstract)Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.SootMethodresolveMethod(SootClass baseType, SootMethodRef m, boolean allowAbstract)Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.SootMethodresolveSpecialDispatch(SootMethod callee, SootMethod container)Returns the target for the given SpecialInvokeExpr.
-
-
-
Field Detail
-
USE_INTERVALS_BOUNDARY
protected static final int USE_INTERVALS_BOUNDARY
- See Also:
- Constant Field Values
-
typeToVtbl
protected com.google.common.collect.Table<SootClass,NumberedString,SootMethod> typeToVtbl
-
classToSubclasses
protected MultiMap<SootClass,SootClass> classToSubclasses
This map holds all key,value pairs such that value.getSuperclass() == key. This is one of the three maps that hold the inverse of the relationships given by the getSuperclass and getInterfaces methods of SootClass.
-
interfaceToSubinterfaces
protected MultiMap<SootClass,SootClass> interfaceToSubinterfaces
This map holds all key,value pairs such that value is an interface and key is in value.getInterfaces(). This is one of the three maps that hold the inverse of the relationships given by the getSuperclass and getInterfaces methods of SootClass.
-
interfaceToImplementers
protected MultiMap<SootClass,SootClass> interfaceToImplementers
This map holds all key,value pairs such that value is a class (NOT an interface) and key is in value.getInterfaces(). This is one of the three maps that hold the inverse of the relationships given by the getSuperclass and getInterfaces methods of SootClass.
-
interfaceToAllSubinterfaces
protected MultiMap<SootClass,SootClass> interfaceToAllSubinterfaces
This map is a transitive closure of interfaceToSubinterfaces, and each set contains its superinterface itself.
-
interfaceToAllImplementers
protected MultiMap<SootClass,SootClass> interfaceToAllImplementers
This map gives, for an interface, all concrete classes that implement that interface and all its subinterfaces, but NOT their subclasses.
-
classToInterval
protected Map<SootClass,FastHierarchy.Interval> classToInterval
For each class (NOT interface), this map contains a Interval, which is a pair of numbers giving a preorder and postorder ordering of classes in the inheritance tree.
-
sc
protected final Scene sc
-
rtObject
protected final RefType rtObject
-
rtSerializable
protected final RefType rtSerializable
-
rtCloneable
protected final RefType rtCloneable
-
cilArray
protected final RefType cilArray
-
cilIcomparable1
protected final RefType cilIcomparable1
-
cilIcomparable
protected final RefType cilIcomparable
-
cilIconvertible
protected final RefType cilIconvertible
-
cilIequatable1
protected final RefType cilIequatable1
-
cilIformattable
protected final RefType cilIformattable
-
-
Method Detail
-
dfsVisit
protected int dfsVisit(int start, SootClass c)
-
buildInverseMaps
protected void buildInverseMaps()
-
isSubclass
public boolean isSubclass(SootClass child, SootClass parent)
Return true if class child is a subclass of class parent, neither of them being allowed to be interfaces. If we don't know any of the classes, we always return false
-
getAllImplementersOfInterface
public Set<SootClass> getAllImplementersOfInterface(SootClass parent)
For an interface parent (MUST be an interface), returns set of all implementers of it but NOT their subclasses.This method can be used concurrently (is thread safe).
- Parameters:
parent- the parent interface.- Returns:
- an set, possibly empty
-
getAllSubinterfaces
public Set<SootClass> getAllSubinterfaces(SootClass parent)
For an interface parent (MUST be an interface), returns set of all subinterfaces includingparent.This method can be used concurrently (is thread safe).
- Parameters:
parent- the parent interface.- Returns:
- an set, possibly empty
-
canStoreType
public boolean canStoreType(Type child, Type parent)
Given an object of declared type child, returns true if the object can be stored in a variable of type parent. If child is an interface that is not a subinterface of parent, this method will return false even though some objects implementing the child interface may also implement the parent interface.
-
canStoreClass
public boolean canStoreClass(SootClass child, SootClass parent)
Given an object of declared type child, returns true if the object can be stored in a variable of type parent. If child is an interface that is not a subinterface of parent, this method will return false even though some objects implementing the child interface may also implement the parent interface.
-
canStoreClassClassic
protected boolean canStoreClassClassic(SootClass child, SootClass parent)
"Classic" implementation using the intuitive approach (without usingFastHierarchy.Interval) to check whetherchildcan be stored in a type ofparent:If
parentis not an interface we simply traverse and check the super-classes ofchild.If
parentis an interface we traverse the super-classes ofchildand check each interface implemented by this class. Also each interface is checked recursively for super interfaces it implements.This implementation can be much faster (compared to the interval based implementation of
canStoreClass(SootClass, SootClass)in cases where one interface is implemented in thousands of classes.- Parameters:
child-parent-- Returns:
-
resolveConcreteDispatchWithoutFailing
public Collection<SootMethod> resolveConcreteDispatchWithoutFailing(Collection<Type> concreteTypes, SootMethod m, RefType declaredTypeOfBase)
-
resolveConcreteDispatch
public Collection<SootMethod> resolveConcreteDispatch(Collection<Type> concreteTypes, SootMethod m, RefType declaredTypeOfBase)
-
resolveAbstractDispatch
public Set<SootMethod> resolveAbstractDispatch(SootClass baseType, SootMethod m)
Given an object of declared type C, returns the methods which could be called on an o.f() invocation.- Parameters:
baseType- The declared type C
-
resolveAbstractDispatch
public Set<SootMethod> resolveAbstractDispatch(SootClass baseType, SootMethodRef m)
Given an object of declared type C, returns the methods which could be called on an o.f() invocation.- Parameters:
baseType- The declared type C
-
resolveConcreteDispatch
public SootMethod resolveConcreteDispatch(SootClass baseType, SootMethod m)
Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.- Parameters:
baseType- The actual type C
-
resolveConcreteDispatch
public SootMethod resolveConcreteDispatch(SootClass baseType, SootMethodRef m)
Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.- Parameters:
baseType- The actual type C
-
resolveMethod
public SootMethod resolveMethod(SootClass baseType, SootMethod m, boolean allowAbstract)
Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.If abstract methods are allowed, it will just resolve to the first method found according to javas method resolution process: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.3
- Parameters:
baseType- The type Cm- The method f to resolve- Returns:
- The concrete method o.f() to call
-
resolveMethod
public SootMethod resolveMethod(SootClass baseType, SootMethodRef m, boolean allowAbstract)
Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.If abstract methods are allowed, it will just resolve to the first method found according to javas method resolution process: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.3
- Parameters:
baseType- The type Cm- The method f to resolve- Returns:
- The concrete method o.f() to call
-
resolveMethod
public SootMethod resolveMethod(SootClass baseType, SootClass declaringClass, String name, List<Type> parameterTypes, Type returnType, boolean allowAbstract)
Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.If abstract methods are allowed, it will just resolve to the first method found according to javas method resolution process: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.3
- Parameters:
baseType- The type CdeclaringClass- declaring class of the method to resolvename- Name of the method to resolve- Returns:
- The concrete method o.f() to call
-
resolveMethod
public SootMethod resolveMethod(SootClass baseType, SootClass declaringClass, String name, List<Type> parameterTypes, Type returnType, boolean allowAbstract, NumberedString subsignature)
Conducts the actual dispatch by searching up the baseType's superclass hierarchy and interface hierarchy if the sourcecode level is beyond Java 7 (due to default interface methods.) Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation.If abstract methods are allowed, it will just resolve to the first method found according to javas method resolution process: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.3
- Parameters:
baseType- The type CdeclaringClass- declaring class of the method to resolvename- Name of the method to resolvesubsignature- The subsignature (can be null) to speed up the resolving process.- Returns:
- The concrete method o.f() to call
-
isHandleDefaultMethods
protected boolean isHandleDefaultMethods()
-
resolveSpecialDispatch
public SootMethod resolveSpecialDispatch(SootMethod callee, SootMethod container)
Returns the target for the given SpecialInvokeExpr.
-
getSubclassesOf
public Collection<SootClass> getSubclassesOf(SootClass c)
Gets the direct subclasses of a given class. The class needs to be resolved at least at the HIERARCHY level.- Parameters:
c- the class- Returns:
- a collection (possibly empty) of the direct subclasses
-
-