Académique Documents
Professionnel Documents
Culture Documents
You should understand at a high level how the Java Virtual Machine (JVM)
operates underneath your application server and the differences between the
JVM’s on platforms
You should understand what the IBM J9 JVM is and what new features it provides
to the runtime as well as when to use those features.
You will understand how different garbage collection schemes work and how to
use them to effect your applications response times
You will have a knowledge and understanding of some critical JVM tuning
parameters that effect the runtime performance of the JVM
Lastly you will get to know which debugging tools are available for the JVM as
well as understand when and where to use them most effectively.
2
Overview
JVM Basics
Debugging Tools
3
JVM Basics
Highest Level Overview
Java is a Write Once Run Anywhere (WORA) 3rd generation Object Oriented
programming language that is executed on a virtual machine
The Java Virtual Machine (JVM) runs applications written in Java after the Java
code has been compiled to bytecode via the javac process.
There are multiple implementations of the JVM which all “should” execute any
application written for the Java specification level that JVM was developed for.
4
JVM Basics
Which JVM do I have?
The different platforms that WebSphere Application Server runs on have different
JVM implementations in some cases
The IBM J9 JVM is the runtime environment on the following Operating Systems
or Platforms
9 AIX, Windows, Linux (x86), Linux (PPC), iSeries, zSeries
The Sun JVM is the runtime environment on all platforms running the Solaris
Operating System
The HP JVM (which is a very simple Sun JVM port) is the runtime environment on
all platforms running the HP-UX Operating System
5
JVM Basics
The Overall Java Application Stack
JVM is built using OO design. Building
Block components providing higher
level function for simplified end user
development and runtime
Pluggable components
that dynamically load
into the virtual machine J2SE
Thread model Port Library (file IO, sockets, memory allocation, etc.)
Operating system
7
JVM Basics
Class loader basics
8
JVM Basics
JIT Basics
The just-in-time compiler (JIT) is not really part of the JVM but is essential for a
high performing Java application
9 Java is Write Once Run Anywhere thus it is interpreted by nature and without
the JIT could not compete with native code applications
The JIT works by compiling byte code loaded from the class loader when it is
access by an application.
9 Due to different platforms having different JITs there is no standard method for
when a method is compiled.
9 As your code accesses methods the JIT determines how frequently specific
methods are accessed and compiles those touched often quickly to optimize
performance
9
Overview
JVM Basics
Debugging Tools
10
Overview of IBM’s J9 JVM
Background
IBM Toronto Laboratory has a long history (30+ years) of expertise in programming language
compilation and optimization technologies.
9 C, C++, Fortran, XML Parser, HPJ (statically compiled Java)
9 Language independent, interprocedural optimizers
9 Parallelization technology
9 Low-level compiler backends: optimizers, linkers, and code generators
9 Dynamic compilation: Java just-in-time (JIT) compilers
Deep IP portfolio
9 Java JIT group alone filed 14 U.S. patents in 2004, 6 in 2005.
11
Overview of IBM’s J9 JVM
What is the J9 JVM?
Sun IP-free, but Java 2 (1.3) compliant (J2ME) and J2SE (1.4.2, 5.0)
Multi-platform
9 PowerPC, IA32, x86-64, and 390 (Linux or z/OS)
9 More applications than the above outside of the middleware space
12
Overview of IBM’s J9 JVM
Scalability
Asynchronous compilation
9 Compilation of Java methods proceeds on a background thread
• Other application threads do not have to wait to execute the method
9 Improves startup time of heavily multithreaded applications on SMPs
13
Overview of IBM’s J9 JVM
Key Highlights for WAS
14
Overview
JVM Basics
Debugging Tools
15
Memory Management / Garbage Collection
Overview
16
Memory Management / Garbage Collection
JVM Memory Layout
JVM
Stack JVM
Data
Segment JVM
Segment Data
Segment
JVM
Native interpreter, verifier, JIT
Code compiler, memory manager, etc
JVM OS Interface
Operating System
Operating System
Typical JVM Architecture
17
Memory Management / Garbage Collection
Total Application Memory Footprint
Total available memory – is there enough memory to satisfy every request for
memory ?
Allocation Rate – how often does the application requests for memory ?
Object Lifetime – how long do these objects stay reserved by the application ?
19
Memory Management / Garbage Collection
Parallel VS Concurrent Collectors
20
Memory Management / Garbage Collection
What garbage collection algorithms are available on my JDK?
1. Serial – Collects objects one at a time in both new and old generations
2. Throughput - Uses a parallel model for collecting objects in the new generation
3. Concurrent – Uses parallel collection in the new generation and concurrent in old.
21
Memory Management / Garbage Collection
How the IBM Mark and Sweep Garbage Collector Works
Wilderness
Thread B
Used HeapHeap
Thread Local
Stack Garbage
Used Heap
Collector
Global Heap
Heap lock Used Heap
Thread A
Thread Local Heap
Stack
System Heap Thread Local Heap
(JDK 1.4.2)
22
Memory Management / Garbage Collection
How the IBM J9 Generational and Sun/HP Garbage Collectors Work
JVM Heap
24
Overview
JVM Basics
Debugging Tools
25
Runtime Performance Tuning
Overview
Tuning the JVM properly is a process that takes time and must be tailored to your
application.
9 HOWEVER you can typically get 80% of the maximum performance with 20%
of the work by ensuring that you are making good choice on a few key settings
9 To truly extract maximum performance from your application you must know
your applications memory allocation and runtime needs
The JVM must be tuned in two iterative steps over a testing cycle
9 Step 1: Heap Size tuning
9 Step 2: Applying runtime optimization
9 Applying these two steps repeatedly will lead you to a JVM tuned for your
application
26
Runtime Performance Tuning
Key Parameters
The key setting for the IBM JVM that effects performance most on all Java
application and should get you near 80% of your maximum performance if
set correctly is:
9 Heap Size (-Xms / -Xmx)
9 Ensure that you are setting your minimum and maximum to values that
are under you physical memory limitation but allow you to have a
substantially large interval between GC’s
• Typical low end bound on frequency of GC’s is 10sec
• Typical high end bound on duration of GC’s is 1-2sec
For the Sun/HP JVM a lot more work is required to get optimal performance
than just tuning the heap size as you need to tune the garbage collector and
runtime as well
9 A new JVM setting was introduced in JDK 1.4.1 that for Sun has shown
promise in automatically tuning the rest of heap settings for your machine
• -XX:+AggresiveHeap is issued at the command line and it makes
decisions on GC algorithms, Young/Old Generation spaces, and other
resources to use.
9 One must also issue the –server parameter to the Sun/HP JVMs to get
them to run in their highest performing mode.
27
Runtime Performance Tuning
What GC Policy should I choose for the J9 JVM?
28
Runtime Performance Tuning
Real world examples
29
Runtime Performance Tuning
Other IBM JVM Tuning Parameters
-Xnocompactgc - turns off compaction which can lead to fragmentation (default is false)
-Xmaxe / -Xmine - sets the maxium or minimum expansion unit during allocation
30
Runtime Performance Tuning
What GC Policy should I choose for the Sun JVM?
31
Runtime Performance Tuning
Other Sun/HP JVM Tuning Parameters
-Xincgc - incremental GC, uses the Train algorithm (default is disabled)
32
Runtime Performance Tuning
How to tune a generation GC setup – General
We need to consider the respective size of the nursery and the tenured
space.
Two approaches
9 Dynamic
• Specify the mininum and maxiumum heap size (e.g. –Xms512m –
Xmx1024m) and in the Sun JDK case -XX:+AggressiveHeap
• The JVM will dynamically size the nursery and tenured space.
• May not give optimal performance
• Could be good for low response times.
9 Fixed
• Be more specific on the nursery and/or tenured space sizes.
• Recommended approach for performance sensitive, server-side
applications.
33
Runtime Performance Tuning
How to tune a generation GC setup – Setting the tenured/old space
The tenured space must be large enough to hold all persistent data of
the application. Too small will cause excessive GC or even out of
memory conditions.
For a typical WebSphere Application Server application this is ~100-
400Mb.
One way to determine the tenure space size is to look at the amount of
free heap exists after each GC in default mode
9 %free heap x Total heap size
35
Tuning
Heap size options
-XmnAm -XmoBm
Nursery Tenured
0 A 0 B
A B C
36
Runtime Performance Tuning
Process for tuning heap settings
Set your
Performance
Give your best Tips
Tips
Start estimate for
Requirements mx and ms ••Run
Runyour
yourapplication,
application,
analyzeheap
analyze heapusage
usage
anddetermine
and determinethe the
Adjust mx steadystate.
steady state.
Stress test
and/or
your Setyour
Set your ms ms totothe
the
ms and possibly
application
switch GC steadystate.
steady state.
policy
••Make
Makesuresureyour
yourheap
heap
neverpages.
never pages.Monitor
Monitor
No yourpaging
your pagingactivities.
activities.
GC profile Analyze GC
Profile objects
If needed is good? behavior ••AArule
ruleof ofthumb
thumbisistoto
keep30%
keep 30%of ofyour
your
heapfree
heap freemost
mostof of
Yes
thetime.
the time.
Done.
37
Runtime Performance Tuning
Process for other runtime tuning settings
Set your
Tips
Tips
Set your
Start Performance
baseline
tuning
••Measure
Measurethroughput
throughput
Requirements
parameters duringsteady
during steadystate
stateof
of
thebenchmark
the benchmarkto to
ensureconsistent
ensure consistent
Stress test
results
results
Apply new
Tuning parameter
your
application
••Some
Sometuning
tuning
To runtime parameterswill
parameters willeffect
effect
performancenegatively
performance negatively
asthey
as theymight
mightbe be
targetedfor
targeted foranan
No
Remove tuning Is throughput as Analyze Runtime applicationwith
application withdifferent
different
behavior
Parameter if expected? runtimecharacteristics
runtime characteristics
Negative effect
thanyour
than yourapplication
application
Yes •• Add
Addonly
onlyone
onetuning
tuning
parameterat
parameter ataatime
timetoto
Done. measureits
measure itsimpact
impactalone
alone
38
Overview
JVM Basics
Debugging Tools
39
Debugging Tools
Garbage Collection Debugging/Analysis Tools (Verbose:GC)
Pros
9 can give a lot of detailed low-level information for serious debugging, enough
for initial investigation
9 readily available and it is free
Cons
9 Have to restart your server Æ not suitable for production environments
9 does not give object-level information for further analysis
40
Runtime Performance Tuning
Verbose:GC from J9
<af type="nursery" id="35" timestamp="Thu Aug 11 21:47:11 2005" intervalms="10730.361">
<minimum requested_bytes="144" />
<time exclusiveaccessms="1.193" />
<nursery freebytes="0" totalbytes="1226833920" percent="0" />
Allocation request
<tenured freebytes="68687704" totalbytes="209715200" percent="32" > details, time it took
<soa freebytes="58201944" totalbytes="199229440" percent="29" /> to stop all mutator
<loa freebytes="10485760" totalbytes="10485760" percent="100" /> threads.
</tenured>
<gc type="scavenger" id="35" totalid="35" intervalms="10731.054">
<flipped objectcount="1059594" bytes="56898904" /> Heap occupancy
<tenured objectcount="12580" bytes="677620" /> details before GC.
<refs_cleared soft="0" weak="691" phantom="39" />
<finalization objectsqueued="1216" />
<scavenger tiltratio="90" />
<nursery freebytes="1167543760" totalbytes="1226833920" percent="95" tenureage="14" />
Details about the
<tenured freebytes="67508056" totalbytes="209715200" percent="32" > scavenge.
<soa freebytes="57022296" totalbytes="199229440" percent="28" />
<loa freebytes="10485760" totalbytes="10485760" percent="100" />
</tenured>
<time totalms="368.309" /> Heap occupancy
</gc>
details after GC.
<nursery freebytes="1167541712" totalbytes="1226833920" percent="95" />
<tenured freebytes="67508056" totalbytes="209715200" percent="32" >
<soa freebytes="57022296" totalbytes="199229440" percent="28" />
<loa freebytes="10485760" totalbytes="10485760" percent="100" />
</tenured>
<time totalms="377.634" />
</af>
41
Debugging Tools
Garbage Collection Debugging/Analysis Tools – Sun/HP JVM verbose:gc output
-verbose:gc –XX:+PrintTenuringDistribution –XX:+PrintGCDetails –XX:+PrintGCStamps
Example:
0.0000013: [Full GC 0.0005366: [Tenured: 0K->4185K(1380352K), 0.3102502 secs] 62984K->4185K(2057344K), 0.3103787 secs]
42
Debugging Tools
IBM JDK Debugging/Analysis Tools
Thread dumps
9 Available on all JVM’s by issuing kill -3 <pid> on the command line where
the<pid> is your servers process id
9 In essence a snap shot in time of what your system is executing. Used to
debug and find where threads are spending time in your system, or are hung in
your system
Heap dump
9 Can be enabled to occur with a thread dump by setting the following JVM
properties
• Click on Application Server -> server1 -> Process definition -> custom
properties ->
• Enter Name = IBM_HEAPDUMP
• Value = true
• Enter Name = IBM_JAVA_HEAPDUMP_TEXT (this enables generating
heapdump in txt format, which can be analyzed using heaproots)
• Value = true
9 Can be analyzed using HeapRoots at
http://www.alphaworks.ibm.com/tech/heaproots
43
Debugging Tools
IBM JDK Debugging/Analysis Tools
44
A few VERY useful URLs
http://www-106.ibm.com/developerworks/java/jdk/diagnosis/
9 Contains all the diagnostic guides for our JVMs
9 PDF on GC and Memory usage
http://java.sun.com/docs/performance
9 Contains a large amount of documentation and tuning for the Sun JVM
9 Reference to all SUN JVM flags as well as an explanation of them
http://www.hp.com/products1/unix/java/infolibrary/index.html
9 Wealth of information on tuning and configuring the HPUX JVM
45
Thank you
Any questions ?
46
Backup and Extras
47
JVM Basics
The high level JVM Building Blocks – Part 1
IBM JVM
Execution Management –
Provides process control and
management
9 Threading engine resides here
49
Storage (ST)
HPI – A set of well defined
functions that provide low level HPI
facilities and services in a
platform neutral way.
50
-XX:SurvivorRatio=nn -XX:MaxTenuringThreshold=nn
Survivor Survivor
Eden
Space Space
51