src/hotspot/share/oops/accessDecorators.hpp
author kbarrett
Tue, 26 Jun 2018 16:59:38 -0400
changeset 50803 45c1fde86050
parent 50728 9375184cec98
child 51350 57565f7dcb2a
permissions -rw-r--r--
8205559: Remove IN_CONCURRENT_ROOT Access decorator Summary: Removed decorator and made all NativeAccess use barriers. Reviewed-by: pliden, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     1
/*
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     4
 *
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     8
 *
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    13
 * accompanied this code).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    14
 *
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    18
 *
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    21
 * questions.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    22
 *
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    23
 */
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    24
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    25
#ifndef SHARE_OOPS_ACCESSDECORATORS_HPP
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    26
#define SHARE_OOPS_ACCESSDECORATORS_HPP
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    27
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
    28
#include "gc/shared/barrierSetConfig.hpp"
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
    29
#include "memory/allocation.hpp"
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
    30
#include "metaprogramming/integralConstant.hpp"
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
    32
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    33
// A decorator is an attribute or property that affects the way a memory access is performed in some way.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    34
// There are different groups of decorators. Some have to do with memory ordering, others to do with,
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    35
// e.g. strength of references, strength of GC barriers, or whether compression should be applied or not.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    36
// Some decorators are set at buildtime, such as whether primitives require GC barriers or not, others
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    37
// at callsites such as whether an access is in the heap or not, and others are resolved at runtime
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    38
// such as GC-specific barriers and encoding/decoding compressed oops.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    39
typedef uint64_t DecoratorSet;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    40
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    41
// The HasDecorator trait can help at compile-time determining whether a decorator set
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    42
// has an intersection with a certain other decorator set
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    43
template <DecoratorSet decorators, DecoratorSet decorator>
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    44
struct HasDecorator: public IntegralConstant<bool, (decorators & decorator) != 0> {};
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    45
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    46
// == Internal Decorators - do not use ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    47
// * INTERNAL_EMPTY: This is the name for the empty decorator set (in absence of other decorators).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    48
// * INTERNAL_CONVERT_COMPRESSED_OOPS: This is an oop access that will require converting an oop
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    49
//   to a narrowOop or vice versa, if UseCompressedOops is known to be set.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    50
// * INTERNAL_VALUE_IS_OOP: Remember that the involved access is on oop rather than primitive.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    51
const DecoratorSet INTERNAL_EMPTY                    = UCONST64(0);
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    52
const DecoratorSet INTERNAL_CONVERT_COMPRESSED_OOP   = UCONST64(1) << 1;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    53
const DecoratorSet INTERNAL_VALUE_IS_OOP             = UCONST64(1) << 2;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    54
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    55
// == Internal build-time Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    56
// * INTERNAL_BT_BARRIER_ON_PRIMITIVES: This is set in the barrierSetConfig.hpp file.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    57
// * INTERNAL_BT_TO_SPACE_INVARIANT: This is set in the barrierSetConfig.hpp file iff
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    58
//   no GC is bundled in the build that is to-space invariant.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    59
const DecoratorSet INTERNAL_BT_BARRIER_ON_PRIMITIVES = UCONST64(1) << 3;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    60
const DecoratorSet INTERNAL_BT_TO_SPACE_INVARIANT    = UCONST64(1) << 4;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    61
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    62
// == Internal run-time Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    63
// * INTERNAL_RT_USE_COMPRESSED_OOPS: This decorator will be set in runtime resolved
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    64
//   access backends iff UseCompressedOops is true.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    65
const DecoratorSet INTERNAL_RT_USE_COMPRESSED_OOPS   = UCONST64(1) << 5;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    66
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    67
const DecoratorSet INTERNAL_DECORATOR_MASK           = INTERNAL_CONVERT_COMPRESSED_OOP | INTERNAL_VALUE_IS_OOP |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    68
                                                       INTERNAL_BT_BARRIER_ON_PRIMITIVES | INTERNAL_RT_USE_COMPRESSED_OOPS;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    69
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    70
// == Memory Ordering Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    71
// The memory ordering decorators can be described in the following way:
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    72
// === Decorator Rules ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    73
// The different types of memory ordering guarantees have a strict order of strength.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    74
// Explicitly specifying the stronger ordering implies that the guarantees of the weaker
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    75
// property holds too. The names come from the C++11 atomic operations, and typically
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    76
// have a JMM equivalent property.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    77
// The equivalence may be viewed like this:
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    78
// MO_UNORDERED is equivalent to JMM plain.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    79
// MO_VOLATILE has no equivalence in JMM, because it's a C++ thing.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    80
// MO_RELAXED is equivalent to JMM opaque.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    81
// MO_ACQUIRE is equivalent to JMM acquire.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    82
// MO_RELEASE is equivalent to JMM release.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    83
// MO_SEQ_CST is equivalent to JMM volatile.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    84
//
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    85
// === Stores ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    86
//  * MO_UNORDERED (Default): No guarantees.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    87
//    - The compiler and hardware are free to reorder aggressively. And they will.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    88
//  * MO_VOLATILE: Volatile stores (in the C++ sense).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    89
//    - The stores are not reordered by the compiler (but possibly the HW) w.r.t. other
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    90
//      volatile accesses in program order (but possibly non-volatile accesses).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    91
//  * MO_RELAXED: Relaxed atomic stores.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    92
//    - The stores are atomic.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    93
//    - Guarantees from volatile stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    94
//  * MO_RELEASE: Releasing stores.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    95
//    - The releasing store will make its preceding memory accesses observable to memory accesses
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    96
//      subsequent to an acquiring load observing this releasing store.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    97
//    - Guarantees from relaxed stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    98
//  * MO_SEQ_CST: Sequentially consistent stores.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    99
//    - The stores are observed in the same order by MO_SEQ_CST loads on other processors
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   100
//    - Preceding loads and stores in program order are not reordered with subsequent loads and stores in program order.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   101
//    - Guarantees from releasing stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   102
// === Loads ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   103
//  * MO_UNORDERED (Default): No guarantees
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   104
//    - The compiler and hardware are free to reorder aggressively. And they will.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   105
//  * MO_VOLATILE: Volatile loads (in the C++ sense).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   106
//    - The loads are not reordered by the compiler (but possibly the HW) w.r.t. other
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   107
//      volatile accesses in program order (but possibly non-volatile accesses).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   108
//  * MO_RELAXED: Relaxed atomic loads.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   109
//    - The loads are atomic.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   110
//    - Guarantees from volatile loads hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   111
//  * MO_ACQUIRE: Acquiring loads.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   112
//    - An acquiring load will make subsequent memory accesses observe the memory accesses
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   113
//      preceding the releasing store that the acquiring load observed.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   114
//    - Guarantees from relaxed loads hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   115
//  * MO_SEQ_CST: Sequentially consistent loads.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   116
//    - These loads observe MO_SEQ_CST stores in the same order on other processors
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   117
//    - Preceding loads and stores in program order are not reordered with subsequent loads and stores in program order.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   118
//    - Guarantees from acquiring loads hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   119
// === Atomic Cmpxchg ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   120
//  * MO_RELAXED: Atomic but relaxed cmpxchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   121
//    - Guarantees from MO_RELAXED loads and MO_RELAXED stores hold unconditionally.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   122
//  * MO_SEQ_CST: Sequentially consistent cmpxchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   123
//    - Guarantees from MO_SEQ_CST loads and MO_SEQ_CST stores hold unconditionally.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   124
// === Atomic Xchg ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   125
//  * MO_RELAXED: Atomic but relaxed atomic xchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   126
//    - Guarantees from MO_RELAXED loads and MO_RELAXED stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   127
//  * MO_SEQ_CST: Sequentially consistent xchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   128
//    - Guarantees from MO_SEQ_CST loads and MO_SEQ_CST stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   129
const DecoratorSet MO_UNORDERED      = UCONST64(1) << 6;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   130
const DecoratorSet MO_VOLATILE       = UCONST64(1) << 7;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   131
const DecoratorSet MO_RELAXED        = UCONST64(1) << 8;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   132
const DecoratorSet MO_ACQUIRE        = UCONST64(1) << 9;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   133
const DecoratorSet MO_RELEASE        = UCONST64(1) << 10;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   134
const DecoratorSet MO_SEQ_CST        = UCONST64(1) << 11;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   135
const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_VOLATILE | MO_RELAXED |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   136
                                       MO_ACQUIRE | MO_RELEASE | MO_SEQ_CST;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   137
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   138
// === Barrier Strength Decorators ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   139
// * AS_RAW: The access will translate into a raw memory access, hence ignoring all semantic concerns
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   140
//   except memory ordering and compressed oops. This will bypass runtime function pointer dispatching
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   141
//   in the pipeline and hardwire to raw accesses without going trough the GC access barriers.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   142
//  - Accesses on oop* translate to raw memory accesses without runtime checks
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   143
//  - Accesses on narrowOop* translate to encoded/decoded memory accesses without runtime checks
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   144
//  - Accesses on HeapWord* translate to a runtime check choosing one of the above
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   145
//  - Accesses on other types translate to raw memory accesses without runtime checks
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   146
// * AS_NO_KEEPALIVE: The barrier is used only on oop references and will not keep any involved objects
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   147
//   alive, regardless of the type of reference being accessed. It will however perform the memory access
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   148
//   in a consistent way w.r.t. e.g. concurrent compaction, so that the right field is being accessed,
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   149
//   or maintain, e.g. intergenerational or interregional pointers if applicable. This should be used with
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   150
//   extreme caution in isolated scopes.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   151
// * AS_NORMAL: The accesses will be resolved to an accessor on the BarrierSet class, giving the
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   152
//   responsibility of performing the access and what barriers to be performed to the GC. This is the default.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   153
//   Note that primitive accesses will only be resolved on the barrier set if the appropriate build-time
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   154
//   decorator for enabling primitive barriers is enabled for the build.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   155
const DecoratorSet AS_RAW                  = UCONST64(1) << 12;
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   156
const DecoratorSet AS_NO_KEEPALIVE         = UCONST64(1) << 13;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   157
const DecoratorSet AS_NORMAL               = UCONST64(1) << 14;
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   158
const DecoratorSet AS_DECORATOR_MASK       = AS_RAW | AS_NO_KEEPALIVE | AS_NORMAL;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   159
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   160
// === Reference Strength Decorators ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   161
// These decorators only apply to accesses on oop-like types (oop/narrowOop).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   162
// * ON_STRONG_OOP_REF: Memory access is performed on a strongly reachable reference.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   163
// * ON_WEAK_OOP_REF: The memory access is performed on a weakly reachable reference.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   164
// * ON_PHANTOM_OOP_REF: The memory access is performed on a phantomly reachable reference.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   165
//   This is the same ring of strength as jweak and weak oops in the VM.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   166
// * ON_UNKNOWN_OOP_REF: The memory access is performed on a reference of unknown strength.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   167
//   This could for example come from the unsafe API.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   168
// * Default (no explicit reference strength specified): ON_STRONG_OOP_REF
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   169
const DecoratorSet ON_STRONG_OOP_REF  = UCONST64(1) << 15;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   170
const DecoratorSet ON_WEAK_OOP_REF    = UCONST64(1) << 16;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   171
const DecoratorSet ON_PHANTOM_OOP_REF = UCONST64(1) << 17;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   172
const DecoratorSet ON_UNKNOWN_OOP_REF = UCONST64(1) << 18;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   173
const DecoratorSet ON_DECORATOR_MASK  = ON_STRONG_OOP_REF | ON_WEAK_OOP_REF |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   174
                                        ON_PHANTOM_OOP_REF | ON_UNKNOWN_OOP_REF;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   175
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   176
// === Access Location ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   177
// Accesses can take place in, e.g. the heap, old or young generation and different native roots.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   178
// The location is important to the GC as it may imply different actions. The following decorators are used:
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   179
// * IN_HEAP: The access is performed in the heap. Many barriers such as card marking will
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   180
//   be omitted if this decorator is not set.
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50532
diff changeset
   181
// * IN_NATIVE: The access is performed in an off-heap data structure pointing into the Java heap.
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   182
const DecoratorSet IN_HEAP            = UCONST64(1) << 19;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   183
const DecoratorSet IN_NATIVE          = UCONST64(1) << 20;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   184
const DecoratorSet IN_DECORATOR_MASK  = IN_HEAP | IN_NATIVE;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   185
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   186
// == Boolean Flag Decorators ==
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   187
// * IS_ARRAY: The access is performed on a heap allocated array. This is sometimes a special case
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   188
//   for some GCs.
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   189
// * IS_DEST_UNINITIALIZED: This property can be important to e.g. SATB barriers by
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   190
//   marking that the previous value is uninitialized nonsense rather than a real value.
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   191
// * IS_NOT_NULL: This property can make certain barriers faster such as compressing oops.
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   192
const DecoratorSet IS_ARRAY              = UCONST64(1) << 21;
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   193
const DecoratorSet IS_DEST_UNINITIALIZED = UCONST64(1) << 22;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   194
const DecoratorSet IS_NOT_NULL           = UCONST64(1) << 23;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   195
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   196
// == Arraycopy Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   197
// * ARRAYCOPY_CHECKCAST: This property means that the class of the objects in source
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   198
//   are not guaranteed to be subclasses of the class of the destination array. This requires
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   199
//   a check-cast barrier during the copying operation. If this is not set, it is assumed
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   200
//   that the array is covariant: (the source array type is-a destination array type)
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   201
// * ARRAYCOPY_DISJOINT: This property means that it is known that the two array ranges
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   202
//   are disjoint.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   203
// * ARRAYCOPY_ARRAYOF: The copy is in the arrayof form.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   204
// * ARRAYCOPY_ATOMIC: The accesses have to be atomic over the size of its elements.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   205
// * ARRAYCOPY_ALIGNED: The accesses have to be aligned on a HeapWord.
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   206
const DecoratorSet ARRAYCOPY_CHECKCAST            = UCONST64(1) << 24;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   207
const DecoratorSet ARRAYCOPY_DISJOINT             = UCONST64(1) << 25;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   208
const DecoratorSet ARRAYCOPY_ARRAYOF              = UCONST64(1) << 26;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   209
const DecoratorSet ARRAYCOPY_ATOMIC               = UCONST64(1) << 27;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   210
const DecoratorSet ARRAYCOPY_ALIGNED              = UCONST64(1) << 28;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   211
const DecoratorSet ARRAYCOPY_DECORATOR_MASK       = ARRAYCOPY_CHECKCAST | ARRAYCOPY_DISJOINT |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   212
                                                    ARRAYCOPY_DISJOINT | ARRAYCOPY_ARRAYOF |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   213
                                                    ARRAYCOPY_ATOMIC | ARRAYCOPY_ALIGNED;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   214
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   215
// Keep track of the last decorator.
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   216
const DecoratorSet DECORATOR_LAST = UCONST64(1) << 28;
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   217
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   218
namespace AccessInternal {
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   219
  // This class adds implied decorators that follow according to decorator rules.
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   220
  // For example adding default reference strength and default memory ordering
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   221
  // semantics.
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   222
  template <DecoratorSet input_decorators>
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   223
  struct DecoratorFixup: AllStatic {
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   224
    // If no reference strength has been picked, then strong will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   225
    static const DecoratorSet ref_strength_default = input_decorators |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   226
      (((ON_DECORATOR_MASK & input_decorators) == 0 && (INTERNAL_VALUE_IS_OOP & input_decorators) != 0) ?
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   227
       ON_STRONG_OOP_REF : INTERNAL_EMPTY);
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   228
    // If no memory ordering has been picked, unordered will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   229
    static const DecoratorSet memory_ordering_default = ref_strength_default |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   230
      ((MO_DECORATOR_MASK & ref_strength_default) == 0 ? MO_UNORDERED : INTERNAL_EMPTY);
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   231
    // If no barrier strength has been picked, normal will be used
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   232
    static const DecoratorSet barrier_strength_default = memory_ordering_default |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   233
      ((AS_DECORATOR_MASK & memory_ordering_default) == 0 ? AS_NORMAL : INTERNAL_EMPTY);
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   234
    static const DecoratorSet value = barrier_strength_default | BT_BUILDTIME_DECORATORS;
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   235
  };
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   236
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   237
  // This function implements the above DecoratorFixup rules, but without meta
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   238
  // programming for code generation that does not use templates.
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   239
  inline DecoratorSet decorator_fixup(DecoratorSet input_decorators) {
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   240
    // If no reference strength has been picked, then strong will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   241
    DecoratorSet ref_strength_default = input_decorators |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   242
      (((ON_DECORATOR_MASK & input_decorators) == 0 && (INTERNAL_VALUE_IS_OOP & input_decorators) != 0) ?
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   243
       ON_STRONG_OOP_REF : INTERNAL_EMPTY);
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   244
    // If no memory ordering has been picked, unordered will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   245
    DecoratorSet memory_ordering_default = ref_strength_default |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   246
      ((MO_DECORATOR_MASK & ref_strength_default) == 0 ? MO_UNORDERED : INTERNAL_EMPTY);
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   247
    // If no barrier strength has been picked, normal will be used
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   248
    DecoratorSet barrier_strength_default = memory_ordering_default |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   249
      ((AS_DECORATOR_MASK & memory_ordering_default) == 0 ? AS_NORMAL : INTERNAL_EMPTY);
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   250
    DecoratorSet value = barrier_strength_default | BT_BUILDTIME_DECORATORS;
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   251
    return value;
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   252
  }
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   253
}
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   254
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   255
#endif // SHARE_OOPS_ACCESSDECORATORS_HPP