src/share/vm/memory/barrierSet.hpp

Thu, 03 Dec 2009 15:01:57 -0800

author
ysr
date
Thu, 03 Dec 2009 15:01:57 -0800
changeset 1526
6aa7255741f3
parent 1280
df6caf649ff7
child 1680
6484c4ee11cb
permissions
-rw-r--r--

6906727: UseCompressedOops: some card-marking fixes related to object arrays
Summary: Introduced a new write_ref_array(HeapWords* start, size_t count) method that does the requisite MemRegion range calculation so (some of the) clients of the erstwhile write_ref_array(MemRegion mr) do not need to worry. This removed all external uses of array_size(), which was also simplified and made private. Asserts were added to catch other possible issues. Further, less essential, fixes stemming from this investigation are deferred to CR 6904516 (to follow shortly in hs17).
Reviewed-by: kvn, coleenp, jmasa

duke@435 1 /*
xdono@631 2 * Copyright 2000-2008 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // This class provides the interface between a barrier implementation and
duke@435 26 // the rest of the system.
duke@435 27
duke@435 28 class BarrierSet: public CHeapObj {
duke@435 29 friend class VMStructs;
duke@435 30 public:
duke@435 31 enum Name {
duke@435 32 ModRef,
duke@435 33 CardTableModRef,
duke@435 34 CardTableExtension,
ysr@777 35 G1SATBCT,
ysr@777 36 G1SATBCTLogging,
duke@435 37 Other,
duke@435 38 Uninit
duke@435 39 };
duke@435 40
duke@435 41 protected:
duke@435 42 int _max_covered_regions;
duke@435 43 Name _kind;
duke@435 44
duke@435 45 public:
duke@435 46
ysr@777 47 BarrierSet() { _kind = Uninit; }
duke@435 48 // To get around prohibition on RTTI.
ysr@777 49 BarrierSet::Name kind() { return _kind; }
duke@435 50 virtual bool is_a(BarrierSet::Name bsn) = 0;
duke@435 51
duke@435 52 // These operations indicate what kind of barriers the BarrierSet has.
duke@435 53 virtual bool has_read_ref_barrier() = 0;
duke@435 54 virtual bool has_read_prim_barrier() = 0;
duke@435 55 virtual bool has_write_ref_barrier() = 0;
ysr@777 56 virtual bool has_write_ref_pre_barrier() = 0;
duke@435 57 virtual bool has_write_prim_barrier() = 0;
duke@435 58
duke@435 59 // These functions indicate whether a particular access of the given
duke@435 60 // kinds requires a barrier.
coleenp@548 61 virtual bool read_ref_needs_barrier(void* field) = 0;
duke@435 62 virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0;
coleenp@548 63 virtual bool write_ref_needs_barrier(void* field, oop new_val) = 0;
ysr@777 64 virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes,
ysr@777 65 juint val1, juint val2) = 0;
duke@435 66
duke@435 67 // The first four operations provide a direct implementation of the
duke@435 68 // barrier set. An interpreter loop, for example, could call these
duke@435 69 // directly, as appropriate.
duke@435 70
duke@435 71 // Invoke the barrier, if any, necessary when reading the given ref field.
coleenp@548 72 virtual void read_ref_field(void* field) = 0;
duke@435 73
duke@435 74 // Invoke the barrier, if any, necessary when reading the given primitive
duke@435 75 // "field" of "bytes" bytes in "obj".
duke@435 76 virtual void read_prim_field(HeapWord* field, size_t bytes) = 0;
duke@435 77
duke@435 78 // Invoke the barrier, if any, necessary when writing "new_val" into the
duke@435 79 // ref field at "offset" in "obj".
duke@435 80 // (For efficiency reasons, this operation is specialized for certain
duke@435 81 // barrier types. Semantically, it should be thought of as a call to the
duke@435 82 // virtual "_work" function below, which must implement the barrier.)
ysr@777 83 // First the pre-write versions...
ysr@1280 84 template <class T> inline void write_ref_field_pre(T* field, oop new_val);
ysr@1280 85 private:
ysr@1280 86 // Keep this private so as to catch violations at build time.
ysr@1280 87 virtual void write_ref_field_pre_work( void* field, oop new_val) { guarantee(false, "Not needed"); };
ysr@777 88 protected:
ysr@1280 89 virtual void write_ref_field_pre_work( oop* field, oop new_val) {};
ysr@1280 90 virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {};
ysr@777 91 public:
ysr@777 92
ysr@777 93 // ...then the post-write version.
coleenp@548 94 inline void write_ref_field(void* field, oop new_val);
duke@435 95 protected:
coleenp@548 96 virtual void write_ref_field_work(void* field, oop new_val) = 0;
duke@435 97 public:
duke@435 98
duke@435 99 // Invoke the barrier, if any, necessary when writing the "bytes"-byte
duke@435 100 // value(s) "val1" (and "val2") into the primitive "field".
duke@435 101 virtual void write_prim_field(HeapWord* field, size_t bytes,
duke@435 102 juint val1, juint val2) = 0;
duke@435 103
duke@435 104 // Operations on arrays, or general regions (e.g., for "clone") may be
duke@435 105 // optimized by some barriers.
duke@435 106
duke@435 107 // The first six operations tell whether such an optimization exists for
duke@435 108 // the particular barrier.
duke@435 109 virtual bool has_read_ref_array_opt() = 0;
duke@435 110 virtual bool has_read_prim_array_opt() = 0;
ysr@777 111 virtual bool has_write_ref_array_pre_opt() { return true; }
duke@435 112 virtual bool has_write_ref_array_opt() = 0;
duke@435 113 virtual bool has_write_prim_array_opt() = 0;
duke@435 114
duke@435 115 virtual bool has_read_region_opt() = 0;
duke@435 116 virtual bool has_write_region_opt() = 0;
duke@435 117
duke@435 118 // These operations should assert false unless the correponding operation
duke@435 119 // above returns true. Otherwise, they should perform an appropriate
duke@435 120 // barrier for an array whose elements are all in the given memory region.
duke@435 121 virtual void read_ref_array(MemRegion mr) = 0;
duke@435 122 virtual void read_prim_array(MemRegion mr) = 0;
duke@435 123
ysr@1526 124 // Below length is the # array elements being written
ysr@1280 125 virtual void write_ref_array_pre( oop* dst, int length) {}
ysr@1280 126 virtual void write_ref_array_pre(narrowOop* dst, int length) {}
ysr@1526 127 // Below MemRegion mr is expected to be HeapWord-aligned
duke@435 128 inline void write_ref_array(MemRegion mr);
ysr@1526 129 // Below count is the # array elements being written, starting
ysr@1526 130 // at the address "start", which may not necessarily be HeapWord-aligned
ysr@1526 131 inline void write_ref_array(HeapWord* start, size_t count);
ysr@777 132
ysr@1526 133 // Static versions, suitable for calling from generated code;
ysr@1526 134 // count is # array elements being written, starting with "start",
ysr@1526 135 // which may not necessarily be HeapWord-aligned.
ysr@777 136 static void static_write_ref_array_pre(HeapWord* start, size_t count);
ysr@777 137 static void static_write_ref_array_post(HeapWord* start, size_t count);
ysr@777 138
duke@435 139 protected:
duke@435 140 virtual void write_ref_array_work(MemRegion mr) = 0;
duke@435 141 public:
duke@435 142 virtual void write_prim_array(MemRegion mr) = 0;
duke@435 143
duke@435 144 virtual void read_region(MemRegion mr) = 0;
duke@435 145
duke@435 146 // (For efficiency reasons, this operation is specialized for certain
duke@435 147 // barrier types. Semantically, it should be thought of as a call to the
duke@435 148 // virtual "_work" function below, which must implement the barrier.)
duke@435 149 inline void write_region(MemRegion mr);
duke@435 150 protected:
duke@435 151 virtual void write_region_work(MemRegion mr) = 0;
duke@435 152 public:
duke@435 153
duke@435 154 // Some barrier sets create tables whose elements correspond to parts of
duke@435 155 // the heap; the CardTableModRefBS is an example. Such barrier sets will
duke@435 156 // normally reserve space for such tables, and commit parts of the table
duke@435 157 // "covering" parts of the heap that are committed. The constructor is
duke@435 158 // passed the maximum number of independently committable subregions to
duke@435 159 // be covered, and the "resize_covoered_region" function allows the
duke@435 160 // sub-parts of the heap to inform the barrier set of changes of their
duke@435 161 // sizes.
duke@435 162 BarrierSet(int max_covered_regions) :
duke@435 163 _max_covered_regions(max_covered_regions) {}
duke@435 164
duke@435 165 // Inform the BarrierSet that the the covered heap region that starts
duke@435 166 // with "base" has been changed to have the given size (possibly from 0,
duke@435 167 // for initialization.)
duke@435 168 virtual void resize_covered_region(MemRegion new_region) = 0;
duke@435 169
duke@435 170 // If the barrier set imposes any alignment restrictions on boundaries
duke@435 171 // within the heap, this function tells whether they are met.
duke@435 172 virtual bool is_aligned(HeapWord* addr) = 0;
duke@435 173
duke@435 174 };

mercurial