Skip to content

[GR-75880] Support Native Image JFR emergency dumps on Windows#13607

Open
graalvmbot wants to merge 11 commits into
masterfrom
GR-75880
Open

[GR-75880] Support Native Image JFR emergency dumps on Windows#13607
graalvmbot wants to merge 11 commits into
masterfrom
GR-75880

Conversation

@graalvmbot

Copy link
Copy Markdown
Collaborator

Adds Native Image support for JFR emergency dumps on Windows.

Native Image already supports writing regular JFR recordings on Windows, but out-of-memory emergency dumps were still unavailable because the emergency-dump implementation was tied to POSIX directory and file handling. This PR makes emergency dumping an OS-independent feature with small platform-specific adapters.

Implementation overview:

  • Introduces AbstractJfrEmergencyDumpSupport for the common emergency-dump flow: dump path handling, repository fallback, emergency chunk creation, chunk filename validation/sorting, dump file assembly, and lifecycle test hooks.
  • Refactors PosixJfrEmergencyDumpSupport to use the shared base while keeping POSIX-specific repository scanning, openat-based file opening, and path-buffer handling local to the POSIX implementation.
  • Adds WindowsJfrEmergencyDumpSupport, using Win32 APIs for repository enumeration, file opening, file attributes, system time, path conversion, and cleanup.
  • Extends the Windows native header bindings needed by the implementation.
  • Updates JFR emergency dump tests so the same behavioral coverage can run on both POSIX and Windows, including repository fallback, support lifecycle, emergency dump contents, metadata-only dumps, constant-pool data, and non-ASCII path handling.
  • Enables the JFR image demo on Windows and updates the Native Image JFR documentation to list Windows emergency dumps as supported.

Reviewer notes:

  • The shared base intentionally contains the JFR/HotSpot-derived emergency-dump algorithm; the platform classes are responsible only for OS-specific path, directory, and file operations.
  • Emergency repository chunks now use timestamp-style names with retry suffixes instead of a single fixed emergency_chunk.jfr, so repeated fallback chunk creation does not depend on replacing the same file.
  • The companion graal-enterprise PR updates the JDK checksum metadata required by the new Windows support.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 24, 2026
@thomaswue thomaswue requested a review from roberttoyonaga May 24, 2026 08:21

@roberttoyonaga roberttoyonaga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall changes look good to me. I've done some manual testing on my Windows machine and everything seems okay. I've left a few minor comments below.

This section outlines the JFR features that are available in Native Image.

On Windows, Native Image supports local JFR recordings written to `.jfr` files. JFR emergency dumps on out-of-memory, remote JMX access to `FlightRecorderMXBean`, and JFR control through `jcmd` are not currently available on Windows.
On Windows, Native Image supports local JFR recordings written to `.jfr` files and JFR emergency dumps on out-of-memory. Remote JMX access to `FlightRecorderMXBean` and JFR control through `jcmd` are not currently available on Windows.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the recurring callback sampler will work, but what about the SIGPROF one? That probably relies on some POSIX specific code. Maybe it would be good to include a note about the JFR method sampling here too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note here: the signal-handler-based sampler uses POSIX SIGPROF support and is not available on Windows; Windows uses the default recurring-callback sampler for JFR method profiling.

Comment on lines +589 to +597
protected abstract void setPid(String pid);

protected abstract void setSavedCwdText(String cwd);

protected abstract void setDumpPathText(String dumpPath);

protected abstract void setDumpPathToSavedCwd();

protected abstract void setRepositoryLocationText(String repositoryLocation);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are a bit confusing/inconsistent: setPid, setSavedCwdText, setDumpPathText, setDumpPathToSavedCwd, setRepositoryLocationText.

There are fields in AbstractJfrEmergencyDumpSupport with the names pidText, cwdText, dumpPathText, but they don't correspond to the methods above. Instead, for example, setSavedCwdText corresponds to the byte[] char[] cached in the platform-dependent classes.

I suggest renaming to setSavedPid, setSavedCwd, setSavedDumpPath, setSavedDumpPathToSavedCwd, setSavedRepositoryLocation. What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, renamed these hooks to make it clearer that they cache the Java strings in the platform-specific representation: savePidText, saveCwdText, saveDumpPathText, useSavedCwdAsDumpPath, and saveRepositoryLocationText.

Comment on lines +265 to +267
idx = writeDumpFilePrefix(idx);
idx = appendPidToPathBuffer(idx);
idx = writeChunkFileExtension(idx);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why some of these methods are named write* while others are named append*?
I think that we are appending in both cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed these for consistency: appendDumpFilePrefixToPathBuffer, appendPidTextToPathBuffer, and appendChunkFileExtensionToPathBuffer now all use append...ToPathBuffer naming.

return createEmergencyChunkPath();
}

protected final RawFileDescriptor createEmergencyChunkPath() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why must this be protected?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not need to be protected. Made createEmergencyChunkPath() private.

return createEmergencyChunkPath(pathBuffer(), idx);
}

protected final RawFileDescriptor createEmergencyChunkPath(RawFilePath path, int baseNameEndIndex) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why must this be protected? Since this only has one caller, why not inline this into createEmergencyChunkPath()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the second overload and inlined its logic into the now-private createEmergencyChunkPath().

protected static final int DUMP_FILE_PREFIX_LEN = 12;
protected static final int EMERGENCY_CHUNK_CREATE_ATTEMPTS = 100;
protected static final String DUMP_FILE_PREFIX = "svm_oom_pid_";
protected static final String CHUNKFILE_EXTENSION = ".jfr";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this no longer used?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these string constants became unused. Removed them; only the length constants and allocation-free char helpers remain for the emergency dump path.

@roberttoyonaga roberttoyonaga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants