src/hotspot/share/oops/accessDecorators.hpp
author coleenp
Wed, 24 Jul 2019 10:22:11 -0400
changeset 57511 00ae3b739184
parent 53075 747d29313e5a
permissions -rw-r--r--
8228485: JVM crashes when bootstrap method for condy triggers loading of class whose static initializer throws exception Summary: Add case for JVM_CONSTANT_Dynamic in error_message function. Reviewed-by: dholmes, shade
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
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
    46
// == General Decorators ==
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
    47
// * DECORATORS_NONE: This is the name for the empty decorator set (in absence of other decorators).
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
    48
const DecoratorSet DECORATORS_NONE                   = UCONST64(0);
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
    49
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    50
// == Internal Decorators - do not use ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    51
// * 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
    52
//   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
    53
// * 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
    54
const DecoratorSet INTERNAL_CONVERT_COMPRESSED_OOP   = UCONST64(1) << 1;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    55
const DecoratorSet INTERNAL_VALUE_IS_OOP             = UCONST64(1) << 2;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    56
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    57
// == Internal build-time Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    58
// * 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
    59
// * 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
    60
//   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
    61
const DecoratorSet INTERNAL_BT_BARRIER_ON_PRIMITIVES = UCONST64(1) << 3;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    62
const DecoratorSet INTERNAL_BT_TO_SPACE_INVARIANT    = UCONST64(1) << 4;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    63
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    64
// == Internal run-time Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    65
// * 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
    66
//   access backends iff UseCompressedOops is true.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    67
const DecoratorSet INTERNAL_RT_USE_COMPRESSED_OOPS   = UCONST64(1) << 5;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    68
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    69
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
    70
                                                       INTERNAL_BT_BARRIER_ON_PRIMITIVES | INTERNAL_RT_USE_COMPRESSED_OOPS;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    71
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    72
// == Memory Ordering Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    73
// The memory ordering decorators can be described in the following way:
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    74
// === Decorator Rules ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    75
// 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
    76
// 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
    77
// 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
    78
// have a JMM equivalent property.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    79
// The equivalence may be viewed like this:
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    80
// MO_UNORDERED is equivalent to JMM plain.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    81
// 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
    82
// MO_RELAXED is equivalent to JMM opaque.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    83
// MO_ACQUIRE is equivalent to JMM acquire.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    84
// MO_RELEASE is equivalent to JMM release.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    85
// MO_SEQ_CST is equivalent to JMM volatile.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    86
//
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    87
// === Stores ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    88
//  * MO_UNORDERED (Default): No guarantees.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    89
//    - 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
    90
//  * MO_VOLATILE: Volatile stores (in the C++ sense).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    91
//    - 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
    92
//      volatile accesses in program order (but possibly non-volatile accesses).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    93
//  * MO_RELAXED: Relaxed atomic stores.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    94
//    - The stores are atomic.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    95
//    - Guarantees from volatile stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    96
//  * MO_RELEASE: Releasing stores.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    97
//    - 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
    98
//      subsequent to an acquiring load observing this releasing store.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
    99
//    - Guarantees from relaxed stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   100
//  * MO_SEQ_CST: Sequentially consistent stores.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   101
//    - 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
   102
//    - 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
   103
//    - Guarantees from releasing stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   104
// === Loads ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   105
//  * MO_UNORDERED (Default): No guarantees
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   106
//    - 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
   107
//  * MO_VOLATILE: Volatile loads (in the C++ sense).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   108
//    - 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
   109
//      volatile accesses in program order (but possibly non-volatile accesses).
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   110
//  * MO_RELAXED: Relaxed atomic loads.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   111
//    - The loads are atomic.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   112
//    - Guarantees from volatile loads hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   113
//  * MO_ACQUIRE: Acquiring loads.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   114
//    - 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
   115
//      preceding the releasing store that the acquiring load observed.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   116
//    - Guarantees from relaxed loads hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   117
//  * MO_SEQ_CST: Sequentially consistent loads.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   118
//    - 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
   119
//    - 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
   120
//    - Guarantees from acquiring loads hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   121
// === Atomic Cmpxchg ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   122
//  * MO_RELAXED: Atomic but relaxed cmpxchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   123
//    - Guarantees from MO_RELAXED loads and MO_RELAXED stores hold unconditionally.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   124
//  * MO_SEQ_CST: Sequentially consistent cmpxchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   125
//    - 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
   126
// === Atomic Xchg ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   127
//  * MO_RELAXED: Atomic but relaxed atomic xchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   128
//    - Guarantees from MO_RELAXED loads and MO_RELAXED stores hold.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   129
//  * MO_SEQ_CST: Sequentially consistent xchg.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   130
//    - 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
   131
const DecoratorSet MO_UNORDERED      = UCONST64(1) << 6;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   132
const DecoratorSet MO_VOLATILE       = UCONST64(1) << 7;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   133
const DecoratorSet MO_RELAXED        = UCONST64(1) << 8;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   134
const DecoratorSet MO_ACQUIRE        = UCONST64(1) << 9;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   135
const DecoratorSet MO_RELEASE        = UCONST64(1) << 10;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   136
const DecoratorSet MO_SEQ_CST        = UCONST64(1) << 11;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   137
const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_VOLATILE | MO_RELAXED |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   138
                                       MO_ACQUIRE | MO_RELEASE | MO_SEQ_CST;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   139
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   140
// === Barrier Strength Decorators ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   141
// * 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
   142
//   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
   143
//   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
   144
//  - Accesses on oop* translate to raw memory accesses without runtime checks
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   145
//  - 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
   146
//  - 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
   147
//  - 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
   148
// * 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
   149
//   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
   150
//   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
   151
//   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
   152
//   extreme caution in isolated scopes.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   153
// * 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
   154
//   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
   155
//   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
   156
//   decorator for enabling primitive barriers is enabled for the build.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   157
const DecoratorSet AS_RAW                  = UCONST64(1) << 12;
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   158
const DecoratorSet AS_NO_KEEPALIVE         = UCONST64(1) << 13;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   159
const DecoratorSet AS_NORMAL               = UCONST64(1) << 14;
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   160
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
   161
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   162
// === Reference Strength Decorators ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   163
// 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
   164
// * 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
   165
// * 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
   166
// * 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
   167
//   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
   168
// * 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
   169
//   This could for example come from the unsafe API.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   170
// * Default (no explicit reference strength specified): ON_STRONG_OOP_REF
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   171
const DecoratorSet ON_STRONG_OOP_REF  = UCONST64(1) << 15;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   172
const DecoratorSet ON_WEAK_OOP_REF    = UCONST64(1) << 16;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   173
const DecoratorSet ON_PHANTOM_OOP_REF = UCONST64(1) << 17;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   174
const DecoratorSet ON_UNKNOWN_OOP_REF = UCONST64(1) << 18;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   175
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
   176
                                        ON_PHANTOM_OOP_REF | ON_UNKNOWN_OOP_REF;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   177
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   178
// === Access Location ===
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   179
// 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
   180
// 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
   181
// * 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
   182
//   be omitted if this decorator is not set.
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50532
diff changeset
   183
// * 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
   184
const DecoratorSet IN_HEAP            = UCONST64(1) << 19;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   185
const DecoratorSet IN_NATIVE          = UCONST64(1) << 20;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   186
const DecoratorSet IN_DECORATOR_MASK  = IN_HEAP | IN_NATIVE;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   187
50728
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   188
// == Boolean Flag Decorators ==
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   189
// * 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
   190
//   for some GCs.
9375184cec98 8205459: Rename Access API flag decorators
kbarrett
parents: 50599
diff changeset
   191
// * 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
   192
//   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
   193
// * 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
   194
const DecoratorSet IS_ARRAY              = UCONST64(1) << 21;
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   195
const DecoratorSet IS_DEST_UNINITIALIZED = UCONST64(1) << 22;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   196
const DecoratorSet IS_NOT_NULL           = UCONST64(1) << 23;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   197
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   198
// == Arraycopy Decorators ==
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   199
// * 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
   200
//   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
   201
//   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
   202
//   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
   203
// * 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
   204
//   are disjoint.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   205
// * ARRAYCOPY_ARRAYOF: The copy is in the arrayof form.
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   206
// * 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
   207
// * 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
   208
const DecoratorSet ARRAYCOPY_CHECKCAST            = UCONST64(1) << 24;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   209
const DecoratorSet ARRAYCOPY_DISJOINT             = UCONST64(1) << 25;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   210
const DecoratorSet ARRAYCOPY_ARRAYOF              = UCONST64(1) << 26;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   211
const DecoratorSet ARRAYCOPY_ATOMIC               = UCONST64(1) << 27;
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   212
const DecoratorSet ARRAYCOPY_ALIGNED              = UCONST64(1) << 28;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   213
const DecoratorSet ARRAYCOPY_DECORATOR_MASK       = ARRAYCOPY_CHECKCAST | ARRAYCOPY_DISJOINT |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   214
                                                    ARRAYCOPY_DISJOINT | ARRAYCOPY_ARRAYOF |
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   215
                                                    ARRAYCOPY_ATOMIC | ARRAYCOPY_ALIGNED;
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   216
51350
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   217
// == Resolve barrier decorators ==
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   218
// * ACCESS_READ: Indicate that the resolved object is accessed read-only. This allows the GC
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   219
//   backend to use weaker and more efficient barriers.
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   220
// * ACCESS_WRITE: Indicate that the resolved object is used for write access.
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   221
const DecoratorSet ACCESS_READ                    = UCONST64(1) << 29;
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   222
const DecoratorSet ACCESS_WRITE                   = UCONST64(1) << 30;
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   223
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   224
// Keep track of the last decorator.
51350
57565f7dcb2a 8205523: Explicit barriers for interpreter
rkennke
parents: 50803
diff changeset
   225
const DecoratorSet DECORATOR_LAST = UCONST64(1) << 30;
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   226
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   227
namespace AccessInternal {
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   228
  // This class adds implied decorators that follow according to decorator rules.
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   229
  // For example adding default reference strength and default memory ordering
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   230
  // semantics.
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   231
  template <DecoratorSet input_decorators>
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   232
  struct DecoratorFixup: AllStatic {
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   233
    // If no reference strength has been picked, then strong will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   234
    static const DecoratorSet ref_strength_default = input_decorators |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   235
      (((ON_DECORATOR_MASK & input_decorators) == 0 && (INTERNAL_VALUE_IS_OOP & input_decorators) != 0) ?
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
   236
       ON_STRONG_OOP_REF : DECORATORS_NONE);
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   237
    // If no memory ordering has been picked, unordered will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   238
    static const DecoratorSet memory_ordering_default = ref_strength_default |
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
   239
      ((MO_DECORATOR_MASK & ref_strength_default) == 0 ? MO_UNORDERED : DECORATORS_NONE);
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   240
    // If no barrier strength has been picked, normal will be used
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   241
    static const DecoratorSet barrier_strength_default = memory_ordering_default |
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
   242
      ((AS_DECORATOR_MASK & memory_ordering_default) == 0 ? AS_NORMAL : DECORATORS_NONE);
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   243
    static const DecoratorSet value = barrier_strength_default | BT_BUILDTIME_DECORATORS;
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   244
  };
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   245
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   246
  // This function implements the above DecoratorFixup rules, but without meta
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   247
  // programming for code generation that does not use templates.
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   248
  inline DecoratorSet decorator_fixup(DecoratorSet input_decorators) {
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   249
    // If no reference strength has been picked, then strong will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   250
    DecoratorSet ref_strength_default = input_decorators |
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   251
      (((ON_DECORATOR_MASK & input_decorators) == 0 && (INTERNAL_VALUE_IS_OOP & input_decorators) != 0) ?
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
   252
       ON_STRONG_OOP_REF : DECORATORS_NONE);
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   253
    // If no memory ordering has been picked, unordered will be picked
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   254
    DecoratorSet memory_ordering_default = ref_strength_default |
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
   255
      ((MO_DECORATOR_MASK & ref_strength_default) == 0 ? MO_UNORDERED : DECORATORS_NONE);
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   256
    // If no barrier strength has been picked, normal will be used
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   257
    DecoratorSet barrier_strength_default = memory_ordering_default |
53075
747d29313e5a 8215492: Rename INTERNAL_EMPTY to something less "internal"
pliden
parents: 51350
diff changeset
   258
      ((AS_DECORATOR_MASK & memory_ordering_default) == 0 ? AS_NORMAL : DECORATORS_NONE);
50803
45c1fde86050 8205559: Remove IN_CONCURRENT_ROOT Access decorator
kbarrett
parents: 50728
diff changeset
   259
    DecoratorSet value = barrier_strength_default | BT_BUILDTIME_DECORATORS;
49906
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   260
    return value;
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   261
  }
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   262
}
4bb58f644e4e 8201543: Modularize C1 GC barriers
eosterlund
parents: 49658
diff changeset
   263
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents:
diff changeset
   264
#endif // SHARE_OOPS_ACCESSDECORATORS_HPP