hotspot/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp
author lana
Mon, 16 Jul 2012 14:49:27 -0700
changeset 13239 7bea6829e8d6
parent 10565 dc90c239f4ec
child 15855 2ac9ebea17f3
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * Copyright 2007, 2008, 2011 Red Hat, Inc.
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
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    26
#ifndef OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_INLINE_HPP
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
#define OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_INLINE_HPP
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
#include "orderAccess_bsd_zero.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
#include "runtime/atomic.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
#include "runtime/os.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
#include "vm_version_zero.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
// Implementation of class atomic
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
 * __m68k_cmpxchg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
 * Returns newval on success and oldval if no exchange happened.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
 * This implementation is processor specific and works on
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
 * 68020 68030 68040 and 68060.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
 * It will not work on ColdFire, 68000 and 68010 since they lack the CAS
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
 * instruction.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
 * Using a kernelhelper would be better for arch complete implementation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
static inline int __m68k_cmpxchg(int oldval, int newval, volatile int *ptr) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
  int ret;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
  __asm __volatile ("cas%.l %0,%2,%1"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
                   : "=d" (ret), "+m" (*(ptr))
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
                   : "d" (newval), "0" (oldval));
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
  return ret;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
/* Perform an atomic compare and swap: if the current value of `*PTR'
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
   `*PTR' before the operation.*/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
static inline int m68k_compare_and_swap(volatile int *ptr,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
                                        int oldval,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
                                        int newval) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
      if (prev != oldval)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
      if (__m68k_cmpxchg (prev, newval, ptr) == newval)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
        // Success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
      // We failed even though prev == oldval.  Try again.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
/* Atomically add an int to memory.  */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
static inline int m68k_add_and_fetch(volatile int *ptr, int add_value) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
      // Loop until success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
      if (__m68k_cmpxchg (prev, prev + add_value, ptr) == prev + add_value)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    87
        return prev + add_value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    88
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    90
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
/* Atomically write VALUE into `*PTR' and returns the previous
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
   contents of `*PTR'.  */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
static inline int m68k_lock_test_and_set(volatile int *ptr, int newval) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
      // Loop until success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
      if (__m68k_cmpxchg (prev, newval, ptr) == prev)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
 * __kernel_cmpxchg
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
 * Return zero if *ptr was changed or non-zero if no exchange happened.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
 * The C flag is also set if *ptr was changed to allow for assembly
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
 * optimization in the calling code.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   121
/* Perform an atomic compare and swap: if the current value of `*PTR'
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   122
   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   123
   `*PTR' before the operation.*/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
static inline int arm_compare_and_swap(volatile int *ptr,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
                                       int oldval,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
                                       int newval) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
      if (prev != oldval)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
        // Success.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
      // We failed even though prev == oldval.  Try again.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   138
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   140
/* Atomically add an int to memory.  */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
static inline int arm_add_and_fetch(volatile int *ptr, int add_value) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
      // Loop until a __kernel_cmpxchg succeeds.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
      if (__kernel_cmpxchg (prev, prev + add_value, ptr) == 0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
        return prev + add_value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   151
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
/* Atomically write VALUE into `*PTR' and returns the previous
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   153
   contents of `*PTR'.  */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   154
static inline int arm_lock_test_and_set(volatile int *ptr, int newval) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   155
  for (;;) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   156
      // Loop until a __kernel_cmpxchg succeeds.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   157
      int prev = *ptr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   158
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   159
      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   160
        return prev;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   161
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   162
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   163
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   164
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   165
inline void Atomic::store(jint store_value, volatile jint* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   166
#if !defined(ARM) && !defined(M68K)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   167
  __sync_synchronize();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   168
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   169
  *dest = store_value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   170
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   171
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   172
inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   173
#if !defined(ARM) && !defined(M68K)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   174
  __sync_synchronize();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   175
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   176
  *dest = store_value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   177
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   178
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   179
inline jint Atomic::add(jint add_value, volatile jint* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   180
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   181
  return arm_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   182
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   183
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   184
  return m68k_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   185
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   186
  return __sync_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   187
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   188
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   189
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   190
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   191
inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   192
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   193
  return arm_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   194
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   195
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   196
  return m68k_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   197
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   198
  return __sync_add_and_fetch(dest, add_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   199
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   200
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   201
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   202
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   203
inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   204
  return (void *) add_ptr(add_value, (volatile intptr_t *) dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   205
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   206
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   207
inline void Atomic::inc(volatile jint* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   208
  add(1, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   209
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   210
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   211
inline void Atomic::inc_ptr(volatile intptr_t* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   212
  add_ptr(1, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   213
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   214
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   215
inline void Atomic::inc_ptr(volatile void* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   216
  add_ptr(1, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   217
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   218
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   219
inline void Atomic::dec(volatile jint* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   220
  add(-1, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   221
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   222
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   223
inline void Atomic::dec_ptr(volatile intptr_t* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   224
  add_ptr(-1, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   225
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   226
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   227
inline void Atomic::dec_ptr(volatile void* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   228
  add_ptr(-1, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   229
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   230
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   231
inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   232
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   233
  return arm_lock_test_and_set(dest, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   234
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   235
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   236
  return m68k_lock_test_and_set(dest, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   237
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   238
  // __sync_lock_test_and_set is a bizarrely named atomic exchange
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   239
  // operation.  Note that some platforms only support this with the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   240
  // limitation that the only valid value to store is the immediate
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   241
  // constant 1.  There is a test for this in JNI_CreateJavaVM().
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   242
  return __sync_lock_test_and_set (dest, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   243
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   244
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   245
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   246
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   247
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   248
                                 volatile intptr_t* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   249
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   250
  return arm_lock_test_and_set(dest, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   251
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   252
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   253
  return m68k_lock_test_and_set(dest, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   254
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   255
  return __sync_lock_test_and_set (dest, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   256
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   257
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   258
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   259
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   260
inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   261
  return (void *) xchg_ptr((intptr_t) exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   262
                           (volatile intptr_t*) dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   263
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   264
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   265
inline jint Atomic::cmpxchg(jint exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   266
                            volatile jint* dest,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   267
                            jint compare_value) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   268
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   269
  return arm_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   270
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   271
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   272
  return m68k_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   273
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   274
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   275
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   276
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   277
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   278
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   279
inline jlong Atomic::cmpxchg(jlong exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   280
                             volatile jlong* dest,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   281
                             jlong compare_value) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   282
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   283
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   284
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   285
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   286
inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   287
                                    volatile intptr_t* dest,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   288
                                    intptr_t compare_value) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   289
#ifdef ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   290
  return arm_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   291
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   292
#ifdef M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   293
  return m68k_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   294
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   295
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   296
#endif // M68K
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   297
#endif // ARM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   298
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   299
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   300
inline void* Atomic::cmpxchg_ptr(void* exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   301
                                 volatile void* dest,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   302
                                 void* compare_value) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   303
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   304
  return (void *) cmpxchg_ptr((intptr_t) exchange_value,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   305
                              (volatile intptr_t*) dest,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   306
                              (intptr_t) compare_value);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   307
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   308
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   309
inline jlong Atomic::load(volatile jlong* src) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   310
  volatile jlong dest;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   311
  os::atomic_copy64(src, &dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   312
  return dest;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   313
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   314
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   315
inline void Atomic::store(jlong store_value, jlong* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   316
  os::atomic_copy64((volatile jlong*)&store_value, (volatile jlong*)dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   317
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   318
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   319
inline void Atomic::store(jlong store_value, volatile jlong* dest) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   320
  os::atomic_copy64((volatile jlong*)&store_value, dest);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   321
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   322
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   323
#endif // OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_INLINE_HPP