Skip to content

Conversation

@JonasNorlinder
Copy link
Member

@JonasNorlinder JonasNorlinder commented Dec 15, 2025

Background

When Java applications uses APIs like java.io.FileOutputStream it will hook into native implementations in e.g. io_util_md.c for Unix/Linux. Java does not allow reading a directory and the implementation reflect this fact. For Unix there are three access modes O_RDONLY, O_WRONLY, O_RDWR. Moreover, on Unix it is possible to read a directory and an extra check has been added in the code to ensure that the user is trying to read a file (with O_RDONLY) and not a directory. This extra check results in an additional syscall.

This check is actually redundant in case user are using access mode O_WRONLY or O_RDWR. If one is trying to call open on a directory with these modes the specification in Unix and Linux specifies that EISDIR shall be returned. For the case of Unix standard it has been part of the standard at least since 1997 (https://pubs.opengroup.org/onlinepubs/007908799/xsh/open.html) and Linux since at least 2004 (see v 2.0 https://www.kernel.org/pub/linux/docs/man-pages/Archive/ ) to return error if user is trying to write to an directory. In OpenJDK we also include AIX and they are certified to follow the Unix standard (https://www.opengroup.org/openbrand/register/ibm.htm). I believe that it is therefore safe to assume that this is a well implemented aspect of the Unix standard by now and that this technical debt can be eliminated (assuming that this check was indeed needed at some point).

Performance Improvements

A stress-test that opens a huge amount of files to trigger a syscall storm reveals that a removal of this redundant syscall may also improve performance during high load:

JDK 27 baseline
Benchmark            Mode   Cnt     Score    Error   Units
FileWriteStress.test sample 8438452 3722.451 ± 2.402 ns/op

JDK 27 patched
Benchmark            Mode   Cnt     Score    Error   Units
FileWriteStress.test sample 4952304 3191.912 ± 4.011 ns/op

~17% performance boost.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8373647: Avoid unnecessary fstat when opening file for write (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28823/head:pull/28823
$ git checkout pull/28823

Update a local copy of the PR:
$ git checkout pull/28823
$ git pull https://git.openjdk.org/jdk.git pull/28823/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28823

View PR using the GUI difftool:
$ git pr show -t 28823

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28823.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 15, 2025

👋 Welcome back jnorlinder! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 15, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Dec 15, 2025
@openjdk
Copy link

openjdk bot commented Dec 15, 2025

@JonasNorlinder The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@JonasNorlinder JonasNorlinder marked this pull request as ready for review December 15, 2025 12:14
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 15, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 15, 2025

Webrevs

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

Labels

core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant