13. Concurrent Mark-Sweep (CMS)
Old gen is collected concurrently
1. STW, Mark roots
2. Mark concurrently with application
3. STW, mark again to catch up
4. Sweep
15. CMS Pros and Cons
Reduces pause
Does not collect all garbage.
Leaves the heap fragmented so allocation
is more expensive.
CMS failures.
Needs more heap.
Steals threads and CPU from application.
19. GC Monitoring
Use tools to visualize GC activity
Some such tools:
JConsole
JStat
VisualVM (with GC extension)
20. Some Important Parameters
GC - The garbage collector in use.
Size of the Java heap.
Size of the young and old generation spaces.
Duration of minor garbage collections.
Frequency of minor garbage collections.
Duration of full garbage collections.
Frequency of full garbage collections.
What initiates full GC; old gen or perm space.
21. Attributes of Java Performance
Pause Time: Minimal pause time due to
GC
Throughput: Overall performance of user
process ignoring pauses due to GC
Footprint: Amount of memory required for
GC to run efficiently
22. GC Friendly Coding
GCs love small, immutable, short-lived objects
Object pooling is usually bad
Large objects are expensive to allocate,
expensive to initialize and may fragment CMS
Nulling references is usually bad
Avoid finalize()
Avoid calling System.gc()
Avoid memory Leaks
Some sources: Objects in the wrong scope
Instances of inner classes