src/share/vm/memory/barrierSet.hpp

changeset 0
f90c822e73f8
child 116
09e17e497778
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/barrierSet.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,187 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_MEMORY_BARRIERSET_HPP
    1.29 +#define SHARE_VM_MEMORY_BARRIERSET_HPP
    1.30 +
    1.31 +#include "memory/memRegion.hpp"
    1.32 +#include "oops/oopsHierarchy.hpp"
    1.33 +
    1.34 +// This class provides the interface between a barrier implementation and
    1.35 +// the rest of the system.
    1.36 +
    1.37 +class BarrierSet: public CHeapObj<mtGC> {
    1.38 +  friend class VMStructs;
    1.39 +public:
    1.40 +  enum Name {
    1.41 +    ModRef,
    1.42 +    CardTableModRef,
    1.43 +    CardTableExtension,
    1.44 +    G1SATBCT,
    1.45 +    G1SATBCTLogging,
    1.46 +    Other,
    1.47 +    Uninit
    1.48 +  };
    1.49 +
    1.50 +  enum Flags {
    1.51 +    None                = 0,
    1.52 +    TargetUninitialized = 1
    1.53 +  };
    1.54 +protected:
    1.55 +  int _max_covered_regions;
    1.56 +  Name _kind;
    1.57 +
    1.58 +public:
    1.59 +
    1.60 +  BarrierSet() { _kind = Uninit; }
    1.61 +  // To get around prohibition on RTTI.
    1.62 +  BarrierSet::Name kind() { return _kind; }
    1.63 +  virtual bool is_a(BarrierSet::Name bsn) = 0;
    1.64 +
    1.65 +  // These operations indicate what kind of barriers the BarrierSet has.
    1.66 +  virtual bool has_read_ref_barrier() = 0;
    1.67 +  virtual bool has_read_prim_barrier() = 0;
    1.68 +  virtual bool has_write_ref_barrier() = 0;
    1.69 +  virtual bool has_write_ref_pre_barrier() = 0;
    1.70 +  virtual bool has_write_prim_barrier() = 0;
    1.71 +
    1.72 +  // These functions indicate whether a particular access of the given
    1.73 +  // kinds requires a barrier.
    1.74 +  virtual bool read_ref_needs_barrier(void* field) = 0;
    1.75 +  virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0;
    1.76 +  virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes,
    1.77 +                                        juint val1, juint val2) = 0;
    1.78 +
    1.79 +  // The first four operations provide a direct implementation of the
    1.80 +  // barrier set.  An interpreter loop, for example, could call these
    1.81 +  // directly, as appropriate.
    1.82 +
    1.83 +  // Invoke the barrier, if any, necessary when reading the given ref field.
    1.84 +  virtual void read_ref_field(void* field) = 0;
    1.85 +
    1.86 +  // Invoke the barrier, if any, necessary when reading the given primitive
    1.87 +  // "field" of "bytes" bytes in "obj".
    1.88 +  virtual void read_prim_field(HeapWord* field, size_t bytes) = 0;
    1.89 +
    1.90 +  // Invoke the barrier, if any, necessary when writing "new_val" into the
    1.91 +  // ref field at "offset" in "obj".
    1.92 +  // (For efficiency reasons, this operation is specialized for certain
    1.93 +  // barrier types.  Semantically, it should be thought of as a call to the
    1.94 +  // virtual "_work" function below, which must implement the barrier.)
    1.95 +  // First the pre-write versions...
    1.96 +  template <class T> inline void write_ref_field_pre(T* field, oop new_val);
    1.97 +private:
    1.98 +  // Keep this private so as to catch violations at build time.
    1.99 +  virtual void write_ref_field_pre_work(     void* field, oop new_val) { guarantee(false, "Not needed"); };
   1.100 +protected:
   1.101 +  virtual void write_ref_field_pre_work(      oop* field, oop new_val) {};
   1.102 +  virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {};
   1.103 +public:
   1.104 +
   1.105 +  // ...then the post-write version.
   1.106 +  inline void write_ref_field(void* field, oop new_val, bool release = false);
   1.107 +protected:
   1.108 +  virtual void write_ref_field_work(void* field, oop new_val, bool release = false) = 0;
   1.109 +public:
   1.110 +
   1.111 +  // Invoke the barrier, if any, necessary when writing the "bytes"-byte
   1.112 +  // value(s) "val1" (and "val2") into the primitive "field".
   1.113 +  virtual void write_prim_field(HeapWord* field, size_t bytes,
   1.114 +                                juint val1, juint val2) = 0;
   1.115 +
   1.116 +  // Operations on arrays, or general regions (e.g., for "clone") may be
   1.117 +  // optimized by some barriers.
   1.118 +
   1.119 +  // The first six operations tell whether such an optimization exists for
   1.120 +  // the particular barrier.
   1.121 +  virtual bool has_read_ref_array_opt() = 0;
   1.122 +  virtual bool has_read_prim_array_opt() = 0;
   1.123 +  virtual bool has_write_ref_array_pre_opt() { return true; }
   1.124 +  virtual bool has_write_ref_array_opt() = 0;
   1.125 +  virtual bool has_write_prim_array_opt() = 0;
   1.126 +
   1.127 +  virtual bool has_read_region_opt() = 0;
   1.128 +  virtual bool has_write_region_opt() = 0;
   1.129 +
   1.130 +  // These operations should assert false unless the correponding operation
   1.131 +  // above returns true.  Otherwise, they should perform an appropriate
   1.132 +  // barrier for an array whose elements are all in the given memory region.
   1.133 +  virtual void read_ref_array(MemRegion mr) = 0;
   1.134 +  virtual void read_prim_array(MemRegion mr) = 0;
   1.135 +
   1.136 +  // Below length is the # array elements being written
   1.137 +  virtual void write_ref_array_pre(oop* dst, int length,
   1.138 +                                   bool dest_uninitialized = false) {}
   1.139 +  virtual void write_ref_array_pre(narrowOop* dst, int length,
   1.140 +                                   bool dest_uninitialized = false) {}
   1.141 +  // Below count is the # array elements being written, starting
   1.142 +  // at the address "start", which may not necessarily be HeapWord-aligned
   1.143 +  inline void write_ref_array(HeapWord* start, size_t count);
   1.144 +
   1.145 +  // Static versions, suitable for calling from generated code;
   1.146 +  // count is # array elements being written, starting with "start",
   1.147 +  // which may not necessarily be HeapWord-aligned.
   1.148 +  static void static_write_ref_array_pre(HeapWord* start, size_t count);
   1.149 +  static void static_write_ref_array_post(HeapWord* start, size_t count);
   1.150 +
   1.151 +protected:
   1.152 +  virtual void write_ref_array_work(MemRegion mr) = 0;
   1.153 +public:
   1.154 +  virtual void write_prim_array(MemRegion mr) = 0;
   1.155 +
   1.156 +  virtual void read_region(MemRegion mr) = 0;
   1.157 +
   1.158 +  // (For efficiency reasons, this operation is specialized for certain
   1.159 +  // barrier types.  Semantically, it should be thought of as a call to the
   1.160 +  // virtual "_work" function below, which must implement the barrier.)
   1.161 +  inline void write_region(MemRegion mr);
   1.162 +protected:
   1.163 +  virtual void write_region_work(MemRegion mr) = 0;
   1.164 +public:
   1.165 +
   1.166 +  // Some barrier sets create tables whose elements correspond to parts of
   1.167 +  // the heap; the CardTableModRefBS is an example.  Such barrier sets will
   1.168 +  // normally reserve space for such tables, and commit parts of the table
   1.169 +  // "covering" parts of the heap that are committed.  The constructor is
   1.170 +  // passed the maximum number of independently committable subregions to
   1.171 +  // be covered, and the "resize_covoered_region" function allows the
   1.172 +  // sub-parts of the heap to inform the barrier set of changes of their
   1.173 +  // sizes.
   1.174 +  BarrierSet(int max_covered_regions) :
   1.175 +    _max_covered_regions(max_covered_regions) {}
   1.176 +
   1.177 +  // Inform the BarrierSet that the the covered heap region that starts
   1.178 +  // with "base" has been changed to have the given size (possibly from 0,
   1.179 +  // for initialization.)
   1.180 +  virtual void resize_covered_region(MemRegion new_region) = 0;
   1.181 +
   1.182 +  // If the barrier set imposes any alignment restrictions on boundaries
   1.183 +  // within the heap, this function tells whether they are met.
   1.184 +  virtual bool is_aligned(HeapWord* addr) = 0;
   1.185 +
   1.186 +  // Print a description of the memory for the barrier set
   1.187 +  virtual void print_on(outputStream* st) const = 0;
   1.188 +};
   1.189 +
   1.190 +#endif // SHARE_VM_MEMORY_BARRIERSET_HPP

mercurial