Scrivio Interview library

JVM diagnostics and troubleshooting

29 questions in 8 subtopics.

Jcmd, jstack, jmap

ConceptFoundations7 min read
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?
DebuggingFoundations7 min read
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)
InternalsIntermediate6 min read
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?
ScenarioIntermediate7 min read
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

ConceptFoundations7 min read
How do you capture a heap dump automatically on OutOfMemoryError and manually from a running process? What risks should you consider?
ConceptIntermediate6 min read
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.
LeadershipAdvanced6 min read
Heap dumps from production contain customer data and sometimes credentials. Write the policy for capturing, storing and analysing them across the engineering organisation.
DesignPrincipal6 min read
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

ConceptFoundations7 min read
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?
CodingIntermediate7 min read
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.
DesignIntermediate7 min read
Design an always-on JFR setup for production services so that engineers can investigate an incident after it has happened.
LeadershipPrincipal7 min read
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

ConceptFoundations7 min read
When would you profile a Java service in wall-clock mode rather than CPU mode?
ConceptIntermediate7 min read
How does async-profiler differ from a sampling profiler that uses JVMTI GetAllStackTraces, and which profiling modes does it offer?
DebuggingIntermediate7 min read
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

ConceptFoundations7 min read
List the different OutOfMemoryError messages a JVM can produce, and what each one points to.
ScenarioIntermediate7 min read
A pod keeps restarting with exit code 137. There is no OutOfMemoryError in the application logs and no heap dump. How do you investigate?
LeadershipAdvanced7 min read
Should JVM services in your company crash on OutOfMemoryError or try to keep running? Define the policy and justify it.
LeadershipPrincipal6 min read
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

CodingFoundations7 min read
A servlet filter does BUFFER.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?
DebuggingIntermediate7 min read
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.
ScenarioIntermediate7 min read
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.
ScenarioAdvanced7 min read
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

DebuggingFoundations7 min read
A JVM process on Linux is using 100 percent CPU. How do you find which Java thread and which code is responsible?
DebuggingIntermediate7 min read
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?
DesignAdvanced7 min read
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.
LeadershipPrincipal6 min read
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

ConceptFoundations6 min read
Name the main categories of non-heap memory a JVM uses, which native memory tracking reports separately.
InternalsIntermediate6 min read
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?