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

Thu, 16 Feb 2012 17:12:49 -0800

author
kvn
date
Thu, 16 Feb 2012 17:12:49 -0800
changeset 3577
9b8ce46870df
parent 2434
4fc084dac61e
child 4675
63e54c37ac64
permissions
-rw-r--r--

7145346: VerifyStackAtCalls is broken
Summary: Replace call_epilog() encoding with macroassembler use. Moved duplicated code to x86.ad. Fixed return_addr() definition.
Reviewed-by: never

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

mercurial