Download presentation
Presentation is loading. Please wait.
Published byJoy Elliott Modified over 8 years ago
1
Using Datalog for deadlock detection Mentor: Yannis Smaragdakis Oleg Nabiullin (oleg.nabiullin@gmail.com)oleg.nabiullin@gmail.com Sergey Fedorov (sergey.y.fedorov@gmail.com)sergey.y.fedorov@gmail.com Victor Samun (victor.samun@gmail.com)victor.samun@gmail.com Alexander Panin (ag.panin@gmail.com)ag.panin@gmail.com Summer School in Software Engineering and Verification 2011 Moscow, 2011
2
Project goals Goal: investigate possible ways to use Datalog in deadlock detection problem Motivation: Learn Datalog Get experience in deadlock detection algorithms
3
Language Rationale: Simple JS-like language with minimal syntax required s := if then else s := while do s := s := ; s := start_thread ( ) ; s := lock ( ) ; s := unlock ( ) ; e := ( ); # function call
4
Deadlock example & detection f1 = function () { lock (a); lock (b); z = 10; unlock (b); unlock (a); } f2 = function () { lock (b); lock (a); z = 20; unlock (a); unlock (b); } start_thread (f1); start_thread (f2); Detection algorithm: searching circles in data-flow graph
5
Technology Language Abstract Syntax Tree Datalog facts Analysis results Parser Flow-graph analysis Datalog reasoner
6
Algorithm Premise: – Track each individual thread in presence of ‘while’ loop is non-trivial Idea: – Treat each function (including ‘main’) as potentially callable from different threads – Each branch should only be tested against incorrect lock sequences
7
Contexts Contexts partially ordered by inheritance.
8
Example (code)
9
Screenshot
10
Example (facts) Lock('id1', 'va'). Lock('id2', 'vb'). IntConst('id3', '7', 'v1'). AssignVariable('id4', 'v1', 't'). Unlock('id5', 'vb'). Unlock('id6', 'va'). Lock('id9', 'vb'). Lock('id10', 'va'). IntConst('id11', '8', 'v3'). AssignVariable('id12', 'v3', 't'). Unlock('id13', 'va'). Unlock('id14', 'vb'). FunctionLiteral('id7', 'v2'). AssignVariable('id8', 'v2', 'x'). FunctionLiteral('id15', 'v4'). AssignVariable('id16', 'v4', 'y'). StartThread('id17', 'vx'). StartThread('id18', 'vy'). Successor('id7', 'id8'). Successor('id8', 'id15'). Successor('id15', 'id16'). Successor('id16', 'id17'). Successor('id17', 'id18'). Successor('id1', 'id2'). Successor('id2', 'id3'). Successor('id3', 'id4'). Successor('id4', 'id5'). Successor('id5', 'id6'). Successor('id9', 'id10'). Successor('id10', 'id11'). Successor('id11', 'id12'). Successor('id12', 'id13'). Successor('id13', 'id14'). Successor('id7', 'id8'). Successor('id8', 'id15'). Successor('id15', 'id16'). Successor('id16', 'id17'). Successor('id17', 'id18').
11
Datalog rules AnySuccessor(?id1,?id2) :- Successor(?id1,?id2). AnySuccessor(?id1,?id2) :- Successor(?id1,?id3),AnySuccessor(?id3,?id2). UnlockedBefore(?l1,?l2) :- Unlock(?u,?l1),AnySuccessor(?u,?l2). LockFlow(?l1, ?l2) :- AnySuccessor(?l1,?l2),!UnlockedBefore(?l1,?l2). Deadlock(?l12,?l22) :- LockFlow(?l11, ?l12),LockFlow(?l21, ?l22), Lock(?l11, ?n11),Lock(?l12, ?n12),Lock(?l21, ?n21),Lock(?l22, ?n22), ?n11=?n22,?n12=?n21. ?-Deadlock(?x,?y).
12
Example 1 (with deadlock) x = function() { lock(a); lock(b); t = 7; unlock(b); unlock(a); }; y = function() { lock(b); lock(a); t = 8; unlock(a); unlock(b); }; start_thread(x); start_thread(y); Query: ?- Deadlock(?x, ?y). ==>> 2 rows in 1ms Variables: ?x, ?y ('id2', 'id10') ('id10', 'id2')
13
Example 2 (w/o deadlock) x = function() { lock(a); lock(b); t = 7; unlock(b); unlock(a); }; y = function() { lock(a); lock(b); t = 8; unlock(b); unlock(a); }; start_thread(x); start_thread(y); Query: ?- Deadlock(?x, ?y). ==>> 0 rows in 1ms Variables: ?x, ?y
14
Project discussion Pro: +Clear sample of Datalog application +Complete toolchain Contra: –False positives –Oversimplified solution
15
To be done… Fixing suggestions – Include lines of source code as Datalog facts – Include possible suggestion templates as fixed set of facts – Match them using special rules for deadlock found
16
Thank you! Questions?
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.