ebook img

Data races in Java and static analysis PDF

33 Pages·2008·0.41 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Data races in Java and static analysis

Data races in Java and static analysis Fr´ed´eric Dabrowski 1INRIA, LANDE Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 1 / 33 Outline 1 Concurrency in Java 2 Static Detection of dataraces { Flanagan, Abadi & Freund lock-based typing Boyapati, Lee & Rinard Points-to analysis : Naik & Aiken (Points-to analysis + Type and effect system) 3 Conclusion and ongoing work Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 2 / 33 Concurrency in Java Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 3 / 33 Concurrency in Java Concurrency model Thread-based concurrency : shared memory (fields of shared objects) lexically scoped locking construct : synchronized(x){. . .} Preemptive scheduling (Interleaving semantics) Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 4 / 33 Concurrency in Java Interleaving semantics (small step) interleaving semantics sequential semantics ′ ′ ti , Mem →seq t i , Mem t, Mem →seq t′, Mem′ {. . . , t i , . . .}, Mem →inter {. . . , ti′, . . .}, Mem′ Problem : This semantics is incomplete with respect to the Java Memory Model, unless you write well-synchronized programs Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 5 / 33 Concurrency in Java Natural hypothesis : sequential consistency Intuivively, sequential consistency means that all executions respect the program order. void mn(){ a a should not observe b . . . b } Problem : enforcing sequential consistency for all Java programs makes many of the compiler/processor optimizations illegal. Why ? some optimizations assume well-synchronized programs ! Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 6 / 33 Concurrency in Java Example : code reordering (cache mechanisms,...) Original code Optimized code C.f = C.g = 0 C.f = C.g = 0 1 : x = C.g; 3 : y = C.f ; 2 : C .f = 1; 4 : C .g = 1; 2 : C .f = 1; 4 : C .g = 1; 1 : x = C.g; 3 : y = C.f ; {Perm(1, 2, 3, 4) | 1 < 2, 3 < 4} {Perm(1, 2, 3, 4) | 2 < 1, 4 < 3} 1 3 {x=0,y=0} 2 3 4 {x=0,y=1} original 4 1 2 {x=1,y=0} 3 1 {x=0,y=0} 2 4 1 3 {x=1,y=1} optimized Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 7 / 33 Concurrency in Java Admissible behaviors (w.r.t the JMM) Sequential consitency Behaviors captured by the interleaving sem. Java’s memory model is weak memory model All executions of well-synchronized programs are sequentially consistent a. aManson, Pugh & Adve : The Java Memory Model (Special Popl issue) Programs must be well-synchronyzed several static analysis depend on it Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 8 / 33 Concurrency in Java Well-synchronized programs (P1) : For all execution ( w.r.t the interleaving semantics), every conflicting actions a and b are synchronized synchronized(C){ synchronized(C){ (1 : x = C.g); (2 : C .f = 1)} (3 : y = C.f ); (4 : C .g = 1)} lock(C) 1:x=C.g 2:C.f=1 unlock(C) lock(C) 3:y=C.f 4:C.y=1 unlock(C) seq locking seq lock(C) 3:y=C.f 4:C.y=1 unlock(C) lock(C) 1:x=C.g 2:C.f=1 unlock(C) seq seq locking seq seq compiler/jvm/jit : (P1) ⇒ every exec. is captured by the inter. sem. Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 9 / 33 Concurrency in Java Happens-before relation ≺hb is the transitive closure of the following rules : t 1 t sequentiality a ≺ b hb { 1 t t.start() ≺ a hb start/join synchronisation t 1 a ≺ t.join() hb lock-based synchronisation { 1 unlock(m) ≺ lock(m) hb 1 write(x.f ) ≺ read(x.f ) (f volatile) hb Fr´ed´eric Dabrowski (INRIA, LANDE) Static race detection 10 / 33

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.