src/hotspot/os_cpu/solaris_sparc/atomic_solaris_sparc.hpp
author stefank
Mon, 25 Nov 2019 12:32:40 +0100
changeset 59251 4cbfa5077d68
parent 59249 29b0d0b61615
child 59252 623722a6aeb9
permissions -rw-r--r--
8234739: Harmonize parameter order in Atomic - xchg Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
     2
 * Copyright (c) 1999, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
    25
#ifndef OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
    26
#define OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Implementation of class atomic
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    30
// Implement ADD using a CAS loop.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    31
template<size_t byte_size>
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47593
diff changeset
    32
struct Atomic::PlatformAdd {
59249
29b0d0b61615 8234737: Harmonize parameter order in Atomic - add
stefank
parents: 53244
diff changeset
    33
  template<typename D, typename I>
29b0d0b61615 8234737: Harmonize parameter order in Atomic - add
stefank
parents: 53244
diff changeset
    34
  inline D operator()(D volatile* dest, I add_value, atomic_memory_order order) const {
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    35
    D old_value = *dest;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    36
    while (true) {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    37
      D new_value = old_value + add_value;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    38
      D result = cmpxchg(new_value, dest, old_value);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    39
      if (result == old_value) break;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    40
      old_value = result;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    41
    }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    42
    return old_value + add_value;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    43
  }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    44
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    46
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    47
template<typename T>
59251
4cbfa5077d68 8234739: Harmonize parameter order in Atomic - xchg
stefank
parents: 59249
diff changeset
    48
inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest,
4cbfa5077d68 8234739: Harmonize parameter order in Atomic - xchg
stefank
parents: 59249
diff changeset
    49
                                             T exchange_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 49364
diff changeset
    50
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    51
  STATIC_ASSERT(4 == sizeof(T));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    52
  __asm__ volatile (  "swap [%2],%0"
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    53
                    : "=r" (exchange_value)
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    54
                    : "0" (exchange_value), "r" (dest)
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    55
                    : "memory");
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    56
  return exchange_value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    59
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    60
template<typename T>
59251
4cbfa5077d68 8234739: Harmonize parameter order in Atomic - xchg
stefank
parents: 59249
diff changeset
    61
inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest,
4cbfa5077d68 8234739: Harmonize parameter order in Atomic - xchg
stefank
parents: 59249
diff changeset
    62
                                             T exchange_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 49364
diff changeset
    63
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    64
  STATIC_ASSERT(8 == sizeof(T));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    65
  T old_value = *dest;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    66
  while (true) {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    67
    T result = cmpxchg(exchange_value, dest, old_value);
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    68
    if (result == old_value) break;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    69
    old_value = result;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    70
  }
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    71
  return old_value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    74
// No direct support for cmpxchg of bytes; emulate using int.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    75
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    76
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    78
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    79
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    80
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    81
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    82
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 49364
diff changeset
    83
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    84
  STATIC_ASSERT(4 == sizeof(T));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    85
  T rv;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    86
  __asm__ volatile(
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    87
    " cas    [%2], %3, %0"
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    88
    : "=r" (rv)
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    89
    : "0" (exchange_value), "r" (dest), "r" (compare_value)
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    90
    : "memory");
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    91
  return rv;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    94
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    95
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    96
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    97
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
    98
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 49364
diff changeset
    99
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   100
  STATIC_ASSERT(8 == sizeof(T));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   101
  T rv;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   102
  __asm__ volatile(
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   103
    " casx   [%2], %3, %0"
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   104
    : "=r" (rv)
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   105
    : "0" (exchange_value), "r" (dest), "r" (compare_value)
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   106
    : "memory");
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46534
diff changeset
   107
  return rv;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
   110
#endif // OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP