Prof. Moonzoo Kim Computer Science, KAIST

Slides:



Advertisements
Similar presentations
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Pallavi Joshi  Chang-Seo Park  Koushik Sen  Mayur Naik ‡  Par Lab, EECS, UC Berkeley‡
Advertisements

50.003: Elements of Software Construction Week 6 Thread Safety and Synchronization.
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Koushik Sen CS 265.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Atomicity in Multi-Threaded Programs Prachi Tiwari University of California, Santa Cruz CMPS 203 Programming Languages, Fall 2004.
Threading Part 2 CS221 – 4/22/09. Where We Left Off Simple Threads Program: – Start a worker thread from the Main thread – Worker thread prints messages.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
1HW13 Modify ThreadSafeBankAccount2 to use an assertion that checks a lock is released. Learn how to compile and run Java code with assertions. Define.
Definitions Process – An executing program
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Cormac Flanagan UC Santa Cruz Velodrome: A Sound and Complete Dynamic Atomicity Checker for Multithreaded Programs Jaeheon Yi UC Santa Cruz Stephen Freund.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
50.003: Elements of Software Construction Week 5 Basics of Threads.
What is the output generated by this program? Please assume that each executed print statement completes, e.g., assume that each print is followed by an.
1 Testing Concurrent Programs Why Test?  Eliminate bugs?  Software Engineering vs Computer Science perspectives What properties are we testing for? 
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
CSE 219 Computer Science III Multithreaded Issues.
Threads some important concepts Simon Lynch
Threads. Overview Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Hint for Assignment#4: Implementing Lockset-Based Data Race Detector Prof. Moonzoo Kim Computer Science, KAIST CS492B Analysis of Concurrent Programs.
Internet Software Development Controlling Threads Paul J Krause.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
Dynamic Architectures (Component Reconfiguration) with Fractal.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Random Testing of Concurrent Programs Prof. Moonzoo Kim Computer Science, KAIST CS492B Analysis of Concurrent Programs.
Java Thread and Memory Model
Dr. R R DOCSIT, Dr BAMU. Basic Java :Multi Threading Cont. 2 Objectives of This Session Explain Synchronization in threads Demonstrate use of.
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
Monitors CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Deadlock Bug Detection Techniques Prof. Moonzoo Kim CS KAIST CS492B Analysis of Concurrent Programs 1.
On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Agenda  Quick Review  Finish Introduction  Java Threads.
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
Testing Concurrent Programs Sri Teja Basava Arpit Sud CSCI 5535: Fundamentals of Programming Languages University of Colorado at Boulder Spring 2010.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Week 8, Class 3: Model-View-Controller Final Project Worth 2 labs Cleanup of Ducks Reducing coupling Finishing FactoryMethod Cleanup of Singleton SE-2811.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Java Thread Programming
Multithreading / Concurrency
Multithreading Tutorial
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Hint for Assignment#3: Implementing Lockset-Based Data Race Detector
Multithreading.
Java Concurrency 17-Jan-19.
Multithreading Tutorial
Computer Science 2 06A-Java Multithreading
Java Concurrency.
Java Concurrency.
Threads and Multithreading
Java Concurrency 29-May-19.
Software Engineering and Architecture
some important concepts
Presentation transcript:

Prof. Moonzoo Kim Computer Science, KAIST CS492B Analysis of Concurrent Programs CalFuzzer Tutorial Prof. Moonzoo Kim Computer Science, KAIST

CalFuzzer Tutorial, Prof. Moonzoo Kim Developed by Prof. Koushik Sen’s group at UC Berkeley http://srl.cs.berkeley.edu/~ksen/calfuzzer/ Dynamic analysis + Active testing framework for concurrent Java programs Dynamic analysis: detect/predict concurrency bugs Active testing: generate thread scheduling for inducing detected/predicted concurrency bugs Provide useful infra-structure to construct various dynamic analysis and testing techniques CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Framework Instrumentor Dynamic analyzer Test generator Target program’s Java bytecode Instrumentor Instrumented Java bytecode Instrume- ntation phase Dynamic analysis phase Instrumented Java bytecode Dynamic analyzer Bug prediction information Instrumented Java bytecode Testing phase Test generator Test executions Bug prediction information CalFuzzer CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Instrumentation Calfuzzer modifies a target Javabyte code to insert probes each of which executes before/after certain operations e.g. before every memory read instruction, insert a probe to call Observer.readBefore(thread, addr), which is defined by a user In the dynamic analysis phase, user-written probes are executed to extract runtime information e.g. a user writes Observer.readBefore(thread, addr) to log which thread reads which memory addresses In the testing phase, a user can write probes to pause/continue threads to control a thread scheduler as s/he wants CalFuzzer Tutorial, Prof. Moonzoo Kim

Instrumentation Example public class Account { … public synchronized int balance() { return balance ; } ... public synchronized int balance(); Code: aload_0 getfield #2 // Field balance ireturn <Source code> <Bytecode> ... public synchronized int balance(); Code: invokestatic #39 //invoke Observer.lockAfter(int) invokestatic #40 //invoke Observer.readBefore(thread,addr) aload_0 getfield #2 // Field balance ireturn after lock(this) before read(balance) <Instrumented code> CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Instrumentation CalFuzzer inserts the probes to call the following functions at the following sites Probe method Instrumented site initialize() Before starting a program finish() When a target program terminates methodEnterBefore() Before entering a method call methodExitAfter() After returning from a method call lockBefore()/lockAfter() Before/after entering a synchronized block, or invoking a synchronized method unlockAfter() After existing a synchronized block/method startBefore() Before a new thread is starting joinAfter() After join with a child thread waitAfter() After awaken from a waiting notifyBefore()/ notifyAllBefore() Before notify() / notifyAll() readBefore()/readAfter() Before/after reading a memory address (i.e., object field reference, array access) writeBefore()/writeAfter() Before/after writing a memory address CalFuzzer Tutorial, Prof. Moonzoo Kim

Bytecode Instrumentation CalFuzzer uses Soot for bytecode instrumentation Soot is a Java bytecode engineering framework http://www.sable.mcgill.ca/soot/tutorial/index.html Soot converts a given bytecode to a Jimple code Jimple is a Soot intermediate representation Jimple is 3-addressed typed code in a control-flow graph Each variable has its name and type Jimple code is easier to analyze and instrument than bytecode Only 15 kinds of statements (bytecode has more than 200 kinds of instructions) Using Soot, the Calfuzzer instrumentation module converts target bytecode to jimple code, and modifies the Jimple code to insert probes, and compiles the modified Jimple code into bytecode CalFuzzer Tutorial, Prof. Moonzoo Kim

Dynamic Analysis Phase CalFuzzer binds an instrumented program with an AnalysisImpl instance (i.e., analyzer) which implements each probe method CalFuzzer instruments a given target program and then executes the instrumented program with an analyzer Dynamic analyzer Test generator Target program execution Data race detector Data race tester Thread-1 Thread-2 Thread-3 Observer Thread schedule generator … Deadlock detector Deadlock tester readBefore() read(X) … Atomicity detector Atomicity tester CalFuzzer runtime modules CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Analyzer An analyzer should implements the probe methods to monitor and analyze a target program execution (i.e., implement AnalysisImpl) For each test execution, CalFuzzer creates one instance of analyzer for monitoring a target program execution In an execution, a thread executes probes before and after certain operations Multiple threads may execute methods of an analyzer concurrently A user has to be careful not to raise concurrency errors caused by his/her own probes See src/javato/activetesting/BlankAnalysis.java CalFuzzer Tutorial, Prof. Moonzoo Kim

List of Useful CalFuzzer Probes Initialization & finalization public void initialize(), public void finish() Targeting methods public void methodEnterBefore(Integer iid, Integer thread, String method) public void methodExitAfter(Integer iid, Integer therad, String method) Targeting lock operations public void lockBefore(Integer iid, Integer thread, Integer lock, Object actualLock) public void lockAfter(Integer iid, Integer thread, Integer lock, Object actualLock) public void unlockAfter(Integer iid, Integer thread, Integer lock, Object actualLock) Targeting read/write operations public void readBefore(Integer iid, Integer thread, Long memory, boolean isVolatile) public void readAfter(Integer iid, Integer thread, Long memory, boolean isVolatile) public void writeBefore(Integer iid, Integer thread, Long memory, boolean isVolatile) public void writeAfter(Integer iid, Integer thread, Long memory, boolean isVolatile) Targeting wait-notify operations Targeting thread operations

CalFuzzer Tutorial, Prof. Moonzoo Kim Initialize and Finish public void initialize() Executed before a target program starts To initialize the data structure and read user inputs public void finish() Executed when a target program terminates Analyze the monitored data and print out the result CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Method Related Probes public void methodEnterBefore(Integer iid, Integer thread, String method) Executed before a target method is called iid: the unique identifier of an inserted probe (i.e., code location) thread: the unique identifier of a current thread method: the signature of the called method public void methodExitAfter(Integer iid, Integer therad, String method) Executed after a method call is returned CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Locking Related Probe public void lockBefore(Integer iid, Integer thread, Integer lock, Object actualLock) Executed before a synchronized block or a synchronized method call lock: the unique identifier of a target lock (i.e. object) actualLock: the memory address to a target lock public void lockAfter(Integer iid, Integer thread, Integer lock, Object actualLock) Executed after entering a synchronized block or a synchronized method public void unlockAfter(Integer iid, Integer thread, Integer lock, Object actualLock) Executed after existing a synchronized block or a synchronized method CalFuzzer Tutorial, Prof. Moonzoo Kim

Data Access Related Probes (1/2) public void readBefore(Integer iid, Integer thread, Long memory, boolean isVolatile) Executed before every read operation memory: the unique identifier of a target memory address isVolatile: whether or not a target memory address is volatile (free from data race) http://en.wikipedia.org/wiki/Volatile_variable public void readAfter(Integer iid, Integer thread, Long memory, boolean isVolatile) Executed after every read operation public void writeBefore(Integer iid, Integer thread, Long memory, boolean isVolatile) Executed before every write operation public void writeAfter(Integer iid, Integer thread, Long memory, boolean isVolatile) Executed after every write operation CalFuzzer Tutorial, Prof. Moonzoo Kim

Data Access Related Probes (2/2) Race conditions may occur when there is no synchronization in data access probes Thread-1 Thread-2 writeBefore(x): assume that Thread-1 will access x next writeBefore(x): write(x) write(x) CalFuzzer Tutorial, Prof. Moonzoo Kim

Wait and Notify Related Probes public void waitAfter(Integer iid, Integer thread, Integer lock) Executed after awaken from a waiting operation In Java, a thread can wait on an object, similar to lock/unlock public void notifyBefore(Integer iid, Integer thread, Integer lock) Executed before a notify operation public void notifyAllBefore(Integer iid, Integer thread, Integer lock) Executed after a notify operation CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Thread Related Probes public void startBefore(Integer iid, Integer parent, Integer child) Executed before starting a new thread parent: the unique identifier of the thread that creates a new thread child: the unique identifier of a new thread public void joinAfter(Integer iid, Integer parent, Integer child) Executed after the join operation parent: the unique identifier of the thread that joins on a child thread child: the unique identifier of the child thread CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Useful APIs javato.activetesting.common.Parameters contains the environment configurations on CalFuzzers javato.activetesting.analysis.Observer.getIidToLine(iid) returns a code location as String for a given iid CalFuzzer Tutorial, Prof. Moonzoo Kim

CalFuzzer Tutorial, Prof. Moonzoo Kim Ant Script CalFuzzer uses Apache Ant to build (i.e. compile Java source code) and execute analysis techniques The build script is defined in build.xml The execution scripts are defined in run.xml clean instr Run the generic instrumentor for a target program javato.work.dir: the work directory of a target program javato.app.main.class: the class name of a target program analysis-once Generate a test case execution with a dynamic analyzer javato.activetesting.analysis.class: the class name of the dynamic analysis technique in CalFuzzer CalFuzzer Tutorial, Prof. Moonzoo Kim