15-213 Recitation 7 – 3/5/01 Outline Control Flow Memory Allocation –Lab 3 Details Shaheen Gandhi Office Hours: Wednesday.

Slides:



Advertisements
Similar presentations
An Implementation of Mostly- Copying GC on Ruby VM Tomoharu Ugawa The University of Electro-Communications, Japan.
Advertisements

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
Dynamic Memory Management
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
Dynamic Memory Allocation I Topics Simple explicit allocators Data structures Mechanisms Policies CS 105 Tour of the Black Holes of Computing.
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts / : Introduction to Computer Systems 18 th Lecture, March 24, 2015 Instructors:
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
5. Memory Management From: Chapter 5, Modern Compiler Design, by Dick Grunt et al.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS414 C Programming Tutorial Ben Atkin
OS Fall’02 Memory Management Operating Systems Fall 2002.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
C and Data Structures Baojian Hua
CS61C Midterm Review on C & Memory Management Fall 2006 Aaron Staley Some material taken from slides by: Michael Le Navtej Sadhal.
Memory Layout C and Data Structures Baojian Hua
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
COP 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Introduction to Processes CS Intoduction to Operating Systems.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar.
Chapter 4 Memory Management Virtual Memory.
University of Washington Today Finished up virtual memory On to memory allocation Lab 3 grades up HW 4 up later today. Lab 5 out (this afternoon): time.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Processes and Virtual Memory
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
CSC 660: Advanced Operating Systems
Spring, 2011 –– Computational Thinking – Dennis Kafura – CS 2984 Data Structures Mapping complex structures to linear memory.
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Chapter 17 Free-Space Management
Object Lifetime and Pointers
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Requirements, Partitioning, paging, and segmentation
Names and Attributes Names are a key programming language feature
Dynamic Memory Allocation
Overview of today’s lecture
PA1 is out Best by Feb , 10:00 pm Enjoy early
Checking Memory Management
The Hardware/Software Interface CSE351 Winter 2013
Optimizing Malloc and Free
More examples How many processes does this piece of code create?
System Structure and Process Model
Main Memory Background Swapping Contiguous Allocation Paging
Memory Allocation CS 217.
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Operating System Chapter 7. Memory Management
Recitation 5 – 2/19/01 Outline
CSCI 380: Operating Systems William Killian
CS703 - Advanced Operating Systems
CS510 Operating System Foundations
Buddy Allocation CS 161: Lecture 5 2/11/19.
Structure of Processes
Presentation transcript:

Recitation 7 – 3/5/01 Outline Control Flow Memory Allocation –Lab 3 Details Shaheen Gandhi Office Hours: Wednesday 1:30 – 2:30 Wean 3108 Reminders Lab 3: Conservative Garbage Collector Checkpoint Due 3/13 Lab Due 3/21 At least there’s nothing over Spring Break (I think)

Exceptional Control Flow Higher level abstractions for dealing with miscellaneous conditions: –Error conditions that require errors to be thrown up many stack frames (functions) –Interrupt handling (I/O – Keyboard, Mouse, Network, etc.) –Familiarize yourself with wait(2), exec(3), fork(2), signal(2), etc.

sigsetjmp(3) & siglongjmp(3) sigsetjmp(3) Saves state about: –Stack Context –Registers –Program Counter –Blocked Signals siglongjmp(3) Starts executing by immediately executing code from sigsetjmp() Man page says: “setjmp() and sigsetjmp make programs hard to understand and maintain. If possible an alternative should be used.” –But we make you do it anyway

Dynamic Memory Allocation Applications need variable amounts of memory (unknown at compile time). Use dynamic memory allocation to reserve chunks of memory at run-time. Equivalent to the new operator in Java is malloc(3) in C free(3) un-reserves (‘frees’) malloc ’d memory. –No equivalent in Java, since Java does nifty garbage collection

Dynamic Memory Allocation: How it’s done First a picture kernel virtual memory Memory mapped region for shared libraries run-time heap (via malloc) program text (.text) initialized data (.data) uninitialized data (.bss) stack 0 the “brk” ptr

Dynamic Memory Allocation: How it’s done The malloc package maintains the state of the run-time heap –Basically tons of grungy pointer arithmetic –The “Heap” is just the area between two addresses: dseg_lo and dseg_hi malloc must find a valid contiguous block of memory in the heap and return this to the application free must return the unused space to the heap for further allocations How the functions do this is entirely up to you –Generally, fast and inefficient is preferrable to complex, efficient designs, although both are primary concerns

Conservative Garbage Collection Reclaim unused space from the application –So we can use it to fill future allocations How to do it? –Mark and Sweep Find everything you (might) need Reclaim the rest Where do you find everything you need? –Start with the “roots” Current registers Stack Heap (yes, the same one malloc manages) –Then do a depth first search on the data you find

Conservative Garbage Collection: An Example typedef struct node { struct node *next; } Node; void taste(Node *h) { Node *n = h; h = malloc(sizeof(Node)); h->next = n; } void srees(Node **h) { Node *n = *h; *h = (*h)->next; free(*h); } Node *head = malloc(sizeof(Node)); head->next = malloc(sizeof(Node)); taste(head); srees(&head); What’s wrong?

Lab 3 Tips Start Early –Checkpoint next Wednesday –You need a working collector by then Read the Lab handout –Now read it again Don’t write any code until you know what you want to do Review Pointer Arithmetic