src/os_cpu/solaris_x86/vm/atomic_solaris_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_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_INLINE_HPP
stefank@2314 26 #define OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_INLINE_HPP
stefank@2314 27
stefank@2314 28 #include "orderAccess_solaris_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 inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; }
duke@435 34 inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; }
duke@435 35 inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; }
duke@435 36
duke@435 37
duke@435 38 inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
duke@435 39 inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; }
duke@435 40
duke@435 41 inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; }
duke@435 42 inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; }
duke@435 43 inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; }
duke@435 44 inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
duke@435 45 inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; }
duke@435 46
duke@435 47 inline void Atomic::inc (volatile jint* dest) { (void)add (1, dest); }
duke@435 48 inline void Atomic::inc_ptr(volatile intptr_t* dest) { (void)add_ptr(1, dest); }
duke@435 49 inline void Atomic::inc_ptr(volatile void* dest) { (void)add_ptr(1, dest); }
duke@435 50
duke@435 51 inline void Atomic::dec (volatile jint* dest) { (void)add (-1, dest); }
duke@435 52 inline void Atomic::dec_ptr(volatile intptr_t* dest) { (void)add_ptr(-1, dest); }
duke@435 53 inline void Atomic::dec_ptr(volatile void* dest) { (void)add_ptr(-1, dest); }
duke@435 54
duke@435 55 // For Sun Studio - implementation is in solaris_x86_[32/64].il.
duke@435 56 // For gcc - implementation is just below.
duke@435 57
jcoomes@1902 58 // The lock prefix can be omitted for certain instructions on uniprocessors; to
jcoomes@1902 59 // facilitate this, os::is_MP() is passed as an additional argument. 64-bit
jcoomes@1902 60 // processors are assumed to be multi-threaded and/or multi-core, so the extra
jcoomes@1902 61 // argument is unnecessary.
jcoomes@1902 62 #ifndef _LP64
jcoomes@1902 63 #define IS_MP_DECL() , int is_mp
jcoomes@1902 64 #define IS_MP_ARG() , (int) os::is_MP()
jcoomes@1902 65 #else
jcoomes@1902 66 #define IS_MP_DECL()
jcoomes@1902 67 #define IS_MP_ARG()
jcoomes@1902 68 #endif // _LP64
jcoomes@1902 69
jcoomes@1902 70 extern "C" {
jcoomes@1902 71 jint _Atomic_add(jint add_value, volatile jint* dest IS_MP_DECL());
jcoomes@1902 72 jint _Atomic_xchg(jint exchange_value, volatile jint* dest);
jcoomes@1902 73 jint _Atomic_cmpxchg(jint exchange_value, volatile jint* dest,
jcoomes@1902 74 jint compare_value IS_MP_DECL());
jcoomes@1902 75 jlong _Atomic_cmpxchg_long(jlong exchange_value, volatile jlong* dest,
jcoomes@1902 76 jlong compare_value IS_MP_DECL());
jcoomes@1902 77 }
duke@435 78
duke@435 79 inline jint Atomic::add (jint add_value, volatile jint* dest) {
jcoomes@1902 80 return _Atomic_add(add_value, dest IS_MP_ARG());
jcoomes@1902 81 }
jcoomes@1902 82
jcoomes@1902 83 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
jcoomes@1902 84 return _Atomic_xchg(exchange_value, dest);
duke@435 85 }
duke@435 86
duke@435 87 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
jcoomes@1902 88 return _Atomic_cmpxchg(exchange_value, dest, compare_value IS_MP_ARG());
duke@435 89 }
duke@435 90
duke@435 91 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
jcoomes@1902 92 return _Atomic_cmpxchg_long(exchange_value, dest, compare_value IS_MP_ARG());
duke@435 93 }
duke@435 94
duke@435 95
duke@435 96 #ifdef AMD64
duke@435 97 inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; }
duke@435 98 inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; }
jcoomes@1902 99 extern "C" jlong _Atomic_add_long(jlong add_value, volatile jlong* dest);
duke@435 100 extern "C" jlong _Atomic_xchg_long(jlong exchange_value, volatile jlong* dest);
duke@435 101
duke@435 102 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
jcoomes@1902 103 return (intptr_t)_Atomic_add_long((jlong)add_value, (volatile jlong*)dest);
duke@435 104 }
duke@435 105
duke@435 106 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
jcoomes@1902 107 return (void*)_Atomic_add_long((jlong)add_value, (volatile jlong*)dest);
duke@435 108 }
duke@435 109
duke@435 110 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@435 111 return (intptr_t)_Atomic_xchg_long((jlong)exchange_value, (volatile jlong*)dest);
duke@435 112 }
duke@435 113
duke@435 114 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@435 115 return (void*)_Atomic_xchg_long((jlong)exchange_value, (volatile jlong*)dest);
duke@435 116 }
duke@435 117
duke@435 118 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
jcoomes@1902 119 return (intptr_t)_Atomic_cmpxchg_long((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
duke@435 120 }
duke@435 121
duke@435 122 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
jcoomes@1902 123 return (void*)_Atomic_cmpxchg_long((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value);
duke@435 124 }
duke@435 125
kvn@1329 126 inline jlong Atomic::load(volatile jlong* src) { return *src; }
kvn@1329 127
duke@435 128 #else // !AMD64
duke@435 129
duke@435 130 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
duke@435 131 return (intptr_t)add((jint)add_value, (volatile jint*)dest);
duke@435 132 }
duke@435 133
duke@435 134 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
duke@435 135 return (void*)add((jint)add_value, (volatile jint*)dest);
duke@435 136 }
duke@435 137
duke@435 138 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@435 139 return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest);
duke@435 140 }
duke@435 141
duke@435 142 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@435 143 return (void*)xchg((jint)exchange_value, (volatile jint*)dest);
duke@435 144 }
duke@435 145
duke@435 146 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
duke@435 147 return (intptr_t)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
duke@435 148 }
duke@435 149
duke@435 150 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
duke@435 151 return (void*)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
duke@435 152 }
kvn@1329 153
kvn@2434 154 extern "C" void _Atomic_move_long(volatile jlong* src, volatile jlong* dst);
kvn@1329 155
kvn@1329 156 inline jlong Atomic::load(volatile jlong* src) {
kvn@1329 157 volatile jlong dest;
kvn@2434 158 _Atomic_move_long(src, &dest);
kvn@1329 159 return dest;
kvn@1329 160 }
kvn@1329 161
kvn@2434 162 inline void Atomic::store(jlong store_value, jlong* dest) {
kvn@2434 163 _Atomic_move_long((volatile jlong*)&store_value, (volatile jlong*)dest);
kvn@2434 164 }
kvn@2434 165
kvn@2434 166 inline void Atomic::store(jlong store_value, volatile jlong* dest) {
kvn@2434 167 _Atomic_move_long((volatile jlong*)&store_value, dest);
kvn@2434 168 }
kvn@2434 169
duke@435 170 #endif // AMD64
duke@435 171
duke@435 172 #ifdef _GNU_SOURCE
duke@435 173 // Add a lock prefix to an instruction on an MP machine
duke@435 174 #define LOCK_IF_MP(mp) "cmp $0, " #mp "; je 1f; lock; 1: "
duke@435 175
duke@435 176 extern "C" {
duke@435 177 inline jint _Atomic_add(jint add_value, volatile jint* dest, int mp) {
duke@435 178 jint addend = add_value;
duke@435 179 __asm__ volatile ( LOCK_IF_MP(%3) "xaddl %0,(%2)"
duke@435 180 : "=r" (addend)
duke@435 181 : "0" (addend), "r" (dest), "r" (mp)
duke@435 182 : "cc", "memory");
duke@435 183 return addend + add_value;
duke@435 184 }
duke@435 185
duke@435 186 #ifdef AMD64
duke@435 187 inline jlong _Atomic_add_long(jlong add_value, volatile jlong* dest, int mp) {
duke@435 188 intptr_t addend = add_value;
duke@435 189 __asm__ __volatile__ (LOCK_IF_MP(%3) "xaddq %0,(%2)"
duke@435 190 : "=r" (addend)
duke@435 191 : "0" (addend), "r" (dest), "r" (mp)
duke@435 192 : "cc", "memory");
duke@435 193 return addend + add_value;
duke@435 194 }
duke@435 195
duke@435 196 inline jlong _Atomic_xchg_long(jlong exchange_value, volatile jlong* dest) {
duke@435 197 __asm__ __volatile__ ("xchgq (%2),%0"
duke@435 198 : "=r" (exchange_value)
duke@435 199 : "0" (exchange_value), "r" (dest)
duke@435 200 : "memory");
duke@435 201 return exchange_value;
duke@435 202 }
duke@435 203
duke@435 204 #endif // AMD64
duke@435 205
duke@435 206 inline jint _Atomic_xchg(jint exchange_value, volatile jint* dest) {
duke@435 207 __asm__ __volatile__ ("xchgl (%2),%0"
duke@435 208 : "=r" (exchange_value)
duke@435 209 : "0" (exchange_value), "r" (dest)
duke@435 210 : "memory");
duke@435 211 return exchange_value;
duke@435 212 }
duke@435 213
duke@435 214 inline jint _Atomic_cmpxchg(jint exchange_value, volatile jint* dest, jint compare_value, int mp) {
duke@435 215 __asm__ volatile (LOCK_IF_MP(%4) "cmpxchgl %1,(%3)"
duke@435 216 : "=a" (exchange_value)
duke@435 217 : "r" (exchange_value), "a" (compare_value), "r" (dest), "r" (mp)
duke@435 218 : "cc", "memory");
duke@435 219 return exchange_value;
duke@435 220 }
duke@435 221
duke@435 222 // This is the interface to the atomic instruction in solaris_i486.s.
duke@435 223 jlong _Atomic_cmpxchg_long_gcc(jlong exchange_value, volatile jlong* dest, jlong compare_value, int mp);
duke@435 224
duke@435 225 inline jlong _Atomic_cmpxchg_long(jlong exchange_value, volatile jlong* dest, jlong compare_value, int mp) {
duke@435 226 #ifdef AMD64
duke@435 227 __asm__ __volatile__ (LOCK_IF_MP(%4) "cmpxchgq %1,(%3)"
duke@435 228 : "=a" (exchange_value)
duke@435 229 : "r" (exchange_value), "a" (compare_value), "r" (dest), "r" (mp)
duke@435 230 : "cc", "memory");
duke@435 231 return exchange_value;
duke@435 232 #else
duke@435 233 return _Atomic_cmpxchg_long_gcc(exchange_value, dest, compare_value, os::is_MP());
duke@435 234
duke@435 235 #if 0
duke@435 236 // The code below does not work presumably because of the bug in gcc
duke@435 237 // The error message says:
duke@435 238 // can't find a register in class BREG while reloading asm
duke@435 239 // However I want to save this code and later replace _Atomic_cmpxchg_long_gcc
duke@435 240 // with such inline asm code:
duke@435 241
duke@435 242 volatile jlong_accessor evl, cvl, rv;
duke@435 243 evl.long_value = exchange_value;
duke@435 244 cvl.long_value = compare_value;
duke@435 245 int mp = os::is_MP();
duke@435 246
duke@435 247 __asm__ volatile ("cmp $0, %%esi\n\t"
duke@435 248 "je 1f \n\t"
duke@435 249 "lock\n\t"
duke@435 250 "1: cmpxchg8b (%%edi)\n\t"
duke@435 251 : "=a"(cvl.words[0]), "=d"(cvl.words[1])
duke@435 252 : "a"(cvl.words[0]), "d"(cvl.words[1]),
duke@435 253 "b"(evl.words[0]), "c"(evl.words[1]),
duke@435 254 "D"(dest), "S"(mp)
duke@435 255 : "cc", "memory");
duke@435 256 return cvl.long_value;
duke@435 257 #endif // if 0
duke@435 258 #endif // AMD64
duke@435 259 }
duke@435 260 }
duke@435 261 #undef LOCK_IF_MP
duke@435 262
duke@435 263 #endif // _GNU_SOURCE
stefank@2314 264
stefank@2314 265 #endif // OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_INLINE_HPP

mercurial