-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8318709: Improve System.nanoTime performance on Windows #16336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Welcome back djelinski! A progress list of the required criteria for merging this PR into |
|
@djelinski 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. |
Webrevs
|
|
Hi @djelinski , I hope to review this tomorrow but need to do some research first. :) |
c-cleary
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can see that QueryPerformanceFrequency() sets count the frequency of the performance counter thats fixed at boot too which seems hardware specific, nice gain
dholmes-ora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at:
https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-large_integer-r1
It seems the QuadPart needs native 64-bit compiler support, which I'm unclear is available when building for 32-bit Windows (which IIRC is a deprecated port but still present in this release). Also the web page indicates it is only available from Windows 10, which doesn't make a lot of sense.
To be honest I am struggling to understand how LARGE_INTEGER gets used by QPC/QPF as it is a union, so we have to know which member QPC/QPF sets, so we can read back the correct member. Though I wonder if given endian-ness the layout of the structs simply coincides with that of a native 64-bit variable?
|
Visual Studio supports 64bit integer types even in 32 bit mode. In fact, the JDK requires a compiler with 64bit integer support - it's used in jlong typedef, for example. I checked the typedef for LARGE_INTEGER in Windows SDK, and it looks exactly like the one on the MSDN page - no ifdefs to check if we are compiling in 64bit mode.
That's it exactly. By the way, here's a nice article from Raymond Chen about this: |
|
Hmm that blog ends with:
And I'd like to know why we do not have the same alignment issue? (This all seems rather hackish but presumably their library guys get the okay from their compiler guys ... though I wonder then about folk trying to build the Windows code with gcc? |
|
LARGE_INTEGER does not have the same alignment issue because unions are aligned to the alignment required by the largest type, and LONGLONG (aka int64) QuadPart requires 8-byte alignment on 64bit machines. |
|
Ah I see. Okay. This still seems like a code smell on the MS side but that's not relevent to this PR. |
| return result; | ||
| } | ||
|
|
||
| static double counts_per_nano; // NANOSECS_PER_SEC / performance_frequency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't that calculate nanos_per_count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is what we want of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh! Of course it does. I'll rename in a sec.
dholmes-ora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for this optimization!
|
@djelinski This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 58 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
Thanks for the reviews! /integrate |
|
Going to push as commit 3934127.
Your commit was automatically rebased without conflicts. |
|
@djelinski Pushed as commit 3934127. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Benchmark before:
SystemTime.nanoTime avgt 15 19,366 � 0,383 ns/op
After:
SystemTime.nanoTime avgt 15 15,812 � 0,385 ns/op
Tier1-2 clean.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16336/head:pull/16336$ git checkout pull/16336Update a local copy of the PR:
$ git checkout pull/16336$ git pull https://git.openjdk.org/jdk.git pull/16336/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16336View PR using the GUI difftool:
$ git pr show -t 16336Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16336.diff
Webrev
Link to Webrev Comment