src/share/vm/gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP
aoqi@0 27
aoqi@0 28 #include "memory/genOopClosures.hpp"
aoqi@0 29
aoqi@0 30 /////////////////////////////////////////////////////////////////
aoqi@0 31 // Closures used by ConcurrentMarkSweepGeneration's collector
aoqi@0 32 /////////////////////////////////////////////////////////////////
aoqi@0 33 class ConcurrentMarkSweepGeneration;
aoqi@0 34 class CMSBitMap;
aoqi@0 35 class CMSMarkStack;
aoqi@0 36 class CMSCollector;
aoqi@0 37 class MarkFromRootsClosure;
aoqi@0 38 class Par_MarkFromRootsClosure;
aoqi@0 39
aoqi@0 40 // Decode the oop and call do_oop on it.
aoqi@0 41 #define DO_OOP_WORK_DEFN \
aoqi@0 42 void do_oop(oop obj); \
aoqi@0 43 template <class T> inline void do_oop_work(T* p) { \
aoqi@0 44 T heap_oop = oopDesc::load_heap_oop(p); \
aoqi@0 45 if (!oopDesc::is_null(heap_oop)) { \
aoqi@0 46 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); \
aoqi@0 47 do_oop(obj); \
aoqi@0 48 } \
aoqi@0 49 }
aoqi@0 50
aoqi@0 51 // Applies the given oop closure to all oops in all klasses visited.
aoqi@0 52 class CMKlassClosure : public KlassClosure {
aoqi@0 53 friend class CMSOopClosure;
aoqi@0 54 friend class CMSOopsInGenClosure;
aoqi@0 55
aoqi@0 56 OopClosure* _oop_closure;
aoqi@0 57
aoqi@0 58 // Used when _oop_closure couldn't be set in an initialization list.
aoqi@0 59 void initialize(OopClosure* oop_closure) {
aoqi@0 60 assert(_oop_closure == NULL, "Should only be called once");
aoqi@0 61 _oop_closure = oop_closure;
aoqi@0 62 }
aoqi@0 63 public:
aoqi@0 64 CMKlassClosure(OopClosure* oop_closure = NULL) : _oop_closure(oop_closure) { }
aoqi@0 65
aoqi@0 66 void do_klass(Klass* k);
aoqi@0 67 };
aoqi@0 68
aoqi@0 69 // The base class for all CMS marking closures.
aoqi@0 70 // It's used to proxy through the metadata to the oops defined in them.
aoqi@0 71 class CMSOopClosure: public ExtendedOopClosure {
aoqi@0 72 CMKlassClosure _klass_closure;
aoqi@0 73 public:
aoqi@0 74 CMSOopClosure() : ExtendedOopClosure() {
aoqi@0 75 _klass_closure.initialize(this);
aoqi@0 76 }
aoqi@0 77 CMSOopClosure(ReferenceProcessor* rp) : ExtendedOopClosure(rp) {
aoqi@0 78 _klass_closure.initialize(this);
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 virtual bool do_metadata() { return do_metadata_nv(); }
aoqi@0 82 inline bool do_metadata_nv() { return true; }
aoqi@0 83
aoqi@0 84 virtual void do_klass(Klass* k);
aoqi@0 85 void do_klass_nv(Klass* k);
aoqi@0 86
aoqi@0 87 virtual void do_class_loader_data(ClassLoaderData* cld);
aoqi@0 88 };
aoqi@0 89
aoqi@0 90 // TODO: This duplication of the CMSOopClosure class is only needed because
aoqi@0 91 // some CMS OopClosures derive from OopsInGenClosure. It would be good
aoqi@0 92 // to get rid of them completely.
aoqi@0 93 class CMSOopsInGenClosure: public OopsInGenClosure {
aoqi@0 94 CMKlassClosure _klass_closure;
aoqi@0 95 public:
aoqi@0 96 CMSOopsInGenClosure() {
aoqi@0 97 _klass_closure.initialize(this);
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 virtual bool do_metadata() { return do_metadata_nv(); }
aoqi@0 101 inline bool do_metadata_nv() { return true; }
aoqi@0 102
aoqi@0 103 virtual void do_klass(Klass* k);
aoqi@0 104 void do_klass_nv(Klass* k);
aoqi@0 105
aoqi@0 106 virtual void do_class_loader_data(ClassLoaderData* cld);
aoqi@0 107 };
aoqi@0 108
aoqi@0 109 class MarkRefsIntoClosure: public CMSOopsInGenClosure {
aoqi@0 110 private:
aoqi@0 111 const MemRegion _span;
aoqi@0 112 CMSBitMap* _bitMap;
aoqi@0 113 protected:
aoqi@0 114 DO_OOP_WORK_DEFN
aoqi@0 115 public:
aoqi@0 116 MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap);
aoqi@0 117 virtual void do_oop(oop* p);
aoqi@0 118 virtual void do_oop(narrowOop* p);
aoqi@0 119
aoqi@0 120 Prefetch::style prefetch_style() {
aoqi@0 121 return Prefetch::do_read;
aoqi@0 122 }
aoqi@0 123 };
aoqi@0 124
aoqi@0 125 class Par_MarkRefsIntoClosure: public CMSOopsInGenClosure {
aoqi@0 126 private:
aoqi@0 127 const MemRegion _span;
aoqi@0 128 CMSBitMap* _bitMap;
aoqi@0 129 protected:
aoqi@0 130 DO_OOP_WORK_DEFN
aoqi@0 131 public:
aoqi@0 132 Par_MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap);
aoqi@0 133 virtual void do_oop(oop* p);
aoqi@0 134 virtual void do_oop(narrowOop* p);
aoqi@0 135
aoqi@0 136 Prefetch::style prefetch_style() {
aoqi@0 137 return Prefetch::do_read;
aoqi@0 138 }
aoqi@0 139 };
aoqi@0 140
aoqi@0 141 // A variant of the above used in certain kinds of CMS
aoqi@0 142 // marking verification.
aoqi@0 143 class MarkRefsIntoVerifyClosure: public CMSOopsInGenClosure {
aoqi@0 144 private:
aoqi@0 145 const MemRegion _span;
aoqi@0 146 CMSBitMap* _verification_bm;
aoqi@0 147 CMSBitMap* _cms_bm;
aoqi@0 148 protected:
aoqi@0 149 DO_OOP_WORK_DEFN
aoqi@0 150 public:
aoqi@0 151 MarkRefsIntoVerifyClosure(MemRegion span, CMSBitMap* verification_bm,
aoqi@0 152 CMSBitMap* cms_bm);
aoqi@0 153 virtual void do_oop(oop* p);
aoqi@0 154 virtual void do_oop(narrowOop* p);
aoqi@0 155
aoqi@0 156 Prefetch::style prefetch_style() {
aoqi@0 157 return Prefetch::do_read;
aoqi@0 158 }
aoqi@0 159 };
aoqi@0 160
aoqi@0 161 // The non-parallel version (the parallel version appears further below).
aoqi@0 162 class PushAndMarkClosure: public CMSOopClosure {
aoqi@0 163 private:
aoqi@0 164 CMSCollector* _collector;
aoqi@0 165 MemRegion _span;
aoqi@0 166 CMSBitMap* _bit_map;
aoqi@0 167 CMSBitMap* _mod_union_table;
aoqi@0 168 CMSMarkStack* _mark_stack;
aoqi@0 169 bool _concurrent_precleaning;
aoqi@0 170 protected:
aoqi@0 171 DO_OOP_WORK_DEFN
aoqi@0 172 public:
aoqi@0 173 PushAndMarkClosure(CMSCollector* collector,
aoqi@0 174 MemRegion span,
aoqi@0 175 ReferenceProcessor* rp,
aoqi@0 176 CMSBitMap* bit_map,
aoqi@0 177 CMSBitMap* mod_union_table,
aoqi@0 178 CMSMarkStack* mark_stack,
aoqi@0 179 bool concurrent_precleaning);
aoqi@0 180 virtual void do_oop(oop* p);
aoqi@0 181 virtual void do_oop(narrowOop* p);
aoqi@0 182 inline void do_oop_nv(oop* p) { PushAndMarkClosure::do_oop_work(p); }
aoqi@0 183 inline void do_oop_nv(narrowOop* p) { PushAndMarkClosure::do_oop_work(p); }
aoqi@0 184
aoqi@0 185 Prefetch::style prefetch_style() {
aoqi@0 186 return Prefetch::do_read;
aoqi@0 187 }
aoqi@0 188 };
aoqi@0 189
aoqi@0 190 // In the parallel case, the bit map and the
aoqi@0 191 // reference processor are currently all shared. Access to
aoqi@0 192 // these shared mutable structures must use appropriate
aoqi@0 193 // synchronization (for instance, via CAS). The marking stack
aoqi@0 194 // used in the non-parallel case above is here replaced with
aoqi@0 195 // an OopTaskQueue structure to allow efficient work stealing.
aoqi@0 196 class Par_PushAndMarkClosure: public CMSOopClosure {
aoqi@0 197 private:
aoqi@0 198 CMSCollector* _collector;
aoqi@0 199 MemRegion _span;
aoqi@0 200 CMSBitMap* _bit_map;
aoqi@0 201 OopTaskQueue* _work_queue;
aoqi@0 202 protected:
aoqi@0 203 DO_OOP_WORK_DEFN
aoqi@0 204 public:
aoqi@0 205 Par_PushAndMarkClosure(CMSCollector* collector,
aoqi@0 206 MemRegion span,
aoqi@0 207 ReferenceProcessor* rp,
aoqi@0 208 CMSBitMap* bit_map,
aoqi@0 209 OopTaskQueue* work_queue);
aoqi@0 210 virtual void do_oop(oop* p);
aoqi@0 211 virtual void do_oop(narrowOop* p);
aoqi@0 212 inline void do_oop_nv(oop* p) { Par_PushAndMarkClosure::do_oop_work(p); }
aoqi@0 213 inline void do_oop_nv(narrowOop* p) { Par_PushAndMarkClosure::do_oop_work(p); }
aoqi@0 214
aoqi@0 215 Prefetch::style prefetch_style() {
aoqi@0 216 return Prefetch::do_read;
aoqi@0 217 }
aoqi@0 218 };
aoqi@0 219
aoqi@0 220 // The non-parallel version (the parallel version appears further below).
aoqi@0 221 class MarkRefsIntoAndScanClosure: public CMSOopsInGenClosure {
aoqi@0 222 private:
aoqi@0 223 MemRegion _span;
aoqi@0 224 CMSBitMap* _bit_map;
aoqi@0 225 CMSMarkStack* _mark_stack;
aoqi@0 226 PushAndMarkClosure _pushAndMarkClosure;
aoqi@0 227 CMSCollector* _collector;
aoqi@0 228 Mutex* _freelistLock;
aoqi@0 229 bool _yield;
aoqi@0 230 // Whether closure is being used for concurrent precleaning
aoqi@0 231 bool _concurrent_precleaning;
aoqi@0 232 protected:
aoqi@0 233 DO_OOP_WORK_DEFN
aoqi@0 234 public:
aoqi@0 235 MarkRefsIntoAndScanClosure(MemRegion span,
aoqi@0 236 ReferenceProcessor* rp,
aoqi@0 237 CMSBitMap* bit_map,
aoqi@0 238 CMSBitMap* mod_union_table,
aoqi@0 239 CMSMarkStack* mark_stack,
aoqi@0 240 CMSCollector* collector,
aoqi@0 241 bool should_yield,
aoqi@0 242 bool concurrent_precleaning);
aoqi@0 243 virtual void do_oop(oop* p);
aoqi@0 244 virtual void do_oop(narrowOop* p);
aoqi@0 245 inline void do_oop_nv(oop* p) { MarkRefsIntoAndScanClosure::do_oop_work(p); }
aoqi@0 246 inline void do_oop_nv(narrowOop* p) { MarkRefsIntoAndScanClosure::do_oop_work(p); }
aoqi@0 247
aoqi@0 248 Prefetch::style prefetch_style() {
aoqi@0 249 return Prefetch::do_read;
aoqi@0 250 }
aoqi@0 251 void set_freelistLock(Mutex* m) {
aoqi@0 252 _freelistLock = m;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 private:
aoqi@0 256 inline void do_yield_check();
aoqi@0 257 void do_yield_work();
aoqi@0 258 bool take_from_overflow_list();
aoqi@0 259 };
aoqi@0 260
aoqi@0 261 // Tn this, the parallel avatar of MarkRefsIntoAndScanClosure, the revisit
aoqi@0 262 // stack and the bitMap are shared, so access needs to be suitably
aoqi@0 263 // sycnhronized. An OopTaskQueue structure, supporting efficient
aoqi@0 264 // workstealing, replaces a CMSMarkStack for storing grey objects.
aoqi@0 265 class Par_MarkRefsIntoAndScanClosure: public CMSOopsInGenClosure {
aoqi@0 266 private:
aoqi@0 267 MemRegion _span;
aoqi@0 268 CMSBitMap* _bit_map;
aoqi@0 269 OopTaskQueue* _work_queue;
aoqi@0 270 const uint _low_water_mark;
aoqi@0 271 Par_PushAndMarkClosure _par_pushAndMarkClosure;
aoqi@0 272 protected:
aoqi@0 273 DO_OOP_WORK_DEFN
aoqi@0 274 public:
aoqi@0 275 Par_MarkRefsIntoAndScanClosure(CMSCollector* collector,
aoqi@0 276 MemRegion span,
aoqi@0 277 ReferenceProcessor* rp,
aoqi@0 278 CMSBitMap* bit_map,
aoqi@0 279 OopTaskQueue* work_queue);
aoqi@0 280 virtual void do_oop(oop* p);
aoqi@0 281 virtual void do_oop(narrowOop* p);
aoqi@0 282 inline void do_oop_nv(oop* p) { Par_MarkRefsIntoAndScanClosure::do_oop_work(p); }
aoqi@0 283 inline void do_oop_nv(narrowOop* p) { Par_MarkRefsIntoAndScanClosure::do_oop_work(p); }
aoqi@0 284
aoqi@0 285 Prefetch::style prefetch_style() {
aoqi@0 286 return Prefetch::do_read;
aoqi@0 287 }
aoqi@0 288 void trim_queue(uint size);
aoqi@0 289 };
aoqi@0 290
aoqi@0 291 // This closure is used during the concurrent marking phase
aoqi@0 292 // following the first checkpoint. Its use is buried in
aoqi@0 293 // the closure MarkFromRootsClosure.
aoqi@0 294 class PushOrMarkClosure: public CMSOopClosure {
aoqi@0 295 private:
aoqi@0 296 CMSCollector* _collector;
aoqi@0 297 MemRegion _span;
aoqi@0 298 CMSBitMap* _bitMap;
aoqi@0 299 CMSMarkStack* _markStack;
aoqi@0 300 HeapWord* const _finger;
aoqi@0 301 MarkFromRootsClosure* const
aoqi@0 302 _parent;
aoqi@0 303 protected:
aoqi@0 304 DO_OOP_WORK_DEFN
aoqi@0 305 public:
aoqi@0 306 PushOrMarkClosure(CMSCollector* cms_collector,
aoqi@0 307 MemRegion span,
aoqi@0 308 CMSBitMap* bitMap,
aoqi@0 309 CMSMarkStack* markStack,
aoqi@0 310 HeapWord* finger,
aoqi@0 311 MarkFromRootsClosure* parent);
aoqi@0 312 virtual void do_oop(oop* p);
aoqi@0 313 virtual void do_oop(narrowOop* p);
aoqi@0 314 inline void do_oop_nv(oop* p) { PushOrMarkClosure::do_oop_work(p); }
aoqi@0 315 inline void do_oop_nv(narrowOop* p) { PushOrMarkClosure::do_oop_work(p); }
aoqi@0 316
aoqi@0 317 // Deal with a stack overflow condition
aoqi@0 318 void handle_stack_overflow(HeapWord* lost);
aoqi@0 319 private:
aoqi@0 320 inline void do_yield_check();
aoqi@0 321 };
aoqi@0 322
aoqi@0 323 // A parallel (MT) version of the above.
aoqi@0 324 // This closure is used during the concurrent marking phase
aoqi@0 325 // following the first checkpoint. Its use is buried in
aoqi@0 326 // the closure Par_MarkFromRootsClosure.
aoqi@0 327 class Par_PushOrMarkClosure: public CMSOopClosure {
aoqi@0 328 private:
aoqi@0 329 CMSCollector* _collector;
aoqi@0 330 MemRegion _whole_span;
aoqi@0 331 MemRegion _span; // local chunk
aoqi@0 332 CMSBitMap* _bit_map;
aoqi@0 333 OopTaskQueue* _work_queue;
aoqi@0 334 CMSMarkStack* _overflow_stack;
aoqi@0 335 HeapWord* const _finger;
aoqi@0 336 HeapWord** const _global_finger_addr;
aoqi@0 337 Par_MarkFromRootsClosure* const
aoqi@0 338 _parent;
aoqi@0 339 protected:
aoqi@0 340 DO_OOP_WORK_DEFN
aoqi@0 341 public:
aoqi@0 342 Par_PushOrMarkClosure(CMSCollector* cms_collector,
aoqi@0 343 MemRegion span,
aoqi@0 344 CMSBitMap* bit_map,
aoqi@0 345 OopTaskQueue* work_queue,
aoqi@0 346 CMSMarkStack* mark_stack,
aoqi@0 347 HeapWord* finger,
aoqi@0 348 HeapWord** global_finger_addr,
aoqi@0 349 Par_MarkFromRootsClosure* parent);
aoqi@0 350 virtual void do_oop(oop* p);
aoqi@0 351 virtual void do_oop(narrowOop* p);
aoqi@0 352 inline void do_oop_nv(oop* p) { Par_PushOrMarkClosure::do_oop_work(p); }
aoqi@0 353 inline void do_oop_nv(narrowOop* p) { Par_PushOrMarkClosure::do_oop_work(p); }
aoqi@0 354
aoqi@0 355 // Deal with a stack overflow condition
aoqi@0 356 void handle_stack_overflow(HeapWord* lost);
aoqi@0 357 private:
aoqi@0 358 inline void do_yield_check();
aoqi@0 359 };
aoqi@0 360
aoqi@0 361 // For objects in CMS generation, this closure marks
aoqi@0 362 // given objects (transitively) as being reachable/live.
aoqi@0 363 // This is currently used during the (weak) reference object
aoqi@0 364 // processing phase of the CMS final checkpoint step, as
aoqi@0 365 // well as during the concurrent precleaning of the discovered
aoqi@0 366 // reference lists.
aoqi@0 367 class CMSKeepAliveClosure: public CMSOopClosure {
aoqi@0 368 private:
aoqi@0 369 CMSCollector* _collector;
aoqi@0 370 const MemRegion _span;
aoqi@0 371 CMSMarkStack* _mark_stack;
aoqi@0 372 CMSBitMap* _bit_map;
aoqi@0 373 bool _concurrent_precleaning;
aoqi@0 374 protected:
aoqi@0 375 DO_OOP_WORK_DEFN
aoqi@0 376 public:
aoqi@0 377 CMSKeepAliveClosure(CMSCollector* collector, MemRegion span,
aoqi@0 378 CMSBitMap* bit_map, CMSMarkStack* mark_stack,
aoqi@0 379 bool cpc);
aoqi@0 380 bool concurrent_precleaning() const { return _concurrent_precleaning; }
aoqi@0 381 virtual void do_oop(oop* p);
aoqi@0 382 virtual void do_oop(narrowOop* p);
aoqi@0 383 inline void do_oop_nv(oop* p) { CMSKeepAliveClosure::do_oop_work(p); }
aoqi@0 384 inline void do_oop_nv(narrowOop* p) { CMSKeepAliveClosure::do_oop_work(p); }
aoqi@0 385 };
aoqi@0 386
aoqi@0 387 class CMSInnerParMarkAndPushClosure: public CMSOopClosure {
aoqi@0 388 private:
aoqi@0 389 CMSCollector* _collector;
aoqi@0 390 MemRegion _span;
aoqi@0 391 OopTaskQueue* _work_queue;
aoqi@0 392 CMSBitMap* _bit_map;
aoqi@0 393 protected:
aoqi@0 394 DO_OOP_WORK_DEFN
aoqi@0 395 public:
aoqi@0 396 CMSInnerParMarkAndPushClosure(CMSCollector* collector,
aoqi@0 397 MemRegion span, CMSBitMap* bit_map,
aoqi@0 398 OopTaskQueue* work_queue);
aoqi@0 399 virtual void do_oop(oop* p);
aoqi@0 400 virtual void do_oop(narrowOop* p);
aoqi@0 401 inline void do_oop_nv(oop* p) { CMSInnerParMarkAndPushClosure::do_oop_work(p); }
aoqi@0 402 inline void do_oop_nv(narrowOop* p) { CMSInnerParMarkAndPushClosure::do_oop_work(p); }
aoqi@0 403 };
aoqi@0 404
aoqi@0 405 // A parallel (MT) version of the above, used when
aoqi@0 406 // reference processing is parallel; the only difference
aoqi@0 407 // is in the do_oop method.
aoqi@0 408 class CMSParKeepAliveClosure: public CMSOopClosure {
aoqi@0 409 private:
aoqi@0 410 MemRegion _span;
aoqi@0 411 OopTaskQueue* _work_queue;
aoqi@0 412 CMSBitMap* _bit_map;
aoqi@0 413 CMSInnerParMarkAndPushClosure
aoqi@0 414 _mark_and_push;
aoqi@0 415 const uint _low_water_mark;
aoqi@0 416 void trim_queue(uint max);
aoqi@0 417 protected:
aoqi@0 418 DO_OOP_WORK_DEFN
aoqi@0 419 public:
aoqi@0 420 CMSParKeepAliveClosure(CMSCollector* collector, MemRegion span,
aoqi@0 421 CMSBitMap* bit_map, OopTaskQueue* work_queue);
aoqi@0 422 virtual void do_oop(oop* p);
aoqi@0 423 virtual void do_oop(narrowOop* p);
aoqi@0 424 };
aoqi@0 425
aoqi@0 426 #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP

mercurial