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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Quick introduction to Java Garbage Collector (JVM GC)

780
views

Published on

Published in: Technology

1 Comment
0 Likes
Statistics
Notes
  • If you're interested in realtime garbage collection monitoring you can also take a look at this free VisualVM plugin: http://www.spyglasstools.com/documentation/spyglass-garbage-collector-analyzer/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total Views
780
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
38
Comments
1
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JVM and Garbage Collection by marcos.garcia@savoirfairelinux.com, Jan 2013
  • 2. JVM?● Bytecode interpreter http://viralpatel.net/blogs/java-virtual-machine-an-inside-story/
  • 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” http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.5
  • 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 http://performeister.tistory.com/38
  • 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 http://www.oracle.com/technetwork/java/javase/tech/memorymanagement-whitepaper-1-150020.pdf
  • 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 http://java-espresso.blogspot.ca/2011/05/heap-structure-in-jvm.html
  • 8. GC example● Serial Collector (not currently used in modern JVM) http://www.oracle.com/technetwork/java/javase/tech/memorymanagement-whitepaper-1-150020.pdf
  • 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. http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html
  • 12. G1 Heap Fragmentation Young GC
  • 13. Heap evolution ● Regular case ● OOM caseTool: jconsole
  • 14. Heap evolution ● Regular case ● OOM caseTool: websphere resource analyzer