src/share/vm/memory/barrierSet.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6876
710a3c8b516e
child 8019
3fb3ceb7398f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_MEMORY_BARRIERSET_HPP
aoqi@0 26 #define SHARE_VM_MEMORY_BARRIERSET_HPP
aoqi@0 27
aoqi@0 28 #include "memory/memRegion.hpp"
aoqi@0 29 #include "oops/oopsHierarchy.hpp"
fujie@116 30 #include "runtime/orderAccess.hpp"
aoqi@0 31
aoqi@0 32 // This class provides the interface between a barrier implementation and
aoqi@0 33 // the rest of the system.
aoqi@0 34
aoqi@0 35 class BarrierSet: public CHeapObj<mtGC> {
aoqi@0 36 friend class VMStructs;
aoqi@0 37 public:
aoqi@0 38 enum Name {
aoqi@0 39 ModRef,
aoqi@0 40 CardTableModRef,
aoqi@0 41 CardTableExtension,
aoqi@0 42 G1SATBCT,
aoqi@0 43 G1SATBCTLogging,
aoqi@0 44 Other,
aoqi@0 45 Uninit
aoqi@0 46 };
aoqi@0 47
aoqi@0 48 enum Flags {
aoqi@0 49 None = 0,
aoqi@0 50 TargetUninitialized = 1
aoqi@0 51 };
aoqi@0 52 protected:
aoqi@0 53 int _max_covered_regions;
aoqi@0 54 Name _kind;
aoqi@0 55
aoqi@0 56 public:
aoqi@0 57
aoqi@0 58 BarrierSet() { _kind = Uninit; }
aoqi@0 59 // To get around prohibition on RTTI.
aoqi@0 60 BarrierSet::Name kind() { return _kind; }
aoqi@0 61 virtual bool is_a(BarrierSet::Name bsn) = 0;
aoqi@0 62
aoqi@0 63 // These operations indicate what kind of barriers the BarrierSet has.
aoqi@0 64 virtual bool has_read_ref_barrier() = 0;
aoqi@0 65 virtual bool has_read_prim_barrier() = 0;
aoqi@0 66 virtual bool has_write_ref_barrier() = 0;
aoqi@0 67 virtual bool has_write_ref_pre_barrier() = 0;
aoqi@0 68 virtual bool has_write_prim_barrier() = 0;
aoqi@0 69
aoqi@0 70 // These functions indicate whether a particular access of the given
aoqi@0 71 // kinds requires a barrier.
aoqi@0 72 virtual bool read_ref_needs_barrier(void* field) = 0;
aoqi@0 73 virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0;
aoqi@0 74 virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes,
aoqi@0 75 juint val1, juint val2) = 0;
aoqi@0 76
aoqi@0 77 // The first four operations provide a direct implementation of the
aoqi@0 78 // barrier set. An interpreter loop, for example, could call these
aoqi@0 79 // directly, as appropriate.
aoqi@0 80
aoqi@0 81 // Invoke the barrier, if any, necessary when reading the given ref field.
aoqi@0 82 virtual void read_ref_field(void* field) = 0;
aoqi@0 83
aoqi@0 84 // Invoke the barrier, if any, necessary when reading the given primitive
aoqi@0 85 // "field" of "bytes" bytes in "obj".
aoqi@0 86 virtual void read_prim_field(HeapWord* field, size_t bytes) = 0;
aoqi@0 87
aoqi@0 88 // Invoke the barrier, if any, necessary when writing "new_val" into the
aoqi@0 89 // ref field at "offset" in "obj".
aoqi@0 90 // (For efficiency reasons, this operation is specialized for certain
aoqi@0 91 // barrier types. Semantically, it should be thought of as a call to the
aoqi@0 92 // virtual "_work" function below, which must implement the barrier.)
aoqi@0 93 // First the pre-write versions...
aoqi@0 94 template <class T> inline void write_ref_field_pre(T* field, oop new_val);
aoqi@0 95 private:
aoqi@0 96 // Keep this private so as to catch violations at build time.
aoqi@0 97 virtual void write_ref_field_pre_work( void* field, oop new_val) { guarantee(false, "Not needed"); };
aoqi@0 98 protected:
fujie@116 99 virtual void write_ref_field_pre_work( oop* field, oop new_val) {
fujie@116 100 #ifdef MIPS64
fujie@121 101 if (Use3A2000) OrderAccess::fence();
fujie@116 102 #endif
fujie@116 103 };
fujie@116 104 virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {
fujie@116 105 #ifdef MIPS64
fujie@121 106 if (Use3A2000) OrderAccess::fence();
fujie@116 107 #endif
fujie@116 108 };
aoqi@0 109 public:
aoqi@0 110
aoqi@0 111 // ...then the post-write version.
aoqi@0 112 inline void write_ref_field(void* field, oop new_val, bool release = false);
aoqi@0 113 protected:
aoqi@0 114 virtual void write_ref_field_work(void* field, oop new_val, bool release = false) = 0;
aoqi@0 115 public:
aoqi@0 116
aoqi@0 117 // Invoke the barrier, if any, necessary when writing the "bytes"-byte
aoqi@0 118 // value(s) "val1" (and "val2") into the primitive "field".
aoqi@0 119 virtual void write_prim_field(HeapWord* field, size_t bytes,
aoqi@0 120 juint val1, juint val2) = 0;
aoqi@0 121
aoqi@0 122 // Operations on arrays, or general regions (e.g., for "clone") may be
aoqi@0 123 // optimized by some barriers.
aoqi@0 124
aoqi@0 125 // The first six operations tell whether such an optimization exists for
aoqi@0 126 // the particular barrier.
aoqi@0 127 virtual bool has_read_ref_array_opt() = 0;
aoqi@0 128 virtual bool has_read_prim_array_opt() = 0;
aoqi@0 129 virtual bool has_write_ref_array_pre_opt() { return true; }
aoqi@0 130 virtual bool has_write_ref_array_opt() = 0;
aoqi@0 131 virtual bool has_write_prim_array_opt() = 0;
aoqi@0 132
aoqi@0 133 virtual bool has_read_region_opt() = 0;
aoqi@0 134 virtual bool has_write_region_opt() = 0;
aoqi@0 135
aoqi@0 136 // These operations should assert false unless the correponding operation
aoqi@0 137 // above returns true. Otherwise, they should perform an appropriate
aoqi@0 138 // barrier for an array whose elements are all in the given memory region.
aoqi@0 139 virtual void read_ref_array(MemRegion mr) = 0;
aoqi@0 140 virtual void read_prim_array(MemRegion mr) = 0;
aoqi@0 141
aoqi@0 142 // Below length is the # array elements being written
aoqi@0 143 virtual void write_ref_array_pre(oop* dst, int length,
fujie@116 144 bool dest_uninitialized = false) {
fujie@116 145 #ifdef MIPS64
fujie@121 146 if (Use3A2000) OrderAccess::fence();
fujie@116 147 #endif
fujie@116 148 }
aoqi@0 149 virtual void write_ref_array_pre(narrowOop* dst, int length,
fujie@116 150 bool dest_uninitialized = false) {
fujie@116 151 #ifdef MIPS64
fujie@121 152 if (Use3A2000) OrderAccess::fence();
fujie@116 153 #endif
fujie@116 154 }
aoqi@0 155 // Below count is the # array elements being written, starting
aoqi@0 156 // at the address "start", which may not necessarily be HeapWord-aligned
aoqi@0 157 inline void write_ref_array(HeapWord* start, size_t count);
aoqi@0 158
aoqi@0 159 // Static versions, suitable for calling from generated code;
aoqi@0 160 // count is # array elements being written, starting with "start",
aoqi@0 161 // which may not necessarily be HeapWord-aligned.
aoqi@0 162 static void static_write_ref_array_pre(HeapWord* start, size_t count);
aoqi@0 163 static void static_write_ref_array_post(HeapWord* start, size_t count);
aoqi@0 164
aoqi@0 165 protected:
aoqi@0 166 virtual void write_ref_array_work(MemRegion mr) = 0;
aoqi@0 167 public:
aoqi@0 168 virtual void write_prim_array(MemRegion mr) = 0;
aoqi@0 169
aoqi@0 170 virtual void read_region(MemRegion mr) = 0;
aoqi@0 171
aoqi@0 172 // (For efficiency reasons, this operation is specialized for certain
aoqi@0 173 // barrier types. Semantically, it should be thought of as a call to the
aoqi@0 174 // virtual "_work" function below, which must implement the barrier.)
aoqi@0 175 inline void write_region(MemRegion mr);
aoqi@0 176 protected:
aoqi@0 177 virtual void write_region_work(MemRegion mr) = 0;
aoqi@0 178 public:
aoqi@0 179
aoqi@0 180 // Some barrier sets create tables whose elements correspond to parts of
aoqi@0 181 // the heap; the CardTableModRefBS is an example. Such barrier sets will
aoqi@0 182 // normally reserve space for such tables, and commit parts of the table
aoqi@0 183 // "covering" parts of the heap that are committed. The constructor is
aoqi@0 184 // passed the maximum number of independently committable subregions to
aoqi@0 185 // be covered, and the "resize_covoered_region" function allows the
aoqi@0 186 // sub-parts of the heap to inform the barrier set of changes of their
aoqi@0 187 // sizes.
aoqi@0 188 BarrierSet(int max_covered_regions) :
aoqi@0 189 _max_covered_regions(max_covered_regions) {}
aoqi@0 190
aoqi@0 191 // Inform the BarrierSet that the the covered heap region that starts
aoqi@0 192 // with "base" has been changed to have the given size (possibly from 0,
aoqi@0 193 // for initialization.)
aoqi@0 194 virtual void resize_covered_region(MemRegion new_region) = 0;
aoqi@0 195
aoqi@0 196 // If the barrier set imposes any alignment restrictions on boundaries
aoqi@0 197 // within the heap, this function tells whether they are met.
aoqi@0 198 virtual bool is_aligned(HeapWord* addr) = 0;
aoqi@0 199
aoqi@0 200 // Print a description of the memory for the barrier set
aoqi@0 201 virtual void print_on(outputStream* st) const = 0;
aoqi@0 202 };
aoqi@0 203
aoqi@0 204 #endif // SHARE_VM_MEMORY_BARRIERSET_HPP

mercurial