src/share/vm/memory/barrierSet.hpp

Wed, 15 Feb 2012 10:12:55 -0800

author
never
date
Wed, 15 Feb 2012 10:12:55 -0800
changeset 3571
09d00c18e323
parent 2606
0ac769a57c64
child 3687
fd09f2d8283e
permissions
-rw-r--r--

7145537: minor tweaks to LogEvents
Reviewed-by: kvn, twisti

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

mercurial