Docsity

Garbage Collection: Principles and Techniques, Slides of Computer Science

Partial preview of the text

Download Garbage Collection: Principles and Techniques and more Slides Computer Science in PDF only on Docsity!

Garbage Collectors

Haim Yadid, Head of Performance and Application Infra Group

Motivation & Goals

GC Me allocate myObject = new MyClass(2015) GC cleans So everything is cool!

Goal: Minimize Memory Overhead

Garbage collector memory overhead Internal structures Additional memory required for GC Policy and amount of memory generated before GC

Goal: Responsiveness

Pause Time Garbage collector stops the application During that time the application is not responsive What is the maximal delay your application can sustain: Batch applications seconds… Web applications ½ second? Swing UI 100 ms max Trading application milliseconds Robotics microseconds….

Goals

Memory footprint Throughput Max pause time Garbage Collectors: G Contradicting! Choose 2 of 3

Goal: Locality

TLAB - thread local allocation buffer Maintaining locality utilizes CPU cache Linear allocation mechanism Per thread buffer allocated on first object alloc after new Gen GC. Small objects allocated linearly on that buffer FAST 10 machine instructions Resized automatically ( ResizeTLAB=true) Based on TLABWasteTargetPercent=

Terminology

GC Root

An object which is references from outside the heap or heap region. Java Local JNI Native stack System class Busy monitor Etc…

Sizing : Live Set

Live Set : Object that are reachable from garbage collection roots #LS - number of object in the live set |LS| - The size of live set

Collector

Pauseless Collector (Concurrent Collector ) vs Stop the world (STW) Collector Serial Collector -Single threaded vs Parallel collector -Multi threaded Incremental vs Monolithic Conservative vs Precise

GC Safepoint

A point in thread execution where it is safe for a GC to operate References inside thread stacks are identifiable If a thread is in a safe point GC may commence Thread will not be able to exit a safe-point until GC ends Global Safe-point : All threads enter a safe point Safe points must be frequent

Building Blocks: Copy Collector

Mark: O(#LS) Same as mark and sweep Copy: O(|LS|) = O(#LS) All live objects are copied to an empty region(to space) No fragmentation Downside: Need twice as much memory Copy is very expensive STW - mutators cannot work at the same time as copy A B C^ D^ F^ A^ B^ C^ D^ F from space to space

Building Blocks: Mark (Sweep)Compact Mark: O(#LS) Same as mark&sweep Sliding compaction O(|H|+|LS|) move objects (relocate) fix pointers(remap) Compact to the beginning of the heap Do not need twice the memory Copy is more delicate and may be slower