src/hotspot/os_cpu/windows_x86/atomic_windows_x86.hpp
author darcy
Tue, 12 Nov 2019 10:45:23 -0800
changeset 59037 3d2575331a41
parent 53244 9807daeb47c4
child 59247 56bf71d64d51
permissions -rw-r--r--
8233940: Preview API tests for String methods should use ${jdk.version} as -source arg Reviewed-by: jlaskey, jlahoda
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
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// The following alternative implementations are needed because
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Windows 95 doesn't support (some of) the corresponding Windows NT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// calls. Furthermore, these versions allow inlining in the caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// (More precisely: The documentation for InterlockedExchange says
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// it is supported for Windows 95. However, when single-stepping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// through the assembly code we cannot step into the routine and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// when looking at the routine address we see only garbage code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Better safe then sorry!). Was bug 7/31/98 (gri).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Performance note: On uniprocessors, the 'lock' prefixes are not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// necessary (and expensive). We should generate separate cases if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// this becomes a performance problem.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
#pragma warning(disable: 4035) // Disables warnings reporting missing return statement
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    45
template<size_t byte_size>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    46
struct Atomic::PlatformAdd
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    47
  : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    48
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    49
  template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    50
  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
    51
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    52
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
#ifdef AMD64
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    54
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    55
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    56
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
    57
                                               atomic_memory_order order) const {
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    58
  return add_using_helper<int32_t>(os::atomic_add_func, add_value, dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    61
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    62
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    63
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
    64
                                               atomic_memory_order order) const {
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    65
  return add_using_helper<int64_t>(os::atomic_add_long_func, add_value, dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    68
#define DEFINE_STUB_XCHG(ByteSize, StubType, StubName)                  \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    69
  template<>                                                            \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    70
  template<typename T>                                                  \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    71
  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
    72
                                                      T volatile* dest, \
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    73
                                                      atomic_memory_order order) const { \
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    74
    STATIC_ASSERT(ByteSize == sizeof(T));                               \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    75
    return xchg_using_helper<StubType>(StubName, exchange_value, dest); \
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    76
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    78
DEFINE_STUB_XCHG(4, int32_t, os::atomic_xchg_func)
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    79
DEFINE_STUB_XCHG(8, int64_t, os::atomic_xchg_long_func)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    81
#undef DEFINE_STUB_XCHG
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    83
#define DEFINE_STUB_CMPXCHG(ByteSize, StubType, StubName)               \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    84
  template<>                                                            \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    85
  template<typename T>                                                  \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    86
  inline T Atomic::PlatformCmpxchg<ByteSize>::operator()(T exchange_value, \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    87
                                                         T volatile* dest, \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    88
                                                         T compare_value, \
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    89
                                                         atomic_memory_order order) const { \
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    90
    STATIC_ASSERT(ByteSize == sizeof(T));                               \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    91
    return cmpxchg_using_helper<StubType>(StubName, exchange_value, dest, compare_value); \
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    92
  }
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
    93
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    94
DEFINE_STUB_CMPXCHG(1, int8_t,  os::atomic_cmpxchg_byte_func)
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    95
DEFINE_STUB_CMPXCHG(4, int32_t, os::atomic_cmpxchg_func)
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    96
DEFINE_STUB_CMPXCHG(8, int64_t, os::atomic_cmpxchg_long_func)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    98
#undef DEFINE_STUB_CMPXCHG
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
#else // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   102
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   103
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   104
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
   105
                                               atomic_memory_order order) const {
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   106
  STATIC_ASSERT(4 == sizeof(I));
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   107
  STATIC_ASSERT(4 == sizeof(D));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    mov edx, dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    mov eax, add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    mov ecx, eax;
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   112
    lock xadd dword ptr [edx], eax;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    add eax, ecx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   117
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   118
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   119
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
   120
                                             T volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   121
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   122
  STATIC_ASSERT(4 == sizeof(T));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // alternative for InterlockedExchange
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    mov eax, exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    mov ecx, dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    xchg eax, dword ptr [ecx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   131
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   132
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   133
inline T Atomic::PlatformCmpxchg<1>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   134
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   135
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   136
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   137
  STATIC_ASSERT(1 == sizeof(T));
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   138
  // alternative for InterlockedCompareExchange
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   139
  __asm {
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   140
    mov edx, dest
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   141
    mov cl, exchange_value
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   142
    mov al, compare_value
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   143
    lock cmpxchg byte ptr [edx], cl
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   144
  }
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   145
}
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 25715
diff changeset
   146
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   147
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   148
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   149
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   150
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   151
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   152
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   153
  STATIC_ASSERT(4 == sizeof(T));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // alternative for InterlockedCompareExchange
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    mov edx, dest
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    mov ecx, exchange_value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    mov eax, compare_value
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   159
    lock cmpxchg dword ptr [edx], ecx
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   163
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   164
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   165
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   166
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   167
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   168
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   169
  STATIC_ASSERT(8 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   170
  int32_t ex_lo  = (int32_t)exchange_value;
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   171
  int32_t ex_hi  = *( ((int32_t*)&exchange_value) + 1 );
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   172
  int32_t cmp_lo = (int32_t)compare_value;
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   173
  int32_t cmp_hi = *( ((int32_t*)&compare_value) + 1 );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    push ebx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    push edi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    mov eax, cmp_lo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    mov edx, cmp_hi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    mov edi, dest
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    mov ebx, ex_lo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    mov ecx, ex_hi
46414
5d1d862dc8d8 8169061: Drop os::is_MP checks from Atomics
shade
parents: 40655
diff changeset
   182
    lock cmpxchg8b qword ptr [edi]
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    pop edi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    pop ebx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   188
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   189
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   190
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
   191
  STATIC_ASSERT(8 == sizeof(T));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   192
  volatile T dest;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   193
  volatile T* pdest = &dest;
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   194
  __asm {
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   195
    mov eax, src
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   196
    fild     qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   197
    mov eax, pdest
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   198
    fistp    qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   199
  }
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   200
  return dest;
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   201
}
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   202
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   203
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   204
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   205
inline void Atomic::PlatformStore<8>::operator()(T store_value,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   206
                                                 T volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   207
  STATIC_ASSERT(8 == sizeof(T));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   208
  volatile T* src = &store_value;
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   209
  __asm {
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   210
    mov eax, src
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   211
    fild     qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   212
    mov eax, dest
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   213
    fistp    qword ptr [eax]
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   214
  }
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   215
}
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   216
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
#pragma warning(default: 4035) // Enables warnings reporting missing return statement
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   220
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50029
diff changeset
   221
#endif // OS_CPU_WINDOWS_X86_ATOMIC_WINDOWS_X86_HPP