CS162 Week 9 Kyle Dewey. Overview What needs to be done Quirks with GC on miniJS Implementing GC on miniJS.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Run-time organization  Data representation  Storage organization: –stack –heap –garbage collection Programming Languages 3 © 2012 David A Watt,
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
CS16 Week 2 Part 2 Kyle Dewey. Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors.
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
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.
Generational Stack Collection And Profile driven Pretenuring Perry Cheng Robert Harper Peter Lee Presented By Moti Alperovitch
CS 536 Spring Run-time organization Lecture 19.
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
Run time vs. Compile time
Register Allocation (via graph coloring)
Environments and Evaluation
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Register Allocation (via graph coloring). Lecture Outline Memory Hierarchy Management Register Allocation –Register interference graph –Graph coloring.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
4/29/09Prof. Hilfinger CS164 Lecture 381 Register Allocation Lecture 28 (from notes by G. Necula and R. Bodik)
Garbage Collection and High-Level Languages Programming Languages Fall 2003.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
A Parallel, Real-Time Garbage Collector Author: Perry Cheng, Guy E. Blelloch Presenter: Jun Tao.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
CS162 Week 8 Kyle Dewey. Overview Example online going over fail03.not (from the test suite) in depth A type system for secure information flow Implementing.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
CNIT 133 Interactive Web Pags – JavaScript and AJAX Advanced topic - variable.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Week 9 Part 1 Kyle Dewey. Overview Dynamic allocation continued Heap versus stack Memory-related bugs Exam #2.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Activation Records (in Tiger) CS 471 October 24, 2007.
Advanced Java Programming CS 537 – Data Structures and Algorithms.
CS101 Computer Programming I Chapter 4 Extra Examples.
FT228/3 Web Development Error processing. Introduction READ Chapter 9 of Java Server Pages from O’reilly 2 nd Edition Need to be able to 1) Diagnose and.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
Garbage Collection and Memory Management CS 480/680 – Comparative Languages.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
CS162 Week 4 Kyle Dewey. Overview Reactive imperative programming in a nutshell Reactive imperative programming implementation details.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
® July 21, 2004GC Summer School1 Cycles to Recycle: Copy GC Without Stopping the World The Sapphire Collector Richard L. Hudson J. Eliot B. Moss Originally.
CS162 Week 8 Kyle Dewey. Overview Example online going over fail03.not (from the test suite) in depth A type system for secure information flow Implementing.
Data Structures Arrays and Lists Part 2 More List Operations.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
CS162 Week 3 Kyle Dewey. Overview Grades posted for assignment 1 Secure information flow key implementation issues Reactive imperative programming.
GC Assertions: Using the Garbage Collector To Check Heap Properties Samuel Z. Guyer Tufts University Edward Aftandilian Tufts University.
chap10 Chapter 10 Recursion chap10 2 Recursive Function recursive function The recursive function is a kind of function that calls.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Object Lifetime and Pointers
Lecture 6 of Computer Science II
Dynamic Compilation Vijay Janapa Reddi
Names and Attributes Names are a key programming language feature
Module 9: Memory and Resource Management
Stack Data Structure, Reverse Polish Notation, Homework 7
Object Oriented Programming COP3330 / CGS5409
Strategies for automatic memory management
Stacks.
COP 3330 Object-oriented Programming in C++
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Chapter 3 Discussion Pages
Presentation transcript:

CS162 Week 9 Kyle Dewey

Overview What needs to be done Quirks with GC on miniJS Implementing GC on miniJS

The Plan Implement three garbage collectors: semispace, mark/sweep, and generational Semispace + mark/sweep: 90% of score Semispace + mark/sweep + generational: 130% of score

GC Reachability Reachability means we can access the object

Liveness If we can reach an object from the root set, then the object is live If we cannot reach it, then it is dead Reclaim only dead objects

Question The typical root set consists of the values of variables on the stack What is the root set for miniJS? var a, obj in obj := {foo: “bar”}; obj.bar := obj.foo; a := 12; obj := {b: a, o: obj}

Issue #1: Variables on the Stack miniJS does not have a usual stack Variable values tracked by recursive calls to eval with InScope objects

Solving Issue #1 Introduce a global mutable stack that acts as the environment Variable to address bindings are pushed onto it in the same was as seen with a usual runtime stack

Original New

Issue #2: Intermediate Values What’s problematic with this for GC?

Issue #2: Intermediate Values We can operate on store-allocated values without having a binding in the environment ({foo: “bar”}).baz := {“temp”: 1}

Solving Issue #2 Put all temporary variables into the root set

Getting the Root Set Calling RootSet() will get the global root set This root set is a set of Storable, not Address as in the usual definition

Representing the Heap HeapInterface provides functions for reading / writing objects See the StubCollector for detailed information on usage

Heap With StubCollector After allocating the number 1: Allocated Metadata Size: 2 Type: NumV NumV(1)

Heap With StubCollector After allocating the number 1 and a closure: Allocated Metadata Size: 2 Type: NumV NumV(1) Allocated Metadata Size: 4 Type: CloV >

Heap With StubCollector After allocating the number 1, a closure, and the string “foo”: Allocated Metadata Size: 2 Type: NumV NumV(1) Allocated Metadata Size: 4 Type: CloV > Allocated Metadata Size: 2 Type: StrV StrV(“foo”)

Heap With StubCollector After allocating the number 1, a closure, the string “foo”, and the boolean true: Allocated Metadata Size: 2 Type: NumV NumV(1) Allocated Metadata Size: 4 Type: CloV > Allocated Metadata Size: 2 Type: StrV StrV(“foo”) Allocated Metadata Size: 2 Type: BoolV BoolV(true)

The Collectors Two key functions: gcAlloc and gcRead These do exactly what their names suggest

StubCollector

Mutation in miniJS Old semantics: update the Storable at a given address to be some new Storable What’s wrong with this with respect to the new heap?

Mutation Issue Problem: different objects take up different lengths Since miniJS is dynamically typed, we could switch the kind of object stored If we want to store a new object that’s bigger than what the old one took up, we generally won’t have the space at the same address

Mutation Issue var a, b in a := 1; b := 2; a := () => {output b} Allocated Metadata Size: 2 Type: NumV NumV(1) a

Mutation Issue var a, b in a := 1; b := 2; a := () => {output b} Allocated Metadata Size: 2 Type: NumV NumV(1) Allocated Metadata Size: 2 Type: NumV NumV(2) ab

Mutation Issue var a, b in a := 1; b := 2; a := () => {output b} Allocated Metadata Size: 2 Type: NumV NumV(1) Allocated Metadata Size: 2 Type: NumV NumV(2) ab Closures take up 4 units, but the original address has only 2

Handling Mutation Instead of trying to reuse addresses, we allocate to a new address We update the old address to have the same location as the new address

Handling Mutation For this update to work, your interpreter must have the following invariant: at any point in time, there is at most one Address object associated with each underlying position in the heap If addresses are only made in gcAlloc for freshly allocated values, this will be guaranteed Without this, we can still have Address es that point to the old address after update

Other Assorted Notes

Tracing Be sure to look at values.scala Extra kinds of Storable s have been added This miniJS has lists ObjectV s are implemented internally with lists that extend Storable You need to be able to trace these lists

Backpointers in Generational GC The skeleton code handles backpointers already You may need to trace these backpointers entirely, in violation of typical generational GC Underlying issue: a reference from the tenured space to the nursery may be made long before a tenured object is updated

trace A special trace function is provided, which will simply print the string specified if the -trace flag is set Very useful for debugging If there is inadequate tracing, you will be penalized

assert For any assumptions you have, you should make sure they are true with the assert statement Many bugs will not trigger a typical error until long after they occurred, and proper usage of assert can help shorten this gap I.e. assert can cause bugs to reveal themselves sooner than usual

freelist.scala and gc.scala