Javaforum looking into the memory


Published on

Out Of Memory - Analyze Your Java Heap
A short introduction on why memory usage might not be what you expect it to be and tools for going deeper. Different ways for acquiring memory snapshots and how to examine them with MAT.
Roger Lindsjö, Ericsson

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • The data we need might be larger than we realize Storing too much intentionally (Caches) Storing too much unintentionally (forgetting to dereference)
  • Primitive types vs objects Referencing same object vs a copy Integer.valueOf...
  • Generate a snapshot by sending signal, automatically from keyboard or different external programs.
  • Sample program which tries to store short strings by doing substring on large strings (which actually uses the same large char array as the large string.
  • Different aspects of using MAT
  • Open a snapshot
  • Store each snapshot in a separate folder since opening it in MAT will create several index files used by MAT and will soon clutter up a folder with several snapshots.
  • Opening can take some time (indexes are generated)
  • After startup dirrerent reports can automatically be run.
  • MAT shows if a few objects are holding on to most of the memory and makes them suspects.
  • Generate class histograms from the histogram button.
  • You can now see the number of objects, their shallow heap (memory by the object itself) and retained heap (memory by objects referenced, such as lists, maps etc)
  • To the left info about the class / instance can be seen
  • Show instances of this class with instances pointing to it.
  • Filter histogram with regexp
  • Show instances with what it points to
  • StoreLargeString is small, but references a List which is large, has an array of 1000000 elements, and 1000000 strings, each referencing an array of 26KB
  • Select previous searches into compare basket
  • Compare and you can see actual values or differences between queries
  • With OQL you can select objects from their type and member values
  • Handle the snapshots with care, they can contain sensitive information
  • Links. The Java API mainly points to discussion of how to use.
  • Javaforum looking into the memory

    1. 1. Out Of Memory Analyze Your Java Heap
    2. 2. GC silver bullet• Unreferenced memory cleared Fragmentation cleanup Incorrect understanding of data / structures• Packratting
    3. 3. Data / Structures• Primitives vs Objects Byte vs byte• Overhead of structure • LinkedList vs ArrayList JVM settings • UseCompressedOops, UseCompressedStrings
    4. 4. Packratting• Unintentionally storing data Unbounded caches • Classloaders • Containers / plugins ThreadLocals • Statics
    5. 5. What nowAvoid situation ;-)
    6. 6. Snapshot• -XX:+HeapDumpOnCtrlBreak -XX:+HeapDumpOnOutOfMemoryError jmap -dump:format=b,file=snapshot.bin pid• jconsole
    7. 7. MAT Eclipse Memory Analyzer Eclipse Memory Analyzer• Wizards Compare• Explore Query
    8. 8. Watch out• Can be large Takes time to produce• Can contain sensitive information
    9. 9. LInks MAT jconsole jmap jstat• Java API