SlideShare a Scribd company logo
Chris Bailey – IBM Runtime Monitoring and Diagnostics 
30th September 2014 
Java Debugging 
Tools and Tricks for Troubleshooting 
Document number 
© 2014 IBM Corporation
© 2014 IBM Corporation 
Important Disclaimers 
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. 
WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION 
CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED. 
ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED 
ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR 
INFRASTRUCTURE DIFFERENCES. 
ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. 
IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT 
PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. 
IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE 
USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. 
NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: 
- CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR 
SUPPLIERS AND/OR LICENSORS 
2
Introduction to the speaker 
 Chris Bailey 
IBM Runtime Monitoring and Diagnostics Architect 
- 14 years working with Java and JVM technologies 
 Recent work focus: 
- Java monitoring, diagnostics and troubleshooting 
- Java integration into the cloud 
- JavaScript monitoring, diagnostics and troubleshooting 
 My contact information: 
- baileyc@uk.ibm.com 
- http://www.linkedin.com/in/chrisbaileyibm 
- http://www.slideshare.net/cnbailey/ 
- @Chris__Bailey 
© 2014 3 IBM Corporation
OutOfMemory 
© 2014 4 IBM Corporation
Java Memory Usage 
 Maximum memory available to a process is determined by architecture 
– 32bit process is limited to 2^32 bytes = 4GB 
– 64bit process is limited to 2^64 bytes = 16 EiB 
● Example for 32bit: 
0 GB 4 GB 
-Xmx 
OS and C-Runtime Java Heap(s) 
Native Heap 
0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 
 Amount and location of memory used for “OS and C Runtime” determined by OS 
© 2014 5 IBM Corporation
Layout by OS 
 Windows 32bit: 
0 GB 4 GB 
-Xmx 
Java Heap(s) Native Heap 
OS and C-Runtime 
0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 
 Windows 32bit with /3GB: 
Libraries 
0 GB 4 GB 
-Xmx 
Java Heap(s) Native Heap 
OS and C-Runtime 
0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 
Libraries 
© 2014 6 IBM Corporation
Layout by OS 
 Linux 32bit: 
0 GB 4 GB 
-Xmx 
Java Heap(s) Native Heap 
Kernel 
0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 
 Linux with hugemem kernel: 
0 GB 4 GB 
-Xmx 
Java Heap(s) Native Heap 
K 
0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 
© 2014 7 IBM Corporation
Native Heap Usage 
Java Heap Native Heap 
© 2014 8 IBM Corporation
Native Heap Usage 
Java Heap Native Heap 
© 2014 9 IBM Corporation
OutOfMemoryErrors 
 An OutOfMemoryError occurs if the Java heap or Native heap is exhausted 
– Or the PermArea (for HotSpot before Java 8) 
 Tools are needed to track the memory usage of each of the pools: 
– Kernel/OS: OS (malloc) managed 
– Native Heap: OS (malloc) managed 
– Java Heap: Garbage Collection managed 
 Malloc managed memory needs to be tracked at the OS level* 
 Garbage Collection needs to be tracked at the Java runtime level 
* The JVM can grab this information from the OS for you 
© 2014 10 IBM Corporation
OS Level Memory Monitoring 
Linux: “ps” utility Windows: “perfmon” Virtual Bytes counters 
#!/bin/sh 
PID=$1 
INTERVAL=3 
# Echo time at start of monitoring. 
echo timestamp = `date +%s` 
# Echo the interval frequency. 
echo "ps interval = $INTERVAL" 
# Run the system command at intervals. 
while ([ -d /proc/$PID ]) do 
ps -p $PID -o pid,vsz,rss 
sleep $INTERVAL 
done 
Can be collected to CSV file 
© 2014 11 IBM Corporation
OS Level Memory Monitoring 
Linux: “ps” utility Windows: “perfmon” Virtual Bytes counters 
#!/bin/sh 
PID=$1 
INTERVAL=3 
# Echo time at start of monitoring. 
echo timestamp = `date +%s` 
# Echo the interval frequency. 
echo "ps interval = $INTERVAL" 
# Run the system command at intervals. 
while ([ -d /proc/$PID ]) do 
ps -p $PID -o pid,vsz,rss 
sleep $INTERVAL 
done 
Can be collected to CSV file 
© 2014 12 IBM Corporation
Visualization of OS level memory monitoring 
● Garbage Collection and Memory Visualizer (GCMV): 
- Available from 
● Tool to analyze Java Heap and “Native” Heap memory 
● Provides Graphical Display of Data 
- Allows zooming and cropping 
- Allows change of axes value and units 
- Allows comparison of multiple files 
● Analysis and Recommendations 
- Statistical summary and recommendations 
- Flags errors and warnings 
● Supports Linux, Windows, AIX, i5/OS and z/OS 
© 2014 13 IBM Corporation
Runtime Monitoring using JVM Tools 
 IBM Health Center (IBM JVMs*) 
– -Xhealthcenter 
 Machine and process memory usage 
 Native heap breakdown 
* limited support exists for HotSpot 
 Oracle Mission Control (HotSpot JVMs) 
– -XX:+UnlockCommercialFeatures 
– -XX:+FlightRecorder 
 Machine and process memory usage 
© 2014 14 IBM Corporation
OS Level Memory Profiling 
Windows: UMDH 
 Takes snapshot of the current native heap 
 Tracks allocating stack traces 
 Second snapshot is taken and stack traces 
for outstanding memory is produced 
000000AD bytes in 0x1 allocations (@ 0x00000031 + 
0x0000001F) by: BackTrace00468 
ntdll!RtlpNtMakeTemporaryKey+000074D0 
ntdll!RtlInitializeSListHead+00010D08 
ntdll!wcsncat+00000224 
leakyjniapp! 
Java_com_ibm_jtc_demos_LeakyJNIApp_nativeMethod 
 Detailed on Microsoft website: 
http://support.microsoft.com/kb/268343 
 Also check out “debugdiag” 
Linux:Debug Malloc / Malloc Interception 
 Approach 1: 
– Intercept calls to malloc and free 
– Create a stacks allocation table 
– IBM provides a Linux Memory Tracker 
 Approach 2: valgrind 
valgrind --trace-children=yes --leak-check=full 
LEAK SUMMARY: 
definitely lost: 63,957 bytes in 69 blocks. 
indirectly lost: 2,168 bytes in 12 blocks. 
possibly lost: 8,600 bytes in 11 blocks. 
still reachable: 5,156,340 bytes in 980 blocks. 
suppressed: 0 bytes in 0 blocks. 
Reachable blocks (those to which a pointer was 
found) are not shown. 
© 2014 15 IBM Corporation
Garbage Collection Monitoring 
 IBM JVMs: 
– -verbose:gc 
– -Xverbosegclog:<name>,X,Y 
 Oracle JVMs: 
– -XX:+PrintGCDateStamps 
– -XX:+PrintGCDetails 
– -XX:+PrintGCTimeStamps 
– -Xloggc:<name> 
 Visualization available in GCMV for both IBM and Oracle verbose:gc 
© 2014 16 IBM Corporation
Runtime GC Monitoring 
 IBM Health Center (IBM JVMs*) 
– -Xhealthcenter 
 Used Heap and Pause Times 
 Allocation Profiling 
* limited support exists for HotSpot 
 Oracle Mission Control (HotSpot JVMs) 
– -XX:+UnlockCommercialFeatures 
– -XX:+FlightRecorder 
 Used Heap and Pause Times 
 Allocation profiling 
© 2014 17 IBM Corporation
Java Heap Profiling: Heap Dump Analysis 
 IBM JVMs: System Dump of PHD 
– -Xdump:system|heap:events=systhrow, 
filter=java/lang/OutOfMemoryError 
– -Xdump:system|heap:events=user 
– -Xtrace:maximal=mt,trigger= 
method{<name>,sysdump|heapdump} 
– com.ibm.jvm.Dump.JavaDump()/HeapDump() 
– Health Center 
 Oracle JVMs: HPROF dump 
 Visualization available in IBM Memory Analyzer 
– -XX:+HeapDumpOnOutOfMemoryError 
– jmap -dump:format=b 
– JConsole 
– Supports both IBM and HotSpot dumps 
– Provides leak and footprint analysis 
– Provides heap and application visualization 
© 2014 18 IBM Corporation
Java Heap Profiling: Heap Dump Analysis 
© 2014 19 IBM Corporation
Debugging from Dumps 
© 2014 20 IBM Corporation
Debugging from Dumps 
● System dumps and HPROF dumps contain Object fields and values 
● System dumps also have thread stacks and local variables 
● Provides visibility into code flow 
● Zero ongoing performance overhead 
● Dump time is ~2s/GB 
● Makes it possible to diagnose a much wider set of issues 
● Exceptions: ability to look at data not exposed in the message 
● Functional Issues: possible to look at the data being acted on 
© 2014 21 IBM Corporation
Exceptions 
● java.net.ConnectException 
java.net.ConnectException: Connection refused: connect 
at java.net.PlainSocketImpl.socketConnect(Native Method) 
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:352) 
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:214) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:201) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377) 
● Stack trace in Memory Analyzer gives 
access to local variables 
- host Name = Bailey-W530 
- port = 100 
© 2014 22 IBM Corporation
Functional Issues 
● java.lang.OutOfMemoryError allocating a 1,129,665,376 byte object 
at com/ibm/wsspi/security/token/WSOpaqueTokenHelper.readTokens(WSOpaqueTokenHelper.java:924) 
at com/ibm/wsspi/security/token/WSOpaqueTokenHelper.createTokenHolderListFromOpaqueToken(WSOpaqueTokenHelper.java:844) 
at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl.fromBytesInDomain(MessagingEngineIdentityImpl.java:439) 
at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl.access$200(MessagingEngineIdentityImpl.java:91) 
at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl$2.run(MessagingEngineIdentityImpl.java:299) 
at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl$2.run(MessagingEngineIdentityImpl.java:293) 
at com/ibm/ws/sib/security/impl/BusUtilities.doInBusDomain(BusUtilities.java:115) 
● The readTokens method references a ByteArrayInputStream with a pos of 2369 
● Content of ByteArrayStream around 2369: 
● Which converts to 1,129,665,364 
© 2014 23 IBM Corporation
Performance 
© 2014 24 IBM Corporation
Performance Analysis 
 Need to look at each of the layers of the application: 
– Platform: Machine and Operating System resources 
– Runtime: Java heap resources 
– Application: Inefficient code, synchronization 
 Recommended to look at Platform and Runtime first 
– “Easy to resolve” 
 Biggest gains are in the application and back end responsiveness 
– OS and Java Runtime are already highly tuned and self adapting 
© 2014 25 IBM Corporation
OS Level Memory Monitoring 
Linux: 
vmstat {interval} {samples} > vmstat.out 
procs -----------memory---------- -swap- --io-- --system-- ---cpu--- 
r b swpd free buff cache si so bi bo in cs us sy id wa 
0 0 17196 679860 1196656 2594884 0 0 1 4 0 0 0 0 100 0 
0 0 17196 679868 1196656 2594884 0 0 0 40 1012 43 0 0 100 0 
0 0 17196 679992 1196656 2594884 0 0 0 3 1004 43 0 0 100 0 
top -H -b -c > top_threads.out 
Windows: “perfmon”: 
Process > Page Faults/sec 
Process > %Processor Time 
Network > Output Queue Length 
Physical Disk > Current Disk Queue Length 
Can be collected to CSV file 
top - 15:46:52 up 178 days, 4:53, 2 users, load average: 0.31, 
0.08, 0.02 
Tasks: 77 total, 2 running, 74 sleeping, 1 stopped, 0 zombie 
Cpu(s): 24.6% us, 0.5% sy, 0.0% ni, 74.9% id, 0.0% wa, 0.0% hi, 
0.0% si 
Mem: 5591016k total, 5416896k used, 174120k free, 1196656k 
buffers 
Swap: 2104472k total, 17196k used, 2087276k free, 2594884k 
cached 
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 
8502 user1 25 0 599m 466m 5212 R 99.9 8.5 0:23.92 java 
7547 root 15 0 33472 2916 1144 S 0.3 0.1 778:17.98 X 
1 root 16 0 656 228 192 S 0.0 0.0 0:07.43 init 
© 2014 26 IBM Corporation
Garbage Collection Monitoring 
 IBM JVMs: 
– -verbose:gc 
– -Xverbosegclog:<name>,X,Y 
 Oracle JVMs: 
– -XX:+PrintGCDateStamps 
– -XX:+PrintGCDetails 
– -XX:+PrintGCTimeStamps 
– -Xloggc:<name> 
 Visualization available in GCMV for both IBM and Oracle verbose:gc 
© 2014 27 IBM Corporation
Runtime GC Monitoring 
 IBM Health Center (IBM JVMs*) 
– -Xhealthcenter 
 Used Heap and Pause Times 
 Allocation Profiling 
 Oracle Mission Control (HotSpot JVMs) 
– -XX:+UnlockCommercialFeatures 
– -XX:+FlightRecorder 
 Used Heap and Pause Times 
 Allocation profiling 
© 2014 28 IBM Corporation
Application method CPU usage 
 IBM Health Center (IBM JVMs*) 
– -Xhealthcenter 
 CPU usage per method 
 Method call graphs 
 Oracle Mission Control (HotSpot JVMs) 
– -XX:+UnlockCommercialFeatures 
– -XX:+FlightRecorder 
 CPU usage per method 
 Method call graphs 
© 2014 29 IBM Corporation
Application lock usage 
 IBM Health Center (IBM JVMs*) 
– -Xhealthcenter 
 Contention frequency and time 
 Lock hold time 
 Oracle Mission Control (HotSpot JVMs) 
– -XX:+UnlockCommercialFeatures 
– -XX:+FlightRecorder 
 Contention frequency and time 
 Lock hold time 
© 2014 30 IBM Corporation
Questions? 
© 2014 31 IBM Corporation
IBM Developer Kits for Java 
ibm.biz/javasdk 
WebShere Liberty Profile 
wasdev.net 
IBM Bluemix 
ibm.com/bluemix 
IBM Developer Kits for Node.js 
ibm.biz/nodesdk 
© 2014 32 IBM Corporation
www.ibm.com/developer 
Discover 
new technical resources. 
ibm.biz/javaone2014 
Visit Booth 5511 to learn about Cloud, DevOps and Mobile solutions 
© 2014 IBM Corporation 
Develop 
your coding skills. 
Connect 
with developers.
Copyright and Trademarks 
© IBM Corporation 2013. All Rights Reserved. 
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International 
Business Machines Corp., and registered in many jurisdictions worldwide. 
Other product and service names might be trademarks of IBM or other companies. 
A current list of IBM trademarks is available on the Web – see the IBM “Copyright and 
trademark information” page at URL: www.ibm.com/legal/copytrade.shtml 
© 2014 34 IBM Corporation
© 2014 35 IBM Corporation

More Related Content

PDF
Debugging Java from Dumps
PDF
IBM Monitoring and Diagnostic Tools - GCMV 2.8
PDF
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
PDF
Practical Performance: Understand and improve the performance of your applica...
PDF
Introduction to the IBM Java Tools
PDF
Impact2014: Practical Performance Troubleshooting
PPTX
HotSpotコトハジメ
PPTX
Java performance tuning
Debugging Java from Dumps
IBM Monitoring and Diagnostic Tools - GCMV 2.8
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
Practical Performance: Understand and improve the performance of your applica...
Introduction to the IBM Java Tools
Impact2014: Practical Performance Troubleshooting
HotSpotコトハジメ
Java performance tuning

What's hot (20)

PDF
Transparent GPU Exploitation for Java
PDF
Как мы взломали распределенные системы конфигурационного управления
PDF
Going to Mars with Groovy Domain-Specific Languages
PPTX
자바 성능 강의
PDF
Python + GDB = Javaデバッガ
PDF
FLOW3 Tutorial - T3CON11 Frankfurt
PDF
A new execution model for Nashorn in Java 9
PPTX
ClassLoader Leaks
KEY
Scaling Django
PDF
Performance Benchmarking of Clouds Evaluating OpenStack
PDF
The OMR GC talk - Ruby Kaigi 2015
PDF
Advanced AV Foundation (CocoaConf, Aug '11)
PDF
Diagnosing Your Application on the JVM
PDF
[NYC Meetup] Docker at Nuxeo
PDF
Spring Performance Gains
PPTX
Modern Java Workshop
PPT
Find bottleneck and tuning in Java Application
PDF
MySQL and Spark machine learning performance on Azure VMsbased on 3rd Gen AMD...
ODP
Power ai image-pipeline
PDF
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Transparent GPU Exploitation for Java
Как мы взломали распределенные системы конфигурационного управления
Going to Mars with Groovy Domain-Specific Languages
자바 성능 강의
Python + GDB = Javaデバッガ
FLOW3 Tutorial - T3CON11 Frankfurt
A new execution model for Nashorn in Java 9
ClassLoader Leaks
Scaling Django
Performance Benchmarking of Clouds Evaluating OpenStack
The OMR GC talk - Ruby Kaigi 2015
Advanced AV Foundation (CocoaConf, Aug '11)
Diagnosing Your Application on the JVM
[NYC Meetup] Docker at Nuxeo
Spring Performance Gains
Modern Java Workshop
Find bottleneck and tuning in Java Application
MySQL and Spark machine learning performance on Azure VMsbased on 3rd Gen AMD...
Power ai image-pipeline
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Ad

Viewers also liked (16)

PPTX
Hands-on Performance Tuning Lab - Devoxx Poland
PPTX
Java profiling Do It Yourself
PDF
WebSphere Technical University: Introduction to the Java Diagnostic Tools
PDF
Profiler Guided Java Performance Tuning
PDF
Debugging Your Production JVM
PDF
Towards JVM Dynamic Languages Toolchain
PDF
Hotspot Garbage Collection - The Useful Parts
PPT
Efficient Memory and Thread Management in Highly Parallel Java Applications
PDF
Java Performance Tuning
PPT
Java Performance Tuning
PPT
Real Life Java EE Performance Tuning
ODP
An Introduction To Java Profiling
PPTX
Java performance tuning
PPT
Java Performance Monitoring & Tuning
PDF
WebSphere Technical University: Top WebSphere Problem Determination Features
KEY
Everything I Ever Learned About JVM Performance Tuning @Twitter
Hands-on Performance Tuning Lab - Devoxx Poland
Java profiling Do It Yourself
WebSphere Technical University: Introduction to the Java Diagnostic Tools
Profiler Guided Java Performance Tuning
Debugging Your Production JVM
Towards JVM Dynamic Languages Toolchain
Hotspot Garbage Collection - The Useful Parts
Efficient Memory and Thread Management in Highly Parallel Java Applications
Java Performance Tuning
Java Performance Tuning
Real Life Java EE Performance Tuning
An Introduction To Java Profiling
Java performance tuning
Java Performance Monitoring & Tuning
WebSphere Technical University: Top WebSphere Problem Determination Features
Everything I Ever Learned About JVM Performance Tuning @Twitter
Ad

Similar to JavaOne 2014: Java Debugging (20)

PDF
A165 tools for java and javascript
PDF
Impact2014: Introduction to the IBM Java Tools
PDF
Java performance - not so scary after all
PDF
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
PDF
Web Sphere Problem Determination Ext
ODP
Debugging Native heap OOM - JavaOne 2013
ODP
Windows Debugging Tools - JavaOne 2013
PPTX
JavaPerformanceChapter_4
PDF
Java Performance and Profiling
PDF
Java Performance and Using Java Flight Recorder
PDF
A Taste of Monitoring and Post Mortem Debugging with Node
PDF
Hp java heap dump analysis Workshop
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
PDF
Software Profiling: Java Performance, Profiling and Flamegraphs
PDF
NZS-4409 - Enterprise Java Monitoring on zOS Discover, Alert, Optimize
PDF
Software Profiling: Understanding Java Performance and how to profile in Java
PPT
Eclipse Memory Analyzer - More Than Just a Heap Walker
PDF
It's Good to Have (JVM) Options - JavaOne
ODP
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
PDF
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...
A165 tools for java and javascript
Impact2014: Introduction to the IBM Java Tools
Java performance - not so scary after all
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
Web Sphere Problem Determination Ext
Debugging Native heap OOM - JavaOne 2013
Windows Debugging Tools - JavaOne 2013
JavaPerformanceChapter_4
Java Performance and Profiling
Java Performance and Using Java Flight Recorder
A Taste of Monitoring and Post Mortem Debugging with Node
Hp java heap dump analysis Workshop
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Software Profiling: Java Performance, Profiling and Flamegraphs
NZS-4409 - Enterprise Java Monitoring on zOS Discover, Alert, Optimize
Software Profiling: Understanding Java Performance and how to profile in Java
Eclipse Memory Analyzer - More Than Just a Heap Walker
It's Good to Have (JVM) Options - JavaOne
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
JavaOne 2015 CON7547 "Beyond the Coffee Cup: Leveraging Java Runtime Technolo...

More from Chris Bailey (20)

PDF
NodeJS Interactive 2019: FaaS meets Frameworks
PDF
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
PDF
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
PDF
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
PDF
AltConf 2019: Server-Side Swift State of the Union
PDF
Server-side Swift with Swagger
PDF
Node Summit 2018: Cloud Native Node.js
PDF
Index - BFFs vs GraphQL
PDF
Swift Cloud Workshop - Swift Microservices
PDF
Swift Cloud Workshop - Codable, the key to Fullstack Swift
PDF
Try!Swift India 2017: All you need is Swift
PDF
Swift Summit 2017: Server Swift State of the Union
PDF
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
PDF
IBM Cloud University: Java, Node.js and Swift
PDF
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
PDF
FrenchKit 2017: Server(less) Swift
PDF
AltConf 2017: Full Stack Swift in 30 Minutes
PDF
InterConnect: Server Side Swift for Java Developers
PDF
InterConnect: Java, Node.js and Swift - Which, Why and When
PDF
Playgrounds: Mobile + Swift = BFF
NodeJS Interactive 2019: FaaS meets Frameworks
Voxxed Micro-services: Serverless JakartaEE - JAX-RS comes to FaaS
Silicon Valley Code Camp 2019 - Reaching the Cloud Native World
FaaS Meets Java EE: Developing Cloud Native Applications at Speed
AltConf 2019: Server-Side Swift State of the Union
Server-side Swift with Swagger
Node Summit 2018: Cloud Native Node.js
Index - BFFs vs GraphQL
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Codable, the key to Fullstack Swift
Try!Swift India 2017: All you need is Swift
Swift Summit 2017: Server Swift State of the Union
IBM Cloud University: Build, Deploy and Scale Node.js Microservices
IBM Cloud University: Java, Node.js and Swift
Node Interactive: Node.js Performance and Highly Scalable Micro-Services
FrenchKit 2017: Server(less) Swift
AltConf 2017: Full Stack Swift in 30 Minutes
InterConnect: Server Side Swift for Java Developers
InterConnect: Java, Node.js and Swift - Which, Why and When
Playgrounds: Mobile + Swift = BFF

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Digital Strategies for Manufacturing Companies
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
top salesforce developer skills in 2025.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
AI in Product Development-omnex systems
PPTX
L1 - Introduction to python Backend.pptx
PDF
System and Network Administration Chapter 2
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
medical staffing services at VALiNTRY
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Design an Analysis of Algorithms II-SECS-1021-03
How Creative Agencies Leverage Project Management Software.pdf
Operating system designcfffgfgggggggvggggggggg
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Digital Strategies for Manufacturing Companies
Which alternative to Crystal Reports is best for small or large businesses.pdf
top salesforce developer skills in 2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Introduction to Artificial Intelligence
Design an Analysis of Algorithms I-SECS-1021-03
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
AI in Product Development-omnex systems
L1 - Introduction to python Backend.pptx
System and Network Administration Chapter 2
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

JavaOne 2014: Java Debugging

  • 1. Chris Bailey – IBM Runtime Monitoring and Diagnostics 30th September 2014 Java Debugging Tools and Tricks for Troubleshooting Document number © 2014 IBM Corporation
  • 2. © 2014 IBM Corporation Important Disclaimers THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS 2
  • 3. Introduction to the speaker  Chris Bailey IBM Runtime Monitoring and Diagnostics Architect - 14 years working with Java and JVM technologies  Recent work focus: - Java monitoring, diagnostics and troubleshooting - Java integration into the cloud - JavaScript monitoring, diagnostics and troubleshooting  My contact information: - baileyc@uk.ibm.com - http://www.linkedin.com/in/chrisbaileyibm - http://www.slideshare.net/cnbailey/ - @Chris__Bailey © 2014 3 IBM Corporation
  • 4. OutOfMemory © 2014 4 IBM Corporation
  • 5. Java Memory Usage  Maximum memory available to a process is determined by architecture – 32bit process is limited to 2^32 bytes = 4GB – 64bit process is limited to 2^64 bytes = 16 EiB ● Example for 32bit: 0 GB 4 GB -Xmx OS and C-Runtime Java Heap(s) Native Heap 0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000  Amount and location of memory used for “OS and C Runtime” determined by OS © 2014 5 IBM Corporation
  • 6. Layout by OS  Windows 32bit: 0 GB 4 GB -Xmx Java Heap(s) Native Heap OS and C-Runtime 0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000  Windows 32bit with /3GB: Libraries 0 GB 4 GB -Xmx Java Heap(s) Native Heap OS and C-Runtime 0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 Libraries © 2014 6 IBM Corporation
  • 7. Layout by OS  Linux 32bit: 0 GB 4 GB -Xmx Java Heap(s) Native Heap Kernel 0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000  Linux with hugemem kernel: 0 GB 4 GB -Xmx Java Heap(s) Native Heap K 0x0 0x80000000 0xFFFFFFFF 0x40000000 0xC0000000 © 2014 7 IBM Corporation
  • 8. Native Heap Usage Java Heap Native Heap © 2014 8 IBM Corporation
  • 9. Native Heap Usage Java Heap Native Heap © 2014 9 IBM Corporation
  • 10. OutOfMemoryErrors  An OutOfMemoryError occurs if the Java heap or Native heap is exhausted – Or the PermArea (for HotSpot before Java 8)  Tools are needed to track the memory usage of each of the pools: – Kernel/OS: OS (malloc) managed – Native Heap: OS (malloc) managed – Java Heap: Garbage Collection managed  Malloc managed memory needs to be tracked at the OS level*  Garbage Collection needs to be tracked at the Java runtime level * The JVM can grab this information from the OS for you © 2014 10 IBM Corporation
  • 11. OS Level Memory Monitoring Linux: “ps” utility Windows: “perfmon” Virtual Bytes counters #!/bin/sh PID=$1 INTERVAL=3 # Echo time at start of monitoring. echo timestamp = `date +%s` # Echo the interval frequency. echo "ps interval = $INTERVAL" # Run the system command at intervals. while ([ -d /proc/$PID ]) do ps -p $PID -o pid,vsz,rss sleep $INTERVAL done Can be collected to CSV file © 2014 11 IBM Corporation
  • 12. OS Level Memory Monitoring Linux: “ps” utility Windows: “perfmon” Virtual Bytes counters #!/bin/sh PID=$1 INTERVAL=3 # Echo time at start of monitoring. echo timestamp = `date +%s` # Echo the interval frequency. echo "ps interval = $INTERVAL" # Run the system command at intervals. while ([ -d /proc/$PID ]) do ps -p $PID -o pid,vsz,rss sleep $INTERVAL done Can be collected to CSV file © 2014 12 IBM Corporation
  • 13. Visualization of OS level memory monitoring ● Garbage Collection and Memory Visualizer (GCMV): - Available from ● Tool to analyze Java Heap and “Native” Heap memory ● Provides Graphical Display of Data - Allows zooming and cropping - Allows change of axes value and units - Allows comparison of multiple files ● Analysis and Recommendations - Statistical summary and recommendations - Flags errors and warnings ● Supports Linux, Windows, AIX, i5/OS and z/OS © 2014 13 IBM Corporation
  • 14. Runtime Monitoring using JVM Tools  IBM Health Center (IBM JVMs*) – -Xhealthcenter  Machine and process memory usage  Native heap breakdown * limited support exists for HotSpot  Oracle Mission Control (HotSpot JVMs) – -XX:+UnlockCommercialFeatures – -XX:+FlightRecorder  Machine and process memory usage © 2014 14 IBM Corporation
  • 15. OS Level Memory Profiling Windows: UMDH  Takes snapshot of the current native heap  Tracks allocating stack traces  Second snapshot is taken and stack traces for outstanding memory is produced 000000AD bytes in 0x1 allocations (@ 0x00000031 + 0x0000001F) by: BackTrace00468 ntdll!RtlpNtMakeTemporaryKey+000074D0 ntdll!RtlInitializeSListHead+00010D08 ntdll!wcsncat+00000224 leakyjniapp! Java_com_ibm_jtc_demos_LeakyJNIApp_nativeMethod  Detailed on Microsoft website: http://support.microsoft.com/kb/268343  Also check out “debugdiag” Linux:Debug Malloc / Malloc Interception  Approach 1: – Intercept calls to malloc and free – Create a stacks allocation table – IBM provides a Linux Memory Tracker  Approach 2: valgrind valgrind --trace-children=yes --leak-check=full LEAK SUMMARY: definitely lost: 63,957 bytes in 69 blocks. indirectly lost: 2,168 bytes in 12 blocks. possibly lost: 8,600 bytes in 11 blocks. still reachable: 5,156,340 bytes in 980 blocks. suppressed: 0 bytes in 0 blocks. Reachable blocks (those to which a pointer was found) are not shown. © 2014 15 IBM Corporation
  • 16. Garbage Collection Monitoring  IBM JVMs: – -verbose:gc – -Xverbosegclog:<name>,X,Y  Oracle JVMs: – -XX:+PrintGCDateStamps – -XX:+PrintGCDetails – -XX:+PrintGCTimeStamps – -Xloggc:<name>  Visualization available in GCMV for both IBM and Oracle verbose:gc © 2014 16 IBM Corporation
  • 17. Runtime GC Monitoring  IBM Health Center (IBM JVMs*) – -Xhealthcenter  Used Heap and Pause Times  Allocation Profiling * limited support exists for HotSpot  Oracle Mission Control (HotSpot JVMs) – -XX:+UnlockCommercialFeatures – -XX:+FlightRecorder  Used Heap and Pause Times  Allocation profiling © 2014 17 IBM Corporation
  • 18. Java Heap Profiling: Heap Dump Analysis  IBM JVMs: System Dump of PHD – -Xdump:system|heap:events=systhrow, filter=java/lang/OutOfMemoryError – -Xdump:system|heap:events=user – -Xtrace:maximal=mt,trigger= method{<name>,sysdump|heapdump} – com.ibm.jvm.Dump.JavaDump()/HeapDump() – Health Center  Oracle JVMs: HPROF dump  Visualization available in IBM Memory Analyzer – -XX:+HeapDumpOnOutOfMemoryError – jmap -dump:format=b – JConsole – Supports both IBM and HotSpot dumps – Provides leak and footprint analysis – Provides heap and application visualization © 2014 18 IBM Corporation
  • 19. Java Heap Profiling: Heap Dump Analysis © 2014 19 IBM Corporation
  • 20. Debugging from Dumps © 2014 20 IBM Corporation
  • 21. Debugging from Dumps ● System dumps and HPROF dumps contain Object fields and values ● System dumps also have thread stacks and local variables ● Provides visibility into code flow ● Zero ongoing performance overhead ● Dump time is ~2s/GB ● Makes it possible to diagnose a much wider set of issues ● Exceptions: ability to look at data not exposed in the message ● Functional Issues: possible to look at the data being acted on © 2014 21 IBM Corporation
  • 22. Exceptions ● java.net.ConnectException java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:352) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:214) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:201) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377) ● Stack trace in Memory Analyzer gives access to local variables - host Name = Bailey-W530 - port = 100 © 2014 22 IBM Corporation
  • 23. Functional Issues ● java.lang.OutOfMemoryError allocating a 1,129,665,376 byte object at com/ibm/wsspi/security/token/WSOpaqueTokenHelper.readTokens(WSOpaqueTokenHelper.java:924) at com/ibm/wsspi/security/token/WSOpaqueTokenHelper.createTokenHolderListFromOpaqueToken(WSOpaqueTokenHelper.java:844) at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl.fromBytesInDomain(MessagingEngineIdentityImpl.java:439) at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl.access$200(MessagingEngineIdentityImpl.java:91) at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl$2.run(MessagingEngineIdentityImpl.java:299) at com/ibm/ws/sib/security/impl/MessagingEngineIdentityImpl$2.run(MessagingEngineIdentityImpl.java:293) at com/ibm/ws/sib/security/impl/BusUtilities.doInBusDomain(BusUtilities.java:115) ● The readTokens method references a ByteArrayInputStream with a pos of 2369 ● Content of ByteArrayStream around 2369: ● Which converts to 1,129,665,364 © 2014 23 IBM Corporation
  • 24. Performance © 2014 24 IBM Corporation
  • 25. Performance Analysis  Need to look at each of the layers of the application: – Platform: Machine and Operating System resources – Runtime: Java heap resources – Application: Inefficient code, synchronization  Recommended to look at Platform and Runtime first – “Easy to resolve”  Biggest gains are in the application and back end responsiveness – OS and Java Runtime are already highly tuned and self adapting © 2014 25 IBM Corporation
  • 26. OS Level Memory Monitoring Linux: vmstat {interval} {samples} > vmstat.out procs -----------memory---------- -swap- --io-- --system-- ---cpu--- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 17196 679860 1196656 2594884 0 0 1 4 0 0 0 0 100 0 0 0 17196 679868 1196656 2594884 0 0 0 40 1012 43 0 0 100 0 0 0 17196 679992 1196656 2594884 0 0 0 3 1004 43 0 0 100 0 top -H -b -c > top_threads.out Windows: “perfmon”: Process > Page Faults/sec Process > %Processor Time Network > Output Queue Length Physical Disk > Current Disk Queue Length Can be collected to CSV file top - 15:46:52 up 178 days, 4:53, 2 users, load average: 0.31, 0.08, 0.02 Tasks: 77 total, 2 running, 74 sleeping, 1 stopped, 0 zombie Cpu(s): 24.6% us, 0.5% sy, 0.0% ni, 74.9% id, 0.0% wa, 0.0% hi, 0.0% si Mem: 5591016k total, 5416896k used, 174120k free, 1196656k buffers Swap: 2104472k total, 17196k used, 2087276k free, 2594884k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 8502 user1 25 0 599m 466m 5212 R 99.9 8.5 0:23.92 java 7547 root 15 0 33472 2916 1144 S 0.3 0.1 778:17.98 X 1 root 16 0 656 228 192 S 0.0 0.0 0:07.43 init © 2014 26 IBM Corporation
  • 27. Garbage Collection Monitoring  IBM JVMs: – -verbose:gc – -Xverbosegclog:<name>,X,Y  Oracle JVMs: – -XX:+PrintGCDateStamps – -XX:+PrintGCDetails – -XX:+PrintGCTimeStamps – -Xloggc:<name>  Visualization available in GCMV for both IBM and Oracle verbose:gc © 2014 27 IBM Corporation
  • 28. Runtime GC Monitoring  IBM Health Center (IBM JVMs*) – -Xhealthcenter  Used Heap and Pause Times  Allocation Profiling  Oracle Mission Control (HotSpot JVMs) – -XX:+UnlockCommercialFeatures – -XX:+FlightRecorder  Used Heap and Pause Times  Allocation profiling © 2014 28 IBM Corporation
  • 29. Application method CPU usage  IBM Health Center (IBM JVMs*) – -Xhealthcenter  CPU usage per method  Method call graphs  Oracle Mission Control (HotSpot JVMs) – -XX:+UnlockCommercialFeatures – -XX:+FlightRecorder  CPU usage per method  Method call graphs © 2014 29 IBM Corporation
  • 30. Application lock usage  IBM Health Center (IBM JVMs*) – -Xhealthcenter  Contention frequency and time  Lock hold time  Oracle Mission Control (HotSpot JVMs) – -XX:+UnlockCommercialFeatures – -XX:+FlightRecorder  Contention frequency and time  Lock hold time © 2014 30 IBM Corporation
  • 31. Questions? © 2014 31 IBM Corporation
  • 32. IBM Developer Kits for Java ibm.biz/javasdk WebShere Liberty Profile wasdev.net IBM Bluemix ibm.com/bluemix IBM Developer Kits for Node.js ibm.biz/nodesdk © 2014 32 IBM Corporation
  • 33. www.ibm.com/developer Discover new technical resources. ibm.biz/javaone2014 Visit Booth 5511 to learn about Cloud, DevOps and Mobile solutions © 2014 IBM Corporation Develop your coding skills. Connect with developers.
  • 34. Copyright and Trademarks © IBM Corporation 2013. All Rights Reserved. IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., and registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web – see the IBM “Copyright and trademark information” page at URL: www.ibm.com/legal/copytrade.shtml © 2014 34 IBM Corporation
  • 35. © 2014 35 IBM Corporation