annotate src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp @ 5663:1dcea64e9f00

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