8385586: Fix race in Windows map_or_reserve_memory_aligned using VirtualAlloc2 and MapViewOfFile3#31311
8385586: Fix race in Windows map_or_reserve_memory_aligned using VirtualAlloc2 and MapViewOfFile3#31311roberttoyonaga wants to merge 1 commit into
Conversation
|
👋 Welcome back roberttoyonaga! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@roberttoyonaga The following label will be automatically applied to this pull request:
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. |
|
The total number of required reviews for this PR has been set to 2 based on the presence of this label: |
|
Any substantial changes over the old PR or just a clean subset? |
The changes here are just a clean subset of the old bigger PR. I've just dropped everything not related to |
| if (handle == nullptr) { | ||
| log_trace(os)("Failed to load library: %s: %s", name, ebuf); | ||
| } |
There was a problem hiding this comment.
This is wrong! The previous logging in ZGC did GCPrecious logging and so it needs to be put back where it was. This trace message can be removed, the os::dll_load for Windows already logs log_info(os)("shared library load of %s failed, error code %lu", name, errcode);
Summary
Previously on Windows, aligned virtual memory could not be reserved or mapped in a single step. Hotspot used the following race-y pattern on Windows to reserved aligned memory:
VirtualAlloc2andMapViewOfFile3(available since Windows version 1803) removes the need for this race-y code by supporting alignment natively. I have replaced the race-y part ofmap_or_reserve_memory_alignedwith calls to these new APIs. I have also broken upmap_or_reserve_memory_alignedinto two separate functions, one path for mapping and one for reserving. It's awkward to have both code paths sandwiched into the same function.The Windows API functions are dynamically loaded at startup at the end of
os::init_2in os_windows.cpp. This is whenos::win32::VirtualAlloc2andos::win32::MapViewOfFile3are prepared. If the loading fails, the Windows implementation falls back to the old racey approach.lookup_kernelbase_libraryandlookup_kernelbase_symbolhave been moved from zSyscall_windows.cpp toos::win32::to reduce code duplication.This is a scoped-down version of JDK-8376561 and PR for the sake of easier review. This is the first change in a series of changes that take advantage of VirtualAlloc2 to replace races in Windows code.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/31311/head:pull/31311$ git checkout pull/31311Update a local copy of the PR:
$ git checkout pull/31311$ git pull https://git.openjdk.org/jdk.git pull/31311/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 31311View PR using the GUI difftool:
$ git pr show -t 31311Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/31311.diff
Using Webrev
Link to Webrev Comment