src/os_cpu/solaris_x86/vm/atomic_solaris_x86.inline.hpp

Thu, 21 Oct 2010 11:55:10 -0700

author
never
date
Thu, 21 Oct 2010 11:55:10 -0700
changeset 2262
1e9a9d2e6509
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6970683: improvements to hs_err output
Reviewed-by: kvn, jrose, dholmes, coleenp

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

mercurial