On Wed, 29 Apr 2026 23:24:38 GMT, Ashay Rane <[email protected]> wrote:

> On Linux, various `stat()` calls allow probing information about files
> without opening them, but until recently, there wasn't an equivalent API
> available on Windows.  Now that `GetFileInformationByName()` exists,
> we can use it instead of `GetFileInformationByHandle()`, which required
> first opening the file to create a file handle, then reading the file
> attributes, and finally closing the file handle.
> 
> Since `GetFileInformationByName()` is available on only newer versions
> of Windows, this patch uses conditional compilation and `LoadLibrary()`
> + `GetProcAddress()` to dynamically set the pointer to the API function.
> If the dynamic loading fails, we fall back to the old API.  To avoid
> problems with race conditions, we use Windows' `INIT_ONCE` and
> `InitOnceExecuteOnce()` to initialize the function pointer exactly once.
> 
> The rest of the patch is similar to the addition of any new JNI function
> call.  WindowsConstants.java adds the relevant flags and error codes,
> WindowsFileAttributes.java adds the Java entry point,
> WindowsNativeDispatcher.java links the Java function with the C
> function, and WindowsNativeDispatcher.c calls the Win32 API function.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

It might be better if the changes to NIO moved to a separate JBS issue. The 
reason is that the changes impact several very critical methods and it's going 
to take time to fully test and work through possible side effects. Each time we 
switch syscals or move to newer win32 functions we run into issues. In this 
case, it's a new dependency on api-ms-win-core-file-l2-1-4.

I will try to review it next week, don't have time this week.

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

PR Comment: https://git.openjdk.org/jdk/pull/30994#issuecomment-4349889914

Reply via email to