src/hotspot/os_cpu/bsd_x86/orderAccess_bsd_x86.hpp
author pliden
Thu, 07 Nov 2019 15:48:43 +0100
changeset 58965 86c8b22945a1
parent 54323 846bc643f4ef
child 59247 56bf71d64d51
permissions -rw-r--r--
8233793: ZGC: Incorrect type used in ZBarrierSetC2 clone_type() Reviewed-by: eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50429
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50429
diff changeset
    25
#ifndef OS_CPU_BSD_X86_ORDERACCESS_BSD_X86_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50429
diff changeset
    26
#define OS_CPU_BSD_X86_ORDERACCESS_BSD_X86_HPP
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49364
diff changeset
    28
// Included in orderAccess.hpp header file.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    30
// Compiler version last used for testing: clang 5.1
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    31
// Please update this information when this file changes
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    32
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    33
// A compiler barrier, forcing the C++ compiler to invalidate all memory assumptions
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    34
static inline void compiler_barrier() {
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    35
  __asm__ volatile ("" : : : "memory");
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    36
}
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    37
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    38
// x86 is TSO and hence only needs a fence for storeload
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    39
// However, a compiler barrier is still needed to prevent reordering
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    40
// between volatile and non-volatile memory accesses.
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    41
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
// Implementation of class OrderAccess.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    44
inline void OrderAccess::loadload()   { compiler_barrier(); }
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    45
inline void OrderAccess::storestore() { compiler_barrier(); }
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    46
inline void OrderAccess::loadstore()  { compiler_barrier(); }
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    47
inline void OrderAccess::storeload()  { fence();            }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    49
inline void OrderAccess::acquire()    { compiler_barrier(); }
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    50
inline void OrderAccess::release()    { compiler_barrier(); }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
inline void OrderAccess::fence() {
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49364
diff changeset
    53
  // always use locked addl since mfence is sometimes expensive
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
#ifdef AMD64
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49364
diff changeset
    55
  __asm__ volatile ("lock; addl $0,0(%%rsp)" : : : "cc", "memory");
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
#else
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49364
diff changeset
    57
  __asm__ volatile ("lock; addl $0,0(%%esp)" : : : "cc", "memory");
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
#endif
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    59
  compiler_barrier();
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
54323
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53244
diff changeset
    62
inline void OrderAccess::cross_modify_fence() {
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53244
diff changeset
    63
  int idx = 0;
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53244
diff changeset
    64
  __asm__ volatile ("cpuid " : "+a" (idx) : : "ebx", "ecx", "edx", "memory");
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53244
diff changeset
    65
}
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53244
diff changeset
    66
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    67
template<>
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    68
struct OrderAccess::PlatformOrderedStore<1, RELEASE_X_FENCE>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    69
{
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    70
  template <typename T>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    71
  void operator()(T v, volatile T* p) const {
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    72
    __asm__ volatile (  "xchgb (%2),%0"
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    73
                      : "=q" (v)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    74
                      : "0" (v), "r" (p)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    75
                      : "memory");
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    76
  }
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    77
};
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    78
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    79
template<>
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    80
struct OrderAccess::PlatformOrderedStore<2, RELEASE_X_FENCE>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    81
{
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    82
  template <typename T>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    83
  void operator()(T v, volatile T* p) const {
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    84
    __asm__ volatile (  "xchgw (%2),%0"
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    85
                      : "=r" (v)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    86
                      : "0" (v), "r" (p)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    87
                      : "memory");
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    88
  }
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    89
};
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    90
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
    91
template<>
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    92
struct OrderAccess::PlatformOrderedStore<4, RELEASE_X_FENCE>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    93
{
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    94
  template <typename T>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    95
  void operator()(T v, volatile T* p) const {
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    96
    __asm__ volatile (  "xchgl (%2),%0"
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    97
                      : "=r" (v)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    98
                      : "0" (v), "r" (p)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
    99
                      : "memory");
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   100
  }
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   101
};
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
#ifdef AMD64
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
   104
template<>
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   105
struct OrderAccess::PlatformOrderedStore<8, RELEASE_X_FENCE>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   106
{
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   107
  template <typename T>
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   108
  void operator()(T v, volatile T* p) const {
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   109
    __asm__ volatile (  "xchgq (%2), %0"
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   110
                      : "=r" (v)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   111
                      : "0" (v), "r" (p)
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   112
                      : "memory");
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   113
  }
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47216
diff changeset
   114
};
29456
cc1c5203e60d 7143664: Clean up OrderAccess implementations and usage
dholmes
parents: 25715
diff changeset
   115
#endif // AMD64
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50429
diff changeset
   117
#endif // OS_CPU_BSD_X86_ORDERACCESS_BSD_X86_HPP