1 /* 2 * Copyright (c) 2015, 2017, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_INLINE_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_INLINE_HPP 26 27 #include "classfile/javaClasses.inline.hpp" 28 #include "gc/g1/suspendibleThreadSet.hpp" 29 #include "gc/shared/markBitMap.inline.hpp" 30 #include "gc/shared/threadLocalAllocBuffer.inline.hpp" 31 #include "gc/shenandoah/brooksPointer.inline.hpp" 32 #include "gc/shenandoah/shenandoahBarrierSet.inline.hpp" 33 #include "gc/shenandoah/shenandoahCollectionSet.hpp" 34 #include "gc/shenandoah/shenandoahCollectionSet.inline.hpp" 35 #include "gc/shenandoah/shenandoahConnectionMatrix.inline.hpp" 36 #include "gc/shenandoah/shenandoahHeap.hpp" 37 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" 38 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp" 39 #include "gc/shenandoah/shenandoahStringDedup.hpp" 40 #include "gc/shenandoah/shenandoahUtils.hpp" 41 #include "oops/oop.inline.hpp" 42 #include "runtime/atomic.hpp" 43 #include "runtime/interfaceSupport.hpp" 44 #include "runtime/prefetch.hpp" 45 #include "runtime/prefetch.inline.hpp" 46 #include "runtime/thread.hpp" 47 #include "utilities/copy.hpp" 48 49 template <class T> 50 void ShenandoahUpdateRefsClosure::do_oop_work(T* p) { 51 T o = oopDesc::load_heap_oop(p); 52 if (! oopDesc::is_null(o)) { 53 oop obj = oopDesc::decode_heap_oop_not_null(o); 54 _heap->update_oop_ref_not_null(p, obj); 55 } 56 } 57 58 void ShenandoahUpdateRefsClosure::do_oop(oop* p) { do_oop_work(p); } 59 void ShenandoahUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); } 60 61 /* 62 * Marks the object. Returns true if the object has not been marked before and has 63 * been marked by this thread. Returns false if the object has already been marked, 64 * or if a competing thread succeeded in marking this object. 65 */ 66 inline bool ShenandoahHeap::mark(oop obj) const { 67 #ifdef ASSERT 68 if (! oopDesc::unsafe_equals(obj, oopDesc::bs()->read_barrier(obj))) { 69 tty->print_cr("heap region containing obj:"); 70 ShenandoahHeapRegion* obj_region = heap_region_containing(obj); 71 obj_region->print(); 72 tty->print_cr("heap region containing forwardee:"); 73 ShenandoahHeapRegion* forward_region = heap_region_containing(oopDesc::bs()->read_barrier(obj)); 74 forward_region->print(); 75 } 76 #endif 77 78 assert(oopDesc::unsafe_equals(obj, oopDesc::bs()->read_barrier(obj)), "only mark forwarded copy of objects"); 79 return mark_no_checks(obj); 80 } 81 82 inline bool ShenandoahHeap::mark_no_checks(oop obj) const { 83 HeapWord* addr = (HeapWord*) obj; 84 return (! allocated_after_mark_start(addr)) && _mark_bit_map->parMark(addr); 85 } 86 87 inline bool ShenandoahHeap::is_marked(oop obj) const { 88 HeapWord* addr = (HeapWord*) obj; 89 return allocated_after_mark_start(addr) || _mark_bit_map->isMarked(addr); 90 } 91 92 inline bool ShenandoahHeap::need_update_refs() const { 93 return _need_update_refs; 94 } 95 96 inline size_t ShenandoahHeap::heap_region_index_containing(const void* addr) const { 97 uintptr_t region_start = ((uintptr_t) addr); 98 uintptr_t index = (region_start - (uintptr_t) base()) >> ShenandoahHeapRegion::region_size_bytes_shift(); 99 #ifdef ASSERT 100 if (index >= num_regions()) { 101 tty->print_cr("heap region does not contain address, heap base: "PTR_FORMAT \ 102 ", real bottom of first region: "PTR_FORMAT", num_regions: "SIZE_FORMAT", region_size: "SIZE_FORMAT, 103 p2i(base()), 104 p2i(_ordered_regions->get(0)->bottom()), 105 num_regions(), 106 ShenandoahHeapRegion::region_size_bytes()); 107 } 108 #endif 109 assert(index < num_regions(), "heap region index must be in range"); 110 return index; 111 } 112 113 inline ShenandoahHeapRegion* ShenandoahHeap::heap_region_containing(const void* addr) const { 114 size_t index = heap_region_index_containing(addr); 115 ShenandoahHeapRegion* result = _ordered_regions->get(index); 116 #ifdef ASSERT 117 if (!(addr >= result->bottom() && addr < result->end())) { 118 tty->print_cr("heap region does not contain address, heap base: "PTR_FORMAT \ 119 ", real bottom of first region: "PTR_FORMAT", num_regions: "SIZE_FORMAT, 120 p2i(base()), 121 p2i(_ordered_regions->get(0)->bottom()), 122 num_regions()); 123 } 124 #endif 125 assert(addr >= result->bottom() && addr < result->end(), "address must be in found region"); 126 return result; 127 } 128 129 template <class T> 130 inline oop ShenandoahHeap::update_oop_ref_not_null(T* p, oop obj) { 131 if (in_collection_set(obj)) { 132 oop forw = ShenandoahBarrierSet::resolve_oop_static_not_null(obj); 133 assert(! oopDesc::unsafe_equals(forw, obj) || is_full_gc_in_progress() || cancelled_concgc(), "expect forwarded object"); 134 obj = forw; 135 oopDesc::encode_store_heap_oop(p, obj); 136 } 137 #ifdef ASSERT 138 else { 139 assert(oopDesc::unsafe_equals(obj, ShenandoahBarrierSet::resolve_oop_static_not_null(obj)), "expect not forwarded"); 140 } 141 #endif 142 return obj; 143 } 144 145 template <class T> 146 inline oop ShenandoahHeap::maybe_update_oop_ref(T* p) { 147 T o = oopDesc::load_heap_oop(p); 148 if (! oopDesc::is_null(o)) { 149 oop obj = oopDesc::decode_heap_oop_not_null(o); 150 return maybe_update_oop_ref_not_null(p, obj); 151 } else { 152 return NULL; 153 } 154 } 155 156 inline oop ShenandoahHeap::atomic_compare_exchange_oop(oop n, oop* addr, oop c) { 157 return (oop) Atomic::cmpxchg_ptr(n, addr, c); 158 } 159 160 inline oop ShenandoahHeap::atomic_compare_exchange_oop(oop n, narrowOop* addr, oop c) { 161 narrowOop cmp = oopDesc::encode_heap_oop(c); 162 narrowOop val = oopDesc::encode_heap_oop(n); 163 return oopDesc::decode_heap_oop((narrowOop) Atomic::cmpxchg(val, addr, cmp)); 164 } 165 166 template <class T> 167 inline oop ShenandoahHeap::maybe_update_oop_ref_not_null(T* p, oop heap_oop) { 168 169 assert((! is_in(p)) || (! in_collection_set(p)) 170 || is_full_gc_in_progress(), 171 "never update refs in from-space, unless evacuation has been cancelled"); 172 173 #ifdef ASSERT 174 if (! is_in(heap_oop)) { 175 print_heap_regions_on(tty); 176 tty->print_cr("object not in heap: "PTR_FORMAT", referenced by: "PTR_FORMAT, p2i((HeapWord*) heap_oop), p2i(p)); 177 assert(is_in(heap_oop), "object must be in heap"); 178 } 179 #endif 180 assert(is_in(heap_oop), "only ever call this on objects in the heap"); 181 if (in_collection_set(heap_oop)) { 182 oop forwarded_oop = ShenandoahBarrierSet::resolve_oop_static_not_null(heap_oop); // read brooks ptr 183 if (oopDesc::unsafe_equals(forwarded_oop, heap_oop)) { 184 // E.g. during evacuation. 185 return forwarded_oop; 186 } 187 188 assert(! oopDesc::unsafe_equals(forwarded_oop, heap_oop) || is_full_gc_in_progress(), "expect forwarded object"); 189 190 log_develop_trace(gc)("Updating old ref: "PTR_FORMAT" pointing to "PTR_FORMAT" to new ref: "PTR_FORMAT, 191 p2i(p), p2i(heap_oop), p2i(forwarded_oop)); 192 193 assert(oopDesc::is_oop(forwarded_oop), "oop required"); 194 assert(is_in(forwarded_oop), "forwardee must be in heap"); 195 assert(oopDesc::bs()->is_safe(forwarded_oop), "forwardee must not be in collection set"); 196 // If this fails, another thread wrote to p before us, it will be logged in SATB and the 197 // reference be updated later. 198 oop result = atomic_compare_exchange_oop(forwarded_oop, p, heap_oop); 199 200 if (oopDesc::unsafe_equals(result, heap_oop)) { // CAS successful. 201 return forwarded_oop; 202 } else { 203 // Note: we used to assert the following here. This doesn't work because sometimes, during 204 // marking/updating-refs, it can happen that a Java thread beats us with an arraycopy, 205 // which first copies the array, which potentially contains from-space refs, and only afterwards 206 // updates all from-space refs to to-space refs, which leaves a short window where the new array 207 // elements can be from-space. 208 // assert(oopDesc::is_null(result) || 209 // oopDesc::unsafe_equals(result, ShenandoahBarrierSet::resolve_oop_static_not_null(result)), 210 // "expect not forwarded"); 211 return NULL; 212 } 213 } else { 214 assert(oopDesc::unsafe_equals(heap_oop, ShenandoahBarrierSet::resolve_oop_static_not_null(heap_oop)), 215 "expect not forwarded"); 216 return heap_oop; 217 } 218 } 219 220 inline bool ShenandoahHeap::cancelled_concgc() const { 221 return OrderAccess::load_acquire((jbyte*) &_cancelled_concgc) == CANCELLED; 222 } 223 224 inline bool ShenandoahHeap::check_cancelled_concgc_and_yield(bool sts_active) { 225 if (! (sts_active && ShenandoahSuspendibleWorkers)) { 226 return cancelled_concgc(); 227 } 228 jbyte prev = Atomic::cmpxchg((jbyte)NOT_CANCELLED, &_cancelled_concgc, (jbyte)CANCELLABLE); 229 if (prev == CANCELLABLE || prev == NOT_CANCELLED) { 230 231 if (SuspendibleThreadSet::should_yield()) { 232 SuspendibleThreadSet::yield(); 233 } 234 235 // Back to CANCELLABLE. The thread that poked NOT_CANCELLED first gets 236 // to restore to CANCELLABLE. 237 if (prev == CANCELLABLE) { 238 OrderAccess::release_store_fence(&_cancelled_concgc, CANCELLABLE); 239 } 240 return false; 241 } else { 242 return true; 243 } 244 } 245 246 inline bool ShenandoahHeap::try_cancel_concgc() { 247 while (true) { 248 jbyte prev = Atomic::cmpxchg((jbyte)CANCELLED, &_cancelled_concgc, (jbyte)CANCELLABLE); 249 if (prev == CANCELLABLE) return true; 250 else if (prev == CANCELLED) return false; 251 assert(ShenandoahSuspendibleWorkers, "should not get here when not using suspendible workers"); 252 assert(prev == NOT_CANCELLED, "must be NOT_CANCELLED"); 253 { 254 // We need to provide a safepoint here, otherwise we might 255 // spin forever if a SP is pending. 256 ThreadBlockInVM sp(JavaThread::current()); 257 SpinPause(); 258 } 259 } 260 } 261 262 inline void ShenandoahHeap::clear_cancelled_concgc() { 263 OrderAccess::release_store_fence(&_cancelled_concgc, CANCELLABLE); 264 } 265 266 inline HeapWord* ShenandoahHeap::allocate_from_gclab(Thread* thread, size_t size) { 267 if (UseTLAB) { 268 if (!thread->gclab().is_initialized()) { 269 assert(!thread->is_Java_thread() && !thread->is_Worker_thread(), 270 "Performance: thread should have GCLAB: %s", thread->name()); 271 // No GCLABs in this thread, fallback to shared allocation 272 return NULL; 273 } 274 HeapWord* obj = thread->gclab().allocate(size); 275 if (obj != NULL) { 276 return obj; 277 } 278 // Otherwise... 279 return allocate_from_gclab_slow(thread, size); 280 } else { 281 return NULL; 282 } 283 } 284 285 inline oop ShenandoahHeap::evacuate_object(oop p, Thread* thread, bool& evacuated) { 286 evacuated = false; 287 288 size_t size_no_fwdptr = (size_t) p->size(); 289 size_t size_with_fwdptr = size_no_fwdptr + BrooksPointer::word_size(); 290 291 assert(!heap_region_containing(p)->is_humongous(), "never evacuate humongous objects"); 292 293 bool alloc_from_gclab = true; 294 HeapWord* filler = allocate_from_gclab(thread, size_with_fwdptr); 295 if (filler == NULL) { 296 filler = allocate_memory(size_with_fwdptr, _alloc_shared_gc); 297 alloc_from_gclab = false; 298 } 299 300 #ifdef ASSERT 301 // Checking that current Java thread does not hold Threads_lock when we get here. 302 // If that ever be the case, we'd deadlock in oom_during_evacuation. 303 if ((! Thread::current()->is_GC_task_thread()) && (! Thread::current()->is_ConcurrentGC_thread())) { 304 assert(! Threads_lock->owned_by_self() 305 || SafepointSynchronize::is_at_safepoint(), "must not hold Threads_lock here"); 306 } 307 #endif 308 309 if (filler == NULL) { 310 oom_during_evacuation(); 311 // If this is a Java thread, it should have waited 312 // until all GC threads are done, and then we 313 // return the forwardee. 314 oop resolved = ShenandoahBarrierSet::resolve_oop_static(p); 315 return resolved; 316 } 317 318 // Copy the object and initialize its forwarding ptr: 319 HeapWord* copy = filler + BrooksPointer::word_size(); 320 oop copy_val = oop(copy); 321 322 Copy::aligned_disjoint_words((HeapWord*) p, copy, size_no_fwdptr); 323 BrooksPointer::initialize(oop(copy)); 324 325 log_develop_trace(gc, compaction)("Copy object: " PTR_FORMAT " -> " PTR_FORMAT, 326 p2i(p), p2i(copy)); 327 328 // String dedup support 329 bool need_str_dedup = false; 330 if (ShenandoahStringDedup::is_enabled() 331 && java_lang_String::is_instance_inlined(copy_val)) { 332 // We need to increase age before CAS to avoid race condition. 333 // Once new copy is published, other threads may set hash code, 334 // or perform locking, etc. which will race age bits manipulation. 335 copy_val->incr_age(); 336 337 need_str_dedup = ShenandoahStringDedup::is_candidate(copy_val); 338 } 339 340 // Try to install the new forwarding pointer. 341 oop result = BrooksPointer::try_update_forwardee(p, copy_val); 342 343 if (oopDesc::unsafe_equals(result, p)) { 344 // Successfully evacuated. Our copy is now the public one! 345 evacuated = true; 346 log_develop_trace(gc, compaction)("Copy object: " PTR_FORMAT " -> " PTR_FORMAT " succeeded", 347 p2i(p), p2i(copy)); 348 349 // Only dedup evacuated string 350 if (need_str_dedup) { 351 // Shenandoah evacuates objects inside and outside of safepoints. 352 // But string dedup protocol requires deduplication outside of safepoints, 353 // so we need to queue candidates during safepoints. 354 if (SafepointSynchronize::is_at_safepoint()) { 355 assert(thread->is_Worker_thread(), "Must be a worker thread during a safepoint"); 356 // Use worker thread id instead of worker_id to avoid passing down worker_id. 357 // This may cause imbalance among the queues, but it is okay, since deduplication is 358 // single threaded. 359 ShenandoahStringDedup::enqueue_from_safepoint(copy_val, thread->as_Worker_thread()->id()); 360 } else { 361 ShenandoahStringDedup::deduplicate(copy_val); 362 } 363 } 364 365 #ifdef ASSERT 366 assert(oopDesc::is_oop(copy_val), "expect oop"); 367 assert(p->klass() == copy_val->klass(), "Should have the same class p: "PTR_FORMAT", copy: "PTR_FORMAT, 368 p2i(p), p2i(copy)); 369 #endif 370 return copy_val; 371 } else { 372 // Failed to evacuate. We need to deal with the object that is left behind. Since this 373 // new allocation is certainly after TAMS, it will be considered live in the next cycle. 374 // But if it happens to contain references to evacuated regions, those references would 375 // not get updated for this stale copy during this cycle, and we will crash while scanning 376 // it the next cycle. 377 // 378 // For GCLAB allocations, it is enough to rollback the allocation ptr. Either the next 379 // object will overwrite this stale copy, or the filler object on LAB retirement will 380 // do this. For non-GCLAB allocations, we have no way to retract the allocation, and 381 // have to explicitly overwrite the copy with the filler object. With that overwrite, 382 // we have to keep the fwdptr initialized and pointing to our (stale) copy. 383 if (alloc_from_gclab) { 384 thread->gclab().rollback(size_with_fwdptr); 385 } else { 386 fill_with_object(copy, size_no_fwdptr); 387 } 388 log_develop_trace(gc, compaction)("Copy object: " PTR_FORMAT " -> " PTR_FORMAT " failed, use other: " PTR_FORMAT, 389 p2i(p), p2i(copy), p2i(result)); 390 return result; 391 } 392 } 393 394 inline bool ShenandoahHeap::requires_marking(const void* entry) const { 395 return ! is_marked(oop(entry)); 396 } 397 398 bool ShenandoahHeap::region_in_collection_set(size_t region_index) const { 399 assert(collection_set() != NULL, "Sanity"); 400 return collection_set()->is_in(region_index); 401 } 402 403 bool ShenandoahHeap::in_collection_set(ShenandoahHeapRegion* r) const { 404 return region_in_collection_set(r->region_number()); 405 } 406 407 template <class T> 408 inline bool ShenandoahHeap::in_collection_set(T p) const { 409 HeapWord* obj = (HeapWord*) p; 410 assert(collection_set() != NULL, "Sanity"); 411 assert(is_in(obj), "should be in heap"); 412 413 return collection_set()->is_in(obj); 414 } 415 416 inline bool ShenandoahHeap::concurrent_mark_in_progress() const { 417 return _concurrent_mark_in_progress != 0; 418 } 419 420 inline address ShenandoahHeap::concurrent_mark_in_progress_addr() { 421 return (address) &(ShenandoahHeap::heap()->_concurrent_mark_in_progress); 422 } 423 424 inline address ShenandoahHeap::update_refs_in_progress_addr() { 425 return (address) &(ShenandoahHeap::heap()->_update_refs_in_progress); 426 } 427 428 inline bool ShenandoahHeap::is_evacuation_in_progress() const { 429 return _evacuation_in_progress != 0; 430 } 431 432 inline address ShenandoahHeap::evacuation_in_progress_addr() { 433 return (address) &(ShenandoahHeap::heap()->_evacuation_in_progress); 434 } 435 436 inline bool ShenandoahHeap::allocated_after_mark_start(HeapWord* addr) const { 437 uintx index = ((uintx) addr) >> ShenandoahHeapRegion::region_size_bytes_shift(); 438 HeapWord* top_at_mark_start = _top_at_mark_starts[index]; 439 bool alloc_after_mark_start = addr >= top_at_mark_start; 440 return alloc_after_mark_start; 441 } 442 443 template<class T> 444 inline void ShenandoahHeap::marked_object_iterate(ShenandoahHeapRegion* region, T* cl) { 445 marked_object_iterate(region, cl, region->top()); 446 } 447 448 template<class T> 449 inline void ShenandoahHeap::marked_object_safe_iterate(ShenandoahHeapRegion* region, T* cl) { 450 marked_object_iterate(region, cl, region->concurrent_iteration_safe_limit()); 451 } 452 453 template<class T> 454 inline void ShenandoahHeap::marked_object_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* limit) { 455 assert(BrooksPointer::word_offset() < 0, "skip_delta calculation below assumes the forwarding ptr is before obj"); 456 457 assert(! region->is_humongous_continuation(), "no humongous continuation regions here"); 458 assert(is_bitmap_valid(), "only try this with complete marking bitmap"); 459 460 MarkBitMap* mark_bit_map = _mark_bit_map; 461 HeapWord* tams = top_at_mark_start(region->bottom()); 462 463 size_t skip_bitmap_delta = BrooksPointer::word_size() + 1; 464 size_t skip_objsize_delta = BrooksPointer::word_size() /* + actual obj.size() below */; 465 HeapWord* start = region->bottom() + BrooksPointer::word_size(); 466 467 HeapWord* end = MIN2(tams + BrooksPointer::word_size(), region->end()); 468 HeapWord* addr = mark_bit_map->getNextMarkedWordAddress(start, end); 469 470 intx dist = ShenandoahMarkScanPrefetch; 471 if (dist > 0) { 472 // Batched scan that prefetches the oop data, anticipating the access to 473 // either header, oop field, or forwarding pointer. Not that we cannot 474 // touch anything in oop, while it still being prefetched to get enough 475 // time for prefetch to work. This is why we try to scan the bitmap linearly, 476 // disregarding the object size. However, since we know forwarding pointer 477 // preceeds the object, we can skip over it. Once we cannot trust the bitmap, 478 // there is no point for prefetching the oop contents, as oop->size() will 479 // touch it prematurely. 480 481 // No variable-length arrays in standard C++, have enough slots to fit 482 // the prefetch distance. 483 static const int SLOT_COUNT = 256; 484 guarantee(dist <= SLOT_COUNT, "adjust slot count"); 485 oop slots[SLOT_COUNT]; 486 487 bool aborting = false; 488 int avail; 489 do { 490 avail = 0; 491 for (int c = 0; (c < dist) && (addr < limit); c++) { 492 Prefetch::read(addr, BrooksPointer::byte_offset()); 493 oop obj = oop(addr); 494 slots[avail++] = obj; 495 if (addr < tams) { 496 addr += skip_bitmap_delta; 497 addr = mark_bit_map->getNextMarkedWordAddress(addr, end); 498 } else { 499 // cannot trust mark bitmap anymore, finish the current stride, 500 // and switch to accurate traversal 501 addr += obj->size() + skip_objsize_delta; 502 aborting = true; 503 } 504 } 505 506 for (int c = 0; c < avail; c++) { 507 do_marked_object(mark_bit_map, cl, slots[c]); 508 } 509 } while (avail > 0 && !aborting); 510 511 // accurate traversal 512 while (addr < limit) { 513 oop obj = oop(addr); 514 int size = obj->size(); 515 do_marked_object(mark_bit_map, cl, obj); 516 addr += size + skip_objsize_delta; 517 } 518 } else { 519 while (addr < limit) { 520 oop obj = oop(addr); 521 int size = obj->size(); 522 do_marked_object(mark_bit_map, cl, obj); 523 addr += size + skip_objsize_delta; 524 if (addr < tams) { 525 addr = mark_bit_map->getNextMarkedWordAddress(addr, end); 526 } 527 } 528 } 529 } 530 531 template<class T> 532 inline void ShenandoahHeap::do_marked_object(MarkBitMap* bitmap, T* cl, oop obj) { 533 assert(!oopDesc::is_null(obj), "sanity"); 534 assert(oopDesc::is_oop(obj), "sanity"); 535 assert(is_in(obj), "sanity"); 536 assert(bitmap == _mark_bit_map, "only iterate completed mark bitmap"); 537 assert(is_marked(obj), "object expected to be marked"); 538 cl->do_object(obj); 539 } 540 541 template <class T> 542 class ShenandoahObjectToOopClosure : public ObjectClosure { 543 T* _cl; 544 public: 545 ShenandoahObjectToOopClosure(T* cl) : _cl(cl) {} 546 547 void do_object(oop obj) { 548 obj->oop_iterate(_cl); 549 } 550 }; 551 552 template <class T> 553 class ShenandoahObjectToOopBoundedClosure : public ObjectClosure { 554 T* _cl; 555 MemRegion _bounds; 556 public: 557 ShenandoahObjectToOopBoundedClosure(T* cl, HeapWord* bottom, HeapWord* top) : 558 _cl(cl), _bounds(bottom, top) {} 559 560 void do_object(oop obj) { 561 obj->oop_iterate(_cl, _bounds); 562 } 563 }; 564 565 template<class T> 566 inline void ShenandoahHeap::marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl, HeapWord* top) { 567 if (region->is_humongous()) { 568 HeapWord* bottom = region->bottom(); 569 if (top > bottom) { 570 region = region->humongous_start_region(); 571 ShenandoahObjectToOopBoundedClosure<T> objs(cl, bottom, top); 572 marked_object_iterate(region, &objs); 573 } 574 } else { 575 ShenandoahObjectToOopClosure<T> objs(cl); 576 marked_object_iterate(region, &objs, top); 577 } 578 } 579 580 template<class T> 581 inline void ShenandoahHeap::marked_object_oop_iterate(ShenandoahHeapRegion* region, T* cl) { 582 marked_object_oop_iterate(region, cl, region->top()); 583 } 584 585 template<class T> 586 inline void ShenandoahHeap::marked_object_oop_safe_iterate(ShenandoahHeapRegion* region, T* cl) { 587 marked_object_oop_iterate(region, cl, region->concurrent_iteration_safe_limit()); 588 } 589 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAP_INLINE_HPP