hotspot/src/os_cpu/solaris_sparc/vm/atomic_solaris_sparc.inline.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 3594 0ce9158bc84c
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Implementation of class atomic
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
inline void Atomic::store    (jbyte    store_value, jbyte*    dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
inline void Atomic::store    (jshort   store_value, jshort*   dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
inline void Atomic::store    (jint     store_value, jint*     dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
inline void Atomic::store    (jlong    store_value, jlong*    dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
inline void Atomic::store_ptr(void*    store_value, void*     dest) { *(void**)dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
inline void Atomic::store    (jbyte    store_value, volatile jbyte*    dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
inline void Atomic::store    (jshort   store_value, volatile jshort*   dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
inline void Atomic::store    (jint     store_value, volatile jint*     dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
inline void Atomic::store    (jlong    store_value, volatile jlong*    dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
inline void Atomic::store_ptr(void*    store_value, volatile void*     dest) { *(void* volatile *)dest = store_value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
inline void Atomic::inc    (volatile jint*     dest) { (void)add    (1, dest); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
inline void Atomic::inc_ptr(volatile intptr_t* dest) { (void)add_ptr(1, dest); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
inline void Atomic::inc_ptr(volatile void*     dest) { (void)add_ptr(1, dest); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
inline void Atomic::dec    (volatile jint*     dest) { (void)add    (-1, dest); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
inline void Atomic::dec_ptr(volatile intptr_t* dest) { (void)add_ptr(-1, dest); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
inline void Atomic::dec_ptr(volatile void*     dest) { (void)add_ptr(-1, dest); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
#ifdef _GNU_SOURCE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
inline jint     Atomic::add    (jint     add_value, volatile jint*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  intptr_t rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    "1: \n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    " ld     [%2], %%o2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    " add    %1, %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    " cas    [%2], %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    " cmp    %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    " bne    1b\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    "  nop\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    " add    %1, %%o2, %0\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    : "r" (add_value), "r" (dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    : "memory", "o2", "o3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  intptr_t rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    "1: \n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    " ldx    [%2], %%o2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    " add    %0, %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    " casx   [%2], %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    " cmp    %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    " bne    %%xcc, 1b\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    "  nop\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    " add    %0, %%o2, %0\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    : "r" (add_value), "r" (dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    : "memory", "o2", "o3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
#else //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    "1: \n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    " ld     [%2], %%o2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    " add    %1, %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    " cas    [%2], %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    " cmp    %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    " bne    1b\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    "  nop\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    " add    %1, %%o2, %0\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    : "r" (add_value), "r" (dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    : "memory", "o2", "o3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
inline void*    Atomic::add_ptr(intptr_t add_value, volatile void*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
inline jint     Atomic::xchg    (jint     exchange_value, volatile jint*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  intptr_t rv = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    " swap   [%2],%1\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  intptr_t rv = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    "1:\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    " mov    %1, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    " ldx    [%2], %%o2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    " casx   [%2], %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    " cmp    %%o2, %%o3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    " bne    %%xcc, 1b\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    "  nop\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    " mov    %%o2, %0\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    : "r" (exchange_value), "r" (dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    : "memory", "o2", "o3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
#else  //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    "swap    [%2],%1\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
inline void*    Atomic::xchg_ptr(void*    exchange_value, volatile void*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
inline jint     Atomic::cmpxchg    (jint     exchange_value, volatile jint*     dest, jint     compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  jint rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    " cas    [%2], %3, %0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    : "0" (exchange_value), "r" (dest), "r" (compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
inline jlong    Atomic::cmpxchg    (jlong    exchange_value, volatile jlong*    dest, jlong    compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  jlong rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    " casx   [%2], %3, %0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    : "0" (exchange_value), "r" (dest), "r" (compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
#else  //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  assert(VM_Version::v9_instructions_work(), "cas only supported on v9");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  volatile jlong_accessor evl, cvl, rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  evl.long_value = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  cvl.long_value = compare_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    " sllx   %2, 32, %2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    " srl    %3, 0,  %3\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    " or     %2, %3, %2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    " sllx   %5, 32, %5\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    " srl    %6, 0,  %6\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    " or     %5, %6, %5\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    " casx   [%4], %5, %2\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    " srl    %2, 0, %1\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    " srlx   %2, 32, %0\n\t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    : "=r" (rv.words[0]), "=r" (rv.words[1])
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    : "r"  (evl.words[0]), "r" (evl.words[1]), "r" (dest), "r" (cvl.words[0]), "r" (cvl.words[1])
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return rv.long_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
#endif  //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  intptr_t rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    " casx    [%2], %3, %0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    : "0" (exchange_value), "r" (dest), "r" (compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
#else  //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  __asm__ volatile(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    " cas     [%2], %3, %0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    : "=r" (rv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    : "0" (exchange_value), "r" (dest), "r" (compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    : "memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  return rv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
inline void*    Atomic::cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  return (void*)cmpxchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest, (intptr_t)compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
#else // _GNU_SOURCE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
#if defined(COMPILER2) || defined(_LP64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// This is the interface to the atomic instructions in solaris_sparc.il.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
// It's very messy because we need to support v8 and these instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
// are illegal there.  When sparc v8 is dropped, we can drop out lots of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// this code.  Also compiler2 does not support v8 so the conditional code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
// omits the instruction set check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
extern "C" jint     _Atomic_swap32(jint     exchange_value, volatile jint*     dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
extern "C" intptr_t _Atomic_swap64(intptr_t exchange_value, volatile intptr_t* dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
extern "C" jint     _Atomic_cas32(jint     exchange_value, volatile jint*     dest, jint     compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
extern "C" intptr_t _Atomic_cas64(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
extern "C" jlong    _Atomic_casl (jlong    exchange_value, volatile jlong*    dest, jlong    compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
extern "C" jint     _Atomic_add32(jint     inc,       volatile jint*     dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
extern "C" intptr_t _Atomic_add64(intptr_t add_value, volatile intptr_t* dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
inline jint     Atomic::add     (jint    add_value, volatile jint*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  return _Atomic_add32(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  return _Atomic_add64(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
#else  //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  return _Atomic_add32(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
inline void*    Atomic::add_ptr(intptr_t add_value, volatile void*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
inline jint     Atomic::xchg    (jint     exchange_value, volatile jint*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  return _Atomic_swap32(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  return _Atomic_swap64(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
#else  // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  return _Atomic_swap32(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
inline void*    Atomic::xchg_ptr(void*    exchange_value, volatile void*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
inline jint     Atomic::cmpxchg    (jint     exchange_value, volatile jint*     dest, jint     compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  return _Atomic_cas32(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
inline jlong    Atomic::cmpxchg    (jlong    exchange_value, volatile jlong*    dest, jlong    compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // Return 64 bit value in %o0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  return _Atomic_cas64((intptr_t)exchange_value, (intptr_t *)dest, (intptr_t)compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
#else  // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  assert (VM_Version::v9_instructions_work(), "only supported on v9");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // Return 64 bit value in %o0,%o1 by hand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  return _Atomic_casl(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  return _Atomic_cas64(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
#else  // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  return _Atomic_cas32(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
inline void*    Atomic::cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  return (void*)cmpxchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest, (intptr_t)compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#else // _LP64 || COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// 32-bit compiler1 only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
inline jint     Atomic::add    (jint     add_value, volatile jint*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  return (*os::atomic_add_func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  return (intptr_t)add((jint)add_value, (volatile jint*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
inline void*    Atomic::add_ptr(intptr_t add_value, volatile void*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  return (void*)add((jint)add_value, (volatile jint*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
inline jint     Atomic::xchg    (jint     exchange_value, volatile jint*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  return (*os::atomic_xchg_func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
inline void*    Atomic::xchg_ptr(void*    exchange_value, volatile void*     dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  return (void*)xchg((jint)exchange_value, (volatile jint*)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
inline jint     Atomic::cmpxchg    (jint     exchange_value, volatile jint*     dest, jint     compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  return (*os::atomic_cmpxchg_func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
inline jlong    Atomic::cmpxchg    (jlong    exchange_value, volatile jlong*    dest, jlong    compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  return (*os::atomic_cmpxchg_long_func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  return (intptr_t)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
inline void*    Atomic::cmpxchg_ptr(void*    exchange_value, volatile void*     dest, void*    compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  return (void*)cmpxchg((jint)exchange_value, (volatile jint*)dest, (jint)compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
#endif // _LP64 || COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
#endif // _GNU_SOURCE