Title: Maximize Java Performance by using YOURKIT with uPortal development
1Maximize Java Performance by using YOURKIT with
uPortal development
- Faizan Ahmed Sr. Application Developer
2Overview
- Why memory related issues are problem?
- Introduction to YourKit.
- Some terms
- What is Java Memory Leak?
- Find and resolve memory leak (demo)
- Some code tips.
3Why memory related issues can be performance
problem?
- Memory-related issues affect execution speed and
reliability of application.
4Getting started with YourKit
- Download and extract the zip file.
- Set PATH to dll
- ltYJP Homegt\bin\win32
- Check installation
- java -Xrunyjpagenthelp
- IDE configuration
- Plug-in installation
- Enable action group profile
- Windows customize perspective commands
- Agent configuration
- -agentlibyjpagent
5Snapshots
- YourKit investigative model is based upon
snapshots which capture the state of the
application at specific points in time.
6Dynamic Nature of a RootSet
- Root Set is a set of foundational object
references within your application - public class uPortal
- private static uPortal portal null
- public static void main(String args)
- portal new uPortal()
- portal.method1()
Root Set uPortal portal String args
7Dynamic Nature of a RootSet
- Private void method1
- FooObject fooObject new FooObject()
- ..
Root Set uPortal portal String args FooObject
fooObject
8Dynamic Nature of a RootSet
- public class uPortal
- private static uPortal portal null
- public static void main(String args)
- portal new uPortal()
- portal.method1()
- .
Root Set uPortal portal String args
9What is Memory leak in Java?
- Occurs when objects that have outlived their
usefulness to the application remain within the
heap through successive garbage collections
10What is a memory leak in Java?
- We can extend the set of object states to three
- Allocated
- Exists within the JVMs heap
- Reachable
- A path exists (directly or indirectly) from a
member of the root set, through a sequence of
references to that object. - Live
- From the intent of the application design the
program will use the object.
11What is memory leak in java?
Handled by JVM
Allocated
Reachable
Live
Java Memory leak
12What are loitered Objects?
- Loitered objects are reachable, but they are not
live.
13Most common memory leak causes
- Failure to remove Stale Object References from
Data Structures. - Lingering Transitional references.
- A reference to a short-term object is used
transiently by a long-term object but the
long-term object does not clear the reference
when its done with it.
14Preparing for your investigation
- Have a firm conceptual grasp of the architecture
of the application you are about to analyze. - An attitude that you can find, and resolve, the
underlying problem.
15How to find leaked Objects?
16How to find leaked Objects?
- More Disciplined approach.
- Establish a hypothesis (around the expected leak
area) (What you expect to see). - Design and run an experiment to prove your
hypothesis (a use case). - Compare the experimental results against your
hypothesis. - Resolve the differences. (if any)
17Loitering Objects Recap
- Objects that remain within the heap past their
useful life to the application. - To eliminate loitering objects from your
application, you must first - Identify which objects (if any) are loitering
within your application. - Determine why those objects remain reachable
beyond their designed lifetime.
18Some Tips
- Reference variable scope
- Dont be concerned about assignments to
method-based reference variables within methods
of short execution time. - Be attentive of assignments to class-based and
object-based reference variables, and
method-based reference variables within methods
of long execution time.
19Some Tips
- As a general rule do not use finalizer.
- Where appropriate to your design, use the method
attributes - static
- final
- private
20Some Tips (Continued)
- Try to keep critical methods to a few statements
in length, and declare them static, final or
private. - In critical loops, avoid method calls within the
loop termination test.. - Example on next page
21Some Tips (Continued)
- Replace
- for (int i0 i lt collection.size() i)
- .
-
- With
- for(int i0, ncollection.size() iltn i)
- ---
22Some Tips (Continued)
- If you cache some objects you better have a
working caching strategy and remove objects
from cache at some point. - No user session really means 0 user session in
the system.
23Questions Comments !