36 #include "oops/compressedOops.hpp"
37
38 template <bool HAS_FWD, bool EVAC, bool ENQUEUE>
39 class ShenandoahUpdateRefsForOopClosure: public BasicOopIterateClosure {
40 private:
41 ShenandoahHeap* const _heap;
42 ShenandoahBarrierSet* const _bs;
43 const ShenandoahCollectionSet* const _cset;
44 Thread* const _thread;
45
46 template <class T>
47 inline void do_oop_work(T* p) {
48 T o = RawAccess<>::oop_load(p);
49 if (!CompressedOops::is_null(o)) {
50 oop obj = CompressedOops::decode_not_null(o);
51 if (HAS_FWD && _cset->is_in(obj)) {
52 oop fwd = _bs->resolve_forwarded_not_null(obj);
53 if (EVAC && obj == fwd) {
54 fwd = _heap->evacuate_object(obj, _thread);
55 }
56 assert(obj != fwd || _heap->cancelled_gc(), "must be forwarded");
57 ShenandoahHeap::atomic_update_oop(fwd, p, o);
58 obj = fwd;
59 }
60 if (ENQUEUE) {
61 _bs->enqueue(obj);
62 }
63 }
64 }
65 public:
66 ShenandoahUpdateRefsForOopClosure() :
67 _heap(ShenandoahHeap::heap()),
68 _bs(ShenandoahBarrierSet::barrier_set()),
69 _cset(_heap->collection_set()),
70 _thread(Thread::current()) {
71 }
72
73 virtual void do_oop(oop* p) { do_oop_work(p); }
74 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
75 };
76
87 assert(_heap->is_evacuation_in_progress(), "only during evacuation");
88 if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {
89 ShenandoahEvacOOMScope oom_evac_scope;
90 ShenandoahUpdateRefsForOopClosure</* has_fwd = */ true, /* evac = */ true, /* enqueue */ false> cl;
91 obj->oop_iterate(&cl);
92 }
93 }
94
95 void ShenandoahBarrierSet::clone_update(oop obj) {
96 assert(_heap->is_update_refs_in_progress(), "only during update-refs");
97 if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {
98 ShenandoahUpdateRefsForOopClosure</* has_fwd = */ true, /* evac = */ false, /* enqueue */ false> cl;
99 obj->oop_iterate(&cl);
100 }
101 }
102
103 void ShenandoahBarrierSet::clone_barrier(oop obj) {
104 assert(ShenandoahCloneBarrier, "only get here with clone barriers enabled");
105 shenandoah_assert_correct(nullptr, obj);
106
107 int gc_state = _heap->gc_state();
108 if ((gc_state & ShenandoahHeap::MARKING) != 0) {
109 clone_marking(obj);
110 } else if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {
111 clone_evacuation(obj);
112 } else {
113 clone_update(obj);
114 }
115 }
116
117 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSETCLONE_INLINE_HPP
|
36 #include "oops/compressedOops.hpp"
37
38 template <bool HAS_FWD, bool EVAC, bool ENQUEUE>
39 class ShenandoahUpdateRefsForOopClosure: public BasicOopIterateClosure {
40 private:
41 ShenandoahHeap* const _heap;
42 ShenandoahBarrierSet* const _bs;
43 const ShenandoahCollectionSet* const _cset;
44 Thread* const _thread;
45
46 template <class T>
47 inline void do_oop_work(T* p) {
48 T o = RawAccess<>::oop_load(p);
49 if (!CompressedOops::is_null(o)) {
50 oop obj = CompressedOops::decode_not_null(o);
51 if (HAS_FWD && _cset->is_in(obj)) {
52 oop fwd = _bs->resolve_forwarded_not_null(obj);
53 if (EVAC && obj == fwd) {
54 fwd = _heap->evacuate_object(obj, _thread);
55 }
56 shenandoah_assert_forwarded_except(p, obj, _heap->cancelled_gc());
57 ShenandoahHeap::atomic_update_oop(fwd, p, o);
58 obj = fwd;
59 }
60 if (ENQUEUE) {
61 _bs->enqueue(obj);
62 }
63 }
64 }
65 public:
66 ShenandoahUpdateRefsForOopClosure() :
67 _heap(ShenandoahHeap::heap()),
68 _bs(ShenandoahBarrierSet::barrier_set()),
69 _cset(_heap->collection_set()),
70 _thread(Thread::current()) {
71 }
72
73 virtual void do_oop(oop* p) { do_oop_work(p); }
74 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
75 };
76
87 assert(_heap->is_evacuation_in_progress(), "only during evacuation");
88 if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {
89 ShenandoahEvacOOMScope oom_evac_scope;
90 ShenandoahUpdateRefsForOopClosure</* has_fwd = */ true, /* evac = */ true, /* enqueue */ false> cl;
91 obj->oop_iterate(&cl);
92 }
93 }
94
95 void ShenandoahBarrierSet::clone_update(oop obj) {
96 assert(_heap->is_update_refs_in_progress(), "only during update-refs");
97 if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {
98 ShenandoahUpdateRefsForOopClosure</* has_fwd = */ true, /* evac = */ false, /* enqueue */ false> cl;
99 obj->oop_iterate(&cl);
100 }
101 }
102
103 void ShenandoahBarrierSet::clone_barrier(oop obj) {
104 assert(ShenandoahCloneBarrier, "only get here with clone barriers enabled");
105 shenandoah_assert_correct(nullptr, obj);
106
107 // We only need to handle YOUNG_MARKING here because the clone barrier
108 // is only invoked during marking if Shenandoah is in incremental update
109 // mode. OLD_MARKING should only happen when Shenandoah is in generational
110 // mode, which uses the SATB write barrier.
111 int gc_state = _heap->gc_state();
112 if ((gc_state & ShenandoahHeap::YOUNG_MARKING) != 0) {
113 clone_marking(obj);
114 } else if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {
115 clone_evacuation(obj);
116 } else {
117 clone_update(obj);
118 }
119 }
120
121 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSETCLONE_INLINE_HPP
|