annotate src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1999-2005 Sun Microsystems, Inc. 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 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // The following alternative implementations are needed because
duke@0 26 // Windows 95 doesn't support (some of) the corresponding Windows NT
duke@0 27 // calls. Furthermore, these versions allow inlining in the caller.
duke@0 28 // (More precisely: The documentation for InterlockedExchange says
duke@0 29 // it is supported for Windows 95. However, when single-stepping
duke@0 30 // through the assembly code we cannot step into the routine and
duke@0 31 // when looking at the routine address we see only garbage code.
duke@0 32 // Better safe then sorry!). Was bug 7/31/98 (gri).
duke@0 33 //
duke@0 34 // Performance note: On uniprocessors, the 'lock' prefixes are not
duke@0 35 // necessary (and expensive). We should generate separate cases if
duke@0 36 // this becomes a performance problem.
duke@0 37
duke@0 38 #pragma warning(disable: 4035) // Disables warnings reporting missing return statement
duke@0 39
duke@0 40 inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; }
duke@0 41 inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; }
duke@0 42 inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; }
duke@0 43
duke@0 44 inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
duke@0 45 inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; }
duke@0 46
duke@0 47 inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; }
duke@0 48 inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; }
duke@0 49 inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; }
duke@0 50
duke@0 51
duke@0 52 inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
duke@0 53 inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; }
duke@0 54
duke@0 55 // Adding a lock prefix to an instruction on MP machine
duke@0 56 // VC++ doesn't like the lock prefix to be on a single line
duke@0 57 // so we can't insert a label after the lock prefix.
duke@0 58 // By emitting a lock prefix, we can define a label after it.
duke@0 59 #define LOCK_IF_MP(mp) __asm cmp mp, 0 \
duke@0 60 __asm je L0 \
duke@0 61 __asm _emit 0xF0 \
duke@0 62 __asm L0:
duke@0 63
duke@0 64 #ifdef AMD64
duke@0 65 inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; }
duke@0 66 inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; }
duke@0 67
duke@0 68 inline jint Atomic::add (jint add_value, volatile jint* dest) {
duke@0 69 return (jint)(*os::atomic_add_func)(add_value, dest);
duke@0 70 }
duke@0 71
duke@0 72 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
duke@0 73 return (intptr_t)(*os::atomic_add_ptr_func)(add_value, dest);
duke@0 74 }
duke@0 75
duke@0 76 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
duke@0 77 return (void*)(*os::atomic_add_ptr_func)(add_value, (volatile intptr_t*)dest);
duke@0 78 }
duke@0 79
duke@0 80 inline void Atomic::inc (volatile jint* dest) {
duke@0 81 (void)add (1, dest);
duke@0 82 }
duke@0 83
duke@0 84 inline void Atomic::inc_ptr(volatile intptr_t* dest) {
duke@0 85 (void)add_ptr(1, dest);
duke@0 86 }
duke@0 87
duke@0 88 inline void Atomic::inc_ptr(volatile void* dest) {
duke@0 89 (void)add_ptr(1, dest);
duke@0 90 }
duke@0 91
duke@0 92 inline void Atomic::dec (volatile jint* dest) {
duke@0 93 (void)add (-1, dest);
duke@0 94 }
duke@0 95
duke@0 96 inline void Atomic::dec_ptr(volatile intptr_t* dest) {
duke@0 97 (void)add_ptr(-1, dest);
duke@0 98 }
duke@0 99
duke@0 100 inline void Atomic::dec_ptr(volatile void* dest) {
duke@0 101 (void)add_ptr(-1, dest);
duke@0 102 }
duke@0 103
duke@0 104 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
duke@0 105 return (jint)(*os::atomic_xchg_func)(exchange_value, dest);
duke@0 106 }
duke@0 107
duke@0 108 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@0 109 return (intptr_t)(os::atomic_xchg_ptr_func)(exchange_value, dest);
duke@0 110 }
duke@0 111
duke@0 112 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@0 113 return (void *)(os::atomic_xchg_ptr_func)((intptr_t)exchange_value, (volatile intptr_t*)dest);
duke@0 114 }
duke@0 115
duke@0 116 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
duke@0 117 return (*os::atomic_cmpxchg_func)(exchange_value, dest, compare_value);
duke@0 118 }
duke@0 119
duke@0 120 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
duke@0 121 return (*os::atomic_cmpxchg_long_func)(exchange_value, dest, compare_value);
duke@0 122 }
duke@0 123
duke@0 124 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
duke@0 125 return (intptr_t)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
duke@0 126 }
duke@0 127
duke@0 128 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
duke@0 129 return (void*)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
duke@0 130 }
duke@0 131
duke@0 132 #else // !AMD64
duke@0 133
duke@0 134 //inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; }
duke@0 135 //inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; }
duke@0 136 inline jint Atomic::add (jint add_value, volatile jint* dest) {
duke@0 137 int mp = os::is_MP();
duke@0 138 __asm {
duke@0 139 mov edx, dest;
duke@0 140 mov eax, add_value;
duke@0 141 mov ecx, eax;
duke@0 142 LOCK_IF_MP(mp)
duke@0 143 xadd dword ptr [edx], eax;
duke@0 144 add eax, ecx;
duke@0 145 }
duke@0 146 }
duke@0 147
duke@0 148 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
duke@0 149 return (intptr_t)add((jint)add_value, (volatile jint*)dest);
duke@0 150 }
duke@0 151
duke@0 152 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
duke@0 153 return (void*)add((jint)add_value, (volatile jint*)dest);
duke@0 154 }
duke@0 155
duke@0 156 inline void Atomic::inc (volatile jint* dest) {
duke@0 157 // alternative for InterlockedIncrement
duke@0 158 int mp = os::is_MP();
duke@0 159 __asm {
duke@0 160 mov edx, dest;
duke@0 161 LOCK_IF_MP(mp)
duke@0 162 add dword ptr [edx], 1;
duke@0 163 }
duke@0 164 }
duke@0 165
duke@0 166 inline void Atomic::inc_ptr(volatile intptr_t* dest) {
duke@0 167 inc((volatile jint*)dest);
duke@0 168 }
duke@0 169
duke@0 170 inline void Atomic::inc_ptr(volatile void* dest) {
duke@0 171 inc((volatile jint*)dest);
duke@0 172 }
duke@0 173
duke@0 174 inline void Atomic::dec (volatile jint* dest) {
duke@0 175 // alternative for InterlockedDecrement
duke@0 176 int mp = os::is_MP();
duke@0 177 __asm {
duke@0 178 mov edx, dest;
duke@0 179 LOCK_IF_MP(mp)
duke@0 180 sub dword ptr [edx], 1;
duke@0 181 }
duke@0 182 }
duke@0 183
duke@0 184 inline void Atomic::dec_ptr(volatile intptr_t* dest) {
duke@0 185 dec((volatile jint*)dest);
duke@0 186 }
duke@0 187
duke@0 188 inline void Atomic::dec_ptr(volatile void* dest) {
duke@0 189 dec((volatile jint*)dest);
duke@0 190 }
duke@0 191
duke@0 192 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
duke@0 193 // alternative for InterlockedExchange
duke@0 194 __asm {
duke@0 195 mov eax, exchange_value;
duke@0 196 mov ecx, dest;
duke@0 197 xchg eax, dword ptr [ecx];
duke@0 198 }
duke@0 199 }
duke@0 200
duke@0 201 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@0 202 return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest);
duke@0 203 }
duke@0 204
duke@0 205 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@0 206 return (void*)xchg((jint)exchange_value, (volatile jint*)dest);
duke@0 207 }
duke@0 208
duke@0 209 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
duke@0 210 // alternative for InterlockedCompareExchange
duke@0 211 int mp = os::is_MP();
duke@0 212 __asm {
duke@0 213 mov edx, dest
duke@0 214 mov ecx, exchange_value
duke@0 215 mov eax, compare_value
duke@0 216 LOCK_IF_MP(mp)
duke@0 217 cmpxchg dword ptr [edx], ecx
duke@0 218 }
duke@0 219 }
duke@0 220
duke@0 221 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
duke@0 222 int mp = os::is_MP();
duke@0 223 jint ex_lo = (jint)exchange_value;
duke@0 224 jint ex_hi = *( ((jint*)&exchange_value) + 1 );
duke@0 225 jint cmp_lo = (jint)compare_value;
duke@0 226 jint cmp_hi = *( ((jint*)&compare_value) + 1 );
duke@0 227 __asm {
duke@0 228 push ebx
duke@0 229 push edi
duke@0 230 mov eax, cmp_lo
duke@0 231 mov edx, cmp_hi
duke@0 232 mov edi, dest
duke@0 233 mov ebx, ex_lo
duke@0 234 mov ecx, ex_hi
duke@0 235 LOCK_IF_MP(mp)
duke@0 236 cmpxchg8b qword ptr [edi]
duke@0 237 pop edi
duke@0 238 pop ebx
duke@0 239 }
duke@0 240 }
duke@0 241
duke@0 242 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
duke@0 243 return (intptr_t)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
duke@0 244 }
duke@0 245
duke@0 246 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
duke@0 247 return (void*)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
duke@0 248 }
duke@0 249 #endif // AMD64
duke@0 250
duke@0 251 #pragma warning(default: 4035) // Enables warnings reporting missing return statement