Top Banner
GARBAGE COLLECTION INTRODUCTION MARK AND SWEEP COLLECTORS COMPACTING COLLECTORS COPYING COLLECTORS GENERATIONAL COLLECTORS INCREMENTAL & CONCURRENT COLLECTORS DISCOVERING THE ROOT SET 1
10

Garbage collection

Apr 12, 2017

Download

Engineering

sivanantham s
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Garbage collection

1

GARBAGE COLLECTION

INTRODUCTIONMARK AND SWEEP COLLECTORSCOMPACTING COLLECTORSCOPYING COLLECTORSGENERATIONAL COLLECTORSINCREMENTAL & CONCURRENT COLLECTORSDISCOVERING THE ROOT SET

Page 2: Garbage collection

2

1. INTRODUCTION

Memory resources are not unbounded Programs may run out of Memory Objects that are no longer accessible can be collected and reused When a JVM runs out of memory, garbage collector is invoked to collect garbage

objects In JVM, a Root set of references point to objects in the Global memory heap Some objects contains references to other objects in the memory Objects that cannot be reached through this chain are Garbage objects Time spent on garbage collection is not time spent on computing There are number of methods that organize the heap differently and collects garbage

efficiently

Page 3: Garbage collection

3

Page 4: Garbage collection

4

2. MARK AND SWEEP COLLECTORS This method starts with the Root reference and traces through all reachable objects It contains stages namely,

• Marking• Sweeping

Marking• Setting of flag bit to indicate whether the object is reached or not• If already marked object is reached, tracing down that path is stopped

Sweeping• The unmarked object are considered as Garbage• These objects are combined into a linked list of free objects

DisadvantageFormation of lot of Linked lists leads to memory fragmentation and wastage

Page 5: Garbage collection

5

3. COMPACTING COLLECTORS This method slides the live objects to the bottom of the heap memory Automatically garbage objects goes up and cleanedDisadvantageIt requires number of passes1st Pass - Marking live objects2nd Pass - compute new location for live objects3rd Pass – Move objects4th Pass – Updating references Solution To use a Handle Pool

Page 6: Garbage collection

6

4. COPYING COLLECTORS This method divides heap into two halves

• Unused part• Active heap

It performs mark and sweep simultaneously

When a active object is found, it is moved to the unused part of the heap

At the end of the collection, Unused part will become active and active half becomes unused

This method trades memory space to reduce collection time

Page 7: Garbage collection

7

5. GENERATIONAL COLLECTORS Compacting Collectors and Copying Collectors move a very large fraction of live objects during every collection process

A long lived objects may be moved many times during its lifetime

This method uses a bimodal distribution

Generational Collectors attempt to group objects according to their age

Heap memory is divided into sub heaps

One sub heap holds the older objects called the tenured objects

Another heap holds newly created objects called the nursery objects

The nursery is garbage collected frequently than the tenured ones

Page 8: Garbage collection

8

6. INCREMENTAL AND CONCURRENT COLLECTORSAll of the collectors discussed before stop program execution while they perform collection and then return control to programIn Incremental Collectors, Collection time may be spread out if collection is done incrementallyIn multi Processor environment, garbage can be collected concurrently with the help of threads and program execution is not affected seriously Disadvantage

SolutionTo impose write barriers for references to objects that are already marked

Page 9: Garbage collection

9

7. DISCOVERING THE ROOT SET

The root set consists of references held in the stack and static objects called the Architected root set

In some VMs, there are memory locations that may hold root set pointers

At the time of Garbage collection, these pointers to root set will help to discover the root set easily

There are two method for discovering root sets namely,–Type accurate method–Super set method

Page 10: Garbage collection

10

THANK YOU