-
Bug
-
Resolution: Fixed
-
P4
-
21, 22
-
b03
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8340550 | 21.0.6 | Paul Hohensee | P4 | Resolved | Fixed | b01 |
ADDITIONAL SYSTEM INFORMATION :
Tested on OpenJDK 21.0.1 on Ubuntu Linux 64, but behavior goes back to JDK 7.
A DESCRIPTION OF THE PROBLEM :
The method Files.isAccessible() are implemented on checkAccess so need to catch the IOException when the file does not exist or access can't be determined.
When using Files.isReadable() / isWritable() / isExecutable(), we check only for one mode. The native code in UnixNativeDispatcher.c / Java_sun_nio_fs_UnixNativeDispatcher_access0() is able to give us an error code if the single mode we ask for is not valid for the file.
Since we are asking for a single mode, we could translate the value of error code to a boolean directly, instead of creating an exception with is caught in Files.isAccessible() to return a boolean.
I've tested a patch available here : https://github.com/gdarmont/jdk/commit/5d0128fde225844cf9155505ea005ad50fc74a8c
The performance improvement is especially visible on use cases where a call to Files.isXXX() is likely to fail.
This is for example the case when checking if many files are executable, as it is expected that most of them are not.
Eg. the well known JGit library (Java Git Implementation) is affected, as it needs to check if a file is executable to compute Git mode attributes.
Tested on OpenJDK 21.0.1 on Ubuntu Linux 64, but behavior goes back to JDK 7.
A DESCRIPTION OF THE PROBLEM :
The method Files.isAccessible() are implemented on checkAccess so need to catch the IOException when the file does not exist or access can't be determined.
When using Files.isReadable() / isWritable() / isExecutable(), we check only for one mode. The native code in UnixNativeDispatcher.c / Java_sun_nio_fs_UnixNativeDispatcher_access0() is able to give us an error code if the single mode we ask for is not valid for the file.
Since we are asking for a single mode, we could translate the value of error code to a boolean directly, instead of creating an exception with is caught in Files.isAccessible() to return a boolean.
I've tested a patch available here : https://github.com/gdarmont/jdk/commit/5d0128fde225844cf9155505ea005ad50fc74a8c
The performance improvement is especially visible on use cases where a call to Files.isXXX() is likely to fail.
This is for example the case when checking if many files are executable, as it is expected that most of them are not.
Eg. the well known JGit library (Java Git Implementation) is affected, as it needs to check if a file is executable to compute Git mode attributes.
- backported by
-
JDK-8340550 Files.isReadable/isWritable/isExecutable expensive when file does not exist
- Resolved
- links to
-
Commit openjdk/jdk/51be857f
-
Commit(master) openjdk/jdk21u-dev/816706c0
-
Review openjdk/jdk/17133
-
Review(master) openjdk/jdk21u-dev/926