Skip to content
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

8278241: Implement JVM SpinPause on linux-aarch64 #6803

Closed
wants to merge 5 commits into from

Conversation

eastig
Copy link
Member

@eastig eastig commented Dec 10, 2021

This JVM SpinPause uses a spin wait stub. The stub is generated based on the SpinWait description which is defined with OnSpinWaitInst/OnSpinWaitInstCount options. The SpinWait provides the description of the instruction and the instruction count.

The SpinWait description is also used for the _onSpinWait() intrinsic. We don't have use cases when we need different implementations for the _onSpinWait() intrinsic and JVM SpinPause.

Testing results for fastdebug and release builds:

  • gtest: Passed
  • tier1...tier4: Passed
  • hotspot/jtreg/runtime/Thread/TestSpinPause.java: Passed

JVM SpinPause is used for the synchronised statements and can benchmarked with org.openjdk.bench.vm.lang.LockUnlock.testContendedLock.

Benchmarking results (number of samples per an experiment: 150) for Graviton2 (Neoverse N1), 1 ISB instruction:


+-----------+-------------------+------------+-----------+-----------+----------+---------+
| CPU cores | Contended threads | Base ns/op |   Error   |    New    |  Error   |  Diff   |
+-----------+-------------------+------------+-----------+-----------+----------+---------+
|         8 |                64 |  10007.213 | ±910.911  |  8527.346 | ±377.242 | -14.79% |
|        16 |                64 |  10274.935 | ±880.568  |  8310.433 | ±326.845 | -19.12% |
|        32 |                64 |  12231.947 | ±1525.364 |  9205.941 | ±394.409 | -24.74% |
|        64 |                64 |    9929.49 | ±586.074  | 10488.695 | ±570.458 | 5.63%   |
|        64 |                32 |   5605.119 | ±629.340  |  5023.882 | ±230.639 | -10.37% |
|        64 |                16 |   2817.346 | ±263.696  |  2367.528 | ±94.158  | -15.97% |
|        64 |                 2 |    870.389 | ±530.579  |   464.395 | ±126.260 | -46.65% |
+-----------+-------------------+------------+-----------+-----------+----------+---------+

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8278241: Implement JVM SpinPause on linux-aarch64

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6803/head:pull/6803
$ git checkout pull/6803

Update a local copy of the PR:
$ git checkout pull/6803
$ git pull https://git.openjdk.java.net/jdk pull/6803/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6803

View PR using the GUI difftool:
$ git pr show -t 6803

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6803.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 10, 2021

👋 Welcome back eastig! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 10, 2021
@eastig
Copy link
Member Author

eastig commented Dec 10, 2021

@nick-arm @theRealAph @stooart-mon
Hi, could you have a look please?

@openjdk
Copy link

openjdk bot commented Dec 10, 2021

@eastig The following label will be automatically applied to this pull request:

  • hotspot

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.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Dec 10, 2021
@mlbridge
Copy link

mlbridge bot commented Dec 10, 2021

Webrevs

@theRealAph
Copy link
Contributor

@nick-arm @theRealAph @stooart-mon Hi, could you have a look please?

This is way too complicated. I'd use MacroAssembler::spin_wait() to generate a stub and call it from SpinPause.


SpinWait(Inst inst = NONE, int count = 0, InstRunner inst_runner = run_none) :
_inst(inst), _count(count), _inst_runner(inst_runner) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to have _inst_runner initialized in the constructor based on the value of Inst inst?
You aren't differentiating between the two in get_spin_wait_desc anyway.

@eastig
Copy link
Member Author

eastig commented Dec 13, 2021

@nick-arm @theRealAph @stooart-mon Hi, could you have a look please?

This is way too complicated. I'd use MacroAssembler::spin_wait() to generate a stub and call it from SpinPause.

Hi @theRealAph,

Thank you for advice. It was a good exercise to learn how to write a stub generator.
I reimplemented SpinPause to use a generated stub.

return 0;
if (VM_Version::spin_wait_desc().inst() == SpinWait::NONE) {
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be safe and more efficient to test func for NULL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

spin_wait_func_ptr_t func = CAST_TO_FN_PTR(spin_wait_func_ptr_t, StubRoutines::aarch64::spin_wait());
if (func == nullptr) {
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better simply to give _spin_wait a default value that points to a ret instruction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -382,7 +382,13 @@ int os::extra_bang_size_in_bytes() {

extern "C" {
int SpinPause() {
return 0;
using spin_wait_func_ptr_t = void (*)();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want ThreadWXEnable wx(WXExec, thread); for Apple here.

Copy link
Member Author

@eastig eastig Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, why do we need it here? This is linux-aarch64 implementation of SpinPause.
I think it should be in SpinPause in os_cpu/bsd_aarch64/os_bsd_aarch64.cpp. Am I right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are indeed right. We can worry about Apple another day.

@theRealAph
Copy link
Contributor

Two more changes. The first makes the code simpler, and the second makes it less fragile.

diff --git a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
index a8b2820bb62..e946f3be970 100644
--- a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
@@ -6403,9 +6403,7 @@ class StubGenerator: public StubCodeGenerator {
     StubCodeMark mark(this, "StubRoutines", "spin_wait");
     address start = __ pc();
 
-    if (VM_Version::spin_wait_desc().inst() != SpinWait::NONE) {
-      __ spin_wait();
-    }
+    __ spin_wait();
     __ ret(lr);
 
     return start;
diff --git a/src/hotspot/cpu/aarch64/stubRoutines_aarch64.cpp b/src/hotspot/cpu/aarch64/stubRoutines_aarch64.cpp
index bb1a3325cea..f7c27ea7380 100644
--- a/src/hotspot/cpu/aarch64/stubRoutines_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/stubRoutines_aarch64.cpp
@@ -57,7 +57,10 @@ address StubRoutines::aarch64::_string_indexof_linear_uu = NULL;
 address StubRoutines::aarch64::_string_indexof_linear_ul = NULL;
 address StubRoutines::aarch64::_large_byte_array_inflate = NULL;
 address StubRoutines::aarch64::_method_entry_barrier = NULL;
-address StubRoutines::aarch64::_spin_wait = NULL;
+
+static void spin_wait_nop() { }
+address StubRoutines::aarch64::_spin_wait = CAST_FROM_FN_PTR(address, spin_wait_nop);
+
 bool StubRoutines::aarch64::_completed = false;
 
 /**

@eastig
Copy link
Member Author

eastig commented Dec 14, 2021

Two more changes. The first makes the code simpler, and the second makes it less fragile.

Thank you! I forgot __ spin_wait generates nothing with XX:OnSpinWaitInst=none.

Done.

@openjdk
Copy link

openjdk bot commented Dec 14, 2021

@eastig 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:

8278241: Implement JVM SpinPause on linux-aarch64

Reviewed-by: aph, phh

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 162 new commits pushed to the master branch:

  • fcebe65: 8278842: Parallel: Remove unused VerifyObjectStartArrayClosure::_old_gen
  • 4851ad8: 8278548: G1: Remove unnecessary check in forward_to_block_containing_addr
  • 1e3ae3b: 8202579: Revisit VM_Version and VM_Version_ext for overlap and consolidation
  • 7adf7f3: 8278351: Add function to retrieve worker_id from any context
  • 758fe9b: 8273904: debug agent ArrayTypeImp::newInstance() fails to send reply packet if there is an error
  • c442587: 8277619: AArch64: Incorrect parameter type in Advanced SIMD Copy assembler functions
  • 46f99ac: 8244765: Undo exclusiveAccess.dirs changes for JDK-8220295 and see if there are still any testing issues
  • 54c9a99: 8278643: CoreUtils.getCoreFileLocation() should print out the size of the core file found
  • 068a450: 8278825: Unused variable for diagnostic in Resolve
  • 2def7e9: 8278584: compiler/vectorapi/VectorMaskLoadStoreTest.java failed with "Error: ShouldNotReachHere()"
  • ... and 152 more: https://git.openjdk.java.net/jdk/compare/0d938cedcaf55886058b94dc280a8f7181c79fdf...master

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@theRealAph, @phohensee) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 14, 2021
@eastig
Copy link
Member Author

eastig commented Dec 15, 2021

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 15, 2021
@openjdk
Copy link

openjdk bot commented Dec 15, 2021

@eastig
Your change (at version 08e8ce4) is now ready to be sponsored by a Committer.

@phohensee
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 15, 2021

Going to push as commit bcb79fd.
Since your change was applied there have been 162 commits pushed to the master branch:

  • fcebe65: 8278842: Parallel: Remove unused VerifyObjectStartArrayClosure::_old_gen
  • 4851ad8: 8278548: G1: Remove unnecessary check in forward_to_block_containing_addr
  • 1e3ae3b: 8202579: Revisit VM_Version and VM_Version_ext for overlap and consolidation
  • 7adf7f3: 8278351: Add function to retrieve worker_id from any context
  • 758fe9b: 8273904: debug agent ArrayTypeImp::newInstance() fails to send reply packet if there is an error
  • c442587: 8277619: AArch64: Incorrect parameter type in Advanced SIMD Copy assembler functions
  • 46f99ac: 8244765: Undo exclusiveAccess.dirs changes for JDK-8220295 and see if there are still any testing issues
  • 54c9a99: 8278643: CoreUtils.getCoreFileLocation() should print out the size of the core file found
  • 068a450: 8278825: Unused variable for diagnostic in Resolve
  • 2def7e9: 8278584: compiler/vectorapi/VectorMaskLoadStoreTest.java failed with "Error: ShouldNotReachHere()"
  • ... and 152 more: https://git.openjdk.java.net/jdk/compare/0d938cedcaf55886058b94dc280a8f7181c79fdf...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 15, 2021
@openjdk openjdk bot closed this Dec 15, 2021
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Dec 15, 2021
@openjdk
Copy link

openjdk bot commented Dec 15, 2021

@phohensee @eastig Pushed as commit bcb79fd.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants