hotspot/src/os_cpu/linux_zero/vm/atomic_linux_zero.inline.hpp
author lana
Fri, 18 Jul 2014 08:25:26 -0700
changeset 25597 6073de33135f
parent 15855 2ac9ebea17f3
child 25715 d5a8dbdc5150
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     1
/*
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 8326
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
8326
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
     3
 * Copyright 2007, 2008, 2011 Red Hat, Inc.
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     5
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     8
 * published by the Free Software Foundation.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     9
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    14
 * accompanied this code).
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    15
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    19
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4013
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4013
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4013
diff changeset
    22
 * questions.
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    23
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    24
 */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    25
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#ifndef OS_CPU_LINUX_ZERO_VM_ATOMIC_LINUX_ZERO_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#define OS_CPU_LINUX_ZERO_VM_ATOMIC_LINUX_ZERO_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
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_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    33
// Implementation of class atomic
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    34
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    35
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    36
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    37
/*
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    38
 * __m68k_cmpxchg
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    39
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    40
 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    41
 * Returns newval on success and oldval if no exchange happened.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    42
 * This implementation is processor specific and works on
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    43
 * 68020 68030 68040 and 68060.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    44
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    45
 * It will not work on ColdFire, 68000 and 68010 since they lack the CAS
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    46
 * instruction.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    47
 * Using a kernelhelper would be better for arch complete implementation.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    48
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    49
 */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    50
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    51
static inline int __m68k_cmpxchg(int oldval, int newval, volatile int *ptr) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    52
  int ret;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    53
  __asm __volatile ("cas%.l %0,%2,%1"
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    54
                   : "=d" (ret), "+m" (*(ptr))
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    55
                   : "d" (newval), "0" (oldval));
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    56
  return ret;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    57
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    58
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    59
/* Perform an atomic compare and swap: if the current value of `*PTR'
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    60
   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    61
   `*PTR' before the operation.*/
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    62
static inline int m68k_compare_and_swap(volatile int *ptr,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    63
                                        int oldval,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    64
                                        int newval) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    65
  for (;;) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    66
      int prev = *ptr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    67
      if (prev != oldval)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    68
        return prev;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    69
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    70
      if (__m68k_cmpxchg (prev, newval, ptr) == newval)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    71
        // Success.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    72
        return prev;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    73
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    74
      // We failed even though prev == oldval.  Try again.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    75
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    76
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    77
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    78
/* Atomically add an int to memory.  */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    79
static inline int m68k_add_and_fetch(volatile int *ptr, int add_value) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    80
  for (;;) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    81
      // Loop until success.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    82
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    83
      int prev = *ptr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    84
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    85
      if (__m68k_cmpxchg (prev, prev + add_value, ptr) == prev + add_value)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    86
        return prev + add_value;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    87
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    88
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    89
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    90
/* Atomically write VALUE into `*PTR' and returns the previous
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    91
   contents of `*PTR'.  */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    92
static inline int m68k_lock_test_and_set(volatile int *ptr, int newval) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    93
  for (;;) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    94
      // Loop until success.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    95
      int prev = *ptr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    96
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    97
      if (__m68k_cmpxchg (prev, newval, ptr) == prev)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    98
        return prev;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    99
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   100
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   101
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   102
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   103
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   104
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   105
/*
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   106
 * __kernel_cmpxchg
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   107
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   108
 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   109
 * Return zero if *ptr was changed or non-zero if no exchange happened.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   110
 * The C flag is also set if *ptr was changed to allow for assembly
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   111
 * optimization in the calling code.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   112
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   113
 */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   114
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   115
typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   116
#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   117
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   118
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   119
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   120
/* Perform an atomic compare and swap: if the current value of `*PTR'
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   121
   is OLDVAL, then write NEWVAL into `*PTR'.  Return the contents of
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   122
   `*PTR' before the operation.*/
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   123
static inline int arm_compare_and_swap(volatile int *ptr,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   124
                                       int oldval,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   125
                                       int newval) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   126
  for (;;) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   127
      int prev = *ptr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   128
      if (prev != oldval)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   129
        return prev;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   130
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   131
      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   132
        // Success.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   133
        return prev;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   134
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   135
      // We failed even though prev == oldval.  Try again.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   136
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   137
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   138
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   139
/* Atomically add an int to memory.  */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   140
static inline int arm_add_and_fetch(volatile int *ptr, int add_value) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   141
  for (;;) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   142
      // Loop until a __kernel_cmpxchg succeeds.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   143
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   144
      int prev = *ptr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   145
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   146
      if (__kernel_cmpxchg (prev, prev + add_value, ptr) == 0)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   147
        return prev + add_value;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   148
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   149
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   150
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   151
/* Atomically write VALUE into `*PTR' and returns the previous
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   152
   contents of `*PTR'.  */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   153
static inline int arm_lock_test_and_set(volatile int *ptr, int newval) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   154
  for (;;) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   155
      // Loop until a __kernel_cmpxchg succeeds.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   156
      int prev = *ptr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   157
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   158
      if (__kernel_cmpxchg (prev, newval, ptr) == 0)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   159
        return prev;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   160
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   161
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   162
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   163
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   164
inline void Atomic::store(jint store_value, volatile jint* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   165
  *dest = store_value;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   166
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   167
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   168
inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   169
  *dest = store_value;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   170
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   171
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   172
inline jint Atomic::add(jint add_value, volatile jint* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   173
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   174
  return arm_add_and_fetch(dest, add_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   175
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   176
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   177
  return m68k_add_and_fetch(dest, add_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   178
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   179
  return __sync_add_and_fetch(dest, add_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   180
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   181
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   182
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   183
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   184
inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   185
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   186
  return arm_add_and_fetch(dest, add_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   187
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   188
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   189
  return m68k_add_and_fetch(dest, add_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   190
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   191
  return __sync_add_and_fetch(dest, add_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   192
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   193
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   194
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   195
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   196
inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   197
  return (void *) add_ptr(add_value, (volatile intptr_t *) dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   198
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   199
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   200
inline void Atomic::inc(volatile jint* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   201
  add(1, dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   202
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   203
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   204
inline void Atomic::inc_ptr(volatile intptr_t* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   205
  add_ptr(1, dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   206
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   207
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   208
inline void Atomic::inc_ptr(volatile void* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   209
  add_ptr(1, dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   210
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   211
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   212
inline void Atomic::dec(volatile jint* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   213
  add(-1, dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   214
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   215
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   216
inline void Atomic::dec_ptr(volatile intptr_t* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   217
  add_ptr(-1, dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   218
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   219
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   220
inline void Atomic::dec_ptr(volatile void* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   221
  add_ptr(-1, dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   222
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   223
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   224
inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   225
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   226
  return arm_lock_test_and_set(dest, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   227
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   228
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   229
  return m68k_lock_test_and_set(dest, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   230
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   231
  // __sync_lock_test_and_set is a bizarrely named atomic exchange
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   232
  // operation.  Note that some platforms only support this with the
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   233
  // limitation that the only valid value to store is the immediate
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   234
  // constant 1.  There is a test for this in JNI_CreateJavaVM().
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   235
  return __sync_lock_test_and_set (dest, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   236
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   237
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   238
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   239
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   240
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   241
                                 volatile intptr_t* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   242
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   243
  return arm_lock_test_and_set(dest, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   244
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   245
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   246
  return m68k_lock_test_and_set(dest, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   247
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   248
  return __sync_lock_test_and_set (dest, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   249
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   250
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   251
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   252
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   253
inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   254
  return (void *) xchg_ptr((intptr_t) exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   255
                           (volatile intptr_t*) dest);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   256
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   257
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   258
inline jint Atomic::cmpxchg(jint exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   259
                            volatile jint* dest,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   260
                            jint compare_value) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   261
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   262
  return arm_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   263
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   264
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   265
  return m68k_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   266
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   267
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   268
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   269
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   270
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   271
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   272
inline jlong Atomic::cmpxchg(jlong exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   273
                             volatile jlong* dest,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   274
                             jlong compare_value) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   275
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   276
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   277
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   278
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   279
inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   280
                                    volatile intptr_t* dest,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   281
                                    intptr_t compare_value) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   282
#ifdef ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   283
  return arm_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   284
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   285
#ifdef M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   286
  return m68k_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   287
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   288
  return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   289
#endif // M68K
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   290
#endif // ARM
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   291
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   292
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   293
inline void* Atomic::cmpxchg_ptr(void* exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   294
                                 volatile void* dest,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   295
                                 void* compare_value) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   296
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   297
  return (void *) cmpxchg_ptr((intptr_t) exchange_value,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   298
                              (volatile intptr_t*) dest,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   299
                              (intptr_t) compare_value);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   300
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   301
8326
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   302
inline jlong Atomic::load(volatile jlong* src) {
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   303
  volatile jlong dest;
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   304
  os::atomic_copy64(src, &dest);
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   305
  return dest;
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   306
}
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   307
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   308
inline void Atomic::store(jlong store_value, jlong* dest) {
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   309
  os::atomic_copy64((volatile jlong*)&store_value, (volatile jlong*)dest);
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   310
}
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   311
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   312
inline void Atomic::store(jlong store_value, volatile jlong* dest) {
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   313
  os::atomic_copy64((volatile jlong*)&store_value, dest);
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   314
}
752682831ac6 7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents: 7397
diff changeset
   315
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   316
#endif // OS_CPU_LINUX_ZERO_VM_ATOMIC_LINUX_ZERO_INLINE_HPP