Oukseh Lee, Hongseok Yang, and Kwangkeun Yi {cookcu; hyang;

Slides:



Advertisements
Similar presentations
1 Parametric Heap Usage Analysis for Functional Programs Leena Unnikrishnan Scott D. Stoller.
Advertisements

Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Code Generation Steve Johnson. May 23, 2005Copyright (c) Stephen C. Johnson The Problem Given an expression tree and a machine architecture, generate.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
CORK: DYNAMIC MEMORY LEAK DETECTION FOR GARBAGE- COLLECTED LANGUAGES A TRADEOFF BETWEEN EFFICIENCY AND ACCURATE, USEFUL RESULTS.
Increasing Memory Usage in Real-Time GC Tobias Ritzau and Peter Fritzson Department of Computer and Information Science Linköpings universitet
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Run-Time Storage Organization
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina International Symposium on Memory Management June, 2006.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
PUBLIC: A Decision Tree Classifier that Integrates Building and Pruning RASTOGI, Rajeev and SHIM, Kyuseok Data Mining and Knowledge Discovery, 2000, 4.4.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
Experiments on the Effectiveness of an Automatic Insertion of Memory Reuses into ML-like Programs Oukseh Lee (Hanyang University) Kwangkeun Yi (Seoul National.
Effectiveness of an Automatic Insertion of Safe Memory Reuses into ML-like Programs Oukseh Lee and Kwangkeun Yi {oukseh; Seoul National.
Automatic Verification of Pointer Programs using Grammar-based Shape Analysis Hongseok Yang Seoul National University (Joint Work with Oukseh Lee and Kwangkeun.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Prolog Program Style (ch. 8) Many style issues are applicable to any program in any language. Many style issues are applicable to any program in any language.
Object-Oriented Programming Chapter Chapter
SAFEWARE System Safety and Computers Chap18:Verification of Safety Author : Nancy G. Leveson University of Washington 1995 by Addison-Wesley Publishing.
CMSC 330: Organization of Programming Languages Operational Semantics.
Shape & Alias Analyses Jaehwang Kim and Jaeho Shin Programming Research Laboratory Seoul National University
Symstra: A Framework for Generating Object-Oriented Unit Tests using Symbolic Execution Tao Xie, Darko Marinov, Wolfram Schulte, and David Notkin University.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Memory Management in Java Mr. Gerb Computer Science 4.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
CSE691 Software Models and Analysis.
Data Types In Text: Chapter 6.
Data Flow Analysis Suman Jana
Planning & System installation
Heap Chapter 9 Objectives Define and implement heap structures
Introduction to Parsing (adapted from CS 164 at Berkeley)
Parallel Programming By J. H. Wang May 2, 2017.
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Upper Bound for Defragmenting Buddy Heaps
Run-time organization
CS 153: Concepts of Compiler Design November 28 Class Meeting
Introduction Applications Balance Factor Rotations Deletion Example
Objective: Understand Concepts related to trees.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Capriccio – A Thread Model
Data Structures and Analysis (COMP 410)
Computer Organization & Compilation Process
University Of Virginia
Data Structures and Algorithms
Database Management Systems (CS 564)
Objective of This Course
Zhen Jiang West Chester University
Closure Representations in Higher-Order Programming Languages
CSE341: Programming Languages Lecture 12 Equivalence
A Robust Data Structure
CSE341: Programming Languages Lecture 12 Equivalence
CSE341: Programming Languages Lecture 12 Equivalence
Dongyun Jin, Patrick Meredith, Dennis Griffith, Grigore Rosu
On the Designing of Popular Packages
Presentation made by Steponas Šipaila
CSE341: Programming Languages Lecture 12 Equivalence
Computer Organization & Compilation Process
CSE341: Programming Languages Lecture 12 Equivalence
Run-time environments
Topic 2b ISA Support for High-Level Languages
B+-trees In practice, B-trees are not used much as defined earlier.
Presentation transcript:

An Example of Program Analysis: Inserting Safe Memory Re-use Commands into ML-like Programs Oukseh Lee, Hongseok Yang, and Kwangkeun Yi {cookcu; hyang; kwang}@ropas.kaist.ac.kr Research On Program Analysis System, KAIST http://ropas.kaist.ac.kr December 5, 2002 CS520

Motivation (1/2) Thanks to many compilation techniques, ML can produce fast code, but still has the overhead for managing the memory. Garbage collection is usually faster than the manual memory management. Then what is the reason of the memory inefficiency?

Motivation (2/2) Unnecessary allocation in ML programs: 1 2 3 5 6 1 2 fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in h::z 1 2 3 5 6 1 2 3 4

Our Goal To insert safe memory-reuse commands: 1 2 3 5 6 4 fun insert i l = case l of [] => i::[] | h::t => if i<h then i::l else let z = insert i t in (free l; h::z) 1 2 3 5 6 4

How to Find it? By an accurate but effective program analysis: Individual heap-cell as the unit of analysis. Context pruning at the conditional branches. Keeping sharing information using multi-set formula. Parameterized analysis, so poly-variance at function calls. Deallocation inside a function can be conditioned by extra boolean parameters (called dynamic flags).

Experimental Result

Example: copyright free a? Tree a will not be used later fun copyright a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright a2 in Node(a1, r) free a?

Key: Precise Separation Tree a will not be used later fun copyright a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright a2 in Node(a1, r) # all left subtrees # all result trees free a?

Safe Only Under the Assumption Tree a will not be used later fun copyright a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright a2 in (free a; Node(a1, r)) Tree a has no shared sub-parts X

Passing the Assumption in Run-time Tree a may have shared sub-parts Tree a will not be used later fun copyright [b,bs] a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright [bÆ:bs,bs] a2 in (free a when b; Node(a1, r))

Input Language

Output Language

First Step Memory-usage analysis: free-commands insertion: Computes the memory-type (abstraction of heap objects) and usage for each expression. free-commands insertion: Inserts free-commands and adds dynamic flags using the result from the memory-usage analysis.

How to Represent a Set of Heap Objects? x x x x let x = ... in ...

A Set of Locations (NO!) Not enough for sharing information. x x y y x = Node(Leaf,Leaf) y = Node(x,x) x = Node(Leaf,Leaf) y = Node(x,Leaf) x y x y

Multi-set Formula Describes a set of locations with sharing information: note:

Memory-Type for a Tree Describes a set of trees: root left right note:

Memory-Type for a Function Describes the behavior of the function. The memory-type of function copyright is: input new result usage

Analysis fun copyright a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright a2 in Node(a1, r)

Second Step Memory-usage analysis: Computes the memory-type and usage for each expression. free-commands insertion: Inserts free-commands and adds dynamic flags using the result from the memory-usage analysis.

Insertion (1/3) fun copyright [b,bs] a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright a2 in Node (a1, r) b: it is safe to free the input (excluding the result) bs: the input may have shared sub-parts.

Insertion (2/3) b :bs fun copyright [b,bs] a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright a2 in Node (a1, r) b :bs

Insertion (3/3) a: fun copyright [b,bs] a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright [bÆ:bs,bs] a2 in Node (a1, r) b a: true true

Result fun copyright [b,bs] a = case a of Leaf => Leaf | Node(a1,a2) => let r = copyright [bÆ:bs,bs] a2 in (free a when b; Node (a1, r))

Conclusion We present a static analysis and source-level transformation for inserting safe memory-reuse commands. Reuse ratio: 5.2-98.7% Analysis cost: 415-4500 lines/sec Weak for prevalent sharing but enough for usual cases. Plan to apply this analysis to our nML compiler.