JVM diagnostics and troubleshooting
29 questions in 8 subtopics.
Jcmd, jstack, jmap
Which jcmd commands would you run first on a misbehaving JVM, and what does each tell you? Why is jcmd generally preferred over jstack and jmap today?This thread dump excerpt is from a service that stopped responding. What is wrong and how do you fix it? "http-nio-8080-exec-12"java.lang.Thread.State: BLOCKED (on object monitor) at com.acme.PriceCache.get(PriceCache.java:41) - waiting to lock <0x71a2b3c48> (a com.acme.PriceCache) ... (40 more threads like this) ... "http-nio-8080-exec-3" java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) ... at com.acme.PriceCache.refresh(PriceCache.java:77) - locked <0x71a2b3c48> (a com.acme.PriceCache)jstack prints Found one Java-level deadlock with two threads. How does the JVM detect this, and which kinds of hang will it not report?You need a thread dump and a heap dump from a JVM in a Kubernetes pod. The image contains only a jlinked runtime with no jcmd and no shell. How do you get the diagnostics, and what would you change for next time?Heap dumps and analysis
How do you capture a heap dump automatically onOutOfMemoryError and manually from a running process? What risks should you consider?In a heap dump analyser such as Eclipse MAT, explain shallow size, retained size and the dominator tree, and how you use them to find what is holding memory.Heap dumps from production contain customer data and sometimes credentials. Write the policy for capturing, storing and analysing them across the engineering organisation.Some services now run heaps of 100 GB or more. Taking and analysing a full heap dump would pause them for a long time and produce files too large to handle easily. How do you plan the diagnostics strategy for very large heaps?Java Flight Recorder
What is Java Flight Recorder, and how do you start a recording on a service that is already running? How do you look at the results?Write a custom JFR event that records the duration of each order pricing call together with the order type, and explain what it costs when JFR is not recording.Design an always-on JFR setup for production services so that engineers can investigate an incident after it has happened.JVM observability moved over 15 years from jstat and verbose GC flags to unified logging, JFR, and continuous profiling. What principles would you set for production diagnosability of a large JVM fleet for the next decade?Async-profiler
When would you profile a Java service in wall-clock mode rather than CPU mode?How does async-profiler differ from a sampling profiler that uses JVMTIGetAllStackTraces, and which profiling modes does it offer?An async-profiler CPU flame graph of a REST service shows 35 percent of samples under java.util.regex.Pattern.compile, called from a request filter that validates headers. What is the likely fix and how do you verify it?OutOfMemoryError types
List the differentOutOfMemoryError messages a JVM can produce, and what each one points to.A pod keeps restarting with exit code 137. There is no OutOfMemoryError in the application logs and no heap dump. How do you investigate?Should JVM services in your company crash on OutOfMemoryError or try to keep running? Define the policy and justify it.Looking back at ten years of memory-related production incidents in a large Java organisation, which organisational practices reduce their frequency and impact more than individual expert debugging?Memory leak investigation
A servlet filter doesBUFFER.set(new byte[1_000_000]) at the start of each request, where BUFFER is a static ThreadLocal<byte[]>, but never calls remove. What are the problems?After a release, heap use grows steadily and the heap dump shows millions of Micrometer meter objects. The release added a timer tagged with the request path and the user id. Explain the leak and fix.Heap occupancy after GC grows by about 50 MB per hour in production, and the service fails with OutOfMemoryError every three days. Walk through your investigation from first signal to verified fix.You are incident lead. A memory leak in a new release makes 40 pods of the checkout service restart with OutOfMemoryError at peak traffic. Describe how you lead the response and the follow-up.High CPU investigation
A JVM process on Linux is using 100 percent CPU. How do you find which Java thread and which code is responsible?CPU is high on a service, but thread dumps and top show that most CPU is used by GC threads, and the heap is nearly full right after each collection. What is happening and what do you do?On-call engineers are paged for high CPU on different JVM services every week and take hours to find causes. Design standard tooling and process so a typical case is diagnosed in about ten minutes.Over the next five years, should your company buy a commercial observability product for JVM profiling and diagnostics, or build on open tools such as JFR, async-profiler and open-source profiling backends? Frame the decision.Native memory tracking
Name the main categories of non-heap memory a JVM uses, which native memory tracking reports separately.How do you use native memory tracking to explain why a JVM's resident memory is much larger than its heap? What are its limits?No question matches these choices.