Patch to inline os::SpinPause() for X86 on non-Windows OS
Man Cao
manc at google.com
Thu Jul 19 01:53:19 UTC 2018
Hello,
The Java platform team at Google has maintained a local patch to inline
os::SpinPause() since 2014. We would like to upstream this patch to
OpenJDK. Could someone sponsor this patch?
It is difficult to demonstrate performance improvement in Java benchmarks.
It is more of a code refactoring to better utilize modern GCC. It partly
addresses the comment about inlining SpinPause() above its declaration in
os.hpp.
I found an interesting discussion about PAUSE and a microbenchmark in:
http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2012-August/004352.html
However, the microbenchmark has a large variance in our experiment, making
it difficult to tell if there's any benefit from inlining PAUSE. Inlining
PAUSE does seem to reduce the variance a bit.
The patch is inlined and attached below:
diff --git a/src/hotspot/os_cpu/bsd_x86/bsd_x86_32.s
b/src/hotspot/os_cpu/bsd_x86/bsd_x86_32.s
--- a/src/hotspot/os_cpu/bsd_x86/bsd_x86_32.s
+++ b/src/hotspot/os_cpu/bsd_x86/bsd_x86_32.s
@@ -63,15 +63,6 @@
popl %eax
ret
- .globl SYMBOL(SpinPause)
- ELF_TYPE(SpinPause, at function)
- .p2align 4,,15
-SYMBOL(SpinPause):
- rep
- nop
- movl $1, %eax
- ret
-
# Support for void Copy::conjoint_bytes(void* from,
# void* to,
# size_t count)
diff --git a/src/hotspot/os_cpu/bsd_x86/bsd_x86_64.s
b/src/hotspot/os_cpu/bsd_x86/bsd_x86_64.s
--- a/src/hotspot/os_cpu/bsd_x86/bsd_x86_64.s
+++ b/src/hotspot/os_cpu/bsd_x86/bsd_x86_64.s
@@ -46,15 +46,6 @@
.text
- .globl SYMBOL(SpinPause)
- .p2align 4,,15
- ELF_TYPE(SpinPause, at function)
-SYMBOL(SpinPause):
- rep
- nop
- movq $1, %rax
- ret
-
# Support for void Copy::arrayof_conjoint_bytes(void* from,
# void* to,
# size_t count)
diff --git a/src/hotspot/os_cpu/linux_x86/linux_x86_32.s
b/src/hotspot/os_cpu/linux_x86/linux_x86_32.s
--- a/src/hotspot/os_cpu/linux_x86/linux_x86_32.s
+++ b/src/hotspot/os_cpu/linux_x86/linux_x86_32.s
@@ -42,15 +42,6 @@
.text
- .globl SpinPause
- .type SpinPause, at function
- .p2align 4,,15
-SpinPause:
- rep
- nop
- movl $1, %eax
- ret
-
# Support for void Copy::conjoint_bytes(void* from,
# void* to,
# size_t count)
diff --git a/src/hotspot/os_cpu/linux_x86/linux_x86_64.s
b/src/hotspot/os_cpu/linux_x86/linux_x86_64.s
--- a/src/hotspot/os_cpu/linux_x86/linux_x86_64.s
+++ b/src/hotspot/os_cpu/linux_x86/linux_x86_64.s
@@ -38,15 +38,6 @@
.text
- .globl SpinPause
- .align 16
- .type SpinPause, at function
-SpinPause:
- rep
- nop
- movq $1, %rax
- ret
-
# Support for void Copy::arrayof_conjoint_bytes(void* from,
# void* to,
# size_t count)
diff --git a/src/hotspot/os_cpu/solaris_x86/solaris_x86_64.s
b/src/hotspot/os_cpu/solaris_x86/solaris_x86_64.s
--- a/src/hotspot/os_cpu/solaris_x86/solaris_x86_64.s
+++ b/src/hotspot/os_cpu/solaris_x86/solaris_x86_64.s
@@ -51,15 +51,6 @@
movq %fs:0x0,%rax
ret
- .globl SpinPause
- .align 16
-SpinPause:
- rep
- nop
- movq $1, %rax
- ret
-
-
/ Support for void Copy::arrayof_conjoint_bytes(void* from,
/ void* to,
/ size_t count)
diff --git a/src/hotspot/share/runtime/os.hpp
b/src/hotspot/share/runtime/os.hpp
--- a/src/hotspot/share/runtime/os.hpp
+++ b/src/hotspot/share/runtime/os.hpp
@@ -1031,6 +1031,13 @@
// of the global SpinPause() with C linkage.
// It'd also be eligible for inlining on many platforms.
+#if defined(X86) && !defined(_WINDOWS)
+extern "C" int inline SpinPause() {
+ __asm__ __volatile__ ("pause");
+ return 1;
+}
+#else
extern "C" int SpinPause();
+#endif
#endif // SHARE_VM_RUNTIME_OS_HPP
-Man
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/hotspot-gc-dev/attachments/20180718/b6119d04/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline_spinpause.patch
Type: text/x-patch
Size: 3778 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/hotspot-gc-dev/attachments/20180718/b6119d04/inline_spinpause.patch>
More information about the hotspot-gc-dev
mailing list