< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
 27 
 28 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
 29 
 30 #include "gc/shared/accessBarrierSupport.inline.hpp"

 31 #include "gc/shenandoah/shenandoahAsserts.hpp"
 32 #include "gc/shenandoah/shenandoahCollectionSet.inline.hpp"
 33 #include "gc/shenandoah/shenandoahEvacOOMHandler.inline.hpp"
 34 #include "gc/shenandoah/shenandoahForwarding.inline.hpp"
 35 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 36 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
 37 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
 38 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"


 39 #include "oops/oop.inline.hpp"
 40 
 41 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null(oop p) {
 42   return ShenandoahForwarding::get_forwardee(p);
 43 }
 44 
 45 inline oop ShenandoahBarrierSet::resolve_forwarded(oop p) {
 46   if (p != NULL) {
 47     return resolve_forwarded_not_null(p);
 48   } else {
 49     return p;
 50   }
 51 }
 52 
 53 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null_mutator(oop p) {
 54   return ShenandoahForwarding::get_forwardee_mutator(p);
 55 }
 56 
 57 template <class T>
 58 inline oop ShenandoahBarrierSet::load_reference_barrier_mutator(oop obj, T* load_addr) {

 91     // marking phase.
 92     if (obj == fwd && _heap->is_evacuation_in_progress()) {
 93        Thread* t = Thread::current();
 94       ShenandoahEvacOOMScope oom_evac_scope(t);
 95       return _heap->evacuate_object(obj, t);
 96     }
 97     return fwd;
 98   }
 99   return obj;
100 }
101 
102 template <class T>
103 inline oop ShenandoahBarrierSet::load_reference_barrier(DecoratorSet decorators, oop obj, T* load_addr) {
104   if (obj == NULL) {
105     return NULL;
106   }
107 
108   // Prevent resurrection of unreachable phantom (i.e. weak-native) references.
109   if ((decorators & ON_PHANTOM_OOP_REF) != 0 &&
110       _heap->is_concurrent_weak_root_in_progress() &&

111       !_heap->marking_context()->is_marked(obj)) {
112     return NULL;
113   }
114 
115   // Prevent resurrection of unreachable weak references.
116   if ((decorators & ON_WEAK_OOP_REF) != 0 &&
117       _heap->is_concurrent_weak_root_in_progress() &&

118       !_heap->marking_context()->is_marked_strong(obj)) {
119     return NULL;
120   }
121 
122   // Prevent resurrection of unreachable objects that are visited during
123   // concurrent class-unloading.
124   if ((decorators & AS_NO_KEEPALIVE) != 0 &&
125       _heap->is_evacuation_in_progress() &&
126       !_heap->marking_context()->is_marked(obj)) {
127     return obj;
128   }
129 
130   oop fwd = load_reference_barrier(obj);
131   if (ShenandoahSelfFixing && load_addr != NULL && fwd != obj) {
132     // Since we are here and we know the load address, update the reference.
133     ShenandoahHeap::atomic_update_oop(fwd, load_addr, obj);
134   }
135 
136   return fwd;
137 }

167   if (value != NULL && ShenandoahSATBBarrier && _heap->is_concurrent_mark_in_progress()) {
168     enqueue(value);
169   }
170 }
171 
172 inline void ShenandoahBarrierSet::iu_barrier(oop obj) {
173   if (ShenandoahIUBarrier && obj != NULL && _heap->is_concurrent_mark_in_progress()) {
174     enqueue(obj);
175   }
176 }
177 
178 inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oop value) {
179   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Reference strength must be known");
180   const bool on_strong_oop_ref = (decorators & ON_STRONG_OOP_REF) != 0;
181   const bool peek              = (decorators & AS_NO_KEEPALIVE) != 0;
182   if (!peek && !on_strong_oop_ref) {
183     satb_enqueue(value);
184   }
185 }
186 








187 template <typename T>
188 inline oop ShenandoahBarrierSet::oop_load(DecoratorSet decorators, T* addr) {
189   oop value = RawAccess<>::oop_load(addr);
190   value = load_reference_barrier(decorators, value, addr);
191   keep_alive_if_weak(decorators, value);
192   return value;
193 }
194 
195 template <typename T>
196 inline oop ShenandoahBarrierSet::oop_cmpxchg(DecoratorSet decorators, T* addr, oop compare_value, oop new_value) {
197   iu_barrier(new_value);
198   oop res;
199   oop expected = compare_value;
200   do {
201     compare_value = expected;
202     res = RawAccess<>::oop_atomic_cmpxchg(addr, compare_value, new_value);
203     expected = res;
204   } while ((compare_value != expected) && (resolve_forwarded(compare_value) == resolve_forwarded(expected)));
205 
206   // Note: We don't need a keep-alive-barrier here. We already enqueue any loaded reference for SATB anyway,

230 }
231 
232 template <DecoratorSet decorators, typename BarrierSetT>
233 template <typename T>
234 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap(T* addr) {
235   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "must be absent");
236   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
237   return bs->oop_load(decorators, addr);
238 }
239 
240 template <DecoratorSet decorators, typename BarrierSetT>
241 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap_at(oop base, ptrdiff_t offset) {
242   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
243   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
244   return bs->oop_load(resolved_decorators, AccessInternal::oop_field_addr<decorators>(base, offset));
245 }
246 
247 template <DecoratorSet decorators, typename BarrierSetT>
248 template <typename T>
249 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_not_in_heap(T* addr, oop value) {
250   shenandoah_assert_marked_if(NULL, value, !CompressedOops::is_null(value) && ShenandoahHeap::heap()->is_evacuation_in_progress());

251   shenandoah_assert_not_in_cset_if(addr, value, value != NULL && !ShenandoahHeap::heap()->cancelled_gc());
252   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
253   bs->iu_barrier(value);
254   bs->satb_barrier<decorators>(addr);
255   Raw::oop_store(addr, value);
256 }
257 
258 template <DecoratorSet decorators, typename BarrierSetT>
259 template <typename T>
260 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap(T* addr, oop value) {
261   shenandoah_assert_not_in_cset_loc_except(addr, ShenandoahHeap::heap()->cancelled_gc());
262   shenandoah_assert_not_forwarded_except  (addr, value, value == NULL || ShenandoahHeap::heap()->cancelled_gc() || !ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
263   shenandoah_assert_not_in_cset_except    (addr, value, value == NULL || ShenandoahHeap::heap()->cancelled_gc() || !ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
264 
265   oop_store_not_in_heap(addr, value);

266 }
267 
268 template <DecoratorSet decorators, typename BarrierSetT>
269 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value) {
270   oop_store_in_heap(AccessInternal::oop_field_addr<decorators>(base, offset), value);
271 }
272 
273 template <DecoratorSet decorators, typename BarrierSetT>
274 template <typename T>
275 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_not_in_heap(T* addr, oop compare_value, oop new_value) {
276   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
277   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
278   return bs->oop_cmpxchg(decorators, addr, compare_value, new_value);
279 }
280 
281 template <DecoratorSet decorators, typename BarrierSetT>
282 template <typename T>
283 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap(T* addr, oop compare_value, oop new_value) {
284   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
285   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
286   return bs->oop_cmpxchg(decorators, addr, compare_value, new_value);


287 }
288 
289 template <DecoratorSet decorators, typename BarrierSetT>
290 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, oop new_value) {
291   assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
292   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
293   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
294   return bs->oop_cmpxchg(resolved_decorators, AccessInternal::oop_field_addr<decorators>(base, offset), compare_value, new_value);



295 }
296 
297 template <DecoratorSet decorators, typename BarrierSetT>
298 template <typename T>
299 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_not_in_heap(T* addr, oop new_value) {
300   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
301   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
302   return bs->oop_xchg(decorators, addr, new_value);
303 }
304 
305 template <DecoratorSet decorators, typename BarrierSetT>
306 template <typename T>
307 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap(T* addr, oop new_value) {
308   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
309   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
310   return bs->oop_xchg(decorators, addr, new_value);


311 }
312 
313 template <DecoratorSet decorators, typename BarrierSetT>
314 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value) {
315   assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
316   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
317   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
318   return bs->oop_xchg(resolved_decorators, AccessInternal::oop_field_addr<decorators>(base, offset), new_value);



319 }
320 
321 // Clone barrier support
322 template <DecoratorSet decorators, typename BarrierSetT>
323 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
324   if (ShenandoahCloneBarrier) {
325     ShenandoahBarrierSet::barrier_set()->clone_barrier_runtime(src);
326   }
327   Raw::clone(src, dst, size);
328 }
329 
330 template <DecoratorSet decorators, typename BarrierSetT>
331 template <typename T>
332 bool ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
333                                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
334                                                                                          size_t length) {



335   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
336   bs->arraycopy_barrier(arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw),
337                         arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw),
338                         length);
339   return Raw::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
340 }
341 
342 template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
343 void ShenandoahBarrierSet::arraycopy_work(T* src, size_t count) {
344   assert(HAS_FWD == _heap->has_forwarded_objects(), "Forwarded object status is sane");


345 
346   Thread* thread = Thread::current();
347   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
348   ShenandoahMarkingContext* ctx = _heap->marking_context();
349   const ShenandoahCollectionSet* const cset = _heap->collection_set();
350   T* end = src + count;
351   for (T* elem_ptr = src; elem_ptr < end; elem_ptr++) {
352     T o = RawAccess<>::oop_load(elem_ptr);
353     if (!CompressedOops::is_null(o)) {
354       oop obj = CompressedOops::decode_not_null(o);
355       if (HAS_FWD && cset->is_in(obj)) {
356         oop fwd = resolve_forwarded_not_null(obj);
357         if (EVAC && obj == fwd) {
358           fwd = _heap->evacuate_object(obj, thread);
359         }
360         assert(obj != fwd || _heap->cancelled_gc(), "must be forwarded");
361         ShenandoahHeap::atomic_update_oop(fwd, elem_ptr, o);
362         obj = fwd;
363       }
364       if (ENQUEUE && !ctx->is_marked_strong(obj)) {
365         _satb_mark_queue_set.enqueue_known_active(queue, obj);
366       }
367     }
368   }
369 }
370 
371 template <class T>
372 void ShenandoahBarrierSet::arraycopy_barrier(T* src, T* dst, size_t count) {
373   if (count == 0) {
374     return;
375   }
376   int gc_state = _heap->gc_state();
377   if ((gc_state & ShenandoahHeap::MARKING) != 0) {
378     arraycopy_marking(src, dst, count);
379   } else if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {



380     arraycopy_evacuation(src, count);
381   } else if ((gc_state & ShenandoahHeap::UPDATEREFS) != 0) {
382     arraycopy_update(src, count);
383   }











384 }
385 
386 template <class T>
387 void ShenandoahBarrierSet::arraycopy_marking(T* src, T* dst, size_t count) {
388   assert(_heap->is_concurrent_mark_in_progress(), "only during marking");
389   T* array = ShenandoahSATBBarrier ? dst : src;
390   if (!_heap->marking_context()->allocated_after_mark_start(reinterpret_cast<HeapWord*>(array))) {
391     arraycopy_work<T, false, false, true>(array, count);
392   }
393 }
394 
395 inline bool ShenandoahBarrierSet::need_bulk_update(HeapWord* ary) {
396   return ary < _heap->heap_region_containing(ary)->get_update_watermark();
397 }
398 
399 template <class T>
400 void ShenandoahBarrierSet::arraycopy_evacuation(T* src, size_t count) {
401   assert(_heap->is_evacuation_in_progress(), "only during evacuation");
402   if (need_bulk_update(reinterpret_cast<HeapWord*>(src))) {
403     ShenandoahEvacOOMScope oom_evac;

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
 27 
 28 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
 29 
 30 #include "gc/shared/accessBarrierSupport.inline.hpp"
 31 #include "gc/shared/cardTable.hpp"
 32 #include "gc/shenandoah/shenandoahAsserts.hpp"
 33 #include "gc/shenandoah/shenandoahCollectionSet.inline.hpp"
 34 #include "gc/shenandoah/shenandoahEvacOOMHandler.inline.hpp"
 35 #include "gc/shenandoah/shenandoahForwarding.inline.hpp"
 36 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 37 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
 38 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
 39 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
 40 #include "gc/shenandoah/mode/shenandoahMode.hpp"
 41 #include "memory/iterator.inline.hpp"
 42 #include "oops/oop.inline.hpp"
 43 
 44 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null(oop p) {
 45   return ShenandoahForwarding::get_forwardee(p);
 46 }
 47 
 48 inline oop ShenandoahBarrierSet::resolve_forwarded(oop p) {
 49   if (p != NULL) {
 50     return resolve_forwarded_not_null(p);
 51   } else {
 52     return p;
 53   }
 54 }
 55 
 56 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null_mutator(oop p) {
 57   return ShenandoahForwarding::get_forwardee_mutator(p);
 58 }
 59 
 60 template <class T>
 61 inline oop ShenandoahBarrierSet::load_reference_barrier_mutator(oop obj, T* load_addr) {

 94     // marking phase.
 95     if (obj == fwd && _heap->is_evacuation_in_progress()) {
 96        Thread* t = Thread::current();
 97       ShenandoahEvacOOMScope oom_evac_scope(t);
 98       return _heap->evacuate_object(obj, t);
 99     }
100     return fwd;
101   }
102   return obj;
103 }
104 
105 template <class T>
106 inline oop ShenandoahBarrierSet::load_reference_barrier(DecoratorSet decorators, oop obj, T* load_addr) {
107   if (obj == NULL) {
108     return NULL;
109   }
110 
111   // Prevent resurrection of unreachable phantom (i.e. weak-native) references.
112   if ((decorators & ON_PHANTOM_OOP_REF) != 0 &&
113       _heap->is_concurrent_weak_root_in_progress() &&
114       _heap->is_in_active_generation(obj) &&
115       !_heap->marking_context()->is_marked(obj)) {
116     return NULL;
117   }
118 
119   // Prevent resurrection of unreachable weak references.
120   if ((decorators & ON_WEAK_OOP_REF) != 0 &&
121       _heap->is_concurrent_weak_root_in_progress() &&
122       _heap->is_in_active_generation(obj) &&
123       !_heap->marking_context()->is_marked_strong(obj)) {
124     return NULL;
125   }
126 
127   // Prevent resurrection of unreachable objects that are visited during
128   // concurrent class-unloading.
129   if ((decorators & AS_NO_KEEPALIVE) != 0 &&
130       _heap->is_evacuation_in_progress() &&
131       !_heap->marking_context()->is_marked(obj)) {
132     return obj;
133   }
134 
135   oop fwd = load_reference_barrier(obj);
136   if (ShenandoahSelfFixing && load_addr != NULL && fwd != obj) {
137     // Since we are here and we know the load address, update the reference.
138     ShenandoahHeap::atomic_update_oop(fwd, load_addr, obj);
139   }
140 
141   return fwd;
142 }

172   if (value != NULL && ShenandoahSATBBarrier && _heap->is_concurrent_mark_in_progress()) {
173     enqueue(value);
174   }
175 }
176 
177 inline void ShenandoahBarrierSet::iu_barrier(oop obj) {
178   if (ShenandoahIUBarrier && obj != NULL && _heap->is_concurrent_mark_in_progress()) {
179     enqueue(obj);
180   }
181 }
182 
183 inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oop value) {
184   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Reference strength must be known");
185   const bool on_strong_oop_ref = (decorators & ON_STRONG_OOP_REF) != 0;
186   const bool peek              = (decorators & AS_NO_KEEPALIVE) != 0;
187   if (!peek && !on_strong_oop_ref) {
188     satb_enqueue(value);
189   }
190 }
191 
192 template <DecoratorSet decorators, typename T>
193 inline void ShenandoahBarrierSet::write_ref_field_post(T* field, oop newVal) {
194   if (ShenandoahHeap::heap()->mode()->is_generational()) {
195     volatile CardTable::CardValue* byte = card_table()->byte_for(field);
196     *byte = CardTable::dirty_card_val();
197   }
198 }
199 
200 template <typename T>
201 inline oop ShenandoahBarrierSet::oop_load(DecoratorSet decorators, T* addr) {
202   oop value = RawAccess<>::oop_load(addr);
203   value = load_reference_barrier(decorators, value, addr);
204   keep_alive_if_weak(decorators, value);
205   return value;
206 }
207 
208 template <typename T>
209 inline oop ShenandoahBarrierSet::oop_cmpxchg(DecoratorSet decorators, T* addr, oop compare_value, oop new_value) {
210   iu_barrier(new_value);
211   oop res;
212   oop expected = compare_value;
213   do {
214     compare_value = expected;
215     res = RawAccess<>::oop_atomic_cmpxchg(addr, compare_value, new_value);
216     expected = res;
217   } while ((compare_value != expected) && (resolve_forwarded(compare_value) == resolve_forwarded(expected)));
218 
219   // Note: We don't need a keep-alive-barrier here. We already enqueue any loaded reference for SATB anyway,

243 }
244 
245 template <DecoratorSet decorators, typename BarrierSetT>
246 template <typename T>
247 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap(T* addr) {
248   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "must be absent");
249   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
250   return bs->oop_load(decorators, addr);
251 }
252 
253 template <DecoratorSet decorators, typename BarrierSetT>
254 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap_at(oop base, ptrdiff_t offset) {
255   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
256   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
257   return bs->oop_load(resolved_decorators, AccessInternal::oop_field_addr<decorators>(base, offset));
258 }
259 
260 template <DecoratorSet decorators, typename BarrierSetT>
261 template <typename T>
262 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_not_in_heap(T* addr, oop value) {
263   shenandoah_assert_marked_if(NULL, value, !CompressedOops::is_null(value) && ShenandoahHeap::heap()->is_evacuation_in_progress() &&
264                               !(ShenandoahHeap::heap()->is_gc_generation_young() && ShenandoahHeap::heap()->heap_region_containing(value)->is_old()));
265   shenandoah_assert_not_in_cset_if(addr, value, value != NULL && !ShenandoahHeap::heap()->cancelled_gc());
266   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
267   bs->iu_barrier(value);
268   bs->satb_barrier<decorators>(addr);
269   Raw::oop_store(addr, value);
270 }
271 
272 template <DecoratorSet decorators, typename BarrierSetT>
273 template <typename T>
274 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap(T* addr, oop value) {
275   shenandoah_assert_not_in_cset_loc_except(addr, ShenandoahHeap::heap()->cancelled_gc());
276   shenandoah_assert_not_forwarded_except  (addr, value, value == NULL || ShenandoahHeap::heap()->cancelled_gc() || !ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
277   shenandoah_assert_not_in_cset_except    (addr, value, value == NULL || ShenandoahHeap::heap()->cancelled_gc() || !ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
278 
279   oop_store_not_in_heap(addr, value);
280   ShenandoahBarrierSet::barrier_set()->write_ref_field_post<decorators>(addr, value);
281 }
282 
283 template <DecoratorSet decorators, typename BarrierSetT>
284 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value) {
285   oop_store_in_heap(AccessInternal::oop_field_addr<decorators>(base, offset), value);
286 }
287 
288 template <DecoratorSet decorators, typename BarrierSetT>
289 template <typename T>
290 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_not_in_heap(T* addr, oop compare_value, oop new_value) {
291   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
292   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
293   return bs->oop_cmpxchg(decorators, addr, compare_value, new_value);
294 }
295 
296 template <DecoratorSet decorators, typename BarrierSetT>
297 template <typename T>
298 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap(T* addr, oop compare_value, oop new_value) {
299   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
300   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
301   oop result = bs->oop_cmpxchg(decorators, addr, compare_value, new_value);
302   bs->write_ref_field_post<decorators>(addr, new_value);
303   return result;
304 }
305 
306 template <DecoratorSet decorators, typename BarrierSetT>
307 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, oop new_value) {
308   assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
309   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
310   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
311   auto addr = AccessInternal::oop_field_addr<decorators>(base, offset);
312   oop result = bs->oop_cmpxchg(resolved_decorators, addr, compare_value, new_value);
313   bs->write_ref_field_post<decorators>(addr, new_value);
314   return result;
315 }
316 
317 template <DecoratorSet decorators, typename BarrierSetT>
318 template <typename T>
319 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_not_in_heap(T* addr, oop new_value) {
320   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
321   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
322   return bs->oop_xchg(decorators, addr, new_value);
323 }
324 
325 template <DecoratorSet decorators, typename BarrierSetT>
326 template <typename T>
327 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap(T* addr, oop new_value) {
328   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
329   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
330   oop result = bs->oop_xchg(decorators, addr, new_value);
331   bs->write_ref_field_post<decorators>(addr, new_value);
332   return result;
333 }
334 
335 template <DecoratorSet decorators, typename BarrierSetT>
336 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value) {
337   assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
338   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
339   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
340   auto addr = AccessInternal::oop_field_addr<decorators>(base, offset);
341   oop result = bs->oop_xchg(resolved_decorators, addr, new_value);
342   bs->write_ref_field_post<decorators>(addr, new_value);
343   return result;
344 }
345 
346 // Clone barrier support
347 template <DecoratorSet decorators, typename BarrierSetT>
348 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
349   if (ShenandoahCloneBarrier) {
350     ShenandoahBarrierSet::barrier_set()->clone_barrier_runtime(src);
351   }
352   Raw::clone(src, dst, size);
353 }
354 
355 template <DecoratorSet decorators, typename BarrierSetT>
356 template <typename T>
357 bool ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
358                                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
359                                                                                          size_t length) {
360   T* src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
361   T* dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
362 
363   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
364   bs->arraycopy_barrier(src, dst, length);
365   bool result = Raw::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
366   bs->write_ref_array((HeapWord*) dst, length);
367   return result;
368 }
369 
370 template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
371 void ShenandoahBarrierSet::arraycopy_work(T* src, size_t count) {
372   // We allow forwarding in young generation and marking in old generation
373   // to happen simultaneously.
374   assert(_heap->mode()->is_generational() || HAS_FWD == _heap->has_forwarded_objects(), "Forwarded object status is sane");
375 
376   Thread* thread = Thread::current();
377   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
378   ShenandoahMarkingContext* ctx = _heap->marking_context();
379   const ShenandoahCollectionSet* const cset = _heap->collection_set();
380   T* end = src + count;
381   for (T* elem_ptr = src; elem_ptr < end; elem_ptr++) {
382     T o = RawAccess<>::oop_load(elem_ptr);
383     if (!CompressedOops::is_null(o)) {
384       oop obj = CompressedOops::decode_not_null(o);
385       if (HAS_FWD && cset->is_in(obj)) {
386         oop fwd = resolve_forwarded_not_null(obj);
387         if (EVAC && obj == fwd) {
388           fwd = _heap->evacuate_object(obj, thread);
389         }
390         assert(obj != fwd || _heap->cancelled_gc(), "must be forwarded");
391         ShenandoahHeap::atomic_update_oop(fwd, elem_ptr, o);
392         obj = fwd;
393       }
394       if (ENQUEUE && !ctx->is_marked_strong_or_old(obj)) {
395         _satb_mark_queue_set.enqueue_known_active(queue, obj);
396       }
397     }
398   }
399 }
400 
401 template <class T>
402 void ShenandoahBarrierSet::arraycopy_barrier(T* src, T* dst, size_t count) {
403   if (count == 0) {
404     return;
405   }
406   int gc_state = _heap->gc_state();
407   if ((gc_state & ShenandoahHeap::YOUNG_MARKING) != 0) {
408     arraycopy_marking(src, dst, count);
409     return;
410   }
411 
412   if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {
413     arraycopy_evacuation(src, count);
414   } else if ((gc_state & ShenandoahHeap::UPDATEREFS) != 0) {
415     arraycopy_update(src, count);
416   }
417 
418   if (_heap->mode()->is_generational()) {
419     assert(ShenandoahSATBBarrier, "Generational mode assumes SATB mode");
420     // TODO: Could we optimize here by checking that dst is in an old region?
421     if ((gc_state & ShenandoahHeap::OLD_MARKING) != 0) {
422       // Note that we can't do the arraycopy marking using the 'src' array when
423       // SATB mode is enabled (so we can't do this as part of the iteration for
424       // evacuation or update references).
425       arraycopy_marking(src, dst, count);
426     }
427   }
428 }
429 
430 template <class T>
431 void ShenandoahBarrierSet::arraycopy_marking(T* src, T* dst, size_t count) {
432   assert(_heap->is_concurrent_mark_in_progress(), "only during marking");
433   T* array = ShenandoahSATBBarrier ? dst : src;
434   if (!_heap->marking_context()->allocated_after_mark_start(reinterpret_cast<HeapWord*>(array))) {
435     arraycopy_work<T, false, false, true>(array, count);
436   }
437 }
438 
439 inline bool ShenandoahBarrierSet::need_bulk_update(HeapWord* ary) {
440   return ary < _heap->heap_region_containing(ary)->get_update_watermark();
441 }
442 
443 template <class T>
444 void ShenandoahBarrierSet::arraycopy_evacuation(T* src, size_t count) {
445   assert(_heap->is_evacuation_in_progress(), "only during evacuation");
446   if (need_bulk_update(reinterpret_cast<HeapWord*>(src))) {
447     ShenandoahEvacOOMScope oom_evac;
< prev index next >