Region-based Memory Management. Advanced Operating Systems Lecture 10
|
|
- Ariel Hancock
- 5 years ago
- Views:
Transcription
1 Region-based Memory Management Advanced Operating Systems Lecture 10
2 Lecture Outline Rationale Stack-based memory management Region-based memory management Ownership Borrowing Benefits and limitations 2
3 Rationale Garbage collection tends to have unpredictable timing and high memory overhead Real-time collectors exist, but are uncommon and have significant design implications for applications using them Manual memory management is too error prone Region-based memory management aims for a middle ground between the two approaches Safe, predictable timing Limited impact on application design 3
4 Stack-based Memory Management Automatic allocation/deallocation of variables on the stack is common and efficient: #include <math.h> #include <stdio.h> #include <stdlib.h> static double pi = ; static double conic_area(double w, double h) { double r = w / 2.0; double a = pi * r * (r + sqrt(h*h + r*r)); return a; int main() { double width = 3; double height = 2; double area = conic_area(width, height); printf("area of cone = %f\n", area); Global variables double pi = Stack frame for main() double width = double height = double area = Stack frame for conic_area() double w = double h = double r = double a = return 0; 4
5 Stack-based Memory Management Hierarchy of regions corresponding to call stack: Global variables Local variables in each function Lexically scoped variables within functions double vector_avg(double *vec, int len) { double sum = 0; Lifetime of sum local variable in function for (int i = 0; i < len; i++) { sum += vec[i]; Lifetime of i lexically scoped return sum / len; Variables live within regions, and are deallocated at end of region scope 5
6 Stack-based Memory Management Limitation: requires data to be allocated on stack Example: int hostname_matches(char *requested, char *host, char *domain) { char *tmp = malloc(strlen(host) + strlen(domain) + 2); sprintf(tmp, %s.%s, host, domain); if (strcmp(requested, host) == 0) { return 1; if (strcmp(requested, tmp) == 0) { return 1; return 0; The local variable tmp (pointer of type char *) is freed when the function returns; the allocated memory is not freed Heap storage has to be managed manually 6
7 Region-based Memory Allocation Stack allocation effective within a narrow domain can we extend the ideas to manage the heap? Create pointers to heap allocated memory Pointers are stored on the stack and have lifetime matching the stack frame pointers have type Box<T> for a pointer to heap allocated T The heap allocation has lifetime matching that of the Box when the Box goes out of scope, the heap memory it references is freed i.e., the destructor of the Box<T> frees the heap allocated T Efficient, but loses generality of heap allocation since ties heap allocation to stack frames 7
8 Region-based Memory Management For effective region-based memory management: Allocate objects with lifetimes corresponding to regions Track object ownership, and changes of ownership: What region owns each object at any time Ownership of objects can move between regions Deallocate objects at the end of the lifetime of their owning region Use scoping rules to ensure objects are not referenced after deallocation Example: the Rust programming language Builds on previous research with Cyclone language (AT&T/Cornell) Somewhat similar ideas in Microsoft s Singularity operating system 8
9 Returning Ownership of Data Returning data from a function causes it to outlive the region in which it was created: const PI: f64 = ; fn area_of_cone(w : f64, h : f64) -> f64 { let r = w / 2.0; let a = PI * r * (r + (h*h + r*r).sqrt()); Lifetime of local variables in area_of_cone return a; fn main() { let width = 3.0; let height = 2.0; Lifetime of a let area = area_of_cone(width, height); println!("area = {", area); 9
10 Returning Ownership of Data Runtime must track changes in ownership as data is returned Copies made of stack-allocated local variables; original deallocated, copy has lifetime of stack-allocated local variable in calling function Allows us to return a copy of a Box<T> that references a heap allocated value of type T Effective with a reference counting implementation Creating the new Box<T> temporarily increases the reference count on the heap-allocated T The original box is then immediately deallocated, reducing the reference count again (An optimised runtime can eliminate the changes to the reference count) The heap-allocated T is deallocated when the box goes out of scope of the outer region Allows data to be passed around, if it always has a single owner 10
11 Giving Ownership of Data % cat consume.rs fn consume(mut x : Vec<u32>) { x.push(1); Lifetime of a fn main() { let mut a = Vec::new(); a.push(1); a.push(2); Ownership of parameters passed to a function is transferred to that function Deallocated when function ends, unless it returns the data Data cannot be later used by the calling function enforced at compile time consume(a); Ownership of a transferred to consume() println!("a.len() = {", a.len()); % rustc consume.rs consume.rs:15:28: 15:29 error: use of moved value: `a` [E0382] consume.rs:15 println!("a.len() = {", a.len()); ^ 11
12 Borrowing Data % cat borrow.rs fn borrow(mut x : &mut Vec<u32>) { x.push(1); fn main() { let mut a = &mut Vec::new(); A mutable reference Functions can borrow references to data owned by an enclosing scope Does not transfer ownership of the data Naïvely safe to use, since live longer than the function a.push(1); a.push(2); borrow(a); println!("a.len() = {", a.len()); Can also return references to input parameters passed as references Safe, since these references must live longer than the function % rustc borrow.rs %./borrow a.len() = 3 % 12
13 Problems with Naïve Borrowing % cat borrow.rs fn borrow(mut x : &mut Vec<u32>) { x.push(1); fn main() { let mut a = &mut Vec::new(); a.push(1); a.push(2); borrow(a); println!("a.len() = {", a.len()); The borrow() function changes the contents of the vector But it cannot know whether it is safe to do so In this example, it is safe If main() was iterating over the contents of the vector, changing the contents might lead to elements being skipped or duplicated, or to a result to be calculated with inconsistent data Known as iterator invalidation % rustc borrow.rs %./borrow a.len() = 3 % 13
14 Safe Borrowing Rust has two kinds of pointer: &T a shared reference to an immutable object of type T &mut T a unique reference to a mutable object of type T Runtime system controls pointer ownership and use An object of type T can be referenced by one or more references of type &T, or by exactly 1 reference of type &mut T, but not both Cannot get an &mut T reference to data of type T that is marked as immutable Allows functions to safely borrow objects without needing to give away ownership To change an object: You either own the object, and it is not marked as immutable; or You have the only &mut reference to it Prevents iterator invalidation The iterator requires an &T reference, so other code can t get a mutable reference to the contents to change them: fn main() { let mut data = vec![1, 2, 3, 4, 5, 6]; for x in &data { data.push(2 * x); enforced at compile time fails, since push takes an &mut reference 14
15 Benefits Type system tracks ownership, turning run-time bugs into compile-time errors: Prevents memory leaks and use-after-free bugs Prevents iterator invalidation Prevents race conditions with multiple threads borrowing rules prevent two threads from getting references to a mutable object Efficient run-time behaviour timing and memory usage are predictable 15
16 Limitations of Region-based Systems Can t express cyclic data structures E.g., can t build a doubly linked list: a b c d Can t get mutable reference to c to add the link to d, since already referenced by b Many languages offer an escape hatch from the ownership rules to allow these data structures (e.g., raw pointers and unsafe in Rust) Can t express shared ownership of mutable data Usually a good thing, since avoids race conditions Rust has RefCell<T> that dynamically enforces the borrowing rules (i.e., allows upgrading a shared reference to an immutable object into a unique reference to a mutable object, if it was the only such shared reference) Raises a run-time exception if there could be a race condition, rather than preventing it at compile time 16
17 Limitations of Region-based Systems Forces programmer to consider object ownership early and explicitly Generally good practice, but increases conceptual load early in design process may hinder exploratory programming 17
18 Summary Region-based memory management with strong ownership and borrowing rules Efficient and predictable behaviour Strong correctness guarantees prevent many common bugs Constrains the type of programs that can be written Further reading: D. Grossman, G. Morrisett, T. Jim, M. Hicks, Y. Wang, and J. Cheney, Region-based memory management in Cyclone, Proc. ACM Conference on Programming Language Design and Implementation, Berlin, Germany, June DOI: / You re not expected to read/understand section 4 Will be discussed in tutorial 5 Region-Based Memory Management in Cyclone Dan Grossman Greg Morrisett Trevor Jim Michael Hicks Yanling Wang James Cheney Computer Science Department Cornell University Ithaca, NY {danieljg,jgm,mhicks,wangyl,jcheney@cs.cornell.edu ABSTRACT Cyclone is a type-safe programming language derived from C. The primary design goal of Cyclone is to let programmers control data representation and memory management without sacrificing type-safety. In this paper, we focus on the region-based memory management of Cyclone and its static typing discipline. The design incorporates several advancements, including support for region subtyping and a coherent integration with stack allocation and a garbage collector. To support separate compilation, Cyclone requires programmers to write some explicit region annotations, but acombinationofdefaultannotations,localtypeinference, and a novel treatment of region effects reduces this burden. As a result, we integrate C idioms in a region-based framework. In our experience, porting legacy C to Cyclone has required altering about 8% of the code; of the changes, only 6% (of the 8%) were region annotations. Categories and Subject Descriptors D.3.3 [Programming Languages]: Language Constructs and Features dynamic storage management General Terms Languages 1. INTRODUCTION Many software systems, including operating systems, device drivers, file servers, and databases require fine-grained This research was supported in part by Sloan grant BR- 3734; NSF grant ; AFOSR grants F , F , F , and F ; ONR grant N ; and NSF Graduate Fellowships. Any opinions, findings, and conclusions or recommendations expressed in this publication are those of the authors and do not reflect the views of these agencies. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. PLDI 02, June 17-19, 2002, Berlin, Germany. Copyright 2002 ACM /02/ $5.00. AT&T Labs Research 180 Park Avenue Florham Park, NJ trevor@research.att.com control over data representation (e.g., field layout) and resource management (e.g., memory management). The de facto language for coding such systems is C. However, in providing low-level control, C admits a wide class of dangerous and extremely common safety violations, such as incorrect type casts, buffer overruns, dangling-pointer dereferences, and space leaks. As a result, building large systems in C, especially ones including third-party extensions, is perilous. Higher-level, type-safe languages avoid these drawbacks, but in so doing, they often fail to give programmers the control needed in low-level systems. Moreover, porting or extending legacy code is often prohibitively expensive. Therefore, a safe language at the C level of abstraction, with an easy porting path, would be an attractive option. Toward this end, we have developed Cyclone [6, 19], a language designed to be very close to C, but also safe. We have written or ported over 110,000 lines of Cyclone code, including the Cyclone compiler, an extensive library, lexer and parser generators, compression utilities, device drivers, a multimedia distribution overlay network, a web server, and many smaller benchmarks. In the process, we identified many common C idioms that are usually safe, but which the Ctypesystemistooweaktoverify. Wethenaugmentedthe language with modern features and types so that programmers can still use the idioms, but have safety guarantees. For example, to reduce the need for type casts, Cyclone has features like parametric polymorphism, subtyping, and tagged unions. To prevent bounds violations without making hidden data-representation changes, Cyclone has a variety of pointer types with different compile-time invariants and associated run-time checks. Other projects aimed at making legacy C code safe have addressed these issues with somewhat different approaches, as discussed in Section 7. In this paper, we focus on the most novel aspect of Cyclone: its system for preventing dangling-pointer dereferences and space leaks. The design addresses several seemingly conflicting goals. Specifically, the system is: Sound: Programs never dereference dangling pointers. Static: Dereferencing a dangling pointer is a compiletime error. No run-time checks are needed to determine if memory has been deallocated. Convenient: We minimize the need for explicit programmer annotations while supporting many C idioms. In particular, many uses of the addresses of local variables require no modification. 18
Memory Management. Advanced Operating Systems (M) Lecture 3
Memory Management Advanced Operating Systems (M) Lecture 3 This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/
More informationRegion-Based Memory Management in Cyclone
Region-Based Memory Management in Cyclone Dan Grossman Cornell University June 2002 Joint work with: Greg Morrisett, Trevor Jim (AT&T), Michael Hicks, James Cheney, Yanling Wang Cyclone A safe C-level
More informationAdvances in Programming Languages: Regions
Advances in Programming Languages: Regions Allan Clark and Stephen Gilmore The University of Edinburgh February 22, 2007 Introduction The design decision that memory will be managed on a per-language basis
More informationAdvances in Programming Languages
Advances in Programming Languages Lecture 18: Concurrency and More in Rust Ian Stark School of Informatics The University of Edinburgh Friday 24 November 2016 Semester 1 Week 10 https://blog.inf.ed.ac.uk/apl16
More informationType Checking Systems Code
Type Checking Systems Code Greg Morrisett Cornell University Abstract. Our critical computing systems are coded in low-level, typeunsafe languages such as C, and it is unlikely that they will be re-coded
More informationCMSC 330: Organization of Programming Languages. Ownership, References, and Lifetimes in Rust
CMSC 330: Organization of Programming Languages Ownership, References, and Lifetimes in Rust CMSC330 Spring 2018 1 Memory: the Stack and the Heap The stack constant-time, automatic (de)allocation Data
More informationRust for C++ Programmers
Rust for C++ Programmers Vinzent Steinberg C++ User Group, FIAS April 29, 2015 1 / 27 Motivation C++ has a lot of problems C++ cannot be fixed (because of backwards compatibility) Rust to the rescue! 2
More informationAaron Turon! Mozilla Research
Aaron Turon Mozilla Research C/C++ ML/Haskell Rust Safe systems programming Why Mozilla? Browsers need control. Browsers need safety. Servo: Next-generation browser built in Rust. C++ What is control?
More informationIronclad C++ A Library-Augmented Type-Safe Subset of C++
Ironclad C++ A Library-Augmented Type-Safe Subset of C++ Christian DeLozier, Richard Eisenberg, Peter-Michael Osera, Santosh Nagarakatte*, Milo M. K. Martin, and Steve Zdancewic October 30, 2013 University
More informationNicholas Matsakis! Mozilla Research
Nicholas Matsakis! Mozilla Research Parallel! Systems programming without the hassle crashes! heisenbugs! fear 2 C/C++: efficiency first! destructors memory layout smart pointers monomorphization Research
More informationCS527 Software Security
Security Policies Purdue University, Spring 2018 Security Policies A policy is a deliberate system of principles to guide decisions and achieve rational outcomes. A policy is a statement of intent, and
More informationCCured. One-Slide Summary. Lecture Outline. Type-Safe Retrofitting of C Programs
CCured Type-Safe Retrofitting of C Programs [Necula, McPeak,, Weimer, Condit, Harren] #1 One-Slide Summary CCured enforces memory safety and type safety in legacy C programs. CCured analyzes how you use
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Smart Pointers in Rust CMSC330 Spring 2018 Copyright 2018 Michael Hicks, the University of Maryland. Some material based on https://doc.rustlang.org/book/second-edition/index.html
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationGuaranteeing memory safety in Rust
Guaranteeing memory safety in Rust Nicholas D. Matsakis Mozilla Research 1 Hashtable in C / C++ template struct Hashtable { Bucket *buckets; unsigned num_buckets; template
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationRustBelt: Securing the Foundations of the Rust Programming Language
RustBelt: Securing the Foundations of the Rust Programming Language Ralf Jung, Jacques-Henri Jourdan, Robbert Krebbers, Derek Dreyer POPL 2018 in Los Angeles, USA Max Planck Institute for Software Systems
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.
More informationName, Scope, and Binding. Outline [1]
Name, Scope, and Binding In Text: Chapter 3 Outline [1] Variable Binding Storage bindings and lifetime Type bindings Type Checking Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur 2
More informationRun-time Environments - 3
Run-time Environments - 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time
More informationThe Concept of Ownership in Rust and Swift
The Concept of Ownership in Rust and Swift The Concept of Ownership in Rust and Swift By Elaf A Alhazmi, M.Sc. A Thesis Submitted to The Department of Computing and Software and the School of Graduate
More informationCorrections made in this version not in first posting:
1 Changelog 1 Corrections made in this version not in first posting: 12 April 2017: slide 15: correct arrow from B-freed to D-freed 12 April 2017: slide 42: correct phrasing on what is borrowed fuzzing
More informationGarbage Collection (2) Advanced Operating Systems Lecture 9
Garbage Collection (2) Advanced Operating Systems Lecture 9 Lecture Outline Garbage collection Generational algorithms Incremental algorithms Real-time garbage collection Practical factors 2 Object Lifetimes
More informationHeap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.
Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008. Outline. Dynamic Allocation. Variables and Constants. Aliases and Problems. Garbage. Introduction. On Wednesday, we were talking
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationCS 430 Spring Mike Lam, Professor. Data Types and Type Checking
CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system
More informationCyclone, Regions, and Language-Based Safety
Cyclone, Regions, and Language-Based Safety CS598e, Princeton University 27 February 2002 Dan Grossman Cornell University Some Meta-Comments This is a class lecture (not a conference talk or colloquium)
More informationCPSC 3740 Programming Languages University of Lethbridge. Data Types
Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type
More informationRun-time Environments -Part 3
Run-time Environments -Part 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Outline of the Lecture Part 3 What is run-time support?
More informationLecture Notes on Garbage Collection
Lecture Notes on Garbage Collection 15-411: Compiler Design André Platzer Lecture 20 1 Introduction In the previous lectures we have considered a programming language C0 with pointers and memory and array
More informationIn Java we have the keyword null, which is the value of an uninitialized reference type
+ More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are
More informationProgramming Languages Third Edition. Chapter 7 Basic Semantics
Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables
More informationCS-527 Software Security
CS-527 Software Security Memory Safety Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Kyriakos Ispoglou https://nebelwelt.net/teaching/17-527-softsec/ Spring 2017 Eternal
More informationA program execution is memory safe so long as memory access errors never occur:
A program execution is memory safe so long as memory access errors never occur: Buffer overflows, null pointer dereference, use after free, use of uninitialized memory, illegal free Memory safety categories
More informationLecture Notes on Garbage Collection
Lecture Notes on Garbage Collection 15-411: Compiler Design Frank Pfenning Lecture 21 November 4, 2014 These brief notes only contain a short overview, a few pointers to the literature with detailed descriptions,
More informationGarbage Collection (1)
Garbage Collection (1) Advanced Operating Systems Lecture 7 This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/
More informationLimitations of the stack
The heap hic 1 Limitations of the stack int *table_of(int num, int len) { int table[len+1]; for (int i=0; i
More informationStructure of Programming Languages Lecture 10
Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,
More informationReal-time & Embedded Systems Programming. Advanced Operating Systems Lecture 7
Real-time & Embedded Systems Programming Advanced Operating Systems Lecture 7 Lecture Outline Ensuring predictable timing Embedded systems Constraints Interacting with hardware Device drivers Correctness
More informationVector and Free Store (Vectors and Arrays)
DM560 Introduction to Programming in C++ Vector and Free Store (Vectors and Arrays) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides by Bjarne
More informationProgramming Languages (PL)
1 2 3 4 5 6 7 8 9 10 11 Programming Languages (PL) Programming languages are the medium through which programmers precisely describe concepts, formulate algorithms, and reason about solutions. In the course
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:
More informationRust Advanced Topics
Rust Advanced Topics Adapted from https://skade.github.io/rust-three-dayscourse/presentation/toc/english.html Generic Functions 1. fn takes_anything(thing: T) -> T { 2. thing 3. } 4. fn main() { 5.
More informationC10: Garbage Collection and Constructors
CISC 3120 C10: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/5/2018 CUNY Brooklyn College 1 Outline Recap OOP in Java: composition &
More informationMessage Passing. Advanced Operating Systems Tutorial 7
Message Passing Advanced Operating Systems Tutorial 7 Tutorial Outline Review of Lectured Material Discussion: Erlang and message passing 2 Review of Lectured Material Message passing systems Limitations
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationProcesses. Johan Montelius KTH
Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other
More informationA process. the stack
A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes
More informationCompiler Construction
Compiler Construction Lecture 18: Code Generation V (Implementation of Dynamic Data Structures) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/
More informationClass Information ANNOUCEMENTS
Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to
More informationRegion-Based Memory Management in Cyclone
Region-Based Memory Management in Cyclone Dan Grossman Greg Morrisett Trevor Jim Michael Hicks Yanling Wang James Cheney Computer Science Department Cornell University Ithaca, NY 14853 {danieljg,jgm,mhicks,wangyl,jcheney@cs.cornell.edu
More informationVector and Free Store (Pointers and Memory Allocation)
DM560 Introduction to Programming in C++ Vector and Free Store (Pointers and Memory Allocation) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides
More informationLecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?
Lecture 14 No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions? Friday, February 11 CS 215 Fundamentals of Programming II - Lecture 14 1 Outline Static
More informationCS 241 Honors Memory
CS 241 Honors Memory Ben Kurtovic Atul Sandur Bhuvan Venkatesh Brian Zhou Kevin Hong University of Illinois Urbana Champaign February 20, 2018 CS 241 Course Staff (UIUC) Memory February 20, 2018 1 / 35
More informationAcknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides
Garbage Collection Last time Compiling Object-Oriented Languages Today Motivation behind garbage collection Garbage collection basics Garbage collection performance Specific example of using GC in C++
More informationAdding Lifetime Checking to Chapel Michael Ferguson, Cray Inc. CHIUW 2018 May 25, 2018
Adding Lifetime Checking to Chapel Michael Ferguson, Cray Inc. CHIUW 2018 May 25, 2018 Safe Harbor Statement This presentation may contain forward-looking statements that are based on our current expectations.
More informationSafe Manual Memory Management in Cyclone
Safe Manual Memory Management in Cyclone Nikhil Swamy, Michael Hicks, Greg Morrisett, Dan Grossman and Trevor Jim Abstract The goal of the Cyclone project is to investigate how to make a low-level C-like
More informationObject-Oriented Programming
iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 37 Overview 1 2 3 4 5 2 / 37 Questions we will answer today What is the difference between the stack and the heap? How can we allocate and free memory
More informationChapter 17 vector and Free Store. Bjarne Stroustrup
Chapter 17 vector and Free Store Bjarne Stroustrup www.stroustrup.com/programming Overview Vector revisited How are they implemented? Pointers and free store Allocation (new) Access Arrays and subscripting:
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationUnderstanding Undefined Behavior
Session Developer Tools #WWDC17 Understanding Undefined Behavior 407 Fred Riss, Clang Team Ryan Govostes, Security Engineering and Architecture Team Anna Zaks, Program Analysis Team 2017 Apple Inc. All
More informationIndex. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309
A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48
More informationCS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline
CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can
More informationScope, Functions, and Storage Management
Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)
More informationTowards a Resilient Operating System for Wireless Sensor Networks
Towards a Resilient Operating System for Wireless Sensor Networks Hyoseung Kim Hojung Cha Yonsei University, Korea 2006. 6. 1. Hyoseung Kim hskim@cs.yonsei.ac.kr Motivation (1) Problems: Application errors
More informationSafe Dynamic Memory Management in Ada and SPARK
Safe Dynamic Memory Management in Ada and SPARK Maroua Maalej 1, Tucker Taft 2, Yannick Moy 1 1 AdaCore Paris, France maalej@adacore.com, moy@adacore.com 2 Adacore New York, USA taft@adacore.com Abstract.
More informationMemory Management and Efficient Graph Processing in Rust
Memory Management and Efficient Graph Processing in Rust KEVIN CHEN and ELBERT LIN Stanford University 1. INTRODUCTION Graphs are a common data structure in most object-oriented programming languages due
More informationRun-Time Environments/Garbage Collection
Run-Time Environments/Garbage Collection Department of Computer Science, Faculty of ICT January 5, 2014 Introduction Compilers need to be aware of the run-time environment in which their compiled programs
More informationRust intro. (for Java Developers) JFokus #jfokus 1. 1
Rust intro (for Java Developers) JFokus 2017 - #jfokus 1. 1 Hi! Computer Engineer Programming Electronics Math
More informationMemory Leak. C++: Memory Problems. Memory Leak. Memory Leak. Pointer Ownership. Memory Leak
Memory Leak C++ Memory Problems or When Good Memory Goes Bad A bug in a program that prevents it from freeing up memory that it no longer needs. As a result, the program grabs more and more memory until
More informationOrganization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science
Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and
More informationSE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms
SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms
More informationC11: Garbage Collection and Constructors
CISC 3120 C11: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/5/2017 CUNY Brooklyn College 1 Outline Recap Project progress and lessons
More informationChapter 3:: Names, Scopes, and Bindings
Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation
More informationCOMP6771 Advanced C++ Programming
1.. COMP6771 Advanced C++ Programming Week 5 Part Two: Dynamic Memory Management 2016 www.cse.unsw.edu.au/ cs6771 2.. Revisited 1 #include 2 3 struct X { 4 X() { std::cout
More informationLecture Notes on Memory Management
Lecture Notes on Memory Management 15-122: Principles of Imperative Computation Frank Pfenning Lecture 21 April 5, 2011 1 Introduction Unlike C0 and other modern languages like Java, C#, or ML, C requires
More informationThe Case for Building a Kernel
The Case for Building a Kernel in Rust Amit Levy Brad Campbell Branden Ghena Pat Pannuto Philip Levis Prabal Dutta Stanford University & University of Michigan September 2nd 2017 Memory and type safety
More informationLast week. Data on the stack is allocated automatically when we do a function call, and removed when we return
Last week Data can be allocated on the stack or on the heap (aka dynamic memory) Data on the stack is allocated automatically when we do a function call, and removed when we return f() {... int table[len];...
More informationProgramming In Rust. Jim Blandy, / Portland, (Slides are as presented; followup discussion,
Programming In Rust Jim Blandy, Mozilla @jimblandy / Portland, 2015 (Slides are as presented; followup discussion, fixes, etc. on Reddit: http://goo.gl/thj2pw) 2 The set of Rust enthusiasts certainly seems
More informationMemory management COSC346
Memory management COSC346 Life cycle of an object Create a reference pointer Allocate memory for the object Initialise internal data Do stuff Destroy the object Release memory 2 Constructors and destructors
More informationQUIZ How do we implement run-time constants and. compile-time constants inside classes?
QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of
More informationTypes. What is a type?
Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations
More informationField Analysis. Last time Exploit encapsulation to improve memory system performance
Field Analysis Last time Exploit encapsulation to improve memory system performance This time Exploit encapsulation to simplify analysis Two uses of field analysis Escape analysis Object inlining April
More informationDynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1
Dynamic Memory Dynamic Memory Allocation Strings September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Pointer arithmetic If we know the address of the first element of an array, we can compute the addresses
More informationRust. A safe, concurrent, practical language. Graydon Hoare October 2012
Rust A safe, concurrent, practical language Graydon Hoare October 2012 This is not a marketing talk Purpose: Convince you there's something interesting here Provide some technical
More informationINITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS
INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting
More informationCMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection
CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC330 Fall 2018 1 Memory Attributes Memory to store data in programming languages has the following lifecycle
More informationSeptember 10,
September 10, 2013 1 Bjarne Stroustrup, AT&T Bell Labs, early 80s cfront original C++ to C translator Difficult to debug Potentially inefficient Many native compilers exist today C++ is mostly upward compatible
More informationSustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)
COMP 412 FALL 2017 Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java) Copyright 2017, Keith D. Cooper & Zoran Budimlić, all rights reserved. Students enrolled in Comp 412 at Rice
More informationLecture Notes on Queues
Lecture Notes on Queues 15-122: Principles of Imperative Computation Frank Pfenning Lecture 9 September 25, 2012 1 Introduction In this lecture we introduce queues as a data structure and linked lists
More informationBinding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill
Binding and Storage Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. What s
More informationReal-Time and Embedded Systems (M) Lecture 19
Low-Level/Embedded Programming Real-Time and Embedded Systems (M) Lecture 19 Lecture Outline Hardware developments Implications on system design Low-level programming Automatic memory management Timing
More informationChapter 5. Names, Bindings, and Scopes
Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative
More informationGeneral Purpose GPU Programming. Advanced Operating Systems Tutorial 7
General Purpose GPU Programming Advanced Operating Systems Tutorial 7 Tutorial Outline Review of lectured material Key points Discussion OpenCL Future directions 2 Review of Lectured Material Heterogeneous
More informationPointers and Memory 1
Pointers and Memory 1 Pointer values Pointer values are memory addresses Think of them as a kind of integer values The first byte of memory is 0, the next 1, and so on A pointer p can hold the address
More informationA Framework for Gradual Memory Management
A Framework for Gradual Memory Management A safe, performant technique for integrating custom allocators and garbage collection mechanisms Jonathan Goodwin jondgoodwin@gmail.com September 12, 2017 Abstract
More informationRuntime Environments I. Basilio B. Fraguela
Runtime Environments I Basilio B. Fraguela Runtime System Responsibilities Allocation of storage for program data Sometimes also deallocation Garbage collection Management of data structures the compiled
More informationLecture 9 Assertions and Error Handling CS240
Lecture 9 Assertions and Error Handling CS240 The C preprocessor The C compiler performs Macro expansion and directive handling Preprocessing directive lines, including file inclusion and conditional compilation,
More information