[bgoug] memory analyzer

Post on 07-Nov-2014

2.065 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

A short introduction of Eclipse Memory analyzer and its basic features.

TRANSCRIPT

Eclipse Memory Analyzer

Krasimir Semerdzhiev

Development Architect / SAP Labs Bulgaria

© 2011 SAP AG. All rights reserved. 2

Agenda

Getting started

Get hands dirty

Q&A

© 2011 SAP AG. All rights reserved. 3

Getting startedFew assumptions

You’ve passed beyond “Hello World” in Java

Hello World apps tend not to require too much memory

You’ve gotten an OutOfMemoryError at least once in your life :)

You’re proficient already with Garbage Collection

Attended the previous BGOUG event GC session

© 2011 SAP AG. All rights reserved. 4

Getting startedMemory analyzer basics

Works with heap dumps – live snapshots of:

© 2011 SAP AG. All rights reserved. 5

Getting startedHow to get a heap dump

Non-Interactive

-XX:+HeapDumpOnOutOfMemoryError

On Demand

JDK1.4.2_12+ and -XX:+HeapDumpOnCtrlBreak

JDK6 and JConsole or VisualVM

On IBM VMs-Xdump:system:events=throw,filter=java/lang/OutOfMemoryError,

request=exclusive+prepwalk

More…

http://wiki.eclipse.org/index.php/MemoryAnalyzer#Getting_a_Heap_Dump

© 2011 SAP AG. All rights reserved. 6

Getting startedShallow vs. Retained heap

Shallow heap is the memory consumed by one object

Retained set of X is the set of objects that will be garbage collected if X is garbage

collected

Retained heap of X is the sum of shallow sizes of all objects in the retained set of

X, i.e. memory kept alive by X

Set of elements Retained Set

C

K

C, K

C, F, G, J

K

C, F, G, J, K, I

© 2011 SAP AG. All rights reserved. 7

Getting startedDominator tree

An object x dominates an object y if every path in the object graph from the start (or the root)

node to y must go through x.

In the dominator tree each object is the immediate dominator of its children, so

dependencies between the objects are easily identified.

© 2011 SAP AG. All rights reserved. 8

Getting startedDominator tree

© 2011 SAP AG. All rights reserved. 9

Getting startedJava references – java.lang.ref

Soft reference

GC will try to preserve the object

Will collect it prior to throwing OutOfMemoryError

Weak reference

GC is free to reclaim the object.

Phantom reference

Track object collections

Created Initialized Strongly reachable

Softly reachable

Weakly reachable

Finalized

Phantom reachable

© 2011 SAP AG. All rights reserved. 10

Getting startedGC roots in Java

Keeps the objects in heap from being collected by GC

System Class Finalizer Queue GC handle

JNI Local

JNI Global

Unfinalized Thread stack

ThreadThread block Busy Monitor

Unknown

Unreachable

© 2011 SAP AG. All rights reserved. 11

Getting startedWhat is a leak?

© 2011 SAP AG. All rights reserved. 12

Agenda

Getting started

Get hands dirty

Q&A

© 2011 SAP AG. All rights reserved. 13

Analyze memory consumptionGetting the heap dump: Setup

JConsole refuses to connect

© 2011 SAP AG. All rights reserved. 14

Analyze memory consumption

DEMO

© 2011 SAP AG. All rights reserved. 15

How to get involved?

Eclipse Home Page

http://www.eclipse.org/mat/

Forum

eclipse.technology.memory-analyzer

Blog

http://dev.eclipse.org/blogs/memoryanalyzer

Questions?

Krasimir Semerdzhiev

krasimir.semerdzhiev@sap.com

Thank You!

Krasimir Semerdzhiev

krasimir.semerdzhiev@sap.com

top related