genRemSet.hpp 5.6 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29
#ifndef SHARE_VM_MEMORY_GENREMSET_HPP
#define SHARE_VM_MEMORY_GENREMSET_HPP

#include "oops/oop.hpp"

D
duke 已提交
30 31 32 33 34 35 36 37
// A GenRemSet provides ways of iterating over pointers accross generations.
// (This is especially useful for older-to-younger.)

class Generation;
class BarrierSet;
class OopsInGenClosure;
class CardTableRS;

38 39 40 41 42 43 44 45 46 47 48
// Helper to remember modified oops in all klasses.
class KlassRemSet {
  bool _accumulate_modified_oops;
 public:
  KlassRemSet() : _accumulate_modified_oops(false) {}
  void set_accumulate_modified_oops(bool value) { _accumulate_modified_oops = value; }
  bool accumulate_modified_oops() { return _accumulate_modified_oops; }
  bool mod_union_is_clear();
  void clear_mod_union();
};

Z
zgu 已提交
49
class GenRemSet: public CHeapObj<mtGC> {
D
duke 已提交
50 51 52
  friend class Generation;

  BarrierSet* _bs;
53
  KlassRemSet _klass_rem_set;
D
duke 已提交
54 55 56 57 58 59 60 61

public:
  enum Name {
    CardTable,
    Other
  };

  GenRemSet(BarrierSet * bs) : _bs(bs) {}
62
  GenRemSet() : _bs(NULL) {}
D
duke 已提交
63 64 65 66 67 68 69 70 71 72 73

  virtual Name rs_kind() = 0;

  // These are for dynamic downcasts.  Unfortunately that it names the
  // possible subtypes (but not that they are subtypes!)  Return NULL if
  // the cast is invalide.
  virtual CardTableRS* as_CardTableRS() { return NULL; }

  // Return the barrier set associated with "this."
  BarrierSet* bs() { return _bs; }

74 75 76
  // Set the barrier set.
  void set_bs(BarrierSet* bs) { _bs = bs; }

77 78
  KlassRemSet* klass_rem_set() { return &_klass_rem_set; }

D
duke 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  // Do any (sequential) processing necessary to prepare for (possibly
  // "parallel", if that arg is true) calls to younger_refs_iterate.
  virtual void prepare_for_younger_refs_iterate(bool parallel) = 0;

  // Apply the "do_oop" method of "blk" to (exactly) all oop locations
  //  1) that are in objects allocated in "g" at the time of the last call
  //     to "save_Marks", and
  //  2) that point to objects in younger generations.
  virtual void younger_refs_iterate(Generation* g, OopsInGenClosure* blk) = 0;

  virtual void younger_refs_in_space_iterate(Space* sp,
                                             OopsInGenClosure* cl) = 0;

  // This method is used to notify the remembered set that "new_val" has
  // been written into "field" by the garbage collector.
94
  void write_ref_field_gc(void* field, oop new_val);
D
duke 已提交
95
protected:
96
  virtual void write_ref_field_gc_work(void* field, oop new_val) = 0;
D
duke 已提交
97 98 99
public:

  // A version of the above suitable for use by parallel collectors.
100
  virtual void write_ref_field_gc_par(void* field, oop new_val) = 0;
D
duke 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

  // Resize one of the regions covered by the remembered set.
  virtual void resize_covered_region(MemRegion new_region) = 0;

  // If the rem set imposes any alignment restrictions on boundaries
  // within the heap, this function tells whether they are met.
  virtual bool is_aligned(HeapWord* addr) = 0;

  // If the RS (or BS) imposes an aligment constraint on maximum heap size.
  // (This must be static, and dispatch on "nm", because it is called
  // before an RS is created.)
  static uintx max_alignment_constraint(Name nm);

  virtual void verify() = 0;

  // Verify that the remembered set has no entries for
117 118 119 120 121 122 123 124 125
  // the heap interval denoted by mr.  If there are any
  // alignment constraints on the remembered set, only the
  // part of the region that is aligned is checked.
  //
  //   alignment boundaries
  //   +--------+-------+--------+-------+
  //         [ region mr              )
  //            [ part checked   )
  virtual void verify_aligned_region_empty(MemRegion mr) = 0;
D
duke 已提交
126 127 128 129 130 131 132 133 134 135 136 137

  // If appropriate, print some information about the remset on "tty".
  virtual void print() {}

  // Informs the RS that the given memregion contains no references to
  // younger generations.
  virtual void clear(MemRegion mr) = 0;

  // Informs the RS that there are no references to generations
  // younger than gen from generations gen and older.
  // The parameter clear_perm indicates if the perm_gen's
  // remembered set should also be processed/cleared.
138
  virtual void clear_into_younger(Generation* gen) = 0;
D
duke 已提交
139 140 141

  // Informs the RS that refs in the given "mr" may have changed
  // arbitrarily, and therefore may contain old-to-young pointers.
142 143 144 145
  // If "whole heap" is true, then this invalidation is part of an
  // invalidation of the whole heap, which an implementation might
  // handle differently than that of a sub-part of the heap.
  virtual void invalidate(MemRegion mr, bool whole_heap = false) = 0;
D
duke 已提交
146 147 148

  // Informs the RS that refs in this generation
  // may have changed arbitrarily, and therefore may contain
149 150
  // old-to-young pointers in arbitrary locations.
  virtual void invalidate_or_clear(Generation* gen) = 0;
D
duke 已提交
151
};
152 153

#endif // SHARE_VM_MEMORY_GENREMSET_HPP