Garbage Collection and High-Level Languages Programming Languages Fall 2003.

Slides:



Advertisements
Similar presentations
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Advertisements

Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
Recitation 7 – 3/5/01 Outline Control Flow Memory Allocation –Lab 3 Details Shaheen Gandhi Office Hours: Wednesday.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
Microprocessors VLIW Very Long Instruction Word Computing April 18th, 2002.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
CSC1016 Coursework Clarification Derek Mortimer March 2010.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
Run-Time Storage Organization
Lecture 36: Programming Languages & Memory Management Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due.
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
Garbage collection (& Midterm Topics) David Walker COS 320.
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.
Uniprocessor Garbage Collection Techniques Paul R. Wilson.
Stacks and HeapsCS-502 Fall A Short Digression Stacks and Heaps CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
1 What NOT to do I get sooooo Frustrated! Marking the SAME wrong answer hundreds of times! I will give a list of mistakes which I particularly hate marking.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
CSSE501 Object-Oriented Development. Chapter 12: Implications of Substitution  In this chapter we will investigate some of the implications of the principle.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Memory management (CTM 2.5) Carlos Varela RPI April 6, 2015.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
OOPLs /FEN March 2004 Object-Oriented Languages1 Object-Oriented Languages - Design and Implementation Java: Behind the Scenes Finn E. Nordbjerg,
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
COMP3190: Principle of Programming Languages
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
Finalizers, this reference and static Sangeetha Parthasarathy 06/13/2001.
GARBAGE COLLECTION IN AN UNCOOPERATIVE ENVIRONMENT Hans-Juergen Boehm Computer Science Dept. Rice University, Houston Mark Wieser Xerox Corporation, Palo.
Memory Management -Memory allocation -Garbage collection.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
An Efficient, Incremental, Automatic Garbage Collector P. Deutsch and D. Bobrow Ivan JibajaCS 395T.
Memory Management CSCI 2720 Spring What is memory management? “the prudent utilization of this scarce resource (memory), whether by conservation,
CSE 220 – C Programming malloc, calloc, realloc.
Dynamic Allocation in C
Garbage Collection What is garbage and how can we deal with it?
Core Java Garbage Collection LEVEL – PRACTITIONER.
Names and Attributes Names are a key programming language feature
Type Checking, and Scopes
Memory Management 6/20/ :27 PM
Dynamic Memory Allocation
Storage Management.
Concepts of programming languages
Java Review: Reference Types
Storage.
Simulated Pointers.
Simulated Pointers.
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
COMP755 Advanced Operating Systems
C. M. Overstreet Old Dominion University Fall 2005
The Three Attributes of an Identifier
C. M. Overstreet Old Dominion University Fall 2007
Run-time environments
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

Garbage Collection and High-Level Languages Programming Languages Fall 2003

The Notion of Garbage Collection In a language like Python, we are treat high level data structures like integers. In a language like Python, we are treat high level data structures like integers. Consider a = [1,2,3,6,8,9]; … a = [6.9]; Consider a = [1,2,3,6,8,9]; … a = [6.9]; What happened to the old list? What happened to the old list? Answer from Python programmer: Huh? Answer from Python programmer: Huh?

More on the Basic Notion What do you mean Huh? What do you mean Huh? Sorry I don’t understand, if I write a = 10; … a = 23; Sorry I don’t understand, if I write a = 10; … a = 23; I don’t worry about what happens to the 10, it is just overwritten by the 23 and the 10 is gone. I don’t worry about what happens to the 10, it is just overwritten by the 23 and the 10 is gone.

More on the Basic Notion Yes, but there is a big difference between integers. Integers fit in one word, but lists require dynamic allocation and you have to make sure the dynamic memory is released and reclaimed or you have a memory leak. Yes, but there is a big difference between integers. Integers fit in one word, but lists require dynamic allocation and you have to make sure the dynamic memory is released and reclaimed or you have a memory leak. Sorry I don’t know what you are talking about, to me the two cases are identical. Sorry I don’t know what you are talking about, to me the two cases are identical.

The Point of This If we want genuine high level languages, we do indeed what to treat the two cases as the same If we want genuine high level languages, we do indeed what to treat the two cases as the same And it is not acceptable to have the programmer have to worry about low level implementation details like releasing memory. And it is not acceptable to have the programmer have to worry about low level implementation details like releasing memory.

The Solution: Garbage Collection So, at the implementation level we do indeed have to release and reclaim the memory, but it has to be done automatically (garbage collected). So, at the implementation level we do indeed have to release and reclaim the memory, but it has to be done automatically (garbage collected). Very easy to describe at the abstract level, since garbage collection is semantic free, it’s just a memory optimization. Very easy to describe at the abstract level, since garbage collection is semantic free, it’s just a memory optimization. But implementation concepts are not so clear. But implementation concepts are not so clear.

Some Approaches Try to release memory as soon as it is garbage. Try to release memory as soon as it is garbage. But then we have to be able to determine this efficiently. But then we have to be able to determine this efficiently. Clever idea, reference counts keep track of how many people are referencing a chunk of memory. Clever idea, reference counts keep track of how many people are referencing a chunk of memory. If count is zero, memory is garbage If count is zero, memory is garbage But what about cycles  But what about cycles 

Type Accurate Garbage Collection Figure out all the “roots” in the program, these are values accessible directly by the program which can reference memory blocks. Figure out all the “roots” in the program, these are values accessible directly by the program which can reference memory blocks. These blocks are not garbage, also any blocks referenced by these blocks (recursively to all levels) are not garbage These blocks are not garbage, also any blocks referenced by these blocks (recursively to all levels) are not garbage Everything else is garbage. Everything else is garbage.

Requirements for TA Garbage Collection At run time, when garbage collection occurs, we have to be able to trace all references. At run time, when garbage collection occurs, we have to be able to trace all references. This means that we need information at run-time on the exact data layouts of all data structures in use. This means that we need information at run-time on the exact data layouts of all data structures in use. Probably we have this in Python and other dynamic languages, but less likely to be true in static languages. Probably we have this in Python and other dynamic languages, but less likely to be true in static languages.

Conservative Garbage Collection Assume that if a block is not garbage then there is somewhere in memory a word containing the address of this block. Assume that if a block is not garbage then there is somewhere in memory a word containing the address of this block. Scan in use memory blocks for all addresses of memory blocks, assume all these blocks are not garbage. All other blocks are garbage Scan in use memory blocks for all addresses of memory blocks, assume all these blocks are not garbage. All other blocks are garbage But what if an integer value happens to look like the address of a block. But what if an integer value happens to look like the address of a block.

Worry Spots for Garbage Collection What if some global variables are logically dead, and will be clobbered, but have not been reassigned yet. May hold on to garbage (even with TA Gcol) What if some global variables are logically dead, and will be clobbered, but have not been reassigned yet. May hold on to garbage (even with TA Gcol) What if cycles and using reference counts What if cycles and using reference counts What if conservative gcol, and large blocks retained by accident. What if conservative gcol, and large blocks retained by accident.

Garbage Collection and Real-Time If we use stop-and-collect approach (wait till we run out of memory, then do a TC or conservative garbage collection), this may take a hard to analyze amount of time. If we use stop-and-collect approach (wait till we run out of memory, then do a TC or conservative garbage collection), this may take a hard to analyze amount of time. This hard to analyze amount of time may occur at an embarrassing moment: This hard to analyze amount of time may occur at an embarrassing moment: WARNING: MISSILE THREAD DETECTED! WARNING: MISSILE THREAD DETECTED! (system msg): please wait, garbage collection in progress, normal execution will be resumed as soon as possile (system msg): please wait, garbage collection in progress, normal execution will be resumed as soon as possile

Garbage Collection and Safety-Critical Programs How can we analyze memory use How can we analyze memory use Hard anyway in a language like Python Hard anyway in a language like Python And made harder by garbage collection And made harder by garbage collection Usually we simply forbid dynamic allocation Usually we simply forbid dynamic allocation Does that mean no Python in the next Boeing plane – probably! Does that mean no Python in the next Boeing plane – probably!