|
25 | 25 | #ifndef OS_CPU_WINDOWS_X86_COPY_WINDOWS_X86_HPP
|
26 | 26 | #define OS_CPU_WINDOWS_X86_COPY_WINDOWS_X86_HPP
|
27 | 27 |
|
| 28 | +#include "runtime/atomic.hpp" |
28 | 29 |
|
29 |
| -static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) { |
| 30 | +template <typename T> |
| 31 | +static void pd_conjoint_atomic_helper(const T* from, T* to, size_t count) { |
30 | 32 | if (from > to) {
|
31 | 33 | while (count-- > 0) {
|
32 | 34 | // Copy forwards
|
33 |
| - *to++ = *from++; |
| 35 | + Atomic::store(to++, Atomic::load(from++)); |
34 | 36 | }
|
35 | 37 | } else {
|
36 | 38 | from += count - 1;
|
37 | 39 | to += count - 1;
|
38 | 40 | while (count-- > 0) {
|
39 | 41 | // Copy backwards
|
40 |
| - *to-- = *from--; |
| 42 | + Atomic::store(to--, Atomic::load(from--)); |
41 | 43 | }
|
42 | 44 | }
|
43 | 45 | }
|
44 | 46 |
|
| 47 | +static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) { |
| 48 | + pd_conjoint_atomic_helper(from, to, count); |
| 49 | +} |
| 50 | + |
45 | 51 | static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {
|
46 |
| - if (from > to) { |
47 |
| - while (count-- > 0) { |
48 |
| - // Copy forwards |
49 |
| - *to++ = *from++; |
50 |
| - } |
51 |
| - } else { |
52 |
| - from += count - 1; |
53 |
| - to += count - 1; |
54 |
| - while (count-- > 0) { |
55 |
| - // Copy backwards |
56 |
| - *to-- = *from--; |
57 |
| - } |
58 |
| - } |
| 52 | + pd_conjoint_atomic_helper(from, to, count); |
59 | 53 | }
|
60 | 54 |
|
61 | 55 | static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {
|
62 | 56 | #ifdef AMD64
|
63 |
| - assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); |
64 |
| - pd_conjoint_oops_atomic((const oop*)from, (oop*)to, count); |
| 57 | + pd_conjoint_atomic_helper(from, to, count); |
65 | 58 | #else
|
66 | 59 | // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.
|
67 | 60 | __asm {
|
@@ -92,20 +85,7 @@ static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count
|
92 | 85 | }
|
93 | 86 |
|
94 | 87 | static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) {
|
95 |
| - // Do better than this: inline memmove body NEEDS CLEANUP |
96 |
| - if (from > to) { |
97 |
| - while (count-- > 0) { |
98 |
| - // Copy forwards |
99 |
| - *to++ = *from++; |
100 |
| - } |
101 |
| - } else { |
102 |
| - from += count - 1; |
103 |
| - to += count - 1; |
104 |
| - while (count-- > 0) { |
105 |
| - // Copy backwards |
106 |
| - *to-- = *from--; |
107 |
| - } |
108 |
| - } |
| 88 | + pd_conjoint_atomic_helper(from, to, count); |
109 | 89 | }
|
110 | 90 |
|
111 | 91 | static void pd_arrayof_conjoint_bytes(const HeapWord* from, HeapWord* to, size_t count) {
|
|
0 commit comments