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