150 !_heap->marking_context()->is_marked_strong(obj)) {
151 return nullptr;
152 }
153
154 // Allow runtime to see unreachable objects that are visited during concurrent class-unloading.
155 if ((decorators & AS_NO_KEEPALIVE) != 0 &&
156 _heap->is_concurrent_weak_root_in_progress() &&
157 !_heap->marking_context()->is_marked(obj)) {
158 return obj;
159 }
160
161 oop fwd = load_reference_barrier(obj);
162 if (load_addr != nullptr && fwd != obj) {
163 // Since we are here and we know the load address, update the reference.
164 ShenandoahHeap::atomic_update_oop(fwd, load_addr, obj);
165 }
166
167 return fwd;
168 }
169
170 inline void ShenandoahBarrierSet::enqueue(oop obj) {
171 assert(obj != nullptr, "checked by caller");
172 assert(_satb_mark_queue_set.is_active(), "only get here when SATB active");
173
174 // Filter marked objects before hitting the SATB queues. The same predicate would
175 // be used by SATBMQ::filter to eliminate already marked objects downstream, but
176 // filtering here helps to avoid wasteful SATB queueing work to begin with.
177 if (!_heap->requires_marking(obj)) return;
178
179 SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(Thread::current());
180 _satb_mark_queue_set.enqueue_known_active(queue, obj);
181 }
182
183 template <DecoratorSet decorators, typename T>
184 inline void ShenandoahBarrierSet::satb_barrier(T *field) {
185 // Uninitialized and no-keepalive stores do not need barrier.
186 if (HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value ||
187 HasDecorator<decorators, AS_NO_KEEPALIVE>::value) {
188 return;
189 }
190
191 // Stores to weak/phantom require no barrier. The original references would
192 // have been enqueued in the SATB buffer by the load barrier if they were needed.
193 if (HasDecorator<decorators, ON_WEAK_OOP_REF>::value ||
194 HasDecorator<decorators, ON_PHANTOM_OOP_REF>::value) {
195 return;
196 }
197
385 if (ShenandoahCardBarrier) {
386 bs->write_ref_field_post<decorators>(addr);
387 }
388 return result;
389 }
390
391 template <DecoratorSet decorators, typename BarrierSetT>
392 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value) {
393 assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
394 ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
395 DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
396 auto addr = AccessInternal::oop_field_addr<decorators>(base, offset);
397 oop result = bs->oop_xchg(resolved_decorators, addr, new_value);
398 if (ShenandoahCardBarrier) {
399 bs->write_ref_field_post<decorators>(addr);
400 }
401 return result;
402 }
403
404 // Clone barrier support
405 template <DecoratorSet decorators, typename BarrierSetT>
406 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
407 if (ShenandoahCloneBarrier) {
408 ShenandoahBarrierSet::barrier_set()->clone_barrier_runtime(src);
409 }
410 Raw::clone(src, dst, size);
411 }
412
413 template <DecoratorSet decorators, typename BarrierSetT>
414 template <typename T>
415 OopCopyResult ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
416 arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
417 size_t length) {
418 T* src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
419 T* dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
420
421 ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
422 bs->arraycopy_barrier(src, dst, length);
423 OopCopyResult result = Raw::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
424 if (ShenandoahCardBarrier) {
425 bs->write_ref_array((HeapWord*) dst, length);
426 }
427 return result;
428 }
429
430 template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
|
150 !_heap->marking_context()->is_marked_strong(obj)) {
151 return nullptr;
152 }
153
154 // Allow runtime to see unreachable objects that are visited during concurrent class-unloading.
155 if ((decorators & AS_NO_KEEPALIVE) != 0 &&
156 _heap->is_concurrent_weak_root_in_progress() &&
157 !_heap->marking_context()->is_marked(obj)) {
158 return obj;
159 }
160
161 oop fwd = load_reference_barrier(obj);
162 if (load_addr != nullptr && fwd != obj) {
163 // Since we are here and we know the load address, update the reference.
164 ShenandoahHeap::atomic_update_oop(fwd, load_addr, obj);
165 }
166
167 return fwd;
168 }
169
170 inline void ShenandoahBarrierSet::enqueue(oop obj, bool filter) {
171 assert(obj != nullptr, "checked by caller");
172 assert(_satb_mark_queue_set.is_active(), "only get here when SATB active");
173
174 // Filter marked objects before hitting the SATB queues. The same predicate would
175 // be used by SATBMQ::filter to eliminate already marked objects downstream, but
176 // filtering here helps to avoid wasteful SATB queueing work to begin with.
177 if (filter && !_heap->requires_marking(obj)) return;
178
179 SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(Thread::current());
180 _satb_mark_queue_set.enqueue_known_active(queue, obj);
181 }
182
183 template <DecoratorSet decorators, typename T>
184 inline void ShenandoahBarrierSet::satb_barrier(T *field) {
185 // Uninitialized and no-keepalive stores do not need barrier.
186 if (HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value ||
187 HasDecorator<decorators, AS_NO_KEEPALIVE>::value) {
188 return;
189 }
190
191 // Stores to weak/phantom require no barrier. The original references would
192 // have been enqueued in the SATB buffer by the load barrier if they were needed.
193 if (HasDecorator<decorators, ON_WEAK_OOP_REF>::value ||
194 HasDecorator<decorators, ON_PHANTOM_OOP_REF>::value) {
195 return;
196 }
197
385 if (ShenandoahCardBarrier) {
386 bs->write_ref_field_post<decorators>(addr);
387 }
388 return result;
389 }
390
391 template <DecoratorSet decorators, typename BarrierSetT>
392 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value) {
393 assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
394 ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
395 DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
396 auto addr = AccessInternal::oop_field_addr<decorators>(base, offset);
397 oop result = bs->oop_xchg(resolved_decorators, addr, new_value);
398 if (ShenandoahCardBarrier) {
399 bs->write_ref_field_post<decorators>(addr);
400 }
401 return result;
402 }
403
404 // Clone barrier support
405 template <bool EVAC>
406 class ShenandoahUpdateEvacForCloneOopClosure : public BasicOopIterateClosure {
407 private:
408 ShenandoahHeap* const _heap;
409 const ShenandoahCollectionSet* const _cset;
410 Thread* const _thread;
411
412 template <class T>
413 inline void do_oop_work(T* p) {
414 T o = RawAccess<>::oop_load(p);
415 if (!CompressedOops::is_null(o)) {
416 oop obj = CompressedOops::decode_not_null(o);
417 if (_cset->is_in(obj)) {
418 oop fwd = ShenandoahForwarding::get_forwardee(obj);
419 if (EVAC && obj == fwd) {
420 fwd = _heap->evacuate_object(obj, _thread);
421 }
422 shenandoah_assert_forwarded_except(p, obj, _heap->cancelled_gc());
423 ShenandoahHeap::atomic_update_oop(fwd, p, o);
424 obj = fwd;
425 }
426 }
427 }
428
429 public:
430 ShenandoahUpdateEvacForCloneOopClosure() :
431 _heap(ShenandoahHeap::heap()),
432 _cset(_heap->collection_set()),
433 _thread(Thread::current()) {}
434
435 virtual void do_oop(oop* p) { do_oop_work(p); }
436 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
437 };
438
439 void ShenandoahBarrierSet::clone_evacuation(oop obj) {
440 assert(_heap->is_evacuation_in_progress(), "only during evacuation");
441 if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {
442 ShenandoahUpdateEvacForCloneOopClosure<true> cl;
443 obj->oop_iterate(&cl);
444 }
445 }
446
447 void ShenandoahBarrierSet::clone_update(oop obj) {
448 assert(_heap->is_update_refs_in_progress(), "only during update-refs");
449 if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {
450 ShenandoahUpdateEvacForCloneOopClosure<false> cl;
451 obj->oop_iterate(&cl);
452 }
453 }
454
455 template <DecoratorSet decorators, typename BarrierSetT>
456 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t count) {
457 // Hot code path, called from compiler/runtime. Make sure fast path is fast.
458
459 // Fix up src before doing the copy, if needed.
460 const char gc_state = ShenandoahThreadLocalData::gc_state(Thread::current());
461 if (gc_state > 0 && ShenandoahCloneBarrier) {
462 ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
463 if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {
464 bs->clone_evacuation(src);
465 } else if ((gc_state & ShenandoahHeap::UPDATE_REFS) != 0) {
466 bs->clone_update(src);
467 }
468 }
469
470 Raw::clone(src, dst, count);
471
472 // Safety: clone destination must be in young, otherwise we need card barriers.
473 shenandoah_assert_in_young_if(nullptr, dst, ShenandoahCardBarrier);
474 }
475
476 template <DecoratorSet decorators, typename BarrierSetT>
477 template <typename T>
478 OopCopyResult ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
479 arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
480 size_t length) {
481 T* src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
482 T* dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
483
484 ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
485 bs->arraycopy_barrier(src, dst, length);
486 OopCopyResult result = Raw::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
487 if (ShenandoahCardBarrier) {
488 bs->write_ref_array((HeapWord*) dst, length);
489 }
490 return result;
491 }
492
493 template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
|