Formalisation d analyses statiques pour Java multithreadé LANDE, (ParSec, Rennes, 09/06/2008) 1 INRIA, LANDE LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 1 / 30
Outline Contexte Analyse statique de bytecode Java séquentiel Objectif e.g : non-null pointer, contrôle de ressources,... interprétation abstraite certification Coq Etendre ces techniques au multithreading LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 2 / 30
Deux activités parallèles Prouver la bonne synchronisation Certification a d une analyse statique (Naik & Aiken, POPL 07). a (définition?) Analyser des programmes bien synchronisés Définition et certification d analyses statiques reposant sur l hypothèse de bonne synchronisation. LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 3 / 30
Outline 1 Naik & Aiken, POPL 07 2 Formalisation 3 Dataraces 4 Conclusion LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 4 / 30
Naik & Aiken, POPL 07 Naik & Aiken, POPL 07 LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 5 / 30
Naik & Aiken, POPL 07 Naik & Aiken, POPL 07 calcul des paires d accès a du programme (au moins une écriture) Elimination, par étapes successives b, de paires non impliquées dans une datarace But du jeu : terminer avec un ensemble de paires vide a points de programme b analyse statique LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 5 / 30
Etapes Naik & Aiken, POPL 07 reachable pairs computation aliasing pairs computation escaping pairs computation may happen in parallel pairs computation unlocked pairs computation LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 6 / 30
Etapes Naik & Aiken, POPL 07 reachable pairs computation aliasing pairs computation escaping pairs computation may happen in parallel pairs computation unlocked pairs computation call graph construction thread escape analysis alias analysis may happen in parallel analysis conditional must not alias analysis LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 7 / 30
Unlocked pairs Naik & Aiken, POPL 07 Exemple thread t thread t sync(a){... x.f.g = ; } sync(a){... x.f.g = ; } case A of LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 8 / 30
Unlocked pairs Naik & Aiken, POPL 07 Exemple thread t thread t sync(a){... x.f.g = ; } sync(a){... x.f.g = ; } case A of ClassId.f, ok(me) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 8 / 30
Unlocked pairs Naik & Aiken, POPL 07 Exemple thread t thread t sync(a){... x.f.g = ; } sync(a){... x.f.g = ; } case A of ClassId.f, ok(me) x.f [x.f ] t = [x.f ] t, ok (ME) [x.f ] t [x.f ] t, ok LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 8 / 30
Unlocked pairs Naik & Aiken, POPL 07 Exemple thread t thread t sync(a){... x.f.g = ; } sync(a){... x.f.g = ; } case A of ClassId.f, ok(me) x.f [x.f ] t = [x.f ] t, ok (ME) [x.f ] t [x.f ] t, ok x [x] t = [x] t, ok(me) [x] t [x] t, ok if [x.f ] t [x.f ] t LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 8 / 30
Unlocked pairs Naik & Aiken, POPL 07 Exemple for (i = 0;i < n; i + +){ array[i] = new C; array[i].f = new D } for (i = 0;i < m; i + +){ y = array[ ]; spawn{sync(y){y.f.val = ; }}} sync sync thread t C array threads t,t D D D D D D D D D access access LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 9 / 30
Naik & Aiken, POPL 07 Unlocked pairs Exemple for (i = 0;i < n; i + +){ array[i] = new C; array[i].f = new D } for (i = 0;i < m; i + +){ y = array[ ]; spawn{sync(y){y.f.val = ; }}} sync sync thread t C array threads t,t D D D D D D D D D access access Conditional must-not aliasing MustNotAlias(x, y) MustNotAlias(x..f, y..f ) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 9 / 30
Naik & Aiken, POPL 07 Disjoint Reachability Disjoint Reachability DR({a 1,...,a n }) = {a (a i=1,2 Reachable(a k i )) k 1 = k 2 } Example sync sync thread t C array threads t,t D D D D D D D D D access access {d 1,...,d n } DR({c 1,...,c n }) c i : C, d i : D LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 10 / 30
Naik & Aiken, POPL 07 Conditionnal must-not aliasing sync(x){...x..f =...} sync(y){...y..f =...} P a (x..f ) P(y..f ) DR # (P(x) P(y)) a Points-to analysis LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 11 / 30
Calcul de DR # Naik & Aiken, POPL 07 Problème Distinguer les objets alloués au même site LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 12 / 30
Calcul de DR # Naik & Aiken, POPL 07 Problème Distinguer les objets alloués au même site C array D D D D D D D D D LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 12 / 30
Calcul de DR # Naik & Aiken, POPL 07 Solution Ajouter des compteurs pour distinguer les objets alloués au même site (sémantique dynamique). Garantir que deux objets sont crées à la même itération (sémantique statique). 1 2 n k k D D D D D D D D D 1 2 n C array LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 13 / 30
Naik & Aiken, POPL 07 Dans le papier Langage while, pas de concurrence/procedure Preuve de la correction de la disjoint reachability Pas de formalisation du lien avec les dataraces Nous sous-ensemble du bytecode Java Procédures et Multithreading Preuve de la correction de la disjoint reachability Application aux dataraces LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 14 / 30
Formalisation Formalisation LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 15 / 30
Formalisation Formalisation Classes ClassId {cid,...} Field {f, g, h,...} MethodId {mid,...} Var {x, y, z,...} Type = ClassId {void} C { name ClassId; fields Field; methods M} M { name MethodId; param ClassId n ; rtype Type; body N inst} LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 15 / 30
Langage Formalisation Instructions inst ::= aconstnull new cid aload x astore x getfield f putfield f invokevirtual mid : (ptype)rtype if (cond) l goto l monitorenter monitorexit start LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 16 / 30
Formalisation Sémantique Compteurs p ::= m, i, c, ω, π (code pointer) appels de méthode/contexte arcs de flux de contrôle ω : M C N π : M C N 2 N O o ::= (a, p) (address) cs ::= (p, s, ρ) :: cs ε (call stack) s O stack ρ Var O Etats : st ::= L, σ, µ, ω L = {(cs, o),..., } σ : O F O µ : O {free} (O N ) ω : compteur global LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 17 / 30
Formalisation Sémantique Fonctionnement des compteurs Allocation ( m, i, c, ω, π, s, ρ) ( m, i + 1, c, ω, π[(m, c, i, i + 1) + +], o :: s, ρ) o = (a, m, i, c, ω, π ) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 18 / 30
Formalisation Sémantique Fonctionnement des compteurs Allocation ( m, i, c, ω, π, s, ρ) ( m, i + 1, c, ω, π[(m, c, i, i + 1) + +], o :: s, ρ) o = (a, m, i, c, ω, π ) Appel de méthode (m, c m, c ) ( m, i, c, ω, π, s, ρ). ( m, 0, c, ω, π ) ( m, i + 1, c, ω, π[(m, c, i, i + 1) + +], s, ρ). ω global ω global [(m, c ) + +] ω = ω[m, c ω global (m, c )] π = π[m, c,, 0] LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 18 / 30
Sémantique Formalisation Boucles while 1 ( ){ x = new h1 O; y = new h2 O; x.f = y; } LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 19 / 30
Sémantique Formalisation Boucles while 1 ( ){ x = new h1 O; y = new h2 O; x.f = y; } L : M N N 2 + Condition wf LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 19 / 30
Sémantique Formalisation Boucles while 1 ( ){ x = new h1 O; y = new h2 O; x.f = y; } L : M N N 2 + Condition wf Propriété d unicité (a i, m, i, c, ω i, π i ) dom(σ), i = 1, 2 ω 1 (m, c) = ω 2 (m, c) a 1 = a 2 π 1 (m, c, L(m, i)) = π 2 (m, c, L(m, i)) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 19 / 30
Analyse Formalisation Abstraction (a, m, i, c, ω, π ) : τ = m, i, c, Ω, Π T Ω : M C N Π : M C N 2 N N = {1, } LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 20 / 30
Analyse Formalisation Flow insensitive : Σ Σ T Field T Flow sensitive : M, A M : M C (P(T n ), P(T) {void}) A : ppt P(T) stack (var P(T)) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 21 / 30
Analyse Formalisation Contraintes (1) ( m.body(i) = putfield f A(m, i, c) = φ 2 :: φ 1 :: S, Γ ) {(τ 1, f, τ 2 ) τ i φ i } Σ (2) A(m, 0, c) = kill m,c (A(m, 0, c)) (3) CFlow(m, i, j) kill m,c,i,j ([m.body(i)] # m,i,c (A(m, i, c))) A(m, j, c) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 22 / 30
Analyse Formalisation Fonctions de transfert [new C] # m,i,c (S, Γ) = φ :: S, Γ φ = { m, i, c, λ.1, λ.1 } [getfield f ] # m,i,c (φ :: S, Γ) = φ :: S, Γ φ = { m, i, c, ω, π (τ, f, m, i, c,, ) Σ, τ φ} LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 23 / 30
Analyse Formalisation Disjoint Reachability (m,i,c) DR σ (A) (o i,o) Reach + (σ), i = 1,2 o.cp = (m,i,c) o 1.cp, o 2.cp A o 1 = o 2 (m,i,c) DR Σ (A) (τ 1,τ 3 ) Σ + (τ 2,τ 4 ) Σ + τ 3.cp = (m,i,c) τ 4.cp = (m,i,c) τ 1.cp, τ 2.cp A τ 1 = τ 2 τ 1.cp = (m,i,c ) τ 1.Ω(m,c ) = τ 1.Π(m,c, L(m,i )) = 1 τ 3.Ω(m,c ) = τ 3.Π(m,c, L(m,i )) = 1 τ 4.Ω(m,c ) = τ 4.Π(m,c, L(m,i )) = 1 Correction σ accessible (m, i, c) DR σ (A) (m, i, c) DR Σ (A) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 24 / 30
Analyse Formalisation Example while 1 ( ){ x = new h1 O; x (h 1,, ), y (h 2,, ) while 2 ( ){ y = new h2 O; x (h 1, 1, ), y (h 2,, ) x.f = y; x (h 1, 1, ), y (h 2, 1, 1 ) } } (h 1, 1, ) (h 2, 1, 1 ) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 25 / 30
Analyse Formalisation Exemple m 1 (){ x = new h1 O; x... n(x); x (h 1, 1, 1, 1 ) } ( ) n 2 (x){ y = new h2 O; x (h 1, 1,, 1 ), y... setfield(x, y); x (h 1, 1,, 1 ), y (h 2, 1, 1, 1 ) } ( ) setfield 3 (x, y){ x.f = y; x (h 1, 1,, ), y (h 2, 1, 1, ) } (h 1, 1,, ) (h 2, 1, 1, ) ( ) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 26 / 30
Dataraces Dataraces LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 27 / 30
Dataraces Dataraces Actions / Exécutions e = (a, R, a ) R {? f,! f, ր,, } e E = st 0 e 0 1 e n 1 st1... e n Conflit R {?,!} a?a a Ra sym. Datarace DRF(E) i < j {0, 1,...,n 1}. e i e j e i hb e j LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 27 / 30
Dataraces Sémantique happens-before i j e i = ara e j = ara e i 0 hb e j i j e i = aր a e j = a Ra e i 0 hb e j i j e i = a a e j = a a e i 0 hb e j hb : clotûre transitive de 0 hb N.B. : Notion de race mieux adaptée que le choix non déterministe. LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 28 / 30
Dataraces Dataraces Elimination F Σ (R) = R {(B 1, B 2 ) P(B 1 ) P(B 2 ) DR Σ (P(A 1 ) P(A 2 ))} sync(a i ){...B i...} B i Reachable(A i ) i = 1, 2 LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 29 / 30
Dataraces Dataraces Elimination F Σ (R) = R {(B 1, B 2 ) P(B 1 ) P(B 2 ) DR Σ (P(A 1 ) P(A 2 ))} sync(a i ){...B i...} B i Reachable(A i ) i = 1, 2 Correction Safe(R) Safe(F Σ (R)) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 29 / 30
Pour la suite... Conclusion LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 30 / 30
Conclusion Pour la suite... Activité 1 Certification Coq (en cours) Gérer les autres étapes LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 30 / 30
Conclusion Pour la suite... Activité 1 Certification Coq (en cours) Gérer les autres étapes Activité 2 Cadre d interprétation abstraite pour l analyse de Bytecode Java bien synchronisés (en cours) Null-pointer Points-to Must-alias Polyèdres LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 30 / 30
Conclusion Pour la suite... Activité 1 Certification Coq (en cours) Gérer les autres étapes Activité 2 Cadre d interprétation abstraite pour l analyse de Bytecode Java bien synchronisés (en cours) Null-pointer Points-to Must-alias Polyèdres Application à la gestion des ressources MIDP (Extension du papier ESORICS) LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 30 / 30
Conclusion Pour la suite... Activité 1 Certification Coq (en cours) Gérer les autres étapes Activité 2 Cadre d interprétation abstraite pour l analyse de Bytecode Java bien synchronisés (en cours) Null-pointer Points-to Must-alias Polyèdres Application à la gestion des ressources MIDP (Extension du papier ESORICS) Certification Coq LANDE, (ParSec, Rennes, 09/06/2008) (INRIA, LANDE)Static race detection 30 / 30