Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Bytecode'13 presentation
1. Field-Sensitive Unreachability and Non-Cyclicity Analysis
Enrico Scapin and Fausto Spoto
Dipartimento di Informatica - University of Verona (Italy)
BYTECODE/ETAPS 2013
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 1 / 15
2. Static Analysis
Static Analysis
Definition
Static analysis consists in building compile-time techniques in order to
prove properties of programs before actually running them.
Shape Analyses try to understand how the program execution
manipulates the heap.
e.g.,
sharing analysis determines if two variables might be bound to
overlapping data structures.
reachability analysis determines if exists a path in memory that links
two variables.
cyclicity analysis determines if a variable is bound to a cyclical data
structure.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 2 / 15
3. State of the Art
State of the Art
Reachability and Cyclicity, state of the art:
Stefano Rossignoli and Fausto Spoto, "Detecting non-cyclicity by abstract compilation into boolean
functions". In: VMCAI’06
Samir Genaim and Damiano Zanardini, "Reachability-based Acyclicity Analysis by Abstract Interpretation".
In: CoRR’12
Ðurica Nikolić and Fausto Spoto, "Reachability Analysis of Program Varibles". In: IJCAR’12
x.next=y; This assignment makes x cyclical if and only
if y reaches x.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 3 / 15
4. State of the Art
State of the Art
Reachability and Cyclicity, state of the art:
Stefano Rossignoli and Fausto Spoto, "Detecting non-cyclicity by abstract compilation into boolean
functions". In: VMCAI’06
Samir Genaim and Damiano Zanardini, "Reachability-based Acyclicity Analysis by Abstract Interpretation".
In: CoRR’12
Ðurica Nikolić and Fausto Spoto, "Reachability Analysis of Program Varibles". In: IJCAR’12
x.next=y; This assignment makes x cyclical if and only
if y reaches x.
We defined a state as σ = ρ, µ , where:
Heap
Environment
l1 ... l2
ρ maps variables
x y
to locations; µ
ρ l1 l2 Element Element
...
µ binds locations value next value next
to objects. tikzpicture
...
tikzpicture
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 3 / 15
5. State of the Art
State of the Art
Reachability and Cyclicity, state of the art:
Stefano Rossignoli and Fausto Spoto, "Detecting non-cyclicity by abstract compilation into boolean
functions". In: VMCAI’06
Samir Genaim and Damiano Zanardini, "Reachability-based Acyclicity Analysis by Abstract Interpretation".
In: CoRR’12
Ðurica Nikolić and Fausto Spoto, "Reachability Analysis of Program Varibles". In: IJCAR’12
x.next=y; This assignment makes x cyclical if and only
if y reaches x.
We defined a state as σ = ρ, µ , where:
Heap
Environment
l1 ... l2
ρ maps variables
x y
to locations; µ
ρ l1 l2 Element Element
...
µ binds locations value next value next
to objects. tikzpicture
...
tikzpicture
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 3 / 15
6. Scenario
Scenario
Given the following Java instructions,
while ( x != null )
x = x . next ;
Does the loop halt?
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 4 / 15
7. Scenario
Scenario
Given the following Java instructions,
while ( x != null )
x = x . next ;
Does the loop halt?
Assuming ρ(x) = l1 before starting the loop.
Heap
l1 l2 l3 l4
o1 o2 o3 tikzpicture o
4 The loop
Element Element Element Element terminates in 3
value next value next value next value next
iterations!
tikzpicture tikzpicture tikzpicture tikzpicture
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 4 / 15
8. Scenario
Scenario
Given the following Java instructions,
while ( x != null )
x = x . next ;
Does the loop halt?
Assuming ρ(x) = l1 before starting the loop.
Heap
l1 l2 l3 l4
o1 o2 o3 tikzpicture o
4
Element Element Element Element
The loop does
value next value next value next value next
not terminate!
tikzpicture tikzpicture tikzpicture tikzpicture
It depends on the cyclicity of variable x.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 4 / 15
9. Properties
Can we refine them?
Yes, by developing a field-sensitive analysis!
while ( x != null ) x .next= y ;
x = x .next;
Goal
For each program point, maintain a set of static fields F such that a
program property holds.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 5 / 15
10. Properties
Can we refine them?
Yes, by developing a field-sensitive analysis!
while ( x != null ) x .next= y ;
x = x .next;
Goal
For each program point, maintain a set of static fields F such that a
program property holds.
We introduce the concept of path P as a tuple of fields linking two
locations inside the heap µ.
Heap
l1 l2 l3 l4
e.g., P
1 µ 4 o1 o2 o3 tikzpicture o
4
Element Element Element Element
with P =
value next value next value next value next
El.next, El.next, El.next
tikzpicture tikzpicture tikzpicture tikzpicture
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 5 / 15
11. Properties
Field-sensitive properties
Let
F: set of all fields;
Lσ (x): set of all locations reachable from x.
Unreachability for each path from x to y in state σ, the fields in F
are not part of that path.
∀P ⊆ F x P y =⇒ P ∩ F = ∅ ≡ x Fy
σ σ
Non-cyclicity for each cycle reachable from x in state σ, the fields
in F are not part of the cycle.
P F
∀ ∈ Lσ (x), ∀P ⊆ F µ ⇒P ∩F =∅ ≡ x σ
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 6 / 15
12. Abstract Interpretation
Abstract Interpretation
In order to make our analysis computable, we use the general framework of
Abstract Interpretation.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 7 / 15
13. Abstract Interpretation
Concrete and Abstract Domains
Σ - set of all states
V - set of all variables
F - set of all program fields
Concrete domain: C = ℘(Σ)
Abstract domain: A = ℘(V × V × ℘(F)) ∪ ℘(V × ℘(F))
Concretization map γ : A → C
F F
∀a b ∈ I , ∃F ⊆ F . a σ b∧F ⊆F ∧
γ(I ∈ A) = σ ∈ Σ
F F
∀c ∈ I , ∃F ⊆ F . c σ ∧F ⊆ F
Our properties are under-approximated by the information in I .
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 8 / 15
14. Methodology
Methodology
1 Program Under Analysis
class Element {
private Object value ;
private Element prec , next ;
public Element ( Object value ){
this . value = value ;
}
public Element ( Object value , Element prec ){
this . value = value ;
this . prec = prec ;
prec . next = this ;
}
}
public class MWexample {
public static void main ( String [] args ){
Element top = new Element ( new Integer (0));
for ( int i =1; i <=3; i ++)
top = new Element ( new Integer ( i ) , top );
}
}
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 9 / 15
15. Methodology
Methodology
2 Java Bytecode
invokespecial #1 < Object / < init >() V >
aload_0
1 Program Under Analysis aload_1
putfield #2 Element . value : Object
aload_0
class Element {
aload_2
private Object value ;
putfield #3 Element . prec : Element
private Element prec , next ;
aload_2
aload_0
public Element ( Object value ){
putfield #4 Element . next : Element
this . value = value ;
return
}
public Element(Object value, Element prec){
this.value=value;
this.prec=prec;
prec.next=this;
}
}
public class MWexample {
public static void main ( String [] args ){
Element top = new Element ( new Integer (0));
for ( int i =1; i <=3; i ++)
top = new Element ( new Integer ( i ) , top );
}
}
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 9 / 15
16. Methodology
Methodology
2 Java Bytecode
invokespecial #1 < Object / < init >() V >
aload_0
1 Program Under Analysis aload_1
putfield #2 Element . value : Object
aload_0
class Element {
aload_2
private Object value ;
putfield #3 Element . prec : Element
private Element prec , next ;
aload_2
aload_0
public Element ( Object value ){
putfield #4 Element . next : Element
this . value = value ;
return
}
public Element(Object value, Element prec){
this.value=value;
this.prec=prec; 3 Control Flow Graph
prec.next=this;
call java.lang.Object. init () : void
}
}
public class MWexample { load 0 Element
load 1 Object
public static void main ( String [] args ){ putfield Element.value : Object
catch
Element top = new Element ( new Integer (0)); throw java.lang.Throwable
for ( int i =1; i <=3; i ++)
load 0 Element
top = new Element ( new Integer ( i ) , top ); load 2 Element
putfield Element.prec : Element
}
}
load 2 Element
load 0 Element
putfield Element.next : Element
return void
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 9 / 15
17. Abstract Constraint Graph
Constraint Based Static Analysis
From the Control Flow Graph we build the Abstract Constraint Graph
3
node 2
n
io
Nodes represent bytecode
pt
ex
call java.lang.Object. init () : void
ce
it
ex
11
node 3
instructions. load 0 Element
3
node 4
Arcs represent the abstract #15 load 1 Object
3
node 5
semantics. 14
putfield Element.value : Object
6
node 6
Each node is decorated with an node 14
catch
load 0 Element
3
node 7
abstract set I . 14 load 2 Element
3
node 8
Each arc is decorated with a putfield Element.prec : Element
6
node 9
propagation rule. 14
load 2 Element
3
node 10
Propagation Rules i load 0 Element
3
node 11
defined for each type of arc, putfield Element.next : Element
6
depending on its sources; node 12
return void
state how the information in
each node is propagated.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 10 / 15
18. Propagation Rules
Propagation Rules
3
node 2
n
io
pt
ex
call java.lang.Object. init () : void
ce
it
Their definitions can became
ex
11
node 3
load 0 Element
complex whenever they exploit node 4
3
#15 load 1 Object
other static analyses. node 5
3
putfield Element.value : Object
The unreachability and 14
node 6
6
node 14 load 0 Element
non-cyclicity information is catch
node 7
3
propagated along the arcs of the 14 load 2 Element
node 8
3
ACG until reaching a fix-point. putfield Element.prec : Element
6
node 9
It exists since they are all 14
load 2 Element
node 10
3
monotonic functions. load 0 Element
3
node 11
putfield Element.next : Element
The fix-point is the maximal 6
node 12
solution of the ACG with respect return void
to the partial order ⊇.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 11 / 15
19. Example: putfield κ.f : t
Example: putfield κ.f : t
ins : Σ → Σ
It changes the paths between locations!
How to correctly propagate the information w.r.t this instruction?
KEY IDEA: exploit the result of the possible reachability analysis.
x, y ∈ MRτ =⇒ x y
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 12 / 15
20. Example: putfield κ.f : t
Example: putfield κ.f : t (cont.)
e.g., field-sensitive unreachability
for each d F w such that d sj−2 ∨ sj−1 w , F does not change
after the putfield node.
for each a F x such that a, sj−2 , sj−1 , x ∈ MRτ , F probably
changes:
for sure, after the putfield, F does not contain the field f!
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 13 / 15
21. Conclusions
Conclusions
1 Build an under-approximated analysis to state two field-sensitive
properties.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 14 / 15
22. Conclusions
Conclusions
1 Build an under-approximated analysis to state two field-sensitive
properties.
2 Exploit the abstract interpretation framework to prove its correctness.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 14 / 15
23. Conclusions
Conclusions
1 Build an under-approximated analysis to state two field-sensitive
properties.
2 Exploit the abstract interpretation framework to prove its correctness.
each propagation rule Π i correctly approximates the set of states
obtained by the correspondent instruction ins i execution:
for each I ∈ A, ins (γ (I )) ⊆ γ (Π (I ))
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 14 / 15
24. Conclusions
Conclusions
1 Build an under-approximated analysis to state two field-sensitive
properties.
2 Exploit the abstract interpretation framework to prove its correctness.
each propagation rule Π i correctly approximates the set of states
obtained by the correspondent instruction ins i execution:
for each I ∈ A, ins (γ (I )) ⊆ γ (Π (I ))
the analysis correctly approximates the semantics of the program with
respect to the two properties defined:
let ⇒∗ ins σ be an execution and Iins the approx information,
σ ∈ γ(Iins )
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 14 / 15
25. Conclusions
Conclusions
1 Build an under-approximated analysis to state two field-sensitive
properties.
2 Exploit the abstract interpretation framework to prove its correctness.
each propagation rule Π i correctly approximates the set of states
obtained by the correspondent instruction ins i execution:
for each I ∈ A, ins (γ (I )) ⊆ γ (Π (I ))
the analysis correctly approximates the semantics of the program with
respect to the two properties defined:
let ⇒∗ ins σ be an execution and Iins the approx information,
σ ∈ γ(Iins )
Future works: implementing this analysis in Julia Tool to improve
the precision of its termination checker.
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 14 / 15
26. Conclusions
Thank You
Thank You!
Scapin and Spoto (univr.it) Unreachability & Non-Cyclicity Analysis BYTECODE’13 15 / 15