Cons operation calls for the allocation of a new cons-cell, like new in Pascal. How to make it free?

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Procedures. 2 Procedure Definition A procedure is a mechanism for abstracting a group of related operations into a single operation that can be used repeatedly.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Programming Paradigms and languages
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
Storage Reclamation Explicit Erasure Reference Count Garbage collection.
CS 536 Spring Automatic Memory Management Lecture 24.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
MacLennan Chapter 1 The Beginning: Pseudo-code Interpreters.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
CS 536 Spring Run-time organization Lecture 19.
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
Programming Languages Structure
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Linked lists and memory allocation Prof. Noah Snavely CS1114
Run-time Environment and Program Organization
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS 363 Comparative Programming Languages
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
Shayan Ehsani Hessameddin Akhlaghpour. Remembrance History Eval funciton Applications.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
1 Languages and Compilers (SProg og Oversættere) Heap allocation and Garbage Collection.
Object-Oriented Programming Chapter Chapter
GARBAGE COLLECTION IN AN UNCOOPERATIVE ENVIRONMENT Hans-Juergen Boehm Computer Science Dept. Rice University, Houston Mark Wieser Xerox Corporation, Palo.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Functional Programming
Object Lifetime and Pointers
Garbage Collection What is garbage and how can we deal with it?
Storage 18-May-18.
Why study programming languages?
Types for Programs and Proofs
PROGRAMMING LANGUAGES
CS 326 Programming Languages, Concepts and Implementation
Compiler Construction (CS-636)
ALGORITHMS AND FLOWCHARTS
Storage Management.
Data Structures Interview / VIVA Questions and Answers
Run-time organization
Concepts of programming languages
Automatic Memory Management
Compiler Construction
Programming Languages
Chapter 12 Memory Management
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

Cons operation calls for the allocation of a new cons-cell, like new in Pascal. How to make it free?

1. Explicit Erasure Adopted by Pascal (Dispose function) Releasing each cell by Programmer Linking the cell on to a Free-List

Problems with Explicit Erasure Programmers must work harder Who is the “Good” Programmer? Remember the words against Fortran Computer Take care of bookkeeping Details Violating the Security Principle Dangling Pointers ( pointers that do not point to an allocated cell)

Dangling Pointer A cell still referenced by several other lists Storage allocator reuses this cell Corrupt the storage allocator’s Data structures Dangling Ref. C Free-List

Garbage Collection with no explicit allocation/de-allocation: Responsible Design Principle

Reference count Explicit Erasure is Low level And Error-prone Return a cell to free storage when it is no longer needed (no longer accessible from the program) Keep track of the accessibility of each cell A cell is accessible only if it is referenced by the other accessible cells. The cells that are used by the interpreter are Directly Accessible

Reference count Maintain correctly Increment with additional reference Decrement when a reference destroyed Overwrite the pointer( rplaca , rplacd) The cell containing the pointer become inaccessible (reference count becomes zero) Free-list become exhausted no more free-cell available the program aborted 95% of reference counts are 1

Reference count decrement (C) : reference count (C) := reference count (C) -1; if reference count (C) = 0 then decrement (C^ left); decrement (C^ right); return C to free-list; end if.

Cyclic structures Are not reclaimed. One solution: Disallow cyclic structures Error prone & difficult to understand But some say: Cyclic structures are necessary for some problems. Another solution 

3. Garbage Collection Garbage : inaccessible cells which are not available for reuse Inaccessible cells are abandoned After the exhaustion of the free space the system enters a Garbage Collection Phase in which it identifies all of the unused cells and return them to free storage Ignores the storage reclamation until a crisis develops then deals with that Mark-Sweep garbage collector Mark phase : marks all of the accessible cells Sweep phase : places all the inaccessible cells on the free list

Mark phase Mark phase: for each root R, mark(R) mark (R) : if R is not marked then: set mark bit of R; mark (R^. left); mark (R^. right); end if.

Mark phase There is a problem: So how does this work??? Mark phase is recursive Requires space for it’s activation records. Garbage Collector is called only in crisis (no free storage available) So how does this work??? Invoke G.C before the last cell is allocated and there is enough space for G.C ‘s stack Encode stack in a clever way (reversing link in the marked nodes)

sweep phase Unmarked cell: Marked cell: Inaccessible & can be linked on to the Free-list Marked cell: Accessible & we reset its mark bit for the next garbage collection. Sweep phase: for each cell c: if c is marked then reset c’s mark bit, else link c onto the free-list.

Problems with Garbage Collection Expensive in a large address space It should trace down all of the lists Visit every cell in the memory There is a high-speed execution of the program until a garbage collection take place. The system will stop for minutes while a garbage collection is in the progress. This is apparent in an interactive system A serious problem in real time situations (the program most be guaranteed to respond at a certain amount of time ) solutions Parallel garbage collection: G.C takes place in parallel with normal program execution

LISP Evaluation Successful in Artificial Intelligence Ability to represent and manipulate complex interrelationships among symbolic data. Suited to iII-Specified Problems (In artificial intelligence) the problem will not well understood Specification of Abstract Data Types: 1st decide what data structures and data types 2nd necessary operation in terms of their input and output Finally the representation of the data structures and operators fixed On ill-defined problems this methodology does not work well: What operations on a data type will be required is unknown. It is difficult to fix the input-output when ultimate requirements that the data structure must satisfy are not clear. Lisp with few restriction on invocation of procedures and passing parameters is well suited.

Easy to extend, preprocess, generate Lisp has simple structure syntax. The representation of the Lisp programs as Lisp lists. It has simplified writing programs that process other Lisp programs such as compilers and optimizer. It is very easy to manage Lisp programs using other Lisp programs. ( As we saw in the eval interpreter ) Lisp programmers write many programming tools in Lisp It has encouraged special–purpose extensions to Lisp for pattern matching, text processing, editing, type checking … This tools are provided by conventional languages So why? In conventional languages they are complicated because Pascal and … have character-oriented syntax

Lisp programming environments developed A system that supports all phases of programming including design, program entry, debugging, documentation, maintenance Lisp programs can manipulate other Lisp programs has led to the development of a wide variety of Lisp programming tools. The Interlisp programming environment 1966: BBN( Bolt Beraneck Newman) 1972: a joint project with Xerox PARC (Palo Alto Research Center) that was renamed Interlisp. Grew during 1970s in response to the needs and ideas of implementers and users. The combination of Lisp language and an experimental approach to tool developmentproduced a highly integrated but loosely coupled and flexible programming environment.

Lisp’s inefficiency discouraged it’s use Why doesn’t every one use it? Because it is interpreted and often runs two orders of magnitude slower than the code produced by the compiler ( 2*o(n) n-> compiler) recursion was inefficient on most machines (we don’t have loop in Lisp) Dynamic storage allocation (and reclamation) is one of the more expensive aspects but it is also one of the most valuable (it was a slow process)

Languages Imperative languages : Applicative languages: Dependent heavily on assignment statements and a changeable memory for accomplishing a programming task. Applicative languages: The central idea is function application that is applying a function to it’s arguments.

Lisp shows what can be done with an applicative language Lisp is the closest thing to an applicative language in widespread use. The Lisp experience is evidence in favor of the practicality of functional programming languages.

Function-oriented languages There is an emphasis on the use of pure functions Syntactic structure: Prefix notation Data structure: List is the principle data structure Control structure: Conditional expression and recursion are basic control structures.

Function-oriented language properties High level of abstraction which removes details and committing many classes of errors. (abstraction principle) Independent of assignment statements, therefore allowing functions to be evaluated in many different orders. Suitable for parallel programming. It is easier to prove the correctness mathematically and more suitable for analysis.