Permit the usage of std::invoke in Hotspot#31153
Conversation
|
👋 Welcome back jsjolen! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@johan-sjolen The following labels 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 lists. 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: |
|
Ugh, the forbidden method mechanism seems troublesome every time we want to interact with Standard Library headers. Not really a review, just a reminder to myself to continue work on what I'm doing that will hopefully be less painful to work with when enforcing HotSpot Code Style. |
Hi all,
std::invokeis a C++ feature which provides uniform call syntax for methods, functions, lambdas, and field accesses. This is useful when accessing data from an object whose type is provided by a template and whose accessor is provided separately.I propose that we permit this in Hotspot, as it's useful when writing generic data structures. This PR adds the required
cppstdlib/functional.hppas well as movingstd::invokefrom undecided to accepted in the style docs.Cost
std::invokehas no runtime cost when optimizations are enabled. It does have an increased compilation CPU and memory usage as compared to plain calls.Reading
https://devblogs.microsoft.com/oldnewthing/20220401-00/?p=106426
https://eggs-cpp.github.io/invoke/benchmark.html
Motivating and pedagogical example
Let's say that we have
Persons:We want O(1) access when looking these up, so we decide to store
Persons in a hashtable. However, we don't want to copy thestring namekey unnecessarily, instead we would likePersonto act as the key-value container. So, we set out to implement a generic hashtable that will serve our needs, and we whip this up:Unfortunately, this will fail to compile. Our accessor is a reference to a field, not a callable method. In swoops
std::invoke, allowing us to fix it:The nifty thing is that we have a second user that wants to use a public accessor for its key, then
std::invokewill work for that case as well:Here's a full Godbolt to play around with: https://godbolt.org/z/51eex7T8c
Progress
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/31153/head:pull/31153$ git checkout pull/31153Update a local copy of the PR:
$ git checkout pull/31153$ git pull https://git.openjdk.org/jdk.git pull/31153/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 31153View PR using the GUI difftool:
$ git pr show -t 31153Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/31153.diff