src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp
author michaelm
Thu, 22 Aug 2019 14:36:10 +0100
changeset 57838 78844dceede6
parent 53244 9807daeb47c4
child 59248 e92153ed8bdc
permissions -rw-r--r--
8199849: Add support for UTF-8 encoded credentials in HTTP Basic Authentication Reviewed-by: chegar, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
28468
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
     3
 * Copyright 2007, 2008, 2011, 2015, Red Hat, Inc.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
    26
#ifndef OS_CPU_BSD_ZERO_ATOMIC_BSD_ZERO_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
    27
#define OS_CPU_BSD_ZERO_ATOMIC_BSD_ZERO_HPP
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
#include "runtime/os.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
// Implementation of class atomic
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
 * __m68k_cmpxchg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
 * Returns newval on success and oldval if no exchange happened.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
 * This implementation is processor specific and works on
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
 * 68020 68030 68040 and 68060.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
 * It will not work on ColdFire, 68000 and 68010 since they lack the CAS
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
 * instruction.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
 * Using a kernelhelper would be better for arch complete implementation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
static inline int __m68k_cmpxchg(int oldval, int newval, volatile int *ptr) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
  int ret;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
  __asm __volatile ("cas%.l %0,%2,%1"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
                   : "=d" (ret), "+m" (*(ptr))
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
                   : "d" (newval), "0" (oldval));
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
  return ret;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
/* Perform an atomic compare and swap: if the current value of `*PTR'
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
   `*PTR' before the operation.*/
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    60
static inline int m68k_compare_and_swap(int newval,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    61
                                        volatile int *ptr,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    62
                                        int oldval) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
      if (prev != oldval)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
      if (__m68k_cmpxchg (prev, newval, ptr) == newval)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
        // Success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
      // We failed even though prev == oldval.  Try again.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
/* Atomically add an int to memory.  */
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    77
static inline int m68k_add_and_fetch(int add_value, volatile int *ptr) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
      // Loop until success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
      if (__m68k_cmpxchg (prev, prev + add_value, ptr) == prev + add_value)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
        return prev + add_value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    87
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    88
/* Atomically write VALUE into `*PTR' and returns the previous
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
   contents of `*PTR'.  */
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    90
static inline int m68k_lock_test_and_set(int newval, volatile int *ptr) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
      // Loop until success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
      if (__m68k_cmpxchg (prev, newval, ptr) == prev)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
 * __kernel_cmpxchg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
 * Return zero if *ptr was changed or non-zero if no exchange happened.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
 * The C flag is also set if *ptr was changed to allow for assembly
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
 * optimization in the calling code.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
/* Perform an atomic compare and swap: if the current value of `*PTR'
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
   `*PTR' before the operation.*/
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   121
static inline int arm_compare_and_swap(int newval,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   122
                                       volatile int *ptr,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   123
                                       int oldval) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
      if (prev != oldval)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
        // Success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
      // We failed even though prev == oldval.  Try again.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
/* Atomically add an int to memory.  */
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   138
static inline int arm_add_and_fetch(int add_value, volatile int *ptr) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   140
      // Loop until a __kernel_cmpxchg succeeds.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
      if (__kernel_cmpxchg (prev, prev + add_value, ptr) == 0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
        return prev + add_value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
/* Atomically write VALUE into `*PTR' and returns the previous
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
   contents of `*PTR'.  */
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   151
static inline int arm_lock_test_and_set(int newval, volatile int *ptr) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   153
      // Loop until a __kernel_cmpxchg succeeds.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   154
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   155
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   156
      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   157
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   158
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   159
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   160
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   161
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   162
template<size_t byte_size>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   163
struct Atomic::PlatformAdd
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   164
  : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   165
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   166
  template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   167
  D add_and_fetch(I add_value, D volatile* dest, atomic_memory_order order) const;
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   168
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   169
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   170
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   171
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   172
inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   173
                                               atomic_memory_order order) const {
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   174
  STATIC_ASSERT(4 == sizeof(I));
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   175
  STATIC_ASSERT(4 == sizeof(D));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   176
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   177
#ifdef ARM
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   178
  return add_using_helper<int>(arm_add_and_fetch, add_value, dest);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   179
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   180
#ifdef M68K
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   181
  return add_using_helper<int>(m68k_add_and_fetch, add_value, dest);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   182
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   183
  return __sync_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   184
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   185
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   186
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   187
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   188
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   189
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   190
inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   191
                                               atomic_memory_order order) const {
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   192
  STATIC_ASSERT(8 == sizeof(I));
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   193
  STATIC_ASSERT(8 == sizeof(D));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   194
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   195
  return __sync_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   196
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   197
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   198
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   199
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   200
inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   201
                                             T volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   202
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   203
  STATIC_ASSERT(4 == sizeof(T));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   204
#ifdef ARM
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   205
  return xchg_using_helper<int>(arm_lock_test_and_set, exchange_value, dest);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   206
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   207
#ifdef M68K
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   208
  return xchg_using_helper<int>(m68k_lock_test_and_set, exchange_value, dest);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   209
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   210
  // __sync_lock_test_and_set is a bizarrely named atomic exchange
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   211
  // operation.  Note that some platforms only support this with the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   212
  // limitation that the only valid value to store is the immediate
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   213
  // constant 1.  There is a test for this in JNI_CreateJavaVM().
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   214
  T result = __sync_lock_test_and_set (dest, exchange_value);
28468
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   215
  // All atomic operations are expected to be full memory barriers
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   216
  // (see atomic.hpp). However, __sync_lock_test_and_set is not
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   217
  // a full memory barrier, but an acquire barrier. Hence, this added
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   218
  // barrier.
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   219
  __sync_synchronize();
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   220
  return result;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   221
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   222
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   223
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   224
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   225
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   226
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   227
inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   228
                                             T volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   229
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   230
  STATIC_ASSERT(8 == sizeof(T));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   231
  T result = __sync_lock_test_and_set (dest, exchange_value);
28468
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   232
  __sync_synchronize();
b8e9517bf6b9 8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents: 25715
diff changeset
   233
  return result;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   234
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   235
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   236
// No direct support for cmpxchg of bytes; emulate using int.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   237
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   238
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   239
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   240
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   241
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   242
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   243
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   244
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   245
                                                atomic_memory_order order) const {
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   246
  STATIC_ASSERT(4 == sizeof(T));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   247
#ifdef ARM
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   248
  return cmpxchg_using_helper<int>(arm_compare_and_swap, exchange_value, dest, compare_value);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   249
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   250
#ifdef M68K
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   251
  return cmpxchg_using_helper<int>(m68k_compare_and_swap, exchange_value, dest, compare_value);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   252
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   253
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   254
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   255
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   256
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   257
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   258
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   259
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   260
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   261
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   262
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   263
                                                atomic_memory_order order) const {
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   264
  STATIC_ASSERT(8 == sizeof(T));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   265
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   266
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   267
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   268
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   269
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   270
inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   271
  STATIC_ASSERT(8 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   272
  volatile int64_t dest;
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   273
  os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(src), reinterpret_cast<volatile int64_t*>(&dest));
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   274
  return PrimitiveConversions::cast<T>(dest);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   275
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   276
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   277
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   278
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   279
inline void Atomic::PlatformStore<8>::operator()(T store_value,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   280
                                                 T volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   281
  STATIC_ASSERT(8 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   282
  os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(&store_value), reinterpret_cast<volatile int64_t*>(dest));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   283
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   284
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
   285
#endif // OS_CPU_BSD_ZERO_ATOMIC_BSD_ZERO_HPP