Cosmin Radoi - WALAFacade support for Scala

WALAFacade
façade for using WALA from Scala
Cosmin Rădoi
cosmin.radoi.net
github.com/cos
WoW
13 June 2015
1 / 11
features
1. Richer API for many WALA types
I
e.g., P(cgNode, ssaValue).puts returns all
instructions writing to the LocalPointerKey defined by
cgNode and ssaValue
I
I
I
I
short aliases, e.g., PutI instead of SSAPutInstruction
implicit conversion between regular and Rich∗ types
implicit piggybacking of necessary data
better type safety by wrapping primitives in value classes
2. Alternate way to configure a pointer analysis
I
I
provided by extending FlexibleCallGraphBuilder
uses typesafe/config for configuration
2 / 11
design principles
1. keep the facade API close to the original API
I
I
WALA classes have an associated Rich∗ class
very few truly new classes
2. favor usability, but keep performance in mind
I
uses Scala value classes so performance impact is minimal
3 / 11
short type aliases
type
N = CGNode
P = PointerKey
t y p e LocalP = LocalPointerKey
t y p e O = InstanceKey
type
type
type
I = SSAInstruction
PutI = SSAPutInstruction
C = IClass
M = IMethod
t y p e F = IField
type
type
listed in edu.illinois.wala.TypeAliases
4 / 11
Richer interface for standard WALA classes
E.g., common problem: find field writes/puts to a variable
// t h i s c o d e
uses = cgNode.getDU().getUses(ssaValue);
writes =
for (i <- uses if i.isInstanceOf[PutI] and
V(i.asInstanceOf[PutI].getRef()) == v)
y i e l d i.asInstanceOf[SSAPutInstruction]
val
val
// b e c o m e s
P(cgNode, ssaValue).puts
How:
I
P constructs a pointer key based on various data
I
LocalPointerKey, aliased as LocalP, has an
associated RichLocalP
I
RichLocalP has methods returning commonly-useful
data, e.g., puts
5 / 11
implicit conversions and piggybacking
I
implicit conversion. E.g.,:
I
I
LocalP, i.e., LocalPointerKey, becomes a
RichLocalP when calling method puts on it.
Necessary data as implicit parameters. E.g.,:
I
I
def
SSAPutInstruction has a method f returning the put
field.
can simply invoke putInstruction.f when an
IClassHierarchy is implicitly in context
f(implicit cha: IClassHierarchy) =
cha.resolveField(i.getDeclaredField())
6 / 11
easy pointer analysis configuration
pa = new FlexibleCallGraphBuilder() {
override def cs =
new nCFAContextSelector(2,
new ContextInsensitiveSelector());
val
}
7 / 11
configuring PA using typesafe/config
wala {
jre-lib-path = "/Library/Java/.../rt.jar"
dependencies.binary + = "./classes"
dependencies.jar + = "andthis.jar"
exclusions + = ".*IgnoreAlsoThisPattern.*"
entry {
signature-pattern = ".*Foo.*main.*"
}
}
8 / 11
finds in all the code reachable from methods named bar all
written fields and the names of the variables written to each
i m p l i c i t val c o n f i g = C o n f i g F a c t o r y . l o a d ( )
val pa = new F l e x i b l e C a l l G r a p h B u i l d e r ( ) {
o v e r r i d e def cs = new nCFAContextSelector ( 2 ,
new C o n t e x t I n s e n s i t i v e S e l e c t o r ( ) ) ;
} ; i m p o r t pa .
val s t a r t N o d e s = cg f i l t e r { n : N => n .m. name == ” bar ” }
val reachableNodes = DFS . getReachableNodes ( cg , s t a r t N o d e s )
reachableNodes f l a t M a p { n =>
n. instructions collect {
case i : P u t I =>
val p : LocalP = P( n , i . v )
val variableNames : I t e r a b l e [ S t r i n g ] = p . variableNames ( )
val fieldName : F = i . f . g e t
( fieldName , variableNames )
}
}
9 / 11
finds in all the code reachable from methods named bar all
written fields and the names of the variables written to each
i m p l i c i t val c o n f i g = C o n f i g F a c t o r y . l o a d ( )
val pa = new F l e x i b l e C a l l G r a p h B u i l d e r ( ) {
o v e r r i d e def cs = new nCFAContextSelector ( 2 ,
new C o n t e x t I n s e n s i t i v e S e l e c t o r ( ) ) ;
}
i m p o r t pa .
DFS . getReachableNodes ( cg , cg f i l t e r { .m. name == ” bar ” } )
. f l a t M a p { n =>
n . i n s t r u c t i o n s c o l l e c t { case i : P u t I =>
( i . f . get , P ( n , i . v ) . variableNames ( ) )
}
}
10 / 11
getting WALAFacade
github.com/cos/WALAFacade
libraryDependencies +=
"edu.illinois.wala" %% "walafacade" % "0.1.2"
also pulls in com.ibm.wala.shrike, .util, and .core
11 / 11