src/share/vm/gc_implementation/g1/g1OopClosures.hpp

Fri, 19 Dec 2014 09:21:06 +0100

author
tschatzl
date
Fri, 19 Dec 2014 09:21:06 +0100
changeset 7651
c132be0fb74d
parent 6992
2c6ef90f030a
child 7655
8e9ede9dd2cd
permissions
-rw-r--r--

8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
Summary: Evaluate and improve object copy time by micro-optimizations and splitting out slow and fast paths aggressively.
Reviewed-by: kbarrett, mgerdin, jmasa
Contributed-by: Tony Printezis <tprintezis@twitter.com>, Thomas Schatzl <thomas.schatzl@oracle.com>

ysr@777 1 /*
tschatzl@6269 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 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.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP
stefank@2314 27
stefank@6992 28 #include "memory/iterator.hpp"
tschatzl@7651 29 #include "oops/markOop.hpp"
stefank@6992 30
ysr@777 31 class HeapRegion;
ysr@777 32 class G1CollectedHeap;
ysr@777 33 class G1RemSet;
ysr@777 34 class ConcurrentMark;
ysr@777 35 class DirtyCardToOopClosure;
ysr@777 36 class CMBitMap;
ysr@777 37 class CMMarkStack;
ysr@777 38 class G1ParScanThreadState;
tonyp@2968 39 class CMTask;
johnc@3175 40 class ReferenceProcessor;
ysr@777 41
ysr@777 42 // A class that scans oops in a given heap region (much as OopsInGenClosure
ysr@777 43 // scans oops in a generation.)
tschatzl@6231 44 class OopsInHeapRegionClosure: public ExtendedOopClosure {
ysr@777 45 protected:
ysr@777 46 HeapRegion* _from;
ysr@777 47 public:
tonyp@2962 48 void set_region(HeapRegion* from) { _from = from; }
ysr@777 49 };
ysr@777 50
ysr@777 51 class G1ParClosureSuper : public OopsInHeapRegionClosure {
ysr@777 52 protected:
ysr@777 53 G1CollectedHeap* _g1;
ysr@777 54 G1ParScanThreadState* _par_scan_state;
johnc@3463 55 uint _worker_id;
ysr@777 56 public:
tschatzl@6939 57 // Initializes the instance, leaving _par_scan_state uninitialized. Must be done
tschatzl@6939 58 // later using the set_par_scan_thread_state() method.
tschatzl@6939 59 G1ParClosureSuper(G1CollectedHeap* g1);
ysr@777 60 G1ParClosureSuper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state);
ysr@777 61 bool apply_to_weak_ref_discovered_field() { return true; }
tschatzl@6939 62
tschatzl@6939 63 void set_par_scan_thread_state(G1ParScanThreadState* par_scan_state);
ysr@777 64 };
ysr@777 65
iveresov@1696 66 class G1ParPushHeapRSClosure : public G1ParClosureSuper {
iveresov@1696 67 public:
johnc@3175 68 G1ParPushHeapRSClosure(G1CollectedHeap* g1,
johnc@3179 69 G1ParScanThreadState* par_scan_state):
johnc@3179 70 G1ParClosureSuper(g1, par_scan_state) { }
johnc@3175 71
iveresov@1696 72 template <class T> void do_oop_nv(T* p);
iveresov@1696 73 virtual void do_oop(oop* p) { do_oop_nv(p); }
iveresov@1696 74 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
iveresov@1696 75 };
iveresov@1696 76
ysr@777 77 class G1ParScanClosure : public G1ParClosureSuper {
ysr@777 78 public:
tschatzl@6939 79 G1ParScanClosure(G1CollectedHeap* g1, ReferenceProcessor* rp) :
tschatzl@6939 80 G1ParClosureSuper(g1) {
johnc@3175 81 assert(_ref_processor == NULL, "sanity");
johnc@3175 82 _ref_processor = rp;
johnc@3175 83 }
johnc@3175 84
ysr@1280 85 template <class T> void do_oop_nv(T* p);
ysr@777 86 virtual void do_oop(oop* p) { do_oop_nv(p); }
ysr@777 87 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
ysr@777 88 };
ysr@777 89
coleenp@4037 90 // Add back base class for metadata
coleenp@4037 91 class G1ParCopyHelper : public G1ParClosureSuper {
tschatzl@6329 92 protected:
coleenp@4037 93 Klass* _scanned_klass;
tschatzl@6329 94 ConcurrentMark* _cm;
coleenp@4037 95
tschatzl@6329 96 // Mark the object if it's not already marked. This is used to mark
tschatzl@6329 97 // objects pointed to by roots that are guaranteed not to move
tschatzl@6329 98 // during the GC (i.e., non-CSet objects). It is MT-safe.
tschatzl@6329 99 void mark_object(oop obj);
tschatzl@6329 100
tschatzl@6329 101 // Mark the object if it's not already marked. This is used to mark
tschatzl@6329 102 // objects pointed to by roots that have been forwarded during a
tschatzl@6329 103 // GC. It is MT-safe.
tschatzl@6329 104 void mark_forwarded_object(oop from_obj, oop to_obj);
coleenp@4037 105 public:
tschatzl@6329 106 G1ParCopyHelper(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state);
coleenp@4037 107
coleenp@4037 108 void set_scanned_klass(Klass* k) { _scanned_klass = k; }
coleenp@4037 109 template <class T> void do_klass_barrier(T* p, oop new_obj);
coleenp@4037 110 };
coleenp@4037 111
stefank@6992 112 template <G1Barrier barrier, G1Mark do_mark_object>
coleenp@4037 113 class G1ParCopyClosure : public G1ParCopyHelper {
tschatzl@6331 114 private:
brutisso@3690 115 template <class T> void do_oop_work(T* p);
ysr@777 116
ysr@777 117 public:
johnc@3175 118 G1ParCopyClosure(G1CollectedHeap* g1, G1ParScanThreadState* par_scan_state,
johnc@3175 119 ReferenceProcessor* rp) :
coleenp@4037 120 G1ParCopyHelper(g1, par_scan_state) {
johnc@3175 121 assert(_ref_processor == NULL, "sanity");
johnc@3175 122 }
johnc@3175 123
tschatzl@6329 124 template <class T> void do_oop_nv(T* p) { do_oop_work(p); }
ysr@777 125 virtual void do_oop(oop* p) { do_oop_nv(p); }
ysr@777 126 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
stefank@6992 127
stefank@6992 128 G1CollectedHeap* g1() { return _g1; };
stefank@6992 129 G1ParScanThreadState* pss() { return _par_scan_state; }
stefank@6992 130 ReferenceProcessor* rp() { return _ref_processor; };
ysr@777 131 };
ysr@777 132
stefank@6992 133 typedef G1ParCopyClosure<G1BarrierNone, G1MarkNone> G1ParScanExtRootClosure;
stefank@6992 134 typedef G1ParCopyClosure<G1BarrierNone, G1MarkFromRoot> G1ParScanAndMarkExtRootClosure;
stefank@6992 135 typedef G1ParCopyClosure<G1BarrierNone, G1MarkPromotedFromRoot> G1ParScanAndMarkWeakExtRootClosure;
johnc@3175 136 // We use a separate closure to handle references during evacuation
johnc@3175 137 // failure processing.
johnc@3175 138
stefank@6992 139 typedef G1ParCopyClosure<G1BarrierEvac, G1MarkNone> G1ParScanHeapEvacFailureClosure;
ysr@777 140
coleenp@4037 141 class FilterIntoCSClosure: public ExtendedOopClosure {
ysr@777 142 G1CollectedHeap* _g1;
ysr@777 143 OopClosure* _oc;
ysr@777 144 DirtyCardToOopClosure* _dcto_cl;
ysr@777 145 public:
ysr@777 146 FilterIntoCSClosure( DirtyCardToOopClosure* dcto_cl,
johnc@3175 147 G1CollectedHeap* g1,
johnc@3179 148 OopClosure* oc) :
johnc@3179 149 _dcto_cl(dcto_cl), _g1(g1), _oc(oc) { }
johnc@3175 150
ysr@1280 151 template <class T> void do_oop_nv(T* p);
ysr@1280 152 virtual void do_oop(oop* p) { do_oop_nv(p); }
ysr@1280 153 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
ysr@777 154 bool apply_to_weak_ref_discovered_field() { return true; }
ysr@777 155 };
ysr@777 156
coleenp@4037 157 class FilterOutOfRegionClosure: public ExtendedOopClosure {
ysr@777 158 HeapWord* _r_bottom;
ysr@777 159 HeapWord* _r_end;
ysr@777 160 OopClosure* _oc;
ysr@777 161 public:
ysr@777 162 FilterOutOfRegionClosure(HeapRegion* r, OopClosure* oc);
ysr@1280 163 template <class T> void do_oop_nv(T* p);
ysr@1280 164 virtual void do_oop(oop* p) { do_oop_nv(p); }
ysr@1280 165 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
ysr@777 166 bool apply_to_weak_ref_discovered_field() { return true; }
ysr@777 167 };
stefank@2314 168
tonyp@2968 169 // Closure for iterating over object fields during concurrent marking
stefank@6992 170 class G1CMOopClosure : public MetadataAwareOopClosure {
stefank@6992 171 protected:
stefank@6992 172 ConcurrentMark* _cm;
tonyp@3464 173 private:
tonyp@2968 174 G1CollectedHeap* _g1h;
tonyp@2968 175 CMTask* _task;
tonyp@2968 176 public:
tonyp@2968 177 G1CMOopClosure(G1CollectedHeap* g1h, ConcurrentMark* cm, CMTask* task);
tonyp@2968 178 template <class T> void do_oop_nv(T* p);
tonyp@2968 179 virtual void do_oop( oop* p) { do_oop_nv(p); }
tonyp@2968 180 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
tonyp@2968 181 };
tonyp@2968 182
tonyp@3464 183 // Closure to scan the root regions during concurrent marking
stefank@6992 184 class G1RootRegionScanClosure : public MetadataAwareOopClosure {
tonyp@3464 185 private:
tonyp@3464 186 G1CollectedHeap* _g1h;
tonyp@3464 187 ConcurrentMark* _cm;
tonyp@3464 188 uint _worker_id;
tonyp@3464 189 public:
tonyp@3464 190 G1RootRegionScanClosure(G1CollectedHeap* g1h, ConcurrentMark* cm,
tonyp@3464 191 uint worker_id) :
tonyp@3464 192 _g1h(g1h), _cm(cm), _worker_id(worker_id) { }
tonyp@3464 193 template <class T> void do_oop_nv(T* p);
tonyp@3464 194 virtual void do_oop( oop* p) { do_oop_nv(p); }
tonyp@3464 195 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
tonyp@3464 196 };
tonyp@3464 197
johnc@3466 198 // Closure that applies the given two closures in sequence.
johnc@3466 199 // Used by the RSet refinement code (when updating RSets
johnc@3466 200 // during an evacuation pause) to record cards containing
johnc@3466 201 // pointers into the collection set.
johnc@3466 202
coleenp@4037 203 class G1Mux2Closure : public ExtendedOopClosure {
johnc@3466 204 OopClosure* _c1;
johnc@3466 205 OopClosure* _c2;
johnc@3466 206 public:
johnc@3466 207 G1Mux2Closure(OopClosure *c1, OopClosure *c2);
johnc@3466 208 template <class T> void do_oop_nv(T* p);
johnc@3466 209 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@3466 210 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@3466 211 };
johnc@3466 212
johnc@3466 213 // A closure that returns true if it is actually applied
johnc@3466 214 // to a reference
johnc@3466 215
coleenp@4037 216 class G1TriggerClosure : public ExtendedOopClosure {
johnc@3466 217 bool _triggered;
johnc@3466 218 public:
johnc@3466 219 G1TriggerClosure();
johnc@3466 220 bool triggered() const { return _triggered; }
johnc@3466 221 template <class T> void do_oop_nv(T* p);
johnc@3466 222 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@3466 223 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@3466 224 };
johnc@3466 225
johnc@3466 226 // A closure which uses a triggering closure to determine
johnc@3466 227 // whether to apply an oop closure.
johnc@3466 228
coleenp@4037 229 class G1InvokeIfNotTriggeredClosure: public ExtendedOopClosure {
johnc@3466 230 G1TriggerClosure* _trigger_cl;
johnc@3466 231 OopClosure* _oop_cl;
johnc@3466 232 public:
johnc@3466 233 G1InvokeIfNotTriggeredClosure(G1TriggerClosure* t, OopClosure* oc);
johnc@3466 234 template <class T> void do_oop_nv(T* p);
johnc@3466 235 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@3466 236 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@3466 237 };
johnc@3466 238
coleenp@4037 239 class G1UpdateRSOrPushRefOopClosure: public ExtendedOopClosure {
johnc@3466 240 G1CollectedHeap* _g1;
johnc@3466 241 G1RemSet* _g1_rem_set;
johnc@3466 242 HeapRegion* _from;
johnc@3466 243 OopsInHeapRegionClosure* _push_ref_cl;
johnc@3466 244 bool _record_refs_into_cset;
vkempik@6552 245 uint _worker_i;
johnc@3466 246
johnc@3466 247 public:
johnc@3466 248 G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
johnc@3466 249 G1RemSet* rs,
johnc@3466 250 OopsInHeapRegionClosure* push_ref_cl,
johnc@3466 251 bool record_refs_into_cset,
vkempik@6552 252 uint worker_i = 0);
johnc@3466 253
johnc@3466 254 void set_from(HeapRegion* from) {
johnc@3466 255 assert(from != NULL, "from region must be non-NULL");
johnc@3466 256 _from = from;
johnc@3466 257 }
johnc@3466 258
johnc@3466 259 bool self_forwarded(oop obj) {
tschatzl@7651 260 markOop m = obj->mark();
tschatzl@7651 261 bool result = (m->is_marked() && ((oop)m->decode_pointer() == obj));
johnc@3466 262 return result;
johnc@3466 263 }
johnc@3466 264
johnc@3466 265 bool apply_to_weak_ref_discovered_field() { return true; }
johnc@3466 266
johnc@3466 267 template <class T> void do_oop_nv(T* p);
johnc@3466 268 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@3466 269 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@3466 270 };
johnc@3466 271
stefank@2314 272 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1OOPCLOSURES_HPP

mercurial