SlideShare a Scribd company logo
1 of 91
Model Checking Programs with Java PathFinder Willem Visser < [email_address] > Peter Mehlitz < [email_address] > NASA Ames Research Center
Motivation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Program Model Checking ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],9h00 – 10h30 11h00 – 13h00
What is Java PathFinder (1) ,[object Object],[object Object],[object Object],[object Object],[object Object]
What is JPF (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Key Points ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JPF Status ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Getting and Installing JPF ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How To Run JPF ,[object Object],[object Object],[object Object],[object Object],[object Object]
JPF Configuration
Some Examples ,[object Object],[object Object]
Remote Agent ,[object Object],[object Object],[object Object],[object Object],T1 T2 signal signal notify notify if (no_action) wait(); signal();
K9 Rover ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],commands plans Exec Executive CondChecker Database ActionExec TempChecker
Directory Structure
Under the Hood - Toplevel Structure ,[object Object],[object Object],[object Object]
Under the Hood - Search
Extending JPF - Listeners ,[object Object],[object Object]
Extending JPF - SearchListener public interface SearchListener {   /* got the next state */     void  stateAdvanced  (Search search);   /* state was backtracked one step */   void  stateBacktracked  (Search search);     /* a previously generated state was restored     (can be on a completely different path) */   void  stateRestored  (Search search);     /* JPF encountered a property violation */   void  propertyViolated  (Search search);     /* we get this after we enter the search loop, but BEFORE the first forward */   void  searchStarted  (Search search);     /* there was some contraint hit in the search, we back out could have been turned into a property, but usually is an attribute of the search, not the application */ void  searchConstraintHit  (Search search);     /* we're done, either with or without a preceeding error */   void  searchFinished  (Search search); }
Extending JPF - VMListener public interface VMListener {    void  instructionExecuted  (JVM vm);  // VM has executed next instruction    void  threadStarted  (JVM vm);  / / new Thread entered run() method      void  threadTerminated  (JVM vm);  // Thread exited run() method      void  classLoaded  (JVM vm);  // new class was loaded      void  objectCreated  (JVM vm);  // new object was created      void  objectReleased  (JVM vm);  // object was garbage collected      void  gcBegin  (JVM vm);  // garbage collection mark phase started      void  gcEnd  (JVM vm);  // garbage collection sweep phase terminated      void  exceptionThrown  (JVM vm);  // exception was thrown    void  nextChoice  (JVM vm);  // choice generator returned new value }
Extending JPF - Listener Example public class HeapTracker extends  GenericProperty  implements  VMListener ,  SearchListener  { class PathStat { .. int heapSize = 0; .. }  // helper to store additional state info PathStat stat = new PathStat(); Stack pathStats = new Stack(); public boolean  check  (JVM vm, Object arg) {  // GenericProperty return (stat.heapSize <= maxHeapSizeLimit); } public void  stateAdvanced  (Search search) {  // SearchListener if (search.isNewState()) {.. pathStats.push(stat); stat = (PathStat)stat.clone(); .. } public void  stateBacktracked  (Search search) {  // SearchListener .. if (!pathStats.isEmpty())  stat = (PathStat) pathStats.pop(); }   public void  objectCreated  (JVM vm) {..  // VMListener ElementInfo ei = vm.getLastElementInfo(); ..stat.heapSize += ei.getHeapSize(); .. } public void  objectReleased  (JVM vm) {  // VMListener ElementInfo ei = vm.getLastElementInfo(); ..stat.heapSize -= ei.getHeapSize(); .. } ... }
Extending JPF - Listener Configuration ,[object Object],[object Object],[object Object],[object Object]
Going Native - Model Java Interface ,[object Object],[object Object],[object Object]
MJI - Why? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MJI - Components ,[object Object],[object Object],[object Object]
MJI - How
MJI - Example ,[object Object],[object Object],[object Object],0:  getstatic #2 3:  ldc #3 5:  invokevirtual #4
Scalability - Partial Order Reduction ,[object Object],[object Object],[object Object],[object Object],[object Object]
POR - Scheduling Relevance
POR - Shared Objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Choice Generator Motivation
JPF Perspective State  consists of 2 main components, the state of the JVM and the  current and next choice Generator (i.e. the objects encapsulating the choice enumeration that produces new transitions) Transition  is the sequence of instructions that leads from one state.  There is no context  within a transition, it's all in the same thread.   There can be multiple transitions leading out of one state   Choice  is what starts a new transition. This can be a different thread,  i.e. scheduling choice, or different “random” data value.
Role of Choices In other words, possible existence of Choices is  what terminates the last Transition, and selection  of a Choice value precedes the next Transition.  The first condition corresponds to creating a new  ChoiceGenerator, and letting the SystemState know  about it.  The second condition means to query the next  choice value from this ChoiceGenerator  (either internally within the JVM, or in an  instruction or native method).
Extensions ,[object Object],[object Object],[object Object],Numeric Extension to check for errors such as Overflow Most of this extension was provided by  Aleksandar Milicevic  and  Sasa Misailovic  from UIUC
Regression Tests with JUnit
JUnit Example package gov.nasa.jpf.mc; import org.junit.Test; import org.junit.runner.JUnitCore; import gov.nasa.jpf.jvm.TestJPF; public class TestOldClassicJPF extends TestJPF { static final String TEST_CLASS = &quot;gov.nasa.jpf.mc.oldclassic&quot;; public static void main (String[] args) { JUnitCore.main(&quot;gov.nasa.jpf.mc.TestOldClassicJPF&quot;); } @Test public void testDFSearch () { String[] args = { TEST_CLASS }; runJPFDeadlock(args); } @Test public void testBFSHeuristic () { String[] args = {  &quot;+search.class=gov.nasa.jpf.search.heuristic.HeuristicSearch&quot;, &quot;+search.heuristic.class=gov.nasa.jpf.search.heuristic.BFSHeuristic&quot;,  TEST_CLASS }; runJPFDeadlock(args); } }
TestJPF ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
More Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stoned Hippies Germany Netherlands 5 10 2 1
Stoned Hippies Germany Netherlands 2 5 10 1 2
Stoned Hippies Germany Netherlands 3 5 10 1 2
Stoned Hippies Germany Netherlands 8 10 1 2 5
Stoned Hippies Germany Netherlands 19 1 2 5 10
Symbolic Execution ,[object Object],[object Object],Collaborators Corina Pasareanu Sarfraz Khurshid Saswat Anand
Concrete Execution Path (example) x = 1, y = 0 1 >? 0 x = 1 + 0 = 1 y = 1 – 0 = 1 x = 1 – 1 = 0 0 – 1 >? 0 int x, y; if (x > y) { x = x + y; y = x – y; x = x – y; if (x – y > 0) assert(false); }
Symbolic Execution Tree (example) x = X, y = Y int x, y; if (x > y) { x = x + y; y = x – y; x = x – y; if (x – y > 0) assert(false); } X >? Y [ X > Y ] y = X + Y – Y = X [ X > Y ] x = X + Y – X = Y [ X > Y ] Y - X >? 0 [ X <= Y ] END [ X > Y ] x = X + Y [ X > Y, Y – X <= 0 ] END [ X > Y, Y – X > 0 ]  END
Example class Node { int elem; Node next; Node swapNode() {   if (next != null)   if (elem > next.elem) {   Node t = next;   next = t.next;   t.next = this;   return t;   }   return this; } } ? null E0 E1 E0 E0 E1 null E0 E1 ? E0 E1 E0 E1 Input list  +  Constraint Output list E0 > E1 none E0 <= E1 none E0 > E1 E0 > E1 E0 > E1 E1 E0 ? E1 E0 E1 E0 E1 E0 null E0 E1 E0 ? null NullPointerException
Challenges in Generalizing Symbolic Execution ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generalized Symbolic Execution ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algorithm  (lazy initialization) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algorithm (aliasing) ,[object Object]
Algorithm (illustration) consider executing next = t.next; E0 next E1 next t null t E0 next E1 next ? next E0 next E1 t next E0 next E1 next t E0 next E1 next t Precondition: acyclic list E0 E1 next t null next t E0 E1 next ? next next
Implementation via Instrumentation program instrumentation counterexample(s)/test suite [heap+constraint+thread scheduling] model checking decision procedure instrumented  program correctness specification continue/ backtrack state: original  program path condition (data) heap configuration thread scheduling
Testing with Symbolic Execution ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Red-Black Trees (1) The root is BLACK (2) Red nodes can only  have black children (3) All paths from a node to  its leaves contain the same  number of black nodes.  Self-balancing Binary Search Trees Java  TreeMap  Implementation (4) Acyclic (5) Consistent Parents repOk(): conditions (1)-(5)
repOk() Fragment boolean repOk(Entry e) { // root has no parent, root is black,… // RedHasOnlyBlackChildren workList = new LinkedList(); workList.add(e); while (!workList.isEmpty()) { Entry current=(Entry)workList.removeFirst(); Entry cl = current.left; Entry cr = current.right; if (current.color == RED) { if(cl != null && cl.color == RED)  return false; if(cr != null && cr.color == RED) return false; } if (cl != null) workList.add(cl); if (cr != null) workList.add(cr); } // equal number of black nodes on left and right sub-tree… return true; }
Black-box TIG Symbolic Execution  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Symbolic Execution of repOk() Example public   static   boolean  repOk() { if  (root ==  null ) return   true ; if  (root.color == RED) return  false; … Size 1
White-box TIG Symbolic Execution ,[object Object],[object Object]
repOk() x 2 abstract and concrete Symbolic Execution of Code During Lazy Initialization check  Abstract repOk() When coverage is achieved,  solve the symbolic constraints  to create concrete inputs Concretize inputs  by symbolic execution of  Concrete repOk() over symbolic structures - as with Black-box TIG   - Abstract  repOk() : Symbolic Structure  {true,false,don’t know}   Concrete repOk() : Symbolic Structure  Concrete Structure
Abstract  repOk() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],FALSE TRUE Don’t Know
White-box TIG: cover branches in  deleteEntry(Entry p) /* precondition: p. repOk()  */ private   void   deleteEntry(Entry   p)   { if   (p.left   !=   null   &&   p.right   !=   null )   { Entry   s   =   successor(p); swapPosition(s,   p); } Entry   replacement   =   (p.left   !=   null   ?   p.left   :   p.right); if   (replacement   !=   null )   { replacement.parent   =   p.parent; if   (p.parent   ==   null ) root   =   replacement; else   if   (p   ==   p.parent.left)   { p.parent.left   =   replacement; } else p.parent.right   =   replacement; p.left   =   p.right   =   p.parent   =   null ; if   (p.color   ==   BLACK) fixAfterDeletion(replacement); ...
Symbolic Execution for white-box TIG if   (p.left   !=   null   &&   p.right   !=   null )   { ... Symbolic structure before executing branch Concretize Concrete structure that will cover the  code The symbolic structure  is used as input to  repOk()  and lazily  executed to obtain the  concrete structure Symbolic structure(s) that cover the branch This structure “passes” the abstract  repOk()
API Based Testing SUT ENV (m,n) m is the seq. length of API calls  & n is the number of values  used in the parameters of the calls API … put(v) del(v) Evaluate  different techniques for selecting test-cases from ENV(m,n) to obtain maximum coverage
Framework SUT with minor instrumentation ENV TestListener Abstraction Mapping + State Storage Coverage Manager JPF
Environment Skeleton M : sequence length N : parameter values A : abstraction used for (int i = 0; i < M; i++) { int x = Verify.random(N - 1); switch (Verify.random(1)) { case 0: put(x); break; case 1: remove(x); break; }  } Verify.ignoreIf(checkStateMatch());
Symbolic Environment Skeleton M : sequence length A : abstraction used for (int i = 0; i < M; i++) { SymbolicInteger x = new SymbolicInteger(“X“+i); switch (Verify.random(1)) { case 0: put(x); break; case 1: remove(x); break; }  } Verify.ignoreIf(checkStateMatch());
Sample Output Test case number 77 for '15,L+R+P-REDroot ':  put(0);put(4);put(5);put(1);put(2);put(3);remove(4); Unique ID for the test Branch Number Predicate Values Test-case to achieve above coverage Test case number 7 for '32,L-R-P+RED': X2 (0)   ==   X1 (0)   &&   X2 (0)   <   X0 (1)   &&   X1 (0)   <  X0 (1) put( X0 );put( X1 );remove( X2 ); Test case number 7 for '32,L-R-P+RED':  put(1);put(0);remove(0); Concrete Symbolic Path Condition with solutions Symbolic TC
Subsumption Checking x1 x2 x3 x4 x5 + x1 > x2 &  x2 > x3 &  x2 < x4 &  x5 > x1 x1 x2 x3 x4 x5 + x1 > x2 &  x2 > x3 &  x2 < x4 &  x5 > x1 If only it was this simple!
Existential Elimination x1 x2 x3 x4 x5 PC s1 < s2 & s4 > s3 &  s4 < s1 & s4 < s5 & s7  < s2 &  s7  > s1   s1 s4 s2 s3 s5 +    s1,s2,s3,s4,s5  such that   x1 = s1 & x2 = s4 & x3 = s3 & x4 = s5 & x5 = s2  &  PC x1 > x2 & x2 > x3 &  x2 < x4 & x5 > x1
Results from ISSTA 2006 Paper ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],See examples/issta2006 folder under the SVN repository to  reproduce the experiments
Symbolic Execution Demo ,[object Object],[object Object],[object Object]
JPF Symbolic Execution - BEFORE Omega Interface Formula satisfiable/unsatisfiable Omega Java Version JPF
JPF Symbolic Execution - NOW Generic Decision Procedure Interface Formula satisfiable/unsatisfiable Omega Maryland JPF CVCLite Stanford Yices SRI STP Stanford Collaborator Saswat Anand
Communication Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Optimization using Tables JPF State Path Condition: X > Y & Z > X & … JPF State Path Condition: pc100 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],45 46 100 … …
Optimization – Run DPs incrementally ,[object Object],[object Object],[object Object]
Decision Procedure Options ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Results TCAS
Results TreeMap STP took > 1 hour
State Matching in JPF VM State Matchable + Restorable Stored State (hashed) Matchable compression Collaborator Peter Dillinger Abstract State erase some parts  of the state could be lossy Matchable
Old Architecture StateSet int[] bool VM/Search ,[object Object],[object Object]
New Architecture VM/Search DefaultBacktracker VM bool int[] Restorer Serializer Serialized StateSet int[] set VM
Old Scheme in the New Architecture VM/Search DefaultBacktracker FullStateSet int[] set bool int[] Collapsing (de)Serializer int[] VM
New Architecture VM/Search CollapsingRestorer FilteringSerializer DefaultBacktracker VM bool int[] objects This is the default setting for JPF at the moment: vm.backtracker.class = gov.nasa.jpf.jvm.DefaultBacktracker vm.restorer.class = gov.nasa.jpf.jvm.CollapsingRestorer vm.serializer.class = gov.nasa.jpf.filter.FilteringSerializer vm.storage.class = gov.nasa.jpf.jvm.JenkinsStateSet JenkinsStateSet int[] set VM
FilteringSerializer  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
New Architecture Revisited - Abstraction VM/Search CollapsingRestorer AbstractingSerializer DefaultBacktracker VM bool int[] objects This is the setting for the above configuration: vm.backtracker.class = gov.nasa.jpf.jvm.DefaultBacktracker vm.restorer.class = gov.nasa.jpf.jvm.CollapsingRestorer vm.serializer.class = gov.nasa.jpf.abstraction.abstractingSerializer vm.storage.class = gov.nasa.jpf.jvm.JenkinsStateSet JenkinsStateSet int[] set VM
AbstractingSerializer ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
User-Interface Model Checking ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Collaborator Peter Mehlitz
Something Completely Different ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Collaborator Aaron Tomb

More Related Content

What's hot

QTP Interview Questions and answers
QTP Interview Questions and answersQTP Interview Questions and answers
QTP Interview Questions and answers
Rita Singh
 
香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare
yayao
 
Presentation_C++UnitTest
Presentation_C++UnitTestPresentation_C++UnitTest
Presentation_C++UnitTest
Raihan Masud
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
 

What's hot (20)

QTP Interview Questions and answers
QTP Interview Questions and answersQTP Interview Questions and answers
QTP Interview Questions and answers
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answers
 
Qtp-training A presentation for beginers
Qtp-training  A presentation for beginersQtp-training  A presentation for beginers
Qtp-training A presentation for beginers
 
JUnit 5 - The Next Generation
JUnit 5 - The Next GenerationJUnit 5 - The Next Generation
JUnit 5 - The Next Generation
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
Unit testing on embedded target with C++Test
Unit testing on embedded  target with C++TestUnit testing on embedded  target with C++Test
Unit testing on embedded target with C++Test
 
Software Engineering - RS3
Software Engineering - RS3Software Engineering - RS3
Software Engineering - RS3
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Mastering Mock Objects - Advanced Unit Testing for Java
Mastering Mock Objects - Advanced Unit Testing for JavaMastering Mock Objects - Advanced Unit Testing for Java
Mastering Mock Objects - Advanced Unit Testing for Java
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare
 
Php unit (eng)
Php unit (eng)Php unit (eng)
Php unit (eng)
 
Presentation_C++UnitTest
Presentation_C++UnitTestPresentation_C++UnitTest
Presentation_C++UnitTest
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-framework
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 

Similar to Jpf model checking

eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
vstorm83
 

Similar to Jpf model checking (20)

Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance Diagnostics
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Json generation
Json generationJson generation
Json generation
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_en
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginers
 
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
 
Monitoring and Tuning GlassFish
Monitoring and Tuning GlassFishMonitoring and Tuning GlassFish
Monitoring and Tuning GlassFish
 
Monitoring And Tuning Glass Fish In The Wild Community One 2009
Monitoring And Tuning Glass Fish In The Wild   Community One 2009Monitoring And Tuning Glass Fish In The Wild   Community One 2009
Monitoring And Tuning Glass Fish In The Wild Community One 2009
 
ASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdf
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Jpf model checking

  • 1. Model Checking Programs with Java PathFinder Willem Visser < [email_address] > Peter Mehlitz < [email_address] > NASA Ames Research Center
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 16.
  • 17. Under the Hood - Search
  • 18.
  • 19. Extending JPF - SearchListener public interface SearchListener {   /* got the next state */     void stateAdvanced (Search search);   /* state was backtracked one step */   void stateBacktracked (Search search);     /* a previously generated state was restored     (can be on a completely different path) */   void stateRestored (Search search);     /* JPF encountered a property violation */   void propertyViolated (Search search);     /* we get this after we enter the search loop, but BEFORE the first forward */   void searchStarted (Search search);     /* there was some contraint hit in the search, we back out could have been turned into a property, but usually is an attribute of the search, not the application */ void searchConstraintHit (Search search);     /* we're done, either with or without a preceeding error */   void searchFinished (Search search); }
  • 20. Extending JPF - VMListener public interface VMListener {    void instructionExecuted (JVM vm); // VM has executed next instruction   void threadStarted (JVM vm); / / new Thread entered run() method      void threadTerminated (JVM vm); // Thread exited run() method      void classLoaded (JVM vm); // new class was loaded      void objectCreated (JVM vm); // new object was created      void objectReleased (JVM vm); // object was garbage collected      void gcBegin (JVM vm); // garbage collection mark phase started      void gcEnd (JVM vm); // garbage collection sweep phase terminated      void exceptionThrown (JVM vm); // exception was thrown    void nextChoice (JVM vm); // choice generator returned new value }
  • 21. Extending JPF - Listener Example public class HeapTracker extends GenericProperty implements VMListener , SearchListener { class PathStat { .. int heapSize = 0; .. } // helper to store additional state info PathStat stat = new PathStat(); Stack pathStats = new Stack(); public boolean check (JVM vm, Object arg) { // GenericProperty return (stat.heapSize <= maxHeapSizeLimit); } public void stateAdvanced (Search search) { // SearchListener if (search.isNewState()) {.. pathStats.push(stat); stat = (PathStat)stat.clone(); .. } public void stateBacktracked (Search search) { // SearchListener .. if (!pathStats.isEmpty()) stat = (PathStat) pathStats.pop(); } public void objectCreated (JVM vm) {.. // VMListener ElementInfo ei = vm.getLastElementInfo(); ..stat.heapSize += ei.getHeapSize(); .. } public void objectReleased (JVM vm) { // VMListener ElementInfo ei = vm.getLastElementInfo(); ..stat.heapSize -= ei.getHeapSize(); .. } ... }
  • 22.
  • 23.
  • 24.
  • 25.
  • 27.
  • 28.
  • 29. POR - Scheduling Relevance
  • 30.
  • 32. JPF Perspective State consists of 2 main components, the state of the JVM and the current and next choice Generator (i.e. the objects encapsulating the choice enumeration that produces new transitions) Transition is the sequence of instructions that leads from one state. There is no context within a transition, it's all in the same thread. There can be multiple transitions leading out of one state Choice is what starts a new transition. This can be a different thread, i.e. scheduling choice, or different “random” data value.
  • 33. Role of Choices In other words, possible existence of Choices is what terminates the last Transition, and selection of a Choice value precedes the next Transition. The first condition corresponds to creating a new ChoiceGenerator, and letting the SystemState know about it. The second condition means to query the next choice value from this ChoiceGenerator (either internally within the JVM, or in an instruction or native method).
  • 34.
  • 36. JUnit Example package gov.nasa.jpf.mc; import org.junit.Test; import org.junit.runner.JUnitCore; import gov.nasa.jpf.jvm.TestJPF; public class TestOldClassicJPF extends TestJPF { static final String TEST_CLASS = &quot;gov.nasa.jpf.mc.oldclassic&quot;; public static void main (String[] args) { JUnitCore.main(&quot;gov.nasa.jpf.mc.TestOldClassicJPF&quot;); } @Test public void testDFSearch () { String[] args = { TEST_CLASS }; runJPFDeadlock(args); } @Test public void testBFSHeuristic () { String[] args = { &quot;+search.class=gov.nasa.jpf.search.heuristic.HeuristicSearch&quot;, &quot;+search.heuristic.class=gov.nasa.jpf.search.heuristic.BFSHeuristic&quot;, TEST_CLASS }; runJPFDeadlock(args); } }
  • 37.
  • 38.
  • 39. Stoned Hippies Germany Netherlands 5 10 2 1
  • 40. Stoned Hippies Germany Netherlands 2 5 10 1 2
  • 41. Stoned Hippies Germany Netherlands 3 5 10 1 2
  • 42. Stoned Hippies Germany Netherlands 8 10 1 2 5
  • 43. Stoned Hippies Germany Netherlands 19 1 2 5 10
  • 44.
  • 45. Concrete Execution Path (example) x = 1, y = 0 1 >? 0 x = 1 + 0 = 1 y = 1 – 0 = 1 x = 1 – 1 = 0 0 – 1 >? 0 int x, y; if (x > y) { x = x + y; y = x – y; x = x – y; if (x – y > 0) assert(false); }
  • 46. Symbolic Execution Tree (example) x = X, y = Y int x, y; if (x > y) { x = x + y; y = x – y; x = x – y; if (x – y > 0) assert(false); } X >? Y [ X > Y ] y = X + Y – Y = X [ X > Y ] x = X + Y – X = Y [ X > Y ] Y - X >? 0 [ X <= Y ] END [ X > Y ] x = X + Y [ X > Y, Y – X <= 0 ] END [ X > Y, Y – X > 0 ] END
  • 47. Example class Node { int elem; Node next; Node swapNode() { if (next != null) if (elem > next.elem) { Node t = next; next = t.next; t.next = this; return t; } return this; } } ? null E0 E1 E0 E0 E1 null E0 E1 ? E0 E1 E0 E1 Input list + Constraint Output list E0 > E1 none E0 <= E1 none E0 > E1 E0 > E1 E0 > E1 E1 E0 ? E1 E0 E1 E0 E1 E0 null E0 E1 E0 ? null NullPointerException
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. Algorithm (illustration) consider executing next = t.next; E0 next E1 next t null t E0 next E1 next ? next E0 next E1 t next E0 next E1 next t E0 next E1 next t Precondition: acyclic list E0 E1 next t null next t E0 E1 next ? next next
  • 53. Implementation via Instrumentation program instrumentation counterexample(s)/test suite [heap+constraint+thread scheduling] model checking decision procedure instrumented program correctness specification continue/ backtrack state: original program path condition (data) heap configuration thread scheduling
  • 54.
  • 55. Red-Black Trees (1) The root is BLACK (2) Red nodes can only have black children (3) All paths from a node to its leaves contain the same number of black nodes. Self-balancing Binary Search Trees Java TreeMap Implementation (4) Acyclic (5) Consistent Parents repOk(): conditions (1)-(5)
  • 56. repOk() Fragment boolean repOk(Entry e) { // root has no parent, root is black,… // RedHasOnlyBlackChildren workList = new LinkedList(); workList.add(e); while (!workList.isEmpty()) { Entry current=(Entry)workList.removeFirst(); Entry cl = current.left; Entry cr = current.right; if (current.color == RED) { if(cl != null && cl.color == RED) return false; if(cr != null && cr.color == RED) return false; } if (cl != null) workList.add(cl); if (cr != null) workList.add(cr); } // equal number of black nodes on left and right sub-tree… return true; }
  • 57.
  • 58. Symbolic Execution of repOk() Example public static boolean repOk() { if (root == null ) return true ; if (root.color == RED) return false; … Size 1
  • 59.
  • 60. repOk() x 2 abstract and concrete Symbolic Execution of Code During Lazy Initialization check Abstract repOk() When coverage is achieved, solve the symbolic constraints to create concrete inputs Concretize inputs by symbolic execution of Concrete repOk() over symbolic structures - as with Black-box TIG - Abstract repOk() : Symbolic Structure {true,false,don’t know} Concrete repOk() : Symbolic Structure Concrete Structure
  • 61.
  • 62. White-box TIG: cover branches in deleteEntry(Entry p) /* precondition: p. repOk() */ private void deleteEntry(Entry p) { if (p.left != null && p.right != null ) { Entry s = successor(p); swapPosition(s, p); } Entry replacement = (p.left != null ? p.left : p.right); if (replacement != null ) { replacement.parent = p.parent; if (p.parent == null ) root = replacement; else if (p == p.parent.left) { p.parent.left = replacement; } else p.parent.right = replacement; p.left = p.right = p.parent = null ; if (p.color == BLACK) fixAfterDeletion(replacement); ...
  • 63. Symbolic Execution for white-box TIG if (p.left != null && p.right != null ) { ... Symbolic structure before executing branch Concretize Concrete structure that will cover the code The symbolic structure is used as input to repOk() and lazily executed to obtain the concrete structure Symbolic structure(s) that cover the branch This structure “passes” the abstract repOk()
  • 64. API Based Testing SUT ENV (m,n) m is the seq. length of API calls & n is the number of values used in the parameters of the calls API … put(v) del(v) Evaluate different techniques for selecting test-cases from ENV(m,n) to obtain maximum coverage
  • 65. Framework SUT with minor instrumentation ENV TestListener Abstraction Mapping + State Storage Coverage Manager JPF
  • 66. Environment Skeleton M : sequence length N : parameter values A : abstraction used for (int i = 0; i < M; i++) { int x = Verify.random(N - 1); switch (Verify.random(1)) { case 0: put(x); break; case 1: remove(x); break; } } Verify.ignoreIf(checkStateMatch());
  • 67. Symbolic Environment Skeleton M : sequence length A : abstraction used for (int i = 0; i < M; i++) { SymbolicInteger x = new SymbolicInteger(“X“+i); switch (Verify.random(1)) { case 0: put(x); break; case 1: remove(x); break; } } Verify.ignoreIf(checkStateMatch());
  • 68. Sample Output Test case number 77 for '15,L+R+P-REDroot ': put(0);put(4);put(5);put(1);put(2);put(3);remove(4); Unique ID for the test Branch Number Predicate Values Test-case to achieve above coverage Test case number 7 for '32,L-R-P+RED': X2 (0) == X1 (0) && X2 (0) < X0 (1) && X1 (0) < X0 (1) put( X0 );put( X1 );remove( X2 ); Test case number 7 for '32,L-R-P+RED': put(1);put(0);remove(0); Concrete Symbolic Path Condition with solutions Symbolic TC
  • 69. Subsumption Checking x1 x2 x3 x4 x5 + x1 > x2 & x2 > x3 & x2 < x4 & x5 > x1 x1 x2 x3 x4 x5 + x1 > x2 & x2 > x3 & x2 < x4 & x5 > x1 If only it was this simple!
  • 70. Existential Elimination x1 x2 x3 x4 x5 PC s1 < s2 & s4 > s3 & s4 < s1 & s4 < s5 & s7 < s2 & s7 > s1 s1 s4 s2 s3 s5 +  s1,s2,s3,s4,s5 such that x1 = s1 & x2 = s4 & x3 = s3 & x4 = s5 & x5 = s2 & PC x1 > x2 & x2 > x3 & x2 < x4 & x5 > x1
  • 71.
  • 72.
  • 73. JPF Symbolic Execution - BEFORE Omega Interface Formula satisfiable/unsatisfiable Omega Java Version JPF
  • 74. JPF Symbolic Execution - NOW Generic Decision Procedure Interface Formula satisfiable/unsatisfiable Omega Maryland JPF CVCLite Stanford Yices SRI STP Stanford Collaborator Saswat Anand
  • 75.
  • 76.
  • 77.
  • 78.
  • 80. Results TreeMap STP took > 1 hour
  • 81. State Matching in JPF VM State Matchable + Restorable Stored State (hashed) Matchable compression Collaborator Peter Dillinger Abstract State erase some parts of the state could be lossy Matchable
  • 82.
  • 83. New Architecture VM/Search DefaultBacktracker VM bool int[] Restorer Serializer Serialized StateSet int[] set VM
  • 84. Old Scheme in the New Architecture VM/Search DefaultBacktracker FullStateSet int[] set bool int[] Collapsing (de)Serializer int[] VM
  • 85. New Architecture VM/Search CollapsingRestorer FilteringSerializer DefaultBacktracker VM bool int[] objects This is the default setting for JPF at the moment: vm.backtracker.class = gov.nasa.jpf.jvm.DefaultBacktracker vm.restorer.class = gov.nasa.jpf.jvm.CollapsingRestorer vm.serializer.class = gov.nasa.jpf.filter.FilteringSerializer vm.storage.class = gov.nasa.jpf.jvm.JenkinsStateSet JenkinsStateSet int[] set VM
  • 86.
  • 87. New Architecture Revisited - Abstraction VM/Search CollapsingRestorer AbstractingSerializer DefaultBacktracker VM bool int[] objects This is the setting for the above configuration: vm.backtracker.class = gov.nasa.jpf.jvm.DefaultBacktracker vm.restorer.class = gov.nasa.jpf.jvm.CollapsingRestorer vm.serializer.class = gov.nasa.jpf.abstraction.abstractingSerializer vm.storage.class = gov.nasa.jpf.jvm.JenkinsStateSet JenkinsStateSet int[] set VM
  • 88.
  • 89.
  • 90.
  • 91.

Editor's Notes

  1. To handle this case, we have to leave the ideal world of model checking (that considers all possible choices), and make use of what we know about the real world - we have to use heuristics to make the set of choices finite and manageable. However, heuristics are application and domain specific, and it would be a bad idea to hardcode them into the test drivers we give JPF to analyze. This leads to a number of requirements for the JPF choice mechanism: choice mechanisms have to be decoupled (i.e. thread choices should be indpendent of data choices, double choices from int choices etc.) choice sets and enumeration should be encapsulated in dedicated, type specific objects. The VM should only know about the most basic types, and otherwise use a generic interface to obtain choices selection of classes representing (domain specific) heuristics, and parametrization of ChoiceGenerator instances should be possible at runtime, i.e. via JPF&apos;s configuration mechanism (properties) The diagram shown above depicts this with an example that uses a &amp;quot;randomly&amp;quot; chosen velocity value of type double. As an example heuristic we use a threshold model, i.e. we want to know how the system reacts below, at, and above a certain application specific value (threshold). We reduce an infinite set of choices to only three &amp;quot;interesting&amp;quot; ones. Of course, &amp;quot;interesting&amp;quot; is quite subjective, and we probably want to play with the values (delta, threshold, or even used heuristic) efficiently, without having to rebuild the application each time we run JPF. The code example does not mention the used ChoiceGenerator class (DoubleThresholdGenerator) at all, it just specifies a symbolic name &amp;quot;velocity&amp;quot;, which JPF uses to look up an associated class name from its configuration data (initialized via property files or the command line - see Configuring JPF Runtime Options ). But it doesn&apos;t stop there. Most heuristics need further parameterization (e.g. threshold, delta), and we provide that by passing the JPF configuration data into the ChoiceGenerator constructors (e.g. the &apos;velocity.threshold&apos; property). Each ChoiceGenerator instance knows its symbolic name (e.g. &amp;quot;velocity&amp;quot;), and can use this name to look up whatever parameters it needs.
  2. Transition is the sequence of instructions that leads from one state to the next. There is no context switch within a transition, it&apos;s all in the same thread. There can be multiple transitions leading out of one state (but not