Skip to content

Garbage Collection

April 24, 2009
tags:

GC Concepts
Dead objects: those that do not have any reference by any other object.
Live objects: those that have reference
Allocation/deallocation of memory .

Pausing : when GC runs – application pause.
Throughput:  total time taken by GC.
GC Collection overhead: Time taken by GC/total time
Frequency of collection: how frequently is GC running
footprint: total memory taken by GC to work.
Promptness: time taken after object dead – and memory being reallocated.

======================================
GC types:
Serial Collector: one thing at a time.
Parallel Collector: multi thread exection.
Parallal Compacter
CMS Collector : Compacting vs NonCompacting vs Copying

GC : Weak Generation Hypothesis :
======================
Most allocated objects die young.
Few references from older to younger object exists.
Generations are separate pool of memory holding objects of different ages.

– Young: for allocating/dealloc – with shorter long time: speed , fast, frequent.
– Old  : space oriented.
– Permanent:  used by JVM itself so it can perform GC

Difft ALGO’s for different GENERATIONS.
Young Generation is organized in the following way:
====================================================================================
1. EDEN
Survivor:
2. From
3. To
Movement of objects in GC:( Based on age of an object lifespan)
====================================================================================
When Eden is full the minor collection would take place – it would find the garbage dead
objects and move them to survivor spaces. Promote from EDEN to Survivor FROM.
If FROM is full – then another minor collection would take place. From Eden it would to
survivror Space. If the object is object is relatively new it will move to survivor space named
“TO” else it would move to Old Generation.
Then two survivor spaces swap thier places (FROM and TO)

========================================================

Mark Sweep Compact
marking live objects
sweeping – clearing dead objects
compacting the memory.
===================
J2SE:
Ergonomics:
a. Automatic selection
b. Tuning

Server class:
At least 2 cpu
And 1 gb ram.
and VM chosen.

and based on config : different GC selected

command line options –
If non server machine needs to act as server machine
Give server
jvm.cfg:  config file
-client KNOWN, -server -KNOWN
OR  change sequence
-server -KNOWN -client KNOWN
For non server class:
JVM : Client JVM , GC : Serial GC, initial heap size: 4 m. max : 64 mb.

SERVER Machine:
Server JVM,  Parallel GC ,Heap Size

Tuning:

-XX:MaxGCPauseMillis=500
Increase heap size to achive goal.
-XX:GCTimeRatio=19
(then 5% for GC)
Default Time = 99 (1% for GC)

Evaluating GC Performance:

-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps

-Xmsm
-Xmxm
m = mb , n = bytes

-XX:MinHeapFreeRatio=minimum (40%)
-XX:MaxHeapFreeRatio=(70%)

-XX:NewSize: Max size for young generation
-XX:PermanetGeneration
-XX:ParallelConnector

-XX:UseSerialGC
-XX:UseParalleGC
-XX:UseParalleOldGC
-verbose:gc
size of live objects BEFORE, size of live objects AFTER, time taken
Full gC: Major collection
-XX:PrintGCDetails
Java 6:
Introduced to Garbage-First Collector  – alternative to concurrent collector
Concurrent Mark Sweep Collector: initial mark, concurrent mark, remark, concurrent.
ParallelCompacting – is not used instead of Parallel Connector.
Throughput is directly propotionate to the memory available.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: