g1OopClosures.hpp 9.1 KB
Newer Older
1
/*
2
 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
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.
22 23 24
 *
 */

25 26 27
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP
#define SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP

28 29
#include "memory/iterator.hpp"

30 31 32 33 34 35 36 37
class HeapRegion;
class G1CollectedHeap;
class G1RemSet;
class ConcurrentMark;
class DirtyCardToOopClosure;
class CMBitMap;
class CMMarkStack;
class G1ParScanThreadState;
38
class CMTask;
39
class ReferenceProcessor;
40 41 42

// A class that scans oops in a given heap region (much as OopsInGenClosure
// scans oops in a generation.)
43
class OopsInHeapRegionClosure: public ExtendedOopClosure {
44 45 46
protected:
  HeapRegion* _from;
public:
47
  void set_region(HeapRegion* from) { _from = from; }
48 49 50 51 52 53
};

class G1ParClosureSuper : public OopsInHeapRegionClosure {
protected:
  G1CollectedHeap* _g1;
  G1ParScanThreadState* _par_scan_state;
54
  uint _worker_id;
55
public:
56 57 58
  // Initializes the instance, leaving _par_scan_state uninitialized. Must be done
  // later using the set_par_scan_thread_state() method.
  G1ParClosureSuper(G1CollectedHeap* g1);
59 60
  G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state);
  bool apply_to_weak_ref_discovered_field() { return true; }
61 62

  void set_par_scan_thread_state(G1ParScanThreadState* par_scan_state);
63 64
};

65 66
class G1ParPushHeapRSClosure : public G1ParClosureSuper {
public:
67
  G1ParPushHeapRSClosure(G1CollectedHeap* g1,
68 69
                         G1ParScanThreadState* par_scan_state):
    G1ParClosureSuper(g1, par_scan_state) { }
70

71 72 73 74 75
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(oop* p)          { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p)    { do_oop_nv(p); }
};

76 77
class G1ParScanClosure : public G1ParClosureSuper {
public:
78 79
  G1ParScanClosure(G1CollectedHeap* g1, ReferenceProcessor* rp) :
    G1ParClosureSuper(g1) {
80 81 82 83
    assert(_ref_processor == NULL, "sanity");
    _ref_processor = rp;
  }

84
  template <class T> void do_oop_nv(T* p);
85 86 87 88
  virtual void do_oop(oop* p)          { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p)    { do_oop_nv(p); }
};

89 90
// Add back base class for metadata
class G1ParCopyHelper : public G1ParClosureSuper {
91
protected:
92
  Klass* _scanned_klass;
93 94 95 96 97 98
  ConcurrentMark* _cm;

  // Mark the object if it's not already marked. This is used to mark
  // objects pointed to by roots that are guaranteed not to move
  // during the GC (i.e., non-CSet objects). It is MT-safe.
  void mark_object(oop obj);
99

100 101 102 103
  // Mark the object if it's not already marked. This is used to mark
  // objects pointed to by roots that have been forwarded during a
  // GC. It is MT-safe.
  void mark_forwarded_object(oop from_obj, oop to_obj);
104
 public:
105
  G1ParCopyHelper(G1CollectedHeap* g1,  G1ParScanThreadState* par_scan_state);
106 107 108 109 110

  void set_scanned_klass(Klass* k) { _scanned_klass = k; }
  template <class T> void do_klass_barrier(T* p, oop new_obj);
};

111
template <G1Barrier barrier, G1Mark do_mark_object>
112
class G1ParCopyClosure : public G1ParCopyHelper {
113
private:
B
brutisso 已提交
114
  template <class T> void do_oop_work(T* p);
115 116

public:
117 118
  G1ParCopyClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state,
                   ReferenceProcessor* rp) :
119
      G1ParCopyHelper(g1, par_scan_state) {
120 121 122
    assert(_ref_processor == NULL, "sanity");
  }

123
  template <class T> void do_oop_nv(T* p) { do_oop_work(p); }
124 125
  virtual void do_oop(oop* p)       { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
126

127 128 129 130
  G1CollectedHeap*      g1()  { return _g1; };
  G1ParScanThreadState* pss() { return _par_scan_state; }
  ReferenceProcessor*   rp()  { return _ref_processor; };
};
131

132 133 134
typedef G1ParCopyClosure<G1BarrierNone,  G1MarkNone>             G1ParScanExtRootClosure;
typedef G1ParCopyClosure<G1BarrierNone,  G1MarkFromRoot>         G1ParScanAndMarkExtRootClosure;
typedef G1ParCopyClosure<G1BarrierNone,  G1MarkPromotedFromRoot> G1ParScanAndMarkWeakExtRootClosure;
135 136 137
// We use a separate closure to handle references during evacuation
// failure processing.

138
typedef G1ParCopyClosure<G1BarrierEvac, G1MarkNone> G1ParScanHeapEvacFailureClosure;
139

140
class FilterIntoCSClosure: public ExtendedOopClosure {
141 142 143 144 145
  G1CollectedHeap* _g1;
  OopClosure* _oc;
  DirtyCardToOopClosure* _dcto_cl;
public:
  FilterIntoCSClosure(  DirtyCardToOopClosure* dcto_cl,
146
                        G1CollectedHeap* g1,
147 148
                        OopClosure* oc) :
    _dcto_cl(dcto_cl), _g1(g1), _oc(oc) { }
149

150 151 152
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(oop* p)        { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p)  { do_oop_nv(p); }
153 154 155
  bool apply_to_weak_ref_discovered_field() { return true; }
};

156
class FilterOutOfRegionClosure: public ExtendedOopClosure {
157 158 159 160 161
  HeapWord* _r_bottom;
  HeapWord* _r_end;
  OopClosure* _oc;
public:
  FilterOutOfRegionClosure(HeapRegion* r, OopClosure* oc);
162 163 164
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(oop* p) { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
165 166
  bool apply_to_weak_ref_discovered_field() { return true; }
};
167

168
// Closure for iterating over object fields during concurrent marking
169 170 171
class G1CMOopClosure : public MetadataAwareOopClosure {
protected:
  ConcurrentMark*    _cm;
172
private:
173 174 175 176 177 178 179 180 181
  G1CollectedHeap*   _g1h;
  CMTask*            _task;
public:
  G1CMOopClosure(G1CollectedHeap* g1h, ConcurrentMark* cm, CMTask* task);
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(      oop* p) { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
};

182
// Closure to scan the root regions during concurrent marking
183
class G1RootRegionScanClosure : public MetadataAwareOopClosure {
184 185 186 187 188 189 190 191 192 193 194 195 196
private:
  G1CollectedHeap* _g1h;
  ConcurrentMark*  _cm;
  uint _worker_id;
public:
  G1RootRegionScanClosure(G1CollectedHeap* g1h, ConcurrentMark* cm,
                          uint worker_id) :
    _g1h(g1h), _cm(cm), _worker_id(worker_id) { }
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(      oop* p) { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
};

197 198 199 200 201
// Closure that applies the given two closures in sequence.
// Used by the RSet refinement code (when updating RSets
// during an evacuation pause) to record cards containing
// pointers into the collection set.

202
class G1Mux2Closure : public ExtendedOopClosure {
203 204 205 206 207 208 209 210 211 212 213 214
  OopClosure* _c1;
  OopClosure* _c2;
public:
  G1Mux2Closure(OopClosure *c1, OopClosure *c2);
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(oop* p)        { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p)  { do_oop_nv(p); }
};

// A closure that returns true if it is actually applied
// to a reference

215
class G1TriggerClosure : public ExtendedOopClosure {
216 217 218 219 220 221 222 223 224 225 226 227
  bool _triggered;
public:
  G1TriggerClosure();
  bool triggered() const { return _triggered; }
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(oop* p)        { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p)  { do_oop_nv(p); }
};

// A closure which uses a triggering closure to determine
// whether to apply an oop closure.

228
class G1InvokeIfNotTriggeredClosure: public ExtendedOopClosure {
229 230 231 232 233 234 235 236 237
  G1TriggerClosure* _trigger_cl;
  OopClosure* _oop_cl;
public:
  G1InvokeIfNotTriggeredClosure(G1TriggerClosure* t, OopClosure* oc);
  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(oop* p)        { do_oop_nv(p); }
  virtual void do_oop(narrowOop* p)  { do_oop_nv(p); }
};

238
class G1UpdateRSOrPushRefOopClosure: public ExtendedOopClosure {
239 240 241
  G1CollectedHeap* _g1;
  G1RemSet* _g1_rem_set;
  HeapRegion* _from;
242
  G1ParPushHeapRSClosure* _push_ref_cl;
243
  bool _record_refs_into_cset;
244
  uint _worker_i;
245 246 247 248

public:
  G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
                                G1RemSet* rs,
249
                                G1ParPushHeapRSClosure* push_ref_cl,
250
                                bool record_refs_into_cset,
251
                                uint worker_i = 0);
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269

  void set_from(HeapRegion* from) {
    assert(from != NULL, "from region must be non-NULL");
    _from = from;
  }

  bool self_forwarded(oop obj) {
    bool result = (obj->is_forwarded() && (obj->forwardee()== obj));
    return result;
  }

  bool apply_to_weak_ref_discovered_field() { return true; }

  template <class T> void do_oop_nv(T* p);
  virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
  virtual void do_oop(oop* p)       { do_oop_nv(p); }
};

270
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP