Space Exploration EECS /25

Similar documents
Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Introduction Basic elements of Java

02 B The Java Virtual Machine

Static Analysis of Dynamic Languages. Jennifer Strater

Over-view. CSc Java programs. Java programs. Logging on, and logging o. Slides by Michael Weeks Copyright Unix basics. javac.

JVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls

BASICS.

EECS Mission Critical Systems

Program Dynamic Analysis. Overview

3/15/18. Overview. Program Dynamic Analysis. What is dynamic analysis? [3] Why dynamic analysis? Why dynamic analysis? [3]

CS 11 java track: lecture 1

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Compiler construction 2009

CSE 431S Final Review. Washington University Spring 2013

Under the Hood: The Java Virtual Machine. Problem: Too Many Platforms! Compiling for Different Platforms. Compiling for Different Platforms

Improving Java Performance

CS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II

Bugs in software. Using Static Analysis to Find Bugs. David Hovemeyer

Are You Covered? Keith D Gregory Philly JUG 14 October 2009

Compiling Techniques

Improving Java Code Performance. Make your Java/Dalvik VM happier

Run-time Program Management. Hwansoo Han

Problem: Too Many Platforms!

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Compiling for Different Platforms. Problem: Too Many Platforms! Dream: Platform Independence. Java Platform 5/3/2011

301AA - Advanced Programming [AP-2017]

Tutorial 3: Code Generation

Advanced Programming Introduction

1. Download the JDK 6, from

Advances in Programming Languages: Generics, interoperability and implementation

Exercise 7 Bytecode Verification self-study exercise sheet

Code Profiling. CSE260, Computer Science B: Honors Stony Brook University

Shared Mutable State SWEN-220

Code Generation Introduction

CS 231 Data Structures and Algorithms, Fall 2016

COMP3131/9102: Programming Languages and Compilers

1 689, High-Performance Computing with Java Technology

How to make a "hello world" program in Java with Eclipse *

Nu: Towards a Flexible and Dynamic Aspect- Oriented Intermediate Language Model

Programming Language Concepts: Lecture 2

Compilation 2012 Code Generation

Programming Language Concepts: Lecture 1

JPF Lab Formal Methods Summer School 2011 Menlo College

Concurrency EECS /36

The Java Virtual Machine

CSC 4181 Handout : JVM

Plan for Today. Safe Programming Languages. What is a secure programming language?

Taming the Java Virtual Machine. Li Haoyi, Chicago Scala Meetup, 19 Apr 2017

Getting started with Java

Java Bytecode (binary file)

INFO Object-Oriented Programming

Introduction to Java. Nihar Ranjan Roy.

JSR 292 Cookbook: Fresh Recipes with New Ingredients

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Test the Byte Class 1 / 17

Chapter 3 Intro to Java

INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY. Instructors: Crista Lopes Copyright Instructors.

Java Code Coverage Mechanics. by Evgeny Mandrikov at EclipseCon Europe 2017

Delft-Java Link Translation Buffer

An overview of Java, Data types and variables

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

COMP6700/2140 JDK Tools

Java Code Coverage Mechanics Evgeny Mandrikov Marc Hoffmann #JokerConf 2017, Saint-Petersburg

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CompSci 125 Lecture 02

Simple Java Programs. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Intro to multi-threaded programming in Java

1B1a Programming I Getting Started

1.1 Your First Program

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Java byte code verification

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Java PathFinder: a tool to detect bugs in Java code

Let's talk about invokedynamic

CS263: Runtime Systems Lecture: High-level language virtual machines. Part 1 of 2. Chandra Krintz UCSB Computer Science Department

CS11 Java. Fall Lecture 1

Chapter 5. A Closer Look at Instruction Set Architectures

Functional Programming in Java. CSE 219 Department of Computer Science, Stony Brook University

COMP1007 Principles of Programming

Java Code Coverage Mechanics

INTERMEDIATE REPRESENTATIONS RTL EXAMPLE

Nu: Towards a Flexible and Dynamic Aspect- Oriented Intermediate Language Model

Object-oriented programming in...

Java Class Loading and Bytecode Verification

Lesson 01 Introduction

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Week 2: Data and Output

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

Java Socket Workshop. July Purpose of this workshop:

CS 177 Recitation. Week 1 Intro to Java

Day 2. COMP 1006/1406A Summer M. Jason Hinek Carleton University

The Java Virtual Machine

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Exceptions Handling Errors using Exceptions

Note that this is essentially the same UML as the State pattern! The intent of each of the two patterns is quite different however:

Transcription:

1/25 Space Exploration EECS 4315 www.eecs.yorku.ca/course/4315/

Nondeterminism 2/25 Nondeterministic code is code that, even for the same input, can exhibit different behaviours on different runs, as opposed to deterministic code. Randomization and concurrency both give rise to nondeterminism.

Testing nondeterministic code 3/25 public class RandomFraction { public static void run() { Random random = new Random(System.currentTimeMillis()); System.out.print(1 / random.nextint(1000000)); } } Question If we run the above app 1,000,000 times, what is the probability that it does not throw an exception in any of those runs?

Testing nondeterministic code 4/25 Answer The probability of choosing zero is

Testing nondeterministic code 4/25 Answer The probability of choosing zero is 1 1,000,000. The probability of not choosing zero is

Testing nondeterministic code 4/25 Answer 1 The probability of choosing zero is 1,000,000. The probability of not choosing zero is 1 1 1,000,000 = 999,999 1,000,000. The probability of not choosing zero one million times in a row is

Testing nondeterministic code 4/25 Answer 1 The probability of choosing zero is 1,000,000. The probability of not choosing zero is 1 1 1,000,000 = 999,999 1,000,000. The probability of not choosing zero one million times in a row is ( 999,999 1,000,000 )1,000,000 0.37.

Limitations of testing 5/25 Limitations of testing of nondeterministic code include no guarantee that all different behaviours have been checked, and errors may be difficult to reproduce.

Alternatives to testing 6/25 To detect bugs in nondeterministic code, testing needs to be supplemented with other approaches. Question How to tackle the limitations of testing of nondeterministic code?

Alternatives to testing 6/25 To detect bugs in nondeterministic code, testing needs to be supplemented with other approaches. Question How to tackle the limitations of testing of nondeterministic code? Answer Control the nondeterminism: this allows us to systematically check all different behaviours and reproduce errors.

Exercises 7/25 In groups of two or three, solve the following exercises. Fill in the body of the following main method. public class Exercise { public static void main(string[] args) { Random random = new Random(); } } using only the nextboolean method of the Random class.

Exercises 8/25 1 The app prints either 1 or 2, both with probability 0.5. 2 The app prints 1, 2, 3, or 4, each with probability 0.25. 3 The app prints any integer, each with positive but not necessarily equal probability.

Executions 9/25 The first app has two different executions. The second app has four different executions Question How many different executions has the third application?

Executions 9/25 The first app has two different executions. The second app has four different executions Question How many different executions has the third application? Answer 2 32 = 4, 294, 967, 296.

Execution 10/25 An execution consists of states connected by transitions.

State 11/25 A state of a Java virtual machine (JVM) includes the heap, for each thread its state (runnable, waiting, terminated,... ), its stack, etc, etc. https://docs.oracle.com/javase/8/docs/platform/jvmti/ jvmti.html

Transition 12/25 A transition of a JVM takes the JVM from one state to another by executing a bytecode instruction.

Java code 13/25 public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World"); } }

Java bytecode 14/25 The command javap -c HelloWorld.class produces 0: getstatic // of attribute System.out of class PrintStream 3: ldc // String "Hello World" 5: invokevirtual // of method println with argument String 8: return

Java code and execution 15/25 public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World"); } } getstatic ldc invokevirtual return

Java code 16/25 public class RedOrGreen { public static void main(string[] args) { Random random = new Random(); if (random.nextboolean()) { System.out.println("Red"); } else { System.out.println("Green"); } } }

Java bytecode 17/25 0: new 3: dup 4: invokespecial 7: astore_1 8: aload_1 9: invokevirtual 12: ifeq 15: getstatic 18: ldc 20: invokevirtual 23: goto 26: getstatic 29: ldc 31: invokevirtual 34: return

Executions 18/25 Question Draw the state-transition diagram.

Executions 18/25 Question Draw the state-transition diagram.

Executions 19/25 Question Draw the state-transition diagram corresponding to Random random = new Random(); int value = 0; while (random.nextboolean()) { value++; } System.out.println(value);

Executions 20/25 1 0 8 transitions 5 transitions

Executions 21/25 2 1 5 transitions

Executions 22/25 3 2 5 transitions

Executions 23/25 2 31 2 31 1 5 transitions

Executions 24/25 1 0 5 transitions

The state space explosion problem 25/25 Problem The size of the state space, that is, the number of states, may become very large.

The state space explosion problem 25/25 Problem The size of the state space, that is, the number of states, may become very large. This is one of the major challenges in model checking.