annotate src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp @ 4731:1f114331df92

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