src/hotspot/os_cpu/windows_x86/atomic_windows_x86.hpp
author stefank
Mon, 25 Nov 2019 12:22:13 +0100
changeset 59247 56bf71d64d51
parent 53244 9807daeb47c4
child 59248 e92153ed8bdc
permissions -rw-r--r--
8234562: Move OrderAccess::release_store*/load_acquire to Atomic Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
    25
#ifndef OS_CPU_WINDOWS_X86_ATOMIC_WINDOWS_X86_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
    26
#define OS_CPU_WINDOWS_X86_ATOMIC_WINDOWS_X86_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    30
// Note that in MSVC, volatile memory accesses are explicitly
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    31
// guaranteed to have acquire release semantics (w.r.t. compiler
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    32
// reordering) and therefore does not even need a compiler barrier
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    33
// for normal acquire release accesses. And all generalized
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    34
// bound calls like release_store go through Atomic::load
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    35
// and Atomic::store which do volatile memory accesses.
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    36
template<> inline void ScopedFence<X_ACQUIRE>::postfix()       { }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    37
template<> inline void ScopedFence<RELEASE_X>::prefix()        { }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    38
template<> inline void ScopedFence<RELEASE_X_FENCE>::prefix()  { }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    39
template<> inline void ScopedFence<RELEASE_X_FENCE>::postfix() { OrderAccess::fence(); }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
    40
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// The following alternative implementations are needed because
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Windows 95 doesn't support (some of) the corresponding Windows NT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// calls. Furthermore, these versions allow inlining in the caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// (More precisely: The documentation for InterlockedExchange says
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// it is supported for Windows 95. However, when single-stepping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// through the assembly code we cannot step into the routine and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// when looking at the routine address we see only garbage code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Better safe then sorry!). Was bug 7/31/98 (gri).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// Performance note: On uniprocessors, the 'lock' prefixes are not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// necessary (and expensive). We should generate separate cases if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// this becomes a performance problem.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
#pragma warning(disable: 4035) // Disables warnings reporting missing return statement
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    56
template<size_t byte_size>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    57
struct Atomic::PlatformAdd
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    58
  : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    59
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    60
  template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    61
  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
    62
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    63
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#ifdef AMD64
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    65
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    66
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    67
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
    68
                                               atomic_memory_order order) const {
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    69
  return add_using_helper<int32_t>(os::atomic_add_func, add_value, dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    72
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    73
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    74
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
    75
                                               atomic_memory_order order) const {
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    76
  return add_using_helper<int64_t>(os::atomic_add_long_func, add_value, dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    79
#define DEFINE_STUB_XCHG(ByteSize, StubType, StubName)                  \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    80
  template<>                                                            \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    81
  template<typename T>                                                  \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    82
  inline T Atomic::PlatformXchg<ByteSize>::operator()(T exchange_value, \
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    83
                                                      T volatile* dest, \
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    84
                                                      atomic_memory_order order) const { \
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    85
    STATIC_ASSERT(ByteSize == sizeof(T));                               \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    86
    return xchg_using_helper<StubType>(StubName, exchange_value, dest); \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    87
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    89
DEFINE_STUB_XCHG(4, int32_t, os::atomic_xchg_func)
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    90
DEFINE_STUB_XCHG(8, int64_t, os::atomic_xchg_long_func)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    92
#undef DEFINE_STUB_XCHG
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    94
#define DEFINE_STUB_CMPXCHG(ByteSize, StubType, StubName)               \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    95
  template<>                                                            \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    96
  template<typename T>                                                  \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    97
  inline T Atomic::PlatformCmpxchg<ByteSize>::operator()(T exchange_value, \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    98
                                                         T volatile* dest, \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    99
                                                         T compare_value, \
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   100
                                                         atomic_memory_order order) const { \
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   101
    STATIC_ASSERT(ByteSize == sizeof(T));                               \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   102
    return cmpxchg_using_helper<StubType>(StubName, exchange_value, dest, compare_value); \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   103
  }
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   104
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   105
DEFINE_STUB_CMPXCHG(1, int8_t,  os::atomic_cmpxchg_byte_func)
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   106
DEFINE_STUB_CMPXCHG(4, int32_t, os::atomic_cmpxchg_func)
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   107
DEFINE_STUB_CMPXCHG(8, int64_t, os::atomic_cmpxchg_long_func)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   109
#undef DEFINE_STUB_CMPXCHG
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
#else // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   113
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   114
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   115
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
   116
                                               atomic_memory_order order) const {
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   117
  STATIC_ASSERT(4 == sizeof(I));
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   118
  STATIC_ASSERT(4 == sizeof(D));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    mov edx, dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    mov eax, add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    mov ecx, eax;
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   123
    lock xadd dword ptr [edx], eax;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    add eax, ecx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   128
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   129
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   130
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
   131
                                             T volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   132
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   133
  STATIC_ASSERT(4 == sizeof(T));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // alternative for InterlockedExchange
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    mov eax, exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    mov ecx, dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    xchg eax, dword ptr [ecx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   142
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   143
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   144
inline T Atomic::PlatformCmpxchg<1>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   145
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   146
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   147
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   148
  STATIC_ASSERT(1 == sizeof(T));
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   149
  // alternative for InterlockedCompareExchange
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   150
  __asm {
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   151
    mov edx, dest
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   152
    mov cl, exchange_value
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   153
    mov al, compare_value
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   154
    lock cmpxchg byte ptr [edx], cl
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   155
  }
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   156
}
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   157
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   158
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   159
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   160
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   161
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   162
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   163
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   164
  STATIC_ASSERT(4 == sizeof(T));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // alternative for InterlockedCompareExchange
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    mov edx, dest
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    mov ecx, exchange_value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    mov eax, compare_value
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   170
    lock cmpxchg dword ptr [edx], ecx
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   174
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   175
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   176
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   177
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   178
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   179
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   180
  STATIC_ASSERT(8 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   181
  int32_t ex_lo  = (int32_t)exchange_value;
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   182
  int32_t ex_hi  = *( ((int32_t*)&exchange_value) + 1 );
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   183
  int32_t cmp_lo = (int32_t)compare_value;
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   184
  int32_t cmp_hi = *( ((int32_t*)&compare_value) + 1 );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    push ebx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    push edi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    mov eax, cmp_lo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    mov edx, cmp_hi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    mov edi, dest
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    mov ebx, ex_lo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    mov ecx, ex_hi
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   193
    lock cmpxchg8b qword ptr [edi]
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    pop edi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    pop ebx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   199
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   200
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   201
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
   202
  STATIC_ASSERT(8 == sizeof(T));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   203
  volatile T dest;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   204
  volatile T* pdest = &dest;
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   205
  __asm {
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   206
    mov eax, src
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   207
    fild     qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   208
    mov eax, pdest
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   209
    fistp    qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   210
  }
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   211
  return dest;
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   212
}
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   213
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   214
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   215
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   216
inline void Atomic::PlatformStore<8>::operator()(T store_value,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   217
                                                 T volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   218
  STATIC_ASSERT(8 == sizeof(T));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   219
  volatile T* src = &store_value;
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   220
  __asm {
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   221
    mov eax, src
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   222
    fild     qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   223
    mov eax, dest
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   224
    fistp    qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   225
  }
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   226
}
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   227
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
#pragma warning(default: 4035) // Enables warnings reporting missing return statement
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   231
59247
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   232
#ifndef AMD64
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   233
template<>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   234
struct Atomic::PlatformOrderedStore<1, RELEASE_X_FENCE>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   235
{
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   236
  template <typename T>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   237
  void operator()(T v, volatile T* p) const {
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   238
    __asm {
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   239
      mov edx, p;
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   240
      mov al, v;
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   241
      xchg al, byte ptr [edx];
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   242
    }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   243
  }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   244
};
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   245
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   246
template<>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   247
struct Atomic::PlatformOrderedStore<2, RELEASE_X_FENCE>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   248
{
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   249
  template <typename T>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   250
  void operator()(T v, volatile T* p) const {
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   251
    __asm {
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   252
      mov edx, p;
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   253
      mov ax, v;
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   254
      xchg ax, word ptr [edx];
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   255
    }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   256
  }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   257
};
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   258
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   259
template<>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   260
struct Atomic::PlatformOrderedStore<4, RELEASE_X_FENCE>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   261
{
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   262
  template <typename T>
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   263
  void operator()(T v, volatile T* p) const {
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   264
    __asm {
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   265
      mov edx, p;
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   266
      mov eax, v;
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   267
      xchg eax, dword ptr [edx];
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   268
    }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   269
  }
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   270
};
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   271
#endif // AMD64
56bf71d64d51 8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents: 53244
diff changeset
   272
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
   273
#endif // OS_CPU_WINDOWS_X86_ATOMIC_WINDOWS_X86_HPP