skip to content

On a JDK 25 HotSpot service using the Parallel collector, stopped time exceeds GC pause time and -Xlog:safepoint names operations that are not collections; how do you find who stopped the application?

level: seniorimportance: should knowfreq 36%

answer

  1. sum Total by operation name
  2. the name is the requester
  3. reaching or at, which dominates
  4. dumps, histograms, agents
  5. who sent the request, and when

basics

~20 s

Group the safepoint log by operation name, keep the non-collection names, map each to its requester (PrintThreads to a thread dump, GC_HeapInspection to a class histogram, RedefineClasses to an agent), then correlate timestamps to find the caller.

solid answer

~40 s

I would sum `Total` from the `-Xlog:safepoint` lines by operation name over a busy window. On Parallel, the collector's names are `ParallelCollectForAllocation`, `ParallelGCCollect` and the shared `CollectForMetadataAllocation`, and `ParallelGCCollect` can itself be an explicit request such as `System.gc()`. For each other heavy name I check which phase dominates: a large `At safepoint` means the operation is expensive, a large `Reaching safepoint` means a late thread. Then I map the name to its requester: `PrintThreads` plus `FindDeadlocks` is `jstack`, `jcmd Thread.print` or `kill -3`; `ThreadDump` is an in-process `ThreadMXBean` dump; `GC_HeapInspection` is a class histogram; `HeapDumper` is a heap dump; `RedefineClasses` is an agent redefining or retransforming classes. Wall-clock timestamps line up with cron jobs, sidecars or agent attaches, and the JFR `jdk.ExecuteVMOperation` event names the calling thread.

code

bash · 4 lines
bash
grep -o 'Safepoint "[A-Za-z_0-9]*", .*Total: [0-9]* ns' safepoint.log \
  | sed -E 's/Safepoint "([^"]+)".*Total: ([0-9]+) ns/\1 \2/' \
  | awk '{t[$1]+=$2; n[$1]++} END {for (k in t) printf "%-32s %6d stops %10.1f ms\n", k, n[k], t[k]/1e6}' \
  | sort -k4 -nr

go deeper

for a junior

Know that thread dumps, heap dumps and class redefinition can stop the whole JVM, just as a garbage collection does.

for a middle

Explain how to read the operation name in the safepoint log and why a GC log alone cannot account for every stop.

for a senior

Show the workflow: sum by operation name, split reaching from at, map the name to its requester, and use timestamps or the JFR caller to name the exact tool or library.

for a principal

Use the per-operation totals to set which diagnostic tools may touch production and how often, rather than investigating the same sidecar on every service.

## Why the GC log is not enough A **VM operation** is work that HotSpot's VM thread performs for the runtime. Most VM operations run at a **global safepoint**, with every Java thread halted. Collections are only some of them. The GC log reports collection pauses, so when a service's total stopped time is larger than its GC pause total, the difference belongs to other operations, or to time spent waiting for threads to arrive. The **safepoint log** (`-Xlog:safepoint` on JDK 25) prints a line for every stop and names the operation, so it answers "who stopped the app" directly. ## Step 1: separate the collector from everything else Sum the `Total` field (nanoseconds) by the quoted operation name over a window that contains the latency spikes. On the **Parallel collector** the collector's own names are: - `ParallelCollectForAllocation`: a collection started because an allocation failed. - `ParallelGCCollect`: a collection requested through the heap's collect path, such as `System.gc()` or `jcmd <pid> GC.run`. Even this "GC" name can hide an outside caller. - `CollectForMetadataAllocation`: the shared operation every collector uses when a metaspace allocation fails and a collection is needed first. Every other name is a **non-GC stop**. Rank them by summed `Total`, and for each heavy one compare its phases: 1. **`At safepoint` dominates**: the operation itself is expensive. Find the requester and change how often or where it runs. 2. **`Reaching safepoint` dominates**: the operation is cheap but a thread was slow to arrive. That is a time-to-safepoint problem, diagnosed with `SafepointTimeout` and a time-to-safepoint profile, whatever operation happened to expose it. ## Step 2: translate the name into a requester The names are HotSpot's VM operation types as `runtime/vmOperation.hpp` lists them in JDK 25. The common non-GC ones in production: | Name in the log | Typical requester | |---|---| | `PrintThreads`, then `FindDeadlocks` | `jstack`, `jcmd <pid> Thread.print`, or SIGQUIT (`kill -3`): two back-to-back stops | | `ThreadDump` | In-process `ThreadMXBean.dumpAllThreads`, or `getThreadInfo` with a stack depth | | `GC_HeapInspection` | `jcmd <pid> GC.class_histogram` or `jmap -histo`; without `-all` it requests a full collection first | | `HeapDumper` | `jcmd <pid> GC.heap_dump`, `jmap -dump`, or a heap dump on `OutOfMemoryError` | | `RedefineClasses` | A Java or JVMTI agent calling `RedefineClasses` or `RetransformClasses` | | `PrintClassHierarchy`, `PrintCompileQueue` | `jcmd <pid> VM.class_hierarchy` and `jcmd <pid> Compiler.queue` | Things the table hides: - The cost of `PrintThreads` and `ThreadDump` grows with the number of threads and stack depth, so a dump that is cheap on a 50-thread service can be tens of milliseconds on a 2,000-thread one. - A class histogram without `-all` runs a full collection inside its own stop before it walks the heap, so its `At safepoint` includes a collection the GC log will also show. - `RedefineClasses` appears when an agent instruments classes after start-up, often right after it is attached to a running JVM. - **Dependency-driven deoptimization is usually not here.** On JDK 25, when loading a class invalidates compiled code, the runtime marks the methods and deoptimizes them with a thread-local **handshake** (logged under `-Xlog:handshake` with the name `Deoptimize`) unless it is already at a safepoint. It shows up in the safepoint log only when another operation is already holding one. ## Step 3: find the caller The name tells you the kind of requester; the timestamps and caller tell you which one. 1. Log with wall-clock decorations (`-Xlog:safepoint:file=...:time,uptime,level,tags`) and line the stops up with cron schedules, health-check sidecars, deploy hooks and on-call activity. 2. A regular period (every 30 s, every minute) points at a scheduler: a sidecar that runs `jstack`, a metrics exporter collecting thread stacks. 3. The JFR event `jdk.ExecuteVMOperation` records the operation, whether it ran at a safepoint, and the **caller** thread. An `Attach Listener` caller means an outside tool came in through the attach mechanism (`jcmd`, `jstack`, `jmap`); `Signal Dispatcher` means a SIGQUIT; an application thread name means in-process code, such as a metrics library calling `ThreadMXBean`. ## Step 4: change one thing and compare Only after the requester is named do you act: lower its frequency, move it to an instance out of rotation, replace a stack-collecting call with one that needs no stop, or load the agent at start-up. Then re-sum the safepoint log by operation name and confirm that the name's share of stopped time fell while the GC share stayed the same.

  • The heavy name is ParallelGCCollect but no allocation failure lines up with it. What do you suspect?
    An explicit request. `ParallelGCCollect` is the Parallel collector's operation for a collection asked for through the heap's collect path, which includes `System.gc()` and `jcmd GC.run`. I would look for library code calling `System.gc()` and for tooling that runs `GC.run` on a schedule, and check the GC log's cause for that collection.
  • Why does a single jstack invocation show up as two stops?
    Because the thread-dump command runs two VM operations in sequence: `PrintThreads` walks and prints every thread's stack, and `FindDeadlocks` then checks for monitor deadlocks. Each is its own global safepoint, so the service pays two time-to-safepoint waits and two operation costs per dump.
  • Why might a stop named G1CollectForAllocation on another service still be a non-GC problem?
    Because the name says who requested the stop, not where the time went. If its `Reaching safepoint` phase is most of the `Total`, the collection was quick and a thread was slow to arrive. That is a time-to-safepoint problem, and it would hit any operation, not just the collector.

  • Short GC log pauses prove the application is not stopping for long
  • Only the garbage collector ever stops all application threads
  • Taking a jstack thread dump costs a running service nothing
  • jcmd GC.class_histogram never triggers a collection
  • An agent can retransform classes without stopping any thread
  • On JDK 25 every deoptimization after class loading is a global safepoint

Assumes JDK 25: operation names come from jdk-25.0.4's VM operation list, and dependency-driven deoptimization there runs as a handshake rather than a global safepoint; both have changed across releases.