Your SlideShare is downloading. ×
  • Like
Quick introduction to Java Garbage Collector (JVM GC)
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Quick introduction to Java Garbage Collector (JVM GC)



Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • If you're interested in realtime garbage collection monitoring you can also take a look at this free VisualVM plugin:
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. JVM and Garbage Collection by, Jan 2013
  • 2. JVM?● Bytecode interpreter
  • 3. JVM Memory Vocabulary● Runtime data areas – PC register: ● One for each thread ● Points to current execution code of each thread – JVM stacks ● One dedicated stack for each thread ● Holds many stack frames, one for each invoked method – Every frame has 3 registers – Heap ● Shared among all threads ● Stores Java objects. ● Cleaned up by GC – Method area ● Shared among all threads ● Contains method code (class implementations) ● Has a Runtime constant pool – Native method stack (just for “native methods”
  • 4. JVM Stack● Stack Frame – Used to store data and partial results, as well as to perform dynamic linking, return values for methods, and dispatch exceptions. – Describes all the needed information to run a method, including current method stack as well as other JVM shared spaces● Stack Frame registers (one per method being executed) – Local Vars, used by current method invocation – Frame data / Execution environment, used for internal stack operations – Optop / Operand stack (for bytecode), reference to runtime constant pool ● It is a LIFO stack, need push/pop operations
  • 5. JVM Heap● Two heap memory types ● Other memory – Young Generation Memory – Permanent Generation ● To/From Survivor spaces – Native memory (because of ● Eden space native memory references, – Old Generation Memory to the underlying OS)
  • 6. Garbage collection● Principle: Generational collection or “weak generational hypothesis” – Most allocated objects are not referenced (considered live) for long, that is, they die young – Few references from older to younger objects exist● Minor GC – Young generation collections occur relatively frequently and are efficient and fast because the young generation space is usually small and likely to contain a lot of objects that are no longer referenced.● Major GC – Objects that survive some number of young generation collections are eventually promoted, or tenured, to the old generation
  • 7. Young/Old Memory explained● Young Space – Eden ● Any object created inside a method or as a class variable – 2 survivor spaces (From/To) ● Objects in use, that have survived at least one Minor GC ● 1 space empty, other full. Swaps on every GC pass● Old (Tenured) – Objects referenced since a long time ago, still being used – Very big objects are created directly in Old space
  • 8. GC example● Serial Collector (not currently used in modern JVM)
  • 9. Parallel and CMS GC● CMS is the most used GC implementation
  • 10. Heap fragmentation● We need contiguous space for memory allocation● GC also relocates (called compactation) objects to reduce fragmentation
  • 11. G1 collector (JDK 6 & 7)● Garbage-First (G1) collector: server-style garbage collector, targeted for multi-processor machines with large memories.● It meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput. Designed for applications that: – Can operate concurrently with applications threads like the CMS collector. – Compact free space without lengthy GC induced pause times. – Need more predictable GC pause durations. – Do not want to sacrifice a lot of throughput performance. – Do not require a much larger Java heap.● G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector (CMS).● Better than CMS. – G1 is a compacting collector. G1 compacts sufficiently to completely avoid the use of fine-grained free lists for allocation, and instead relies on regions. This considerably simplifies parts of the collector, and mostly eliminates potential fragmentation issues. – G1 offers more predictable garbage collection pauses than the CMS collector, and allows users to specify desired pause targets.
  • 12. G1 Heap Fragmentation Young GC
  • 13. Heap evolution ● Regular case ● OOM caseTool: jconsole
  • 14. Heap evolution ● Regular case ● OOM caseTool: websphere resource analyzer