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). Hotspot changes look generally okay - though a couple of queries. Unfortunate there is so much code duplication due to the conditionalization. Don't see a way to avoid that as we have no general sharing mechanism between libnio and the VM. src/hotspot/os/windows/os_windows.cpp line 4584: > 4582: log_info(os, thread)("The SetThreadDescription API is%s available.", > _SetThreadDescription == nullptr ? " not" : ""); > 4583: > 4584: HMODULE hFileInfoMod = > ::LoadLibrary(TEXT("api-ms-win-core-file-l2-1-4")); Why do you need this? According to https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyname it is in Kernel32.dll. src/hotspot/os/windows/os_windows_fileinfo.hpp line 2: > 1: /* > 2: * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. You do not work for Oracle so it is not appropriate to add this copyright header. You should add a Microsoft copyright notice. src/hotspot/os/windows/os_windows_fileinfo.hpp line 37: > 35: // WindowsNativeDispatcher.c. > 36: > 37: #if !defined(NTDDI_WIN10_NI) || !(NTDDI_VERSION >= NTDDI_WIN10_NI) Are these documented somewhere? src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c line 514: > 512: > 513: // SDK-guarded definitions for GetFileInformationByName and related > types. > 514: // Keep in sync with os_windows_fileinfo.hpp. It is really unfortunate that this needs to be duplicated. test/jdk/java/io/File/GetFileInformationByName.java line 2: > 1: /* > 2: * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. Use Microsoft copyright not Oracle. Thanks ------------- PR Review: https://git.openjdk.org/jdk/pull/30994#pullrequestreview-4201674196 PR Review Comment: https://git.openjdk.org/jdk/pull/30994#discussion_r3164986219 PR Review Comment: https://git.openjdk.org/jdk/pull/30994#discussion_r3165004164 PR Review Comment: https://git.openjdk.org/jdk/pull/30994#discussion_r3165006924 PR Review Comment: https://git.openjdk.org/jdk/pull/30994#discussion_r3165015396 PR Review Comment: https://git.openjdk.org/jdk/pull/30994#discussion_r3165041881
