In the safepoint log a JDK 25 HotSpot JVM prints with -Xlog:safepoint, what do the Reaching safepoint, At safepoint and Threads fields each tell you?
answer
- one line per stop
- name of the VM operation
- waiting versus working
- nanoseconds, three phases summed
- threads still running at the request
basics
~20 sEach line names one VM operation and splits its stop into nanosecond phases: Reaching safepoint is the wait for every thread to stop, At safepoint is the operation's own work, and Threads counts the threads it had to wait for.
solid answer
~40 sWith `-Xlog:safepoint`, JDK 25 prints one line per safepoint: `Safepoint "<operation>"`, then `Time since last`, `Reaching safepoint`, `At safepoint`, `Leaving safepoint` and `Total`, all in nanoseconds, then `Threads: R runnable, T total`. `Reaching safepoint` is time-to-safepoint, from the request until every Java thread is safe; `At safepoint` is the VM operation's own work; `Leaving safepoint` is the restart; `Total` is their sum. `T` is the number of Java threads, and `R` is how many were still running Java or VM code when the VM thread first checked, so they had to be waited for. A large `Reaching` with a small `R` points at one late thread; a large `At` points at the operation itself.
code
console · 1 line[812.044s][info][safepoint] Safepoint "PrintThreads", Time since last: 9874120332 ns, Reaching safepoint: 386201554 ns, At safepoint: 41022871 ns, Leaving safepoint: 70114 ns, Total: 427294539 ns, Threads: 1 runnable, 310 totalgo deeper
Recall that the JVM can log every stop of all threads with -Xlog:safepoint, and that each line names the operation that caused it.
Explain the phases: reaching is waiting for threads, at is the operation's work, leaving is the restart, and total is their sum in nanoseconds.
Read the split to decide the next step: a long reaching phase with one runnable thread means hunt the late thread; a long at phase means find who requested the operation.
Treat the safepoint log as cheap standing evidence and insist that pause analysis sums stops by operation name rather than trusting GC pause totals alone.
## What the safepoint log records A **VM operation** is a piece of work that HotSpot's VM thread performs on behalf of the runtime: a collection, a thread dump, a class redefinition, a heap dump. Most of them must run while every Java thread is halted at a **safepoint**, a point where the thread's state is known to the runtime. The **safepoint log** prints one line for every such stop, whoever asked for it. That makes it the evidence for a stop the garbage-collection log does not explain. On JDK 25 you turn it on with unified logging at the `info` level of the `safepoint` tag: ```bash java -Xlog:safepoint:file=/var/log/app/safepoint.log:time,uptime,level,tags:filecount=5,filesize=20m -jar app.jar ``` One line, with made-up numbers but the fields and order the JDK 25 source prints: ```console [3605.112s][info][safepoint] Safepoint "ParallelCollectForAllocation", Time since last: 2381194021 ns, Reaching safepoint: 412883 ns, At safepoint: 18237710 ns, Leaving safepoint: 61204 ns, Total: 18711797 ns, Threads: 4 runnable, 96 total ``` ## The fields, one by one | Field | Measured from and to | What it answers | |---|---|---| | `Safepoint "<name>"` | none | Which VM operation asked for the stop | | `Time since last` | end of the previous safepoint to the start of this one | How long the application ran between stops | | `Reaching safepoint` | the request to the moment every Java thread is safe | **Time-to-safepoint**: the wait for latecomers | | `At safepoint` | all threads safe to the operation finishing | The operation's own cost | | `Leaving safepoint` | operation finished to threads released | Restart cost, normally small | | `Total` | the request to the release | The sum of the three phases | | `Threads: R runnable, T total` | taken at the first check | `T` Java threads, `R` of them still running when checked | Points that trip people up: - **All durations are nanoseconds**, not milliseconds. `412883 ns` is 0.4 ms. - **`Total` equals `Reaching` plus `At` plus `Leaving`.** A thread that stopped at once was frozen for close to `Total`; the thread that arrived last ran for most of `Reaching` and was frozen only for the rest. - **The operation name is the requester's name**, not a category. On the Parallel collector the collection operations include `ParallelCollectForAllocation` and `ParallelGCCollect`; on G1 they include `G1CollectForAllocation` and `G1PauseRemark`. Anything else, such as `PrintThreads` or `RedefineClasses`, is not a collection. ## What "runnable" means here The `runnable` count is not the number of `RUNNABLE` threads in a thread dump. When the VM thread arms a safepoint it examines every Java thread once. A thread that is **blocked** (waiting on a lock, parked, sleeping) or **in native code** with a walkable stack is already safe and is not counted. The rest, threads executing Java code or inside the VM, are counted as runnable: they are the ones the VM thread must now wait for. 1. A large `Reaching safepoint` with `1 runnable` says one thread was slow to arrive. The next step is to find that thread. 2. A large `Reaching safepoint` with many runnable threads is ambiguous: one of them may still be the latecomer, or several may have been slow together, as when the process is starved of CPU, for example under container CPU throttling. 3. A large `At safepoint` with a small `Reaching` says the operation itself was expensive, such as a heap dump of a large heap. A thread inside a native call can show `RUNNABLE` in a thread dump and still be safe for a safepoint, which is why the two counts differ. ## Companion output - `-Xlog:safepoint+stats` adds a table row per safepoint, with the columns `VM Operation`, `[ threads: total initial_running ]`, `[ time: sync vmop total ]` and `page_trap_count`, and at exit a count of safepoints per operation plus the maximum sync time and the maximum operation time. - A **thread-local handshake** does not stop every thread and does not print a safepoint line at all; `-Xlog:handshake` logs those. - With `-XX:+SafepointTimeout`, a stop whose reaching phase exceeds `SafepointTimeoutDelay` also prints, at warning level, the threads that did not reach the safepoint. ## Reading a window, not a line One line is an anecdote. Sum `Total` by operation name over an hour, then split the heaviest names by `Reaching` against `At`. That tells you whether to chase a requester (a big `At`), a late thread (a big `Reaching`), or nothing at all.
- Why can Total be large on a line whose At safepoint value is tiny?Because `Total` includes `Reaching safepoint`. If one thread took 300 ms to arrive, every thread that stopped at once waited those 300 ms even though the operation then ran for a millisecond. The cost is time-to-safepoint, so the fix lies with the late thread, not with the operation that requested the stop.
- How would you get a per-operation summary for a whole run instead of reading individual lines?Add `-Xlog:safepoint+stats`. It prints a table row per safepoint with sync, operation and total times, and at JVM exit a count of safepoints per operation name with the maximum sync time and maximum operation time. For a running service, summing `Total` by operation name from the rotated `-Xlog:safepoint` files gives the same picture.
A meeting that cannot start until the last invitee walks in: Reaching safepoint is the time spent waiting at the door, At safepoint is the meeting itself, and the runnable count is how many invitees were still on their way when the chair called it.
- Reaching safepoint is the collector's own pause work
- The runnable count equals the RUNNABLE threads in a thread dump
- Every line in the safepoint log is a garbage collection
- The safepoint log's durations are in milliseconds
- A thread-local handshake prints its own safepoint line
Assumes JDK 25: the field set and order are those the jdk-25.0.4 source prints, and the safepoint log layout has changed across releases, so check the release before parsing an older log.