src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef OS_CPU_WINDOWS_X86_VM_ATOMIC_WINDOWS_X86_INLINE_HPP
aoqi@0 26 #define OS_CPU_WINDOWS_X86_VM_ATOMIC_WINDOWS_X86_INLINE_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/atomic.hpp"
aoqi@0 29 #include "runtime/os.hpp"
aoqi@0 30 #include "vm_version_x86.hpp"
aoqi@0 31
aoqi@0 32 // The following alternative implementations are needed because
aoqi@0 33 // Windows 95 doesn't support (some of) the corresponding Windows NT
aoqi@0 34 // calls. Furthermore, these versions allow inlining in the caller.
aoqi@0 35 // (More precisely: The documentation for InterlockedExchange says
aoqi@0 36 // it is supported for Windows 95. However, when single-stepping
aoqi@0 37 // through the assembly code we cannot step into the routine and
aoqi@0 38 // when looking at the routine address we see only garbage code.
aoqi@0 39 // Better safe then sorry!). Was bug 7/31/98 (gri).
aoqi@0 40 //
aoqi@0 41 // Performance note: On uniprocessors, the 'lock' prefixes are not
aoqi@0 42 // necessary (and expensive). We should generate separate cases if
aoqi@0 43 // this becomes a performance problem.
aoqi@0 44
aoqi@0 45 #pragma warning(disable: 4035) // Disables warnings reporting missing return statement
aoqi@0 46
aoqi@0 47 inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; }
aoqi@0 48 inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; }
aoqi@0 49 inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; }
aoqi@0 50
aoqi@0 51 inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
aoqi@0 52 inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; }
aoqi@0 53
aoqi@0 54 inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; }
aoqi@0 55 inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; }
aoqi@0 56 inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; }
aoqi@0 57
aoqi@0 58
aoqi@0 59 inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
aoqi@0 60 inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; }
aoqi@0 61
aoqi@0 62 // Adding a lock prefix to an instruction on MP machine
aoqi@0 63 // VC++ doesn't like the lock prefix to be on a single line
aoqi@0 64 // so we can't insert a label after the lock prefix.
aoqi@0 65 // By emitting a lock prefix, we can define a label after it.
aoqi@0 66 #define LOCK_IF_MP(mp) __asm cmp mp, 0 \
aoqi@0 67 __asm je L0 \
aoqi@0 68 __asm _emit 0xF0 \
aoqi@0 69 __asm L0:
aoqi@0 70
aoqi@0 71 #ifdef AMD64
aoqi@0 72 inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; }
aoqi@0 73 inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; }
aoqi@0 74
aoqi@0 75 inline jint Atomic::add (jint add_value, volatile jint* dest) {
aoqi@0 76 return (jint)(*os::atomic_add_func)(add_value, dest);
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
aoqi@0 80 return (intptr_t)(*os::atomic_add_ptr_func)(add_value, dest);
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
aoqi@0 84 return (void*)(*os::atomic_add_ptr_func)(add_value, (volatile intptr_t*)dest);
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 inline void Atomic::inc (volatile jint* dest) {
aoqi@0 88 (void)add (1, dest);
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 inline void Atomic::inc_ptr(volatile intptr_t* dest) {
aoqi@0 92 (void)add_ptr(1, dest);
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 inline void Atomic::inc_ptr(volatile void* dest) {
aoqi@0 96 (void)add_ptr(1, dest);
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 inline void Atomic::dec (volatile jint* dest) {
aoqi@0 100 (void)add (-1, dest);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 inline void Atomic::dec_ptr(volatile intptr_t* dest) {
aoqi@0 104 (void)add_ptr(-1, dest);
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 inline void Atomic::dec_ptr(volatile void* dest) {
aoqi@0 108 (void)add_ptr(-1, dest);
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
aoqi@0 112 return (jint)(*os::atomic_xchg_func)(exchange_value, dest);
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
aoqi@0 116 return (intptr_t)(os::atomic_xchg_ptr_func)(exchange_value, dest);
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
aoqi@0 120 return (void *)(os::atomic_xchg_ptr_func)((intptr_t)exchange_value, (volatile intptr_t*)dest);
aoqi@0 121 }
aoqi@0 122
aoqi@0 123 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
aoqi@0 124 return (*os::atomic_cmpxchg_func)(exchange_value, dest, compare_value);
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
aoqi@0 128 return (*os::atomic_cmpxchg_long_func)(exchange_value, dest, compare_value);
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
aoqi@0 132 return (intptr_t)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
aoqi@0 136 return (void*)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 inline jlong Atomic::load(volatile jlong* src) { return *src; }
aoqi@0 140
aoqi@0 141 #else // !AMD64
aoqi@0 142
aoqi@0 143 inline jint Atomic::add (jint add_value, volatile jint* dest) {
aoqi@0 144 int mp = os::is_MP();
aoqi@0 145 __asm {
aoqi@0 146 mov edx, dest;
aoqi@0 147 mov eax, add_value;
aoqi@0 148 mov ecx, eax;
aoqi@0 149 LOCK_IF_MP(mp)
aoqi@0 150 xadd dword ptr [edx], eax;
aoqi@0 151 add eax, ecx;
aoqi@0 152 }
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
aoqi@0 156 return (intptr_t)add((jint)add_value, (volatile jint*)dest);
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
aoqi@0 160 return (void*)add((jint)add_value, (volatile jint*)dest);
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 inline void Atomic::inc (volatile jint* dest) {
aoqi@0 164 // alternative for InterlockedIncrement
aoqi@0 165 int mp = os::is_MP();
aoqi@0 166 __asm {
aoqi@0 167 mov edx, dest;
aoqi@0 168 LOCK_IF_MP(mp)
aoqi@0 169 add dword ptr [edx], 1;
aoqi@0 170 }
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 inline void Atomic::inc_ptr(volatile intptr_t* dest) {
aoqi@0 174 inc((volatile jint*)dest);
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 inline void Atomic::inc_ptr(volatile void* dest) {
aoqi@0 178 inc((volatile jint*)dest);
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 inline void Atomic::dec (volatile jint* dest) {
aoqi@0 182 // alternative for InterlockedDecrement
aoqi@0 183 int mp = os::is_MP();
aoqi@0 184 __asm {
aoqi@0 185 mov edx, dest;
aoqi@0 186 LOCK_IF_MP(mp)
aoqi@0 187 sub dword ptr [edx], 1;
aoqi@0 188 }
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 inline void Atomic::dec_ptr(volatile intptr_t* dest) {
aoqi@0 192 dec((volatile jint*)dest);
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 inline void Atomic::dec_ptr(volatile void* dest) {
aoqi@0 196 dec((volatile jint*)dest);
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
aoqi@0 200 // alternative for InterlockedExchange
aoqi@0 201 __asm {
aoqi@0 202 mov eax, exchange_value;
aoqi@0 203 mov ecx, dest;
aoqi@0 204 xchg eax, dword ptr [ecx];
aoqi@0 205 }
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
aoqi@0 209 return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest);
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
aoqi@0 213 return (void*)xchg((jint)exchange_value, (volatile jint*)dest);
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
aoqi@0 217 // alternative for InterlockedCompareExchange
aoqi@0 218 int mp = os::is_MP();
aoqi@0 219 __asm {
aoqi@0 220 mov edx, dest
aoqi@0 221 mov ecx, exchange_value
aoqi@0 222 mov eax, compare_value
aoqi@0 223 LOCK_IF_MP(mp)
aoqi@0 224 cmpxchg dword ptr [edx], ecx
aoqi@0 225 }
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
aoqi@0 229 int mp = os::is_MP();
aoqi@0 230 jint ex_lo = (jint)exchange_value;
aoqi@0 231 jint ex_hi = *( ((jint*)&exchange_value) + 1 );
aoqi@0 232 jint cmp_lo = (jint)compare_value;
aoqi@0 233 jint cmp_hi = *( ((jint*)&compare_value) + 1 );
aoqi@0 234 __asm {
aoqi@0 235 push ebx
aoqi@0 236 push edi
aoqi@0 237 mov eax, cmp_lo
aoqi@0 238 mov edx, cmp_hi
aoqi@0 239 mov edi, dest
aoqi@0 240 mov ebx, ex_lo
aoqi@0 241 mov ecx, ex_hi
aoqi@0 242 LOCK_IF_MP(mp)
aoqi@0 243 cmpxchg8b qword ptr [edi]
aoqi@0 244 pop edi
aoqi@0 245 pop ebx
aoqi@0 246 }
aoqi@0 247 }
aoqi@0 248
aoqi@0 249 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
aoqi@0 250 return (intptr_t)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
aoqi@0 254 return (void*)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
aoqi@0 255 }
aoqi@0 256
aoqi@0 257 inline jlong Atomic::load(volatile jlong* src) {
aoqi@0 258 volatile jlong dest;
aoqi@0 259 volatile jlong* pdest = &dest;
aoqi@0 260 __asm {
aoqi@0 261 mov eax, src
aoqi@0 262 fild qword ptr [eax]
aoqi@0 263 mov eax, pdest
aoqi@0 264 fistp qword ptr [eax]
aoqi@0 265 }
aoqi@0 266 return dest;
aoqi@0 267 }
aoqi@0 268
aoqi@0 269 inline void Atomic::store(jlong store_value, volatile jlong* dest) {
aoqi@0 270 volatile jlong* src = &store_value;
aoqi@0 271 __asm {
aoqi@0 272 mov eax, src
aoqi@0 273 fild qword ptr [eax]
aoqi@0 274 mov eax, dest
aoqi@0 275 fistp qword ptr [eax]
aoqi@0 276 }
aoqi@0 277 }
aoqi@0 278
aoqi@0 279 inline void Atomic::store(jlong store_value, jlong* dest) {
aoqi@0 280 Atomic::store(store_value, (volatile jlong*)dest);
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 #endif // AMD64
aoqi@0 284
aoqi@0 285 #pragma warning(default: 4035) // Enables warnings reporting missing return statement
aoqi@0 286
aoqi@0 287 #endif // OS_CPU_WINDOWS_X86_VM_ATOMIC_WINDOWS_X86_INLINE_HPP

mercurial