annotate src/os_cpu/solaris_sparc/vm/atomic_solaris_sparc.inline.hpp @ 2153:85c73c0edb06

7012965: Fix failed on sparc for 7009756: volatile variables could be broken throw reflection API Summary: Use LDX/STX on v9 and LDD/STD on v8 sparc for volatile long moves. Reviewed-by: never
author kvn
date Tue, 18 Jan 2011 17:10:03 -0800
parents f95d63e2154a
children f7de3327c683
rev   line source
duke@0 1 /*
kvn@2153 2 * Copyright (c) 1999, 2011, 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@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1992 25 #ifndef OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_INLINE_HPP
stefank@1992 26 #define OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_INLINE_HPP
stefank@1992 27
stefank@1992 28 #include "orderAccess_solaris_sparc.inline.hpp"
stefank@1992 29 #include "runtime/atomic.hpp"
stefank@1992 30 #include "runtime/os.hpp"
stefank@1992 31 #include "vm_version_sparc.hpp"
stefank@1992 32
duke@0 33 // Implementation of class atomic
duke@0 34
duke@0 35 inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; }
duke@0 36 inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; }
duke@0 37 inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; }
duke@0 38 inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
duke@0 39 inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; }
duke@0 40
duke@0 41 inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; }
duke@0 42 inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; }
duke@0 43 inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; }
duke@0 44 inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
duke@0 45 inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; }
duke@0 46
duke@0 47 inline void Atomic::inc (volatile jint* dest) { (void)add (1, dest); }
duke@0 48 inline void Atomic::inc_ptr(volatile intptr_t* dest) { (void)add_ptr(1, dest); }
duke@0 49 inline void Atomic::inc_ptr(volatile void* dest) { (void)add_ptr(1, dest); }
duke@0 50
duke@0 51 inline void Atomic::dec (volatile jint* dest) { (void)add (-1, dest); }
duke@0 52 inline void Atomic::dec_ptr(volatile intptr_t* dest) { (void)add_ptr(-1, dest); }
duke@0 53 inline void Atomic::dec_ptr(volatile void* dest) { (void)add_ptr(-1, dest); }
duke@0 54
kvn@2153 55
kvn@2153 56 #ifdef _LP64
kvn@2153 57
kvn@2153 58 inline void Atomic::store(jlong store_value, jlong* dest) { *dest = store_value; }
kvn@2153 59 inline void Atomic::store(jlong store_value, volatile jlong* dest) { *dest = store_value; }
kvn@945 60 inline jlong Atomic::load(volatile jlong* src) { return *src; }
kvn@945 61
kvn@2153 62 #else
kvn@2153 63
kvn@2153 64 extern "C" void _Atomic_move_long_v8(volatile jlong* src, volatile jlong* dst);
kvn@2153 65 extern "C" void _Atomic_move_long_v9(volatile jlong* src, volatile jlong* dst);
kvn@2153 66
kvn@2153 67 inline void Atomic_move_long(volatile jlong* src, volatile jlong* dst) {
kvn@2153 68 #ifdef COMPILER2
kvn@2153 69 // Compiler2 does not support v8, it is used only for v9.
kvn@2153 70 assert (VM_Version::v9_instructions_work(), "only supported on v9");
kvn@2153 71 _Atomic_move_long_v9(src, dst);
kvn@2153 72 #else
kvn@2153 73 // The branch is cheaper then emulated LDD.
kvn@2153 74 if (VM_Version::v9_instructions_work()) {
kvn@2153 75 _Atomic_move_long_v9(src, dst);
kvn@2153 76 } else {
kvn@2153 77 _Atomic_move_long_v8(src, dst);
kvn@2153 78 }
kvn@2153 79 #endif
kvn@2153 80 }
kvn@2153 81
kvn@2153 82 inline jlong Atomic::load(volatile jlong* src) {
kvn@2153 83 volatile jlong dest;
kvn@2153 84 Atomic_move_long(src, &dest);
kvn@2153 85 return dest;
kvn@2153 86 }
kvn@2153 87
kvn@2153 88 inline void Atomic::store(jlong store_value, jlong* dest) {
kvn@2153 89 Atomic_move_long((volatile jlong*)&store_value, (volatile jlong*)dest);
kvn@2153 90 }
kvn@2153 91
kvn@2153 92 inline void Atomic::store(jlong store_value, volatile jlong* dest) {
kvn@2153 93 Atomic_move_long((volatile jlong*)&store_value, dest);
kvn@2153 94 }
kvn@2153 95
kvn@2153 96 #endif
kvn@2153 97
duke@0 98 #ifdef _GNU_SOURCE
duke@0 99
duke@0 100 inline jint Atomic::add (jint add_value, volatile jint* dest) {
duke@0 101 intptr_t rv;
duke@0 102 __asm__ volatile(
duke@0 103 "1: \n\t"
duke@0 104 " ld [%2], %%o2\n\t"
duke@0 105 " add %1, %%o2, %%o3\n\t"
duke@0 106 " cas [%2], %%o2, %%o3\n\t"
duke@0 107 " cmp %%o2, %%o3\n\t"
duke@0 108 " bne 1b\n\t"
duke@0 109 " nop\n\t"
duke@0 110 " add %1, %%o2, %0\n\t"
duke@0 111 : "=r" (rv)
duke@0 112 : "r" (add_value), "r" (dest)
duke@0 113 : "memory", "o2", "o3");
duke@0 114 return rv;
duke@0 115 }
duke@0 116
duke@0 117 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
duke@0 118 intptr_t rv;
duke@0 119 #ifdef _LP64
duke@0 120 __asm__ volatile(
duke@0 121 "1: \n\t"
duke@0 122 " ldx [%2], %%o2\n\t"
duke@0 123 " add %0, %%o2, %%o3\n\t"
duke@0 124 " casx [%2], %%o2, %%o3\n\t"
duke@0 125 " cmp %%o2, %%o3\n\t"
duke@0 126 " bne %%xcc, 1b\n\t"
duke@0 127 " nop\n\t"
duke@0 128 " add %0, %%o2, %0\n\t"
duke@0 129 : "=r" (rv)
duke@0 130 : "r" (add_value), "r" (dest)
duke@0 131 : "memory", "o2", "o3");
duke@0 132 #else //_LP64
duke@0 133 __asm__ volatile(
duke@0 134 "1: \n\t"
duke@0 135 " ld [%2], %%o2\n\t"
duke@0 136 " add %1, %%o2, %%o3\n\t"
duke@0 137 " cas [%2], %%o2, %%o3\n\t"
duke@0 138 " cmp %%o2, %%o3\n\t"
duke@0 139 " bne 1b\n\t"
duke@0 140 " nop\n\t"
duke@0 141 " add %1, %%o2, %0\n\t"
duke@0 142 : "=r" (rv)
duke@0 143 : "r" (add_value), "r" (dest)
duke@0 144 : "memory", "o2", "o3");
duke@0 145 #endif // _LP64
duke@0 146 return rv;
duke@0 147 }
duke@0 148
duke@0 149 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
duke@0 150 return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
duke@0 151 }
duke@0 152
duke@0 153
duke@0 154 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
duke@0 155 intptr_t rv = exchange_value;
duke@0 156 __asm__ volatile(
duke@0 157 " swap [%2],%1\n\t"
duke@0 158 : "=r" (rv)
duke@0 159 : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
duke@0 160 : "memory");
duke@0 161 return rv;
duke@0 162 }
duke@0 163
duke@0 164 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@0 165 intptr_t rv = exchange_value;
duke@0 166 #ifdef _LP64
duke@0 167 __asm__ volatile(
duke@0 168 "1:\n\t"
duke@0 169 " mov %1, %%o3\n\t"
duke@0 170 " ldx [%2], %%o2\n\t"
duke@0 171 " casx [%2], %%o2, %%o3\n\t"
duke@0 172 " cmp %%o2, %%o3\n\t"
duke@0 173 " bne %%xcc, 1b\n\t"
duke@0 174 " nop\n\t"
duke@0 175 " mov %%o2, %0\n\t"
duke@0 176 : "=r" (rv)
duke@0 177 : "r" (exchange_value), "r" (dest)
duke@0 178 : "memory", "o2", "o3");
duke@0 179 #else //_LP64
duke@0 180 __asm__ volatile(
duke@0 181 "swap [%2],%1\n\t"
duke@0 182 : "=r" (rv)
duke@0 183 : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
duke@0 184 : "memory");
duke@0 185 #endif // _LP64
duke@0 186 return rv;
duke@0 187 }
duke@0 188
duke@0 189 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@0 190 return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
duke@0 191 }
duke@0 192
duke@0 193
duke@0 194 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
duke@0 195 jint rv;
duke@0 196 __asm__ volatile(
duke@0 197 " cas [%2], %3, %0"
duke@0 198 : "=r" (rv)
duke@0 199 : "0" (exchange_value), "r" (dest), "r" (compare_value)
duke@0 200 : "memory");
duke@0 201 return rv;
duke@0 202 }
duke@0 203
duke@0 204 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
duke@0 205 #ifdef _LP64
duke@0 206 jlong rv;
duke@0 207 __asm__ volatile(
duke@0 208 " casx [%2], %3, %0"
duke@0 209 : "=r" (rv)
duke@0 210 : "0" (exchange_value), "r" (dest), "r" (compare_value)
duke@0 211 : "memory");
duke@0 212 return rv;
duke@0 213 #else //_LP64
duke@0 214 assert(VM_Version::v9_instructions_work(), "cas only supported on v9");
duke@0 215 volatile jlong_accessor evl, cvl, rv;
duke@0 216 evl.long_value = exchange_value;
duke@0 217 cvl.long_value = compare_value;
duke@0 218
duke@0 219 __asm__ volatile(
duke@0 220 " sllx %2, 32, %2\n\t"
duke@0 221 " srl %3, 0, %3\n\t"
duke@0 222 " or %2, %3, %2\n\t"
duke@0 223 " sllx %5, 32, %5\n\t"
duke@0 224 " srl %6, 0, %6\n\t"
duke@0 225 " or %5, %6, %5\n\t"
duke@0 226 " casx [%4], %5, %2\n\t"
duke@0 227 " srl %2, 0, %1\n\t"
duke@0 228 " srlx %2, 32, %0\n\t"
duke@0 229 : "=r" (rv.words[0]), "=r" (rv.words[1])
duke@0 230 : "r" (evl.words[0]), "r" (evl.words[1]), "r" (dest), "r" (cvl.words[0]), "r" (cvl.words[1])
duke@0 231 : "memory");
duke@0 232
duke@0 233 return rv.long_value;
duke@0 234 #endif //_LP64
duke@0 235 }
duke@0 236
duke@0 237 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
duke@0 238 intptr_t rv;
duke@0 239 #ifdef _LP64
duke@0 240 __asm__ volatile(
duke@0 241 " casx [%2], %3, %0"
duke@0 242 : "=r" (rv)
duke@0 243 : "0" (exchange_value), "r" (dest), "r" (compare_value)
duke@0 244 : "memory");
duke@0 245 #else //_LP64
duke@0 246 __asm__ volatile(
duke@0 247 " cas [%2], %3, %0"
duke@0 248 : "=r" (rv)
duke@0 249 : "0" (exchange_value), "r" (dest), "r" (compare_value)
duke@0 250 : "memory");
duke@0 251 #endif // _LP64
duke@0 252 return rv;
duke@0 253 }
duke@0 254
duke@0 255 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
duke@0 256 return (void*)cmpxchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest, (intptr_t)compare_value);
duke@0 257 }
duke@0 258
duke@0 259 #else // _GNU_SOURCE
duke@0 260
duke@0 261 #if defined(COMPILER2) || defined(_LP64)
duke@0 262
duke@0 263 // This is the interface to the atomic instructions in solaris_sparc.il.
duke@0 264 // It's very messy because we need to support v8 and these instructions
duke@0 265 // are illegal there. When sparc v8 is dropped, we can drop out lots of
duke@0 266 // this code. Also compiler2 does not support v8 so the conditional code
duke@0 267 // omits the instruction set check.
duke@0 268
duke@0 269 extern "C" jint _Atomic_swap32(jint exchange_value, volatile jint* dest);
duke@0 270 extern "C" intptr_t _Atomic_swap64(intptr_t exchange_value, volatile intptr_t* dest);
duke@0 271
duke@0 272 extern "C" jint _Atomic_cas32(jint exchange_value, volatile jint* dest, jint compare_value);
duke@0 273 extern "C" intptr_t _Atomic_cas64(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value);
duke@0 274 extern "C" jlong _Atomic_casl (jlong exchange_value, volatile jlong* dest, jlong compare_value);
duke@0 275
duke@0 276 extern "C" jint _Atomic_add32(jint inc, volatile jint* dest);
duke@0 277 extern "C" intptr_t _Atomic_add64(intptr_t add_value, volatile intptr_t* dest);
duke@0 278
duke@0 279
duke@0 280 inline jint Atomic::add (jint add_value, volatile jint* dest) {
duke@0 281 return _Atomic_add32(add_value, dest);
duke@0 282 }
duke@0 283
duke@0 284 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
duke@0 285 #ifdef _LP64
duke@0 286 return _Atomic_add64(add_value, dest);
duke@0 287 #else //_LP64
duke@0 288 return _Atomic_add32(add_value, dest);
duke@0 289 #endif // _LP64
duke@0 290 }
duke@0 291
duke@0 292 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
duke@0 293 return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
duke@0 294 }
duke@0 295
duke@0 296
duke@0 297 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
duke@0 298 return _Atomic_swap32(exchange_value, dest);
duke@0 299 }
duke@0 300
duke@0 301 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@0 302 #ifdef _LP64
duke@0 303 return _Atomic_swap64(exchange_value, dest);
duke@0 304 #else // _LP64
duke@0 305 return _Atomic_swap32(exchange_value, dest);
duke@0 306 #endif // _LP64
duke@0 307 }
duke@0 308
duke@0 309 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@0 310 return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
duke@0 311 }
duke@0 312
duke@0 313
duke@0 314 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
duke@0 315 return _Atomic_cas32(exchange_value, dest, compare_value);
duke@0 316 }
duke@0 317
duke@0 318 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
duke@0 319 #ifdef _LP64
duke@0 320 // Return 64 bit value in %o0
duke@0 321 return _Atomic_cas64((intptr_t)exchange_value, (intptr_t *)dest, (intptr_t)compare_value);
duke@0 322 #else // _LP64
duke@0 323 assert (VM_Version::v9_instructions_work(), "only supported on v9");
duke@0 324 // Return 64 bit value in %o0,%o1 by hand
duke@0 325 return _Atomic_casl(exchange_value, dest, compare_value);
duke@0 326 #endif // _LP64
duke@0 327 }
duke@0 328
duke@0 329 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
duke@0 330 #ifdef _LP64
duke@0 331 return _Atomic_cas64(exchange_value, dest, compare_value);
duke@0 332 #else // _LP64
duke@0 333 return _Atomic_cas32(exchange_value, dest, compare_value);
duke@0 334 #endif // _LP64
duke@0 335 }
duke@0 336
duke@0 337 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
duke@0 338 return (void*)cmpxchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest, (intptr_t)compare_value);
duke@0 339 }
duke@0 340
duke@0 341
duke@0 342 #else // _LP64 || COMPILER2
duke@0 343
duke@0 344
duke@0 345 // 32-bit compiler1 only
duke@0 346
duke@0 347 inline jint Atomic::add (jint add_value, volatile jint* dest) {
duke@0 348 return (*os::atomic_add_func)(add_value, dest);
duke@0 349 }
duke@0 350
duke@0 351 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
duke@0 352 return (intptr_t)add((jint)add_value, (volatile jint*)dest);
duke@0 353 }
duke@0 354
duke@0 355 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
duke@0 356 return (void*)add((jint)add_value, (volatile jint*)dest);
duke@0 357 }
duke@0 358
duke@0 359
duke@0 360 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
duke@0 361 return (*os::atomic_xchg_func)(exchange_value, dest);
duke@0 362 }
duke@0 363
duke@0 364 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
duke@0 365 return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest);
duke@0 366 }
duke@0 367
duke@0 368 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
duke@0 369 return (void*)xchg((jint)exchange_value, (volatile jint*)dest);
duke@0 370 }
duke@0 371
duke@0 372
duke@0 373 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
duke@0 374 return (*os::atomic_cmpxchg_func)(exchange_value, dest, compare_value);
duke@0 375 }
duke@0 376
duke@0 377 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
duke@0 378 return (*os::atomic_cmpxchg_long_func)(exchange_value, dest, compare_value);
duke@0 379 }
duke@0 380
duke@0 381 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
duke@0 382 return (intptr_t)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
duke@0 383 }
duke@0 384
duke@0 385 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
duke@0 386 return (void*)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
duke@0 387 }
duke@0 388
duke@0 389 #endif // _LP64 || COMPILER2
duke@0 390
duke@0 391 #endif // _GNU_SOURCE
stefank@1992 392
stefank@1992 393 #endif // OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_INLINE_HPP