Java PathFinder (JPF) cs498dm Software Testing January 19, 2012.

Slides:



Advertisements
Similar presentations
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Advertisements

Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Java Virtual Machine (JVM). Lecture Objectives Learn about the Java Virtual Machine (JVM) Understand the functionalities of the class loader subsystem.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
Java Virtual Machine (JVM). Lecture Objectives Learn about the Java Virtual Machine (JVM) Understand the functionalities of the class loader subsystem.
Introduction to Java Programming
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Unit 061 Java Virtual Machine (JVM) What is Java Virtual Machine? The Class Loader Subsystem Linking oVerification oPreparation oResolution Class Initialization.
1 Further OO Concepts II – Java Program at run-time Overview l Steps in Executing a Java Program. l Loading l Linking l Initialization l Creation of Objects.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
Multithreading.
50.003: Elements of Software Construction Week 5 Basics of Threads.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
JPF Tutorial - Part 1 JPF Core System
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
1 The Java Virtual Machine Yearly Programming Project.
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
Static Keyword. What is static The static keyword is used when a member variable of a class has to be shared between all the instances of the class. All.
Lecture 5 : JAVA Thread Programming Courtesy : MIT Prof. Amarasinghe and Dr. Rabbah’s course note.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Problem of the Day  Why are manhole covers round?
CS527 Topics in Software Engineering (Software Testing and Analysis) Darko Marinov September 9, 2010.
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. Concurrent programming in Java How to make all things run-able?
1 Object Oriented Programming Lecture XII Multithreading in Java, A few words about AWT and Swing, The composite design pattern.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Addendum to Lab 10 What was all that about?. Consider… A static queue class – It has one copy of the queue in the class’s memory : public class StaticQClass.
Model Checking Java Programs using Structural Heuristics
Symbolic Execution with Abstract Subsumption Checking Saswat Anand College of Computing, Georgia Institute of Technology Corina Păsăreanu QSS, NASA Ames.
jFuzz – Java based Whitebox Fuzzing
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 Model Checking of Robotic Control Systems Presenting: Sebastian Scherer Authors: Sebastian Scherer, Flavio Lerda, and Edmund M. Clarke.
Java Programming static keyword.
CS527 Topics in Software Engineering (Software Testing and Analysis) Darko Marinov August 30, 2011.
Programming Languages and Paradigms Activation Records in Java.
Chapter11 Concurrent. 集美大学 计算机工程学院 Java 程序设计 年 第二版 Concurrent ●Computer users take it for granted that their systems can do more than one thing.
CAPP: Change-Aware Preemption Prioritization Vilas Jagannath, Qingzhou Luo, Darko Marinov Sep 6 th 2011.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
1 1 Nastaran Shafiei VERIFICATION OF A NON-BLOCKING ARRAY-BASED QUEUE ALGORITHM.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
RealTimeSystems Lab Jong-Koo, Lim
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two Threads.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
December 1, 2006©2006 Craig Zilles1 Threads & Atomic Operations in Hardware  Previously, we introduced multi-core parallelism & cache coherence —Today.
Healing Data Races On-The-Fly
Concurrency 2 CS 2110 – Spring 2016.
The Java Virtual Machine (JVM)
Model Checking Java Programs (Java PathFinder)
Section 5.7 Concurrency, Interference, and Synchronization.
CompSci 230 Software Construction
Java Virtual Machine Complete subject details are available at:
Introduction to Java Dept. Business Computing University of Winnipeg
Multithreaded Programming in Java
Chapter 6 Arrays Solution Opening Problem
Threads and Concurrency in Java: Part 1
Object Oriented Programming
class PrintOnetoTen { public static void main(String args[]) {
Representation and Management of Data on the Internet
Foundations and Definitions
Presentation transcript:

Java PathFinder (JPF) cs498dm Software Testing January 19, 2012

2 What is Java PathFinder (JPF)? First open source project by NASA (100K) JPF is Java Virtual Machine (JVM) JPF is implemented in Java itself

3 Demo JPF as JVM Obtain a copy –hg clone Build –ant Run –HelloWorld.java –java HelloWorld –bin/jpf HelloWorld

4 What is Actually JPF? Tool for systematic testing of Java programs JVM that has support for fast backtracking “the Swiss army knife of Java verification”

5 Non-determinism Explicit non-determinism with Verify.getInt JPF can be used to find concurrency bugs Thread interleavings are another form of non-determinism

6 GetIntExample import gov.nasa.jpf.jvm.Verify; public class GetIntExample { public static void main(String[] args) { int i = Verify.getInt(0, 1); int j = Verify.getInt(2, 3); System.out.println("i = " + i + " j = " + j); } Demo: (1) run on JVM (x3); (2) run on JPF; (3) visualize

7 Prints in the Middle import gov.nasa.jpf.jvm.Verify; public class GetIntExample { public static void main(String[] args) { int i = Verify.getInt(0, 1); System.out.println("i = " + i); int j = Verify.getInt(2, 3); System.out.println(“j = " + j); } Can be confusing? Documentation not perfect!

8 Inlined print(s) import gov.nasa.jpf.jvm.Verify; public class GetIntExample { public static void main(String[] args) { System.out.println("i = " + Verify.getInt(0, 1)); int j = Verify.getInt(2, 3); System.out.println(“j = " + j); } Example due to Mateusz Ujma

9 JPF How JPF explores all possible interleavings –Regular JVM executes one interleaving, but repeated executions may differ… or not Intuitively, JPF re-executes the program for all possible interleavings –Does not actually re-execute from start –Does not actually explore all interleavings Various search strategies: –DFS, BFS, random… (Demo BFS)

10 java.lang.Thread Basic class for threads in Java All (started) objects of this class can be running concurrently Need to provide code for the thread Some relevant methods –start, join –yield, sleep (not so interesting in JPF)

11 Example 2: Counter class Counter { int c = 0; void increment() { c++; } void decrement() { c--; } int value() { return c; } } What could go wrong with multithreading?

12 Two Threads Sharing Counter What could go wrong with multithreading? final Counter c = new Counter(); Thread t1 = new Thread() { public void run() { c.increment(); } }; Thread t2 = new Thread() { public void run() { c.increment(); } }; System.out.println(c.value());

13 Extending JPF - Listeners Preferred way of extending JPF: –‘Listener’ variant of the Observer pattern - keep extensions out of the core classes

14 Listeners, the JPF Plugins

15 Example Listener: Count Instructions public class CountInstListener extends ListenerAdapter { private int count = 0; public void executeInstruction(JVM vm) { // counts only instance creation if (vm.getCurrentThread().getPC() instanceof NEW) count++; } public void searchFinished(Search search) { System.out.println("COUNT: " + count); }

16 Main JPF Operations Bytecode execution State storing/restoring for backtracking –JPF does not literally re-execute program from the beginning for each choice State comparison –What is in the state?

17 State of a Java Program Stack(s)/thread(s) –Each thread has a stack with a number of stack frames that store local variables –Also a program counter (PC) and thread info Heap (in JPF: dynamic area) –Objects in dynamically allocated memory (can be shared among threads) Classinfo (in JPF: static area) –Static data once it’s loaded

18 Bytecode Execution Each bytecode changes the state Some for local data (e.g., IADD) Some for control/PC (e.g., IFNULL) Some for shared data (e.g., GETFIELD)

19 State Storing/Restoring Stores the entire JVM state (threads, dynamic area, static area) Some pieces of state may not be visible in source code Does NOT restore JPF’s internal info –E.g., getInt counts what it returned

20 State Comparison Compares the entire JVM state (threads, dynamic area, static area) Again, some pieces of state may not be visible in source code

21 JPF Search Start program from the beginning Execute bytecodes to get to a new state Compare if that state was already seen If not, explore successors from the state Various search strategies: –DFS, BFS, random…

22 Reminder: Project Testing a part of JPF Deliverables –Proposal (due in three weeks) –Progress report (around midterm) –Final report (by the grade submission deadline) –Bug reports (hopefully you’ll find some bugs) Extra bonus points for reporting bugs to us

23 How to Test? How would you test JPF? –Execution? –Storing/restoring? –State matching? JPF ? ?

24 Contributions from Darko's Students Personal experience –Have been working with JPF since 2007 –Dozen of bug reports –Numerous patches (enhancements and bug fixes) – –X10X: Model checking X10 programs with JPF –Granted write access for jpf-core in 2010 –Visited NASA Ames in December 2011

25 Conclusions JPF is “the Swiss army knife of Java verification” Complex system –Bytecode execution –State storing/restoring for backtracking –State comparison Your project will focus on testing one of the main (sub)parts of JPF