RFR: 8374945: Avoid fstat in os::open

Johan Sjölen jsjolen at openjdk.org
Mon Jan 12 11:24:17 UTC 2026


On Sat, 10 Jan 2026 16:55:08 GMT, Jonas Norlinder <jnorlinder at openjdk.org> wrote:

> Eliminate unnecessary calls to fstat in os::open akin to JDK-8373647. This optimization reduces system overhead.

This patch shouldn't skip the `FD_CLOEXEC` branch, as it does now. Doing so changes the behavior of the code, right?? The comment is really just the code but in the words, I'd prefer it if it gave a hint as to why the condition let's us bail early (like "Linux doesn't let you open a directory with write privileges").

You probably want this code, but better:

```c++
fd = open(...);
if (fd != -1) return;


// Check whether the file is a directory.
// Only needed if O_RDONLY, as you can't open directories with W or X privileges
if (oflag & O_ACCMODE) == O_RDONLY) {
  struct stat buf;
  ...
}

#ifdef FD_CL0EXEC
...
#endif

return fd;

-------------

PR Review: https://git.openjdk.org/jdk/pull/29152#pullrequestreview-3650284161


More information about the hotspot-runtime-dev mailing list