SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
Debugging Your
Production JVM Machine
Ken Sipe
Perficient (PRFT)
kensipe@gmail.com
Abstract
> Learn the tools and techniques used to monitor,
trace and debugging running Java applications.
2
Agenda
> Java Memory Management
> Memory Management Tools
• Command-line Tools
• VisualVM
> Btrace
> Summary
> Resources
3
Agenda
> Java Memory Management
> Memory Management Tools
• Command-line Tools
• VisualVM
> Btrace
> Summary
> Resources
4
Donʼt Worry…
> C (malloc / free)
> C++ (new / delete)
> Java (new / gc)
> Memory Allocation / Deallocation in Java is
automatic
5
Object Lifetimes
> Most objects live very short lives
• 80-98% of all newly allocated objects die
• within a few million instructions
• Before another megabyte is allocated
> Old objects tend to live a long…. time
Memory Spaces
> New Space
• Where all objects are new (sort of…)
> Old Space
• Where all objects are old
New Space Old Space
Memory Spaces
> New Space Division
• Eden
• Where all objects are created
• Survivor Space 0
• Provide object aging
• Survivor Space 1
Eden Old SpaceSS0 SS1
Perm Spaces
> Permanent Space
• class information
• static information
Eden Old SpaceSS0 SS1 Perm Space
GC Responsibility
> Heap Walking from GC Roots
> Mark / Sweep
• Garbage detection (mark)
• Sort out the live ones from the dead ones
• Reference counting
• Garbage reclamation (sweep)
• Make space available
Minor Garbage Collection
> Minor gc (scavenge)
• When eden is “full” a minor gc is invoked
• Sweeps through eden and the current survivor
space, removing the dead and moving the living to
survivor space or old
• Ss0 and ss1 switch which is “current”
• A new tenuring age is calculated
Major Garbage Collection
> Major gc
• When old is “full”
• All spaces are garbage collected including perm
space
• All other activities in the jvm are suspended
Agenda
> Java Memory Management
> Memory Management Tools
• Command-line Tools
• VisualVM
> Btrace
> Summary
> Resources
14
Java Memory Tools
> JPS
• Getting the Process ID (PID)
> Jstat
• jstat -gcutil <pid> 250 7
Looking at the Heap
> %JAVA_HOME%/bin/jmap – histo:live <pid>
• Looking at all the “live” objects
> %JAVA_HOME%/bin/jmap – histo <pid>
• Looking at all objects
> The difference between is the list of unreachable
objects
Taking a Heap Dump
> %JAVA_HOME%/bin/jmap –
dump:live,file=heap.out,format=b <pid>
• Dumps the Heap to a file
> JConsole
JHat
> %JAVA_HOME%/bin/jhat <filename>
• Starts a web server to investigate the heap
> Queries
• Show instance count for all classes
• Show Heap Histogram
• Show Finalizer
• Use the Execute Object Query Language (OQL)
• select s from java.lang.String s where s.count >=100
JMX – Looking at Flags
MAT – Memory Analyzer Tool
VisualVM
> Open Source All-in-One Java Troubleshooting tool
> https://visualvm.dev.java.net/
21
Visualgc
> visualgc <pid>
> Visual Garbage Collection
Monitoring
• a graphical tool for monitoring the
HotSpot Garbage Collector,
Compiler, and class loader. It can
monitor both local and remote
JVMs.
23
DEMO
Agenda
> Java Memory Management
> Memory Management Tools
• Command-line Tools
• VisualVM
> Btrace
> Summary
> Resources
24
BTrace
> dynamically bytecode instrumenting (BCI)
• read / not write
• probe-based
• observe running Java applications
> Integration with DTrace on Solaris
> http://btrace.dev.java.net
> visualvm plugin
25
BTrace Tools
26
Target JVM
BTrace
Agent
VisualVM +
BTrace Plugin
BTrace command-line
BTrace Terminology
> Probe Point
• “location” or “event” at which tracing statements are
executed
> Trace Actions
• statements which are executed whenever a probe
fires
> Action Methods
• static methods which define a trace
27
Probes and Actions
> Probe Targets
• method entry / exit
• line number
• exceptions
• return from method
• exception throw (before)
• synchronization entry / exit
> Actions
• static methods in trace class
28
BTrace Restrictions
> no new objects
> no new arrays
> no exceptions
> no outer, inner, nested or
local classes
> no synchronization blocks
> no loops
> no interfaces
29
Tracing
> Annotations
• com.sun.btrace.annotations
• @BTrace
• denotes a btrace class
> Probe Points
• @OnMethod
• @OnTimer
• @OnEvent
• @OnExit
30
Simple Example: Looking for Object Size
31
Simple Example: Looking for Object Size
32
BTrace Run Options
> BTrace Command-Line
• btrace
• runs btrace tool (and compiles btrace script if necessary)
• btracec
• btrace script compiler
• btracer
• convenience script to start java project with tracing enabled at
application startup
> VisualVM + BTrace Plugin
33
Testing the Probe
> Start Target Application
• java -jar java2demo.jar
> Get the PID
• jps
> Inject Probe
• btrace <pid> Sizeof.java
34
BTrace + JMX Script
35
BTrace + jstat
36
ThreadLocal
37
BTrace Events
38
Checking Synchronization Entry / Exits
39
Tracing Opportunities
> Thread Monitors
> Socket / Web Services
> Object Creation and Size
> File Access
40
41
DEMO
Known Solutions with BTrace
> Terracotta
• concurrency issue
> Hibernate / Atlassian Issue
• thread / session management issue
• http://jira.atlassian.com/browse/CONF-12201
42
Summary
> jmap, jhat, jconsole, jstat
• tools already in the JDK bin directory
> VisualVM
• swiss army knife for JVM process monitoring and
tracing
> BTrace
• dynamic tracing tool
43
Resources
> Performance and Troubleshooting
• http://java.sun.com/performance/reference/
whitepapers/6_performance.html
• http://java.sun.com/javase/6/webnotes/trouble/TSG-
VM/html/docinfo.html
> VisualVM
• https://visualvm.dev.java.net/
> BTrace
• https://btrace.dev.java.net/
44
Ken Sipe
http://kensipe.blogspot.com
twitter: @kensipe

Contenu connexe

Tendances

Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
Performance and predictability
Performance and predictabilityPerformance and predictability
Performance and predictabilityRichardWarburton
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakensRichardWarburton
 
JCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJoseph Kuo
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it worksMindfire Solutions
 
Finalize() method
Finalize() methodFinalize() method
Finalize() methodJadavsejal
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a clusterGal Marder
 
JVM languages "flame wars"
JVM languages "flame wars"JVM languages "flame wars"
JVM languages "flame wars"Gal Marder
 
Millions quotes per second in pure java
Millions quotes per second in pure javaMillions quotes per second in pure java
Millions quotes per second in pure javaRoman Elizarov
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage CollectionDoug Hawkins
 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVMaragozin
 
BDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part IIBDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part IIDavid Lauzon
 
(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag SessionJens Hadlich
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2Gal Marder
 
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetchRedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetchRedis Labs
 
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtugVk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtugketan_patel25
 

Tendances (20)

Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
Performance and predictability
Performance and predictabilityPerformance and predictability
Performance and predictability
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakens
 
JCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of Java
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Finalize() method
Finalize() methodFinalize() method
Finalize() method
 
cb streams - gavin pickin
cb streams - gavin pickincb streams - gavin pickin
cb streams - gavin pickin
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
 
JVM languages "flame wars"
JVM languages "flame wars"JVM languages "flame wars"
JVM languages "flame wars"
 
Millions quotes per second in pure java
Millions quotes per second in pure javaMillions quotes per second in pure java
Millions quotes per second in pure java
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVM
 
BDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part IIBDM32: AdamCloud Project - Part II
BDM32: AdamCloud Project - Part II
 
(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
 
Java GC
Java GCJava GC
Java GC
 
Extending Node.js using C++
Extending Node.js using C++Extending Node.js using C++
Extending Node.js using C++
 
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetchRedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
 
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtugVk.amberfog.com gtug part1_introduction2_javaandroid_gtug
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
 

Similaire à Debugging Your Production JVM

java-monitoring-troubleshooting
java-monitoring-troubleshootingjava-monitoring-troubleshooting
java-monitoring-troubleshootingWilliam Au
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Jarod Wang
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?Roman Elizarov
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
One-Byte Modification for Breaking Memory Forensic Analysis
One-Byte Modification for Breaking Memory Forensic AnalysisOne-Byte Modification for Breaking Memory Forensic Analysis
One-Byte Modification for Breaking Memory Forensic AnalysisTakahiro Haruyama
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5aminmesbahi
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance TuningProfiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuningosa_ora
 
Micrometrics to forecast performance tsunamis
Micrometrics to forecast performance tsunamisMicrometrics to forecast performance tsunamis
Micrometrics to forecast performance tsunamisTier1app
 
Solaris DTrace, An Introduction
Solaris DTrace, An IntroductionSolaris DTrace, An Introduction
Solaris DTrace, An Introductionsatyajit_t
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxNgLQun
 
JDK Tools For Performance Diagnostics
JDK Tools For Performance DiagnosticsJDK Tools For Performance Diagnostics
JDK Tools For Performance DiagnosticsBaruch Sadogursky
 
Building source code level profiler for C++.pdf
Building source code level profiler for C++.pdfBuilding source code level profiler for C++.pdf
Building source code level profiler for C++.pdfssuser28de9e
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachAlexandre Rafalovitch
 
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Lucidworks
 

Similaire à Debugging Your Production JVM (20)

java-monitoring-troubleshooting
java-monitoring-troubleshootingjava-monitoring-troubleshooting
java-monitoring-troubleshooting
 
Heap & thread dump
Heap & thread dumpHeap & thread dump
Heap & thread dump
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
 
Unit iii pds
Unit iii pdsUnit iii pds
Unit iii pds
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
DIY Java Profiling
DIY Java ProfilingDIY Java Profiling
DIY Java Profiling
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
One-Byte Modification for Breaking Memory Forensic Analysis
One-Byte Modification for Breaking Memory Forensic AnalysisOne-Byte Modification for Breaking Memory Forensic Analysis
One-Byte Modification for Breaking Memory Forensic Analysis
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance TuningProfiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
 
Micrometrics to forecast performance tsunamis
Micrometrics to forecast performance tsunamisMicrometrics to forecast performance tsunamis
Micrometrics to forecast performance tsunamis
 
Solaris DTrace, An Introduction
Solaris DTrace, An IntroductionSolaris DTrace, An Introduction
Solaris DTrace, An Introduction
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
 
JDK Tools For Performance Diagnostics
JDK Tools For Performance DiagnosticsJDK Tools For Performance Diagnostics
JDK Tools For Performance Diagnostics
 
Building source code level profiler for C++.pdf
Building source code level profiler for C++.pdfBuilding source code level profiler for C++.pdf
Building source code level profiler for C++.pdf
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
 
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
 

Dernier

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Dernier (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Debugging Your Production JVM

  • 1. Debugging Your Production JVM Machine Ken Sipe Perficient (PRFT) kensipe@gmail.com
  • 2. Abstract > Learn the tools and techniques used to monitor, trace and debugging running Java applications. 2
  • 3. Agenda > Java Memory Management > Memory Management Tools • Command-line Tools • VisualVM > Btrace > Summary > Resources 3
  • 4. Agenda > Java Memory Management > Memory Management Tools • Command-line Tools • VisualVM > Btrace > Summary > Resources 4
  • 5. Donʼt Worry… > C (malloc / free) > C++ (new / delete) > Java (new / gc) > Memory Allocation / Deallocation in Java is automatic 5
  • 6. Object Lifetimes > Most objects live very short lives • 80-98% of all newly allocated objects die • within a few million instructions • Before another megabyte is allocated > Old objects tend to live a long…. time
  • 7. Memory Spaces > New Space • Where all objects are new (sort of…) > Old Space • Where all objects are old New Space Old Space
  • 8. Memory Spaces > New Space Division • Eden • Where all objects are created • Survivor Space 0 • Provide object aging • Survivor Space 1 Eden Old SpaceSS0 SS1
  • 9. Perm Spaces > Permanent Space • class information • static information Eden Old SpaceSS0 SS1 Perm Space
  • 10. GC Responsibility > Heap Walking from GC Roots > Mark / Sweep • Garbage detection (mark) • Sort out the live ones from the dead ones • Reference counting • Garbage reclamation (sweep) • Make space available
  • 11. Minor Garbage Collection > Minor gc (scavenge) • When eden is “full” a minor gc is invoked • Sweeps through eden and the current survivor space, removing the dead and moving the living to survivor space or old • Ss0 and ss1 switch which is “current” • A new tenuring age is calculated
  • 12. Major Garbage Collection > Major gc • When old is “full” • All spaces are garbage collected including perm space • All other activities in the jvm are suspended
  • 13.
  • 14. Agenda > Java Memory Management > Memory Management Tools • Command-line Tools • VisualVM > Btrace > Summary > Resources 14
  • 15. Java Memory Tools > JPS • Getting the Process ID (PID) > Jstat • jstat -gcutil <pid> 250 7
  • 16. Looking at the Heap > %JAVA_HOME%/bin/jmap – histo:live <pid> • Looking at all the “live” objects > %JAVA_HOME%/bin/jmap – histo <pid> • Looking at all objects > The difference between is the list of unreachable objects
  • 17. Taking a Heap Dump > %JAVA_HOME%/bin/jmap – dump:live,file=heap.out,format=b <pid> • Dumps the Heap to a file > JConsole
  • 18. JHat > %JAVA_HOME%/bin/jhat <filename> • Starts a web server to investigate the heap > Queries • Show instance count for all classes • Show Heap Histogram • Show Finalizer • Use the Execute Object Query Language (OQL) • select s from java.lang.String s where s.count >=100
  • 19. JMX – Looking at Flags
  • 20. MAT – Memory Analyzer Tool
  • 21. VisualVM > Open Source All-in-One Java Troubleshooting tool > https://visualvm.dev.java.net/ 21
  • 22. Visualgc > visualgc <pid> > Visual Garbage Collection Monitoring • a graphical tool for monitoring the HotSpot Garbage Collector, Compiler, and class loader. It can monitor both local and remote JVMs.
  • 24. Agenda > Java Memory Management > Memory Management Tools • Command-line Tools • VisualVM > Btrace > Summary > Resources 24
  • 25. BTrace > dynamically bytecode instrumenting (BCI) • read / not write • probe-based • observe running Java applications > Integration with DTrace on Solaris > http://btrace.dev.java.net > visualvm plugin 25
  • 26. BTrace Tools 26 Target JVM BTrace Agent VisualVM + BTrace Plugin BTrace command-line
  • 27. BTrace Terminology > Probe Point • “location” or “event” at which tracing statements are executed > Trace Actions • statements which are executed whenever a probe fires > Action Methods • static methods which define a trace 27
  • 28. Probes and Actions > Probe Targets • method entry / exit • line number • exceptions • return from method • exception throw (before) • synchronization entry / exit > Actions • static methods in trace class 28
  • 29. BTrace Restrictions > no new objects > no new arrays > no exceptions > no outer, inner, nested or local classes > no synchronization blocks > no loops > no interfaces 29
  • 30. Tracing > Annotations • com.sun.btrace.annotations • @BTrace • denotes a btrace class > Probe Points • @OnMethod • @OnTimer • @OnEvent • @OnExit 30
  • 31. Simple Example: Looking for Object Size 31
  • 32. Simple Example: Looking for Object Size 32
  • 33. BTrace Run Options > BTrace Command-Line • btrace • runs btrace tool (and compiles btrace script if necessary) • btracec • btrace script compiler • btracer • convenience script to start java project with tracing enabled at application startup > VisualVM + BTrace Plugin 33
  • 34. Testing the Probe > Start Target Application • java -jar java2demo.jar > Get the PID • jps > Inject Probe • btrace <pid> Sizeof.java 34
  • 35. BTrace + JMX Script 35
  • 40. Tracing Opportunities > Thread Monitors > Socket / Web Services > Object Creation and Size > File Access 40
  • 42. Known Solutions with BTrace > Terracotta • concurrency issue > Hibernate / Atlassian Issue • thread / session management issue • http://jira.atlassian.com/browse/CONF-12201 42
  • 43. Summary > jmap, jhat, jconsole, jstat • tools already in the JDK bin directory > VisualVM • swiss army knife for JVM process monitoring and tracing > BTrace • dynamic tracing tool 43
  • 44. Resources > Performance and Troubleshooting • http://java.sun.com/performance/reference/ whitepapers/6_performance.html • http://java.sun.com/javase/6/webnotes/trouble/TSG- VM/html/docinfo.html > VisualVM • https://visualvm.dev.java.net/ > BTrace • https://btrace.dev.java.net/ 44

Notes de l'éditeur