Habanero Extreme Scale Software Research Project

Similar documents
Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

Lecture 13: Garbage Collection

CMSC 330: Organization of Programming Languages

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

CMSC 330: Organization of Programming Languages

Exploiting the Behavior of Generational Garbage Collector

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

Runtime. The optimized program is ready to run What sorts of facilities are available at runtime

Garbage Collection. Akim D le, Etienne Renault, Roland Levillain. May 15, CCMP2 Garbage Collection May 15, / 35

Garbage Collection Algorithms. Ganesh Bikshandi

Performance of Non-Moving Garbage Collectors. Hans-J. Boehm HP Labs

Lecture Notes on Garbage Collection

Name, Scope, and Binding. Outline [1]

CS 241 Honors Memory

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

Lesson 2 Dissecting Memory Problems

Algorithms for Dynamic Memory Management (236780) Lecture 4. Lecturer: Erez Petrank

Managed runtimes & garbage collection

MEMORY MANAGEMENT HEAP, STACK AND GARBAGE COLLECTION

Run-Time Environments/Garbage Collection

CSE P 501 Compilers. Memory Management and Garbage Collec<on Hal Perkins Winter UW CSE P 501 Winter 2016 W-1

Structure of Programming Languages Lecture 10

Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End

Lecture 7: Binding Time and Storage

Robust Memory Management Schemes

Memory Management. Chapter Fourteen Modern Programming Languages, 2nd ed. 1

Automatic Memory Management

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

Programming Language Implementation

JVM Troubleshooting MOOC: Troubleshooting Memory Issues in Java Applications

Garbage Collection. Hwansoo Han

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

CS 4120 Lecture 37 Memory Management 28 November 2011 Lecturer: Andrew Myers

Memory Management. Didactic Module 14 Programming Languages - EEL670 1

Heap Management. Heap Allocation

Naming in OOLs and Storage Layout Comp 412

The Processor Memory Hierarchy

Garbage Collection. Steven R. Bagley

ECE 598 Advanced Operating Systems Lecture 10

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

the gamedesigninitiative at cornell university Lecture 9 Memory Management

CA341 - Comparative Programming Languages

Runtime Support for Algol-Like Languages Comp 412

JVM Memory Model and GC

CS 231 Data Structures and Algorithms, Fall 2016

Lecture 15 Garbage Collection

Book keeping. Will post HW5 tonight. OK to work in pairs. Midterm review next Wednesday

THE TROUBLE WITH MEMORY

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

Lecture Notes on Queues

Fundamentals of GC Tuning. Charlie Hunt JVM & Performance Junkie

Heap Compression for Memory-Constrained Java

Advanced Programming & C++ Language

CS399 New Beginnings. Jonathan Walpole

CSCI-1200 Data Structures Spring 2017 Lecture 27 Garbage Collection & Smart Pointers

Manual Allocation. CS 1622: Garbage Collection. Example 1. Memory Leaks. Example 3. Example 2 11/26/2012. Jonathan Misurda

Reference Counting. Reference counting: a way to know whether a record has other users

Parallel GC. (Chapter 14) Eleanor Ainy December 16 th 2014

Reference Counting. Reference counting: a way to know whether a record has other users

Java Performance Tuning

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection.

CPSC 213. Introduction to Computer Systems. Instance Variables and Dynamic Allocation. Unit 1c

Compiler Construction

Garbage Collection (2) Advanced Operating Systems Lecture 9

Automatic Garbage Collection

Compiler Construction

Azul Systems, Inc.

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

Variables, Memory and Pointers

Garbage Collection (1)

CSCI-1200 Data Structures Fall 2011 Lecture 24 Garbage Collection & Smart Pointers

CS61C : Machine Structures

Programming Languages

Run-time Environments - 3

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Review. Partitioning: Divide heap, use different strategies per heap Generational GC: Partition by age Most objects die young

Lecture Notes on Advanced Garbage Collection

Dynamic Memory Allocation

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

Dynamic Memory Allocation

Advances in Programming Languages: Regions

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

Dynamic Storage Allocation

Dynamic Memory Management! Goals of this Lecture!

What goes inside when you declare a variable?

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

CPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2

Dynamic Memory Management

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Lecture Notes on Queues

Running class Timing on Java HotSpot VM, 1

G Programming Languages - Fall 2012

High Performance Managed Languages. Martin Thompson

Dynamic Memory Management

The Fundamentals of JVM Tuning

Why do we care about parallel?

Transcription:

Habanero Extreme Scale Software Research Project

Comp215: Garbage Collection Zoran Budimlić (Rice University) Adapted from Keith Cooper s 2014 lecture in COMP 215.

Garbage Collection

In Beverly Hills... they don't throw their garbage away. They make it into television shows. - Woody Allen

Today s Lecture Focus for today is on the Java memory model, allocation, & recycling How it works How it affects your code s runtime How you should program defensively now that you know

Where do objects live? So far, we have encouraged you to ignore the issue of where objects, variables, and methods live The implementation (Python or Java) takes care of these details Fundamentally, abstraction is a good thing Fred Kate Julia System.out. println() Java World

Where do objects live? So far, we have encouraged you to ignore the issue of where objects, variables, and methods live The implementation (Python or Java) takes care of these details Fundamentally, abstraction is a good thing Right up to the point when it causes problems At some point in your Java career, performance will matter COMP 215 exercises where your code is timed, or COMP 412 At that point, you need to pay attention to details Fred Julia Kate System.out. println() Today s lecture is about details Java World

Where do objects live? The Java System maps Java World onto Processor Resources Processor has finite resources Java suggests that you have enough resources Mapping enough onto what s there is the job of the Java compiler and runtime (JVM) Fred Julia Kate System.out. println() Knowing how that mapping works can help you understand the behavior of your programs, and suggest ways to improve the program s behavior. Java World 0 1 2 k Processor Core Processor Core RAM Processor Core

Fundamentals In this example, what needs storage? The two classes (Point & C) Point s local members (x, y, & draw) C s local members (s, t, & m) m s local variables (a, b, & p) class Point { public int x, y; public void draw(){}; } class C { int s, t; public void m() { int a, b; Point p = new Point(); a = ; b = ; p.draw(); } } A classic example

Fundamentals In this example, what needs storage? The two classes (Point & C) Point s local members (x, y, & draw) C s local members (s, t, & m) m s local variables (a, b, & p) Memory in the Java runtime is divided, broadly speaking, into a Heap and a collection of Stacks One heap per program (large) One stack per thread (smaller) STACK 0 STACK 1 p: a: b: STACK 2 STACK n Point Hello world! C String Pool new point Heap class Point { public int x, y; public void draw(){}; } class C { int s, t; public void m() { int a, b; Point p = new Point(); a = ; b = ; p.draw(); } } A classic example

JVM Memory Layout Stacks Growth space for stacks Heap Globals Code When running code creates a variable, it goes into the thread s stack When running code creates a class or an object (e.g., with a new), it goes into the heap Code lives off to the right So, can a program run out of heap space? Yes. Emphatically yes (might consider it part of the heap) What happens? The runtime system tries to recycle space on the heap (too many news)

Why Garbage Collection? Today s programs consume storage freely 1GB laptops, 1-4GB deskops, 8-512GB servers 64-bit address spaces (SPARC, Itanium, Opteron) and mismanage it Memory leaks, dangling references, double free, misaligned addresses, null pointer dereference, heap fragmentation Poor use of reference locality, resulting in high cache miss rates and/or excessive demand paging Explicit memory management breaks high-level programming abstraction Luckily, you don t have to do that in Java

Sustainable Memory Management (AKA Garbage Collection ) When the heap runs out of space, the system copes Scours the heap looking for objects that are no longer of interest Technical term is live An object is considered live iff it can be reached from the running code Start from all the names in the running code Variables are on the stack 1 Global names such as declared or imported classes Each object on the stack has a declaration which reveals its structure You can imagine chasing down chains of references to find all live objects 2 That s how it was done for a long time Modern garbage collectors are more nuanced They still start from the beginning: local & global names Most modern collectors are copying collectors 1 Locals of the current method are on the stack. Locals of the method that called it are below the current method on the stack. Locals of the method that called that method are below, and so on. That s why the runtime uses a stack 2 H. Schorr and W.M Waite, An efficient machine-independent procedure for garbage collection in various list structures, Comm. ACM, 10 (8), 1967, pages 501 506

Stack on Method Invocation SP - stack pointer VP - variable pointer

Garbage Collection via Copying A copying collector divides the heap into two or more pools New objects are allocated in the current pool When the current pool is full, execution pauses and the collector: copies all live objects from the current pool to the empty pool swaps the designations current and empty Unreachable objects are not copied, so the new pool has free space 1 4 3 2 5 6 Current Pool HEAP Empty Pool BEFORE Objects left in the empty pool are discarded en masse Empty Pool 1 2 3 4 5 6 HEAP Current Pool AFTER

Copying Collector Tradeoffs Good: very low cell allocation overhead Out-of-space check requires just an addr comparison Can efficiently allocate variable-sized cells Good: compacting Eliminates fragmentation, good locality of reference Bad: twice the memory footprint Probably Ok for 64-bit architectures (except for paging) When copying, pages of both spaces need to be swapped in. For programs with large memory footprints, this could lead to lots of page faults for very little garbage collected Large physical memory helps

Generational Garbage Collection Youth is such a wonderful thing. What a crime to waste it on children. - George Bernard Shaw

Generational Garbage Collector Java uses a slightly more complex copying collector All new objects are allocated into Eden Eden is copied, when full, into one of Stable 0 or Stable 1 When Stable is too full, it is added to the Long Term Pool Minor collection Major collection swap minor HEAP major Eden Stable 0 Stable 1 Long Term Pool This is an example of a Generational Garbage Collector Key insight: most objects that die, die young Divide the heap into generations, and GC the younger object more frequently Don t have to trace all objects during a GC cycle Periodically reap the older generations Promote young objects to older pool if they survive several garbage collections Amortize the cost across generations

Implications for Programming If you want performance, pay attention to garbage Collector locates live objects by walking out from variables When you are done with an object, make sure you re not referencing it anymore Leaving a reference to the heap object will keep it live Storage can leak, or become un-recyclable Leaving a reference to a large data structure on the stack, or in a global, or forgotten in another object, that happens to be live Leads to extra collections and, eventually, an out of memory error This is the takeaway message! Stack Globals Hello world! String Pool Heap 10

Does this stuff matter? If performance really matters, pay attention to size of the pool COMP 412 offered a 5% bonus for the fastest lab 1 in a language In the Java labs, the top three or four were separated by the behavior of the garbage collector The fastest lab had no major collections, & fewer minor collections

Does this stuff matter? Performance of One Student s Java Code, COMP 412, Lab 1 30.000 Standard Big Heap Small Heap 22.500 way too many collections 15.000 7.500 0.000 00 26,000.00 52,000.00 78,000.00 104,000.00 130,000.00 major collection (2x in speed)

Live Coding Find garbage in our code!