1 /*
  2  * Copyright (c) 2015, 2022, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
 28 
 29 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
 30 
 31 #include "gc/shared/accessBarrierSupport.inline.hpp"
 32 #include "gc/shared/cardTable.hpp"
 33 #include "gc/shenandoah/shenandoahAsserts.hpp"
 34 #include "gc/shenandoah/shenandoahCollectionSet.inline.hpp"
 35 #include "gc/shenandoah/shenandoahEvacOOMHandler.inline.hpp"
 36 #include "gc/shenandoah/shenandoahForwarding.inline.hpp"
 37 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 38 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
 39 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
 40 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
 41 #include "gc/shenandoah/mode/shenandoahMode.hpp"
 42 #include "memory/iterator.inline.hpp"
 43 #include "oops/oop.inline.hpp"
 44 
 45 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null(oop p) {
 46   return ShenandoahForwarding::get_forwardee(p);
 47 }
 48 
 49 inline oop ShenandoahBarrierSet::resolve_forwarded(oop p) {
 50   if (p != nullptr) {
 51     return resolve_forwarded_not_null(p);
 52   } else {
 53     return p;
 54   }
 55 }
 56 
 57 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null_mutator(oop p) {
 58   return ShenandoahForwarding::get_forwardee_mutator(p);
 59 }
 60 
 61 template <class T>
 62 inline oop ShenandoahBarrierSet::load_reference_barrier_mutator(oop obj, T* load_addr) {
 63   assert(ShenandoahLoadRefBarrier, "should be enabled");
 64   shenandoah_assert_in_cset(load_addr, obj);
 65 
 66   oop fwd = resolve_forwarded_not_null_mutator(obj);
 67   if (obj == fwd) {
 68     assert(_heap->is_evacuation_in_progress(),
 69            "evac should be in progress");
 70     Thread* const t = Thread::current();
 71     ShenandoahEvacOOMScope scope(t);
 72     fwd = _heap->evacuate_object(obj, t);
 73   }
 74 
 75   if (load_addr != nullptr && fwd != obj) {
 76     // Since we are here and we know the load address, update the reference.
 77     ShenandoahHeap::atomic_update_oop(fwd, load_addr, obj);
 78   }
 79 
 80   return fwd;
 81 }
 82 
 83 inline oop ShenandoahBarrierSet::load_reference_barrier(oop obj) {
 84   if (!ShenandoahLoadRefBarrier) {
 85     return obj;
 86   }
 87   if (_heap->has_forwarded_objects() &&
 88       _heap->in_collection_set(obj)) { // Subsumes null-check
 89     assert(obj != nullptr, "cset check must have subsumed null-check");
 90     oop fwd = resolve_forwarded_not_null(obj);
 91     if (obj == fwd && _heap->is_evacuation_in_progress()) {
 92       Thread* t = Thread::current();
 93       ShenandoahEvacOOMScope oom_evac_scope(t);
 94       return _heap->evacuate_object(obj, t);
 95     }
 96     return fwd;
 97   }
 98   return obj;
 99 }
100 
101 template <class T>
102 inline oop ShenandoahBarrierSet::load_reference_barrier(DecoratorSet decorators, oop obj, T* load_addr) {
103   if (obj == nullptr) {
104     return nullptr;
105   }
106 
107   // Prevent resurrection of unreachable phantom (i.e. weak-native) references.
108   if ((decorators & ON_PHANTOM_OOP_REF) != 0 &&
109       _heap->is_concurrent_weak_root_in_progress() &&
110       _heap->is_in_active_generation(obj) &&
111       !_heap->marking_context()->is_marked(obj)) {
112     return nullptr;
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->is_in_active_generation(obj) &&
119       !_heap->marking_context()->is_marked_strong(obj)) {
120     return nullptr;
121   }
122 
123   // Prevent resurrection of unreachable objects that are visited during
124   // concurrent class-unloading.
125   if ((decorators & AS_NO_KEEPALIVE) != 0 &&
126       _heap->is_evacuation_in_progress() &&
127       !_heap->marking_context()->is_marked(obj)) {
128     return obj;
129   }
130 
131   oop fwd = load_reference_barrier(obj);
132   if (load_addr != nullptr && fwd != obj) {
133     // Since we are here and we know the load address, update the reference.
134     ShenandoahHeap::atomic_update_oop(fwd, load_addr, obj);
135   }
136 
137   return fwd;
138 }
139 
140 inline void ShenandoahBarrierSet::enqueue(oop obj) {
141   assert(obj != nullptr, "checked by caller");
142   assert(_satb_mark_queue_set.is_active(), "only get here when SATB active");
143 
144   // Filter marked objects before hitting the SATB queues. The same predicate would
145   // be used by SATBMQ::filter to eliminate already marked objects downstream, but
146   // filtering here helps to avoid wasteful SATB queueing work to begin with.
147   if (!_heap->requires_marking(obj)) return;
148 
149   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(Thread::current());
150   _satb_mark_queue_set.enqueue_known_active(queue, obj);
151 }
152 
153 template <DecoratorSet decorators, typename T>
154 inline void ShenandoahBarrierSet::satb_barrier(T *field) {
155   if (HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value ||
156       HasDecorator<decorators, AS_NO_KEEPALIVE>::value) {
157     return;
158   }
159   if (ShenandoahSATBBarrier && _heap->is_concurrent_mark_in_progress()) {
160     T heap_oop = RawAccess<>::oop_load(field);
161     if (!CompressedOops::is_null(heap_oop)) {
162       enqueue(CompressedOops::decode(heap_oop));
163     }
164   }
165 }
166 
167 inline void ShenandoahBarrierSet::satb_enqueue(oop value) {
168   if (value != nullptr && ShenandoahSATBBarrier && _heap->is_concurrent_mark_in_progress()) {
169     enqueue(value);
170   }
171 }
172 
173 inline void ShenandoahBarrierSet::iu_barrier(oop obj) {
174   if (ShenandoahIUBarrier && obj != nullptr && _heap->is_concurrent_mark_in_progress()) {
175     enqueue(obj);
176   }
177 }
178 
179 inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oop value) {
180   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Reference strength must be known");
181   const bool on_strong_oop_ref = (decorators & ON_STRONG_OOP_REF) != 0;
182   const bool peek              = (decorators & AS_NO_KEEPALIVE) != 0;
183   if (!peek && !on_strong_oop_ref) {
184     satb_enqueue(value);
185   }
186 }
187 
188 template <DecoratorSet decorators, typename T>
189 inline void ShenandoahBarrierSet::write_ref_field_post(T* field) {
190   assert(ShenandoahCardBarrier, "Did you mean to enable ShenandoahCardBarrier?");
191   volatile CardTable::CardValue* byte = card_table()->byte_for(field);
192   *byte = CardTable::dirty_card_val();
193 }
194 
195 template <typename T>
196 inline oop ShenandoahBarrierSet::oop_load(DecoratorSet decorators, T* addr) {
197   oop value = RawAccess<>::oop_load(addr);
198   value = load_reference_barrier(decorators, value, addr);
199   keep_alive_if_weak(decorators, value);
200   return value;
201 }
202 
203 template <typename T>
204 inline oop ShenandoahBarrierSet::oop_cmpxchg(DecoratorSet decorators, T* addr, oop compare_value, oop new_value) {
205   iu_barrier(new_value);
206   oop res;
207   oop expected = compare_value;
208   do {
209     compare_value = expected;
210     res = RawAccess<>::oop_atomic_cmpxchg(addr, compare_value, new_value);
211     expected = res;
212   } while ((compare_value != expected) && (resolve_forwarded(compare_value) == resolve_forwarded(expected)));
213 
214   // Note: We don't need a keep-alive-barrier here. We already enqueue any loaded reference for SATB anyway,
215   // because it must be the previous value.
216   res = load_reference_barrier(decorators, res, static_cast<T*>(nullptr));
217   satb_enqueue(res);
218   return res;
219 }
220 
221 template <typename T>
222 inline oop ShenandoahBarrierSet::oop_xchg(DecoratorSet decorators, T* addr, oop new_value) {
223   iu_barrier(new_value);
224   oop previous = RawAccess<>::oop_atomic_xchg(addr, new_value);
225   // Note: We don't need a keep-alive-barrier here. We already enqueue any loaded reference for SATB anyway,
226   // because it must be the previous value.
227   previous = load_reference_barrier<T>(decorators, previous, static_cast<T*>(nullptr));
228   satb_enqueue(previous);
229   return previous;
230 }
231 
232 template <DecoratorSet decorators, typename BarrierSetT>
233 template <typename T>
234 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_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 template <typename T>
242 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap(T* addr) {
243   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "must be absent");
244   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
245   return bs->oop_load(decorators, addr);
246 }
247 
248 template <DecoratorSet decorators, typename BarrierSetT>
249 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap_at(oop base, ptrdiff_t offset) {
250   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
251   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
252   return bs->oop_load(resolved_decorators, AccessInternal::oop_field_addr<decorators>(base, offset));
253 }
254 
255 template <DecoratorSet decorators, typename BarrierSetT>
256 template <typename T>
257 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_common(T* addr, oop value) {
258   shenandoah_assert_marked_if(nullptr, value,
259                               !CompressedOops::is_null(value) &&
260                               ShenandoahHeap::heap()->is_evacuation_in_progress() &&
261                               !(ShenandoahHeap::heap()->is_gc_generation_young() && ShenandoahHeap::heap()->heap_region_containing(value)->is_old()));
262   shenandoah_assert_not_in_cset_if(addr, value, value != nullptr && !ShenandoahHeap::heap()->cancelled_gc());
263   ShenandoahBarrierSet* const bs = ShenandoahBarrierSet::barrier_set();
264   bs->iu_barrier(value);
265   bs->satb_barrier<decorators>(addr);
266   Raw::oop_store(addr, value);
267 }
268 
269 template <DecoratorSet decorators, typename BarrierSetT>
270 template <typename T>
271 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_not_in_heap(T* addr, oop value) {
272   oop_store_common(addr, value);
273 }
274 
275 template <DecoratorSet decorators, typename BarrierSetT>
276 template <typename T>
277 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap(T* addr, oop value) {
278   shenandoah_assert_not_in_cset_loc_except(addr, ShenandoahHeap::heap()->cancelled_gc());
279   shenandoah_assert_not_forwarded_except  (addr, value, value == nullptr || ShenandoahHeap::heap()->cancelled_gc() || !ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
280 
281   oop_store_common(addr, value);
282   if (ShenandoahCardBarrier) {
283     ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
284     bs->write_ref_field_post<decorators>(addr);
285   }
286 }
287 
288 template <DecoratorSet decorators, typename BarrierSetT>
289 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value) {
290   oop_store_in_heap(AccessInternal::oop_field_addr<decorators>(base, offset), value);
291 }
292 
293 template <DecoratorSet decorators, typename BarrierSetT>
294 template <typename T>
295 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_not_in_heap(T* addr, oop compare_value, oop new_value) {
296   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
297   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
298   return bs->oop_cmpxchg(decorators, addr, compare_value, new_value);
299 }
300 
301 template <DecoratorSet decorators, typename BarrierSetT>
302 template <typename T>
303 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap(T* addr, oop compare_value, oop new_value) {
304   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
305   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
306   oop result = bs->oop_cmpxchg(decorators, addr, compare_value, new_value);
307   if (ShenandoahCardBarrier) {
308     bs->write_ref_field_post<decorators>(addr);
309   }
310   return result;
311 }
312 
313 template <DecoratorSet decorators, typename BarrierSetT>
314 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_at(oop base, ptrdiff_t offset, oop compare_value, 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   auto addr = AccessInternal::oop_field_addr<decorators>(base, offset);
319   oop result = bs->oop_cmpxchg(resolved_decorators, addr, compare_value, new_value);
320   if (ShenandoahCardBarrier) {
321     bs->write_ref_field_post<decorators>(addr);
322   }
323   return result;
324 }
325 
326 template <DecoratorSet decorators, typename BarrierSetT>
327 template <typename T>
328 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_not_in_heap(T* addr, oop new_value) {
329   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
330   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
331   return bs->oop_xchg(decorators, addr, new_value);
332 }
333 
334 template <DecoratorSet decorators, typename BarrierSetT>
335 template <typename T>
336 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap(T* addr, oop new_value) {
337   assert((decorators & (AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF)) == 0, "must be absent");
338   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
339   oop result = bs->oop_xchg(decorators, addr, new_value);
340   if (ShenandoahCardBarrier) {
341     bs->write_ref_field_post<decorators>(addr);
342   }
343   return result;
344 }
345 
346 template <DecoratorSet decorators, typename BarrierSetT>
347 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop base, ptrdiff_t offset, oop new_value) {
348   assert((decorators & AS_NO_KEEPALIVE) == 0, "must be absent");
349   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
350   DecoratorSet resolved_decorators = AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset);
351   auto addr = AccessInternal::oop_field_addr<decorators>(base, offset);
352   oop result = bs->oop_xchg(resolved_decorators, addr, new_value);
353   if (ShenandoahCardBarrier) {
354     bs->write_ref_field_post<decorators>(addr);
355   }
356   return result;
357 }
358 
359 // Clone barrier support
360 template <DecoratorSet decorators, typename BarrierSetT>
361 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
362   if (ShenandoahCloneBarrier) {
363     ShenandoahBarrierSet::barrier_set()->clone_barrier_runtime(src);
364   }
365   Raw::clone(src, dst, size);
366 }
367 
368 template <DecoratorSet decorators, typename BarrierSetT>
369 template <typename T>
370 bool ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
371                                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
372                                                                                          size_t length) {
373   T* src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
374   T* dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
375 
376   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
377   bs->arraycopy_barrier(src, dst, length);
378   bool result = Raw::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
379   if (ShenandoahCardBarrier) {
380     bs->write_ref_array((HeapWord*) dst, length);
381   }
382   return result;
383 }
384 
385 template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
386 void ShenandoahBarrierSet::arraycopy_work(T* src, size_t count) {
387   // We allow forwarding in young generation and marking in old generation
388   // to happen simultaneously.
389   assert(_heap->mode()->is_generational() || HAS_FWD == _heap->has_forwarded_objects(), "Forwarded object status is sane");
390 
391   Thread* thread = Thread::current();
392   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
393   ShenandoahMarkingContext* ctx = _heap->marking_context();
394   const ShenandoahCollectionSet* const cset = _heap->collection_set();
395   T* end = src + count;
396   for (T* elem_ptr = src; elem_ptr < end; elem_ptr++) {
397     T o = RawAccess<>::oop_load(elem_ptr);
398     if (!CompressedOops::is_null(o)) {
399       oop obj = CompressedOops::decode_not_null(o);
400       if (HAS_FWD && cset->is_in(obj)) {
401         oop fwd = resolve_forwarded_not_null(obj);
402         if (EVAC && obj == fwd) {
403           fwd = _heap->evacuate_object(obj, thread);
404         }
405         shenandoah_assert_forwarded_except(elem_ptr, obj, _heap->cancelled_gc());
406         ShenandoahHeap::atomic_update_oop(fwd, elem_ptr, o);
407         obj = fwd;
408       }
409       if (ENQUEUE && !ctx->is_marked_strong_or_old(obj)) {
410         _satb_mark_queue_set.enqueue_known_active(queue, obj);
411       }
412     }
413   }
414 }
415 
416 template <class T>
417 void ShenandoahBarrierSet::arraycopy_barrier(T* src, T* dst, size_t count) {
418   if (count == 0) {
419     return;
420   }
421   int gc_state = _heap->gc_state();
422   if ((gc_state & ShenandoahHeap::YOUNG_MARKING) != 0) {
423     arraycopy_marking(src, dst, count, false);
424     return;
425   }
426 
427   if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {
428     arraycopy_evacuation(src, count);
429   } else if ((gc_state & ShenandoahHeap::UPDATEREFS) != 0) {
430     arraycopy_update(src, count);
431   }
432 
433   if (_heap->mode()->is_generational()) {
434     assert(ShenandoahSATBBarrier, "Generational mode assumes SATB mode");
435     // TODO: Could we optimize here by checking that dst is in an old region?
436     if ((gc_state & ShenandoahHeap::OLD_MARKING) != 0) {
437       // Note that we can't do the arraycopy marking using the 'src' array when
438       // SATB mode is enabled (so we can't do this as part of the iteration for
439       // evacuation or update references).
440       arraycopy_marking(src, dst, count, true);
441     }
442   }
443 }
444 
445 template <class T>
446 void ShenandoahBarrierSet::arraycopy_marking(T* src, T* dst, size_t count, bool is_old_marking) {
447   assert(_heap->is_concurrent_mark_in_progress(), "only during marking");
448   /*
449    * Note that an old-gen object is considered live if it is live at the start of OLD marking or if it is promoted
450    * following the start of OLD marking.
451    *
452    * 1. Every object promoted following the start of OLD marking will be above TAMS within its old-gen region
453    * 2. Every object live at the start of OLD marking will be referenced from a "root" or it will be referenced from
454    *    another live OLD-gen object.  With regards to old-gen, roots include stack locations and all of live young-gen.
455    *    All root references to old-gen are identified during a bootstrap young collection.  All references from other
456    *    old-gen objects will be marked during the traversal of all old objects, or will be marked by the SATB barrier.
457    *
458    * During old-gen marking (which is interleaved with young-gen collections), call arraycopy_work() if:
459    *
460    * 1. The overwritten array resides in old-gen and it is below TAMS within its old-gen region
461    * 2. Do not call arraycopy_work for any array residing in young-gen because young-gen collection is idle at this time
462    *
463    * During young-gen marking, call arraycopy_work() if:
464    *
465    * 1. The overwritten array resides in young-gen and is below TAMS within its young-gen region
466    * 2. Additionally, if array resides in old-gen, regardless of its relationship to TAMS because this old-gen array
467    *    may hold references to young-gen
468    */
469   if (ShenandoahSATBBarrier) {
470     T* array = dst;
471     HeapWord* array_addr = reinterpret_cast<HeapWord*>(array);
472     ShenandoahHeapRegion* r = _heap->heap_region_containing(array_addr);
473     if (is_old_marking) {
474       // Generational, old marking
475       assert(_heap->mode()->is_generational(), "Invariant");
476       if (r->is_old() && (array_addr < _heap->marking_context()->top_at_mark_start(r))) {
477         arraycopy_work<T, false, false, true>(array, count);
478       }
479     } else if (_heap->mode()->is_generational()) {
480       // Generational, young marking
481       if (r->is_old() || (array_addr < _heap->marking_context()->top_at_mark_start(r))) {
482         arraycopy_work<T, false, false, true>(array, count);
483       }
484     } else if (array_addr < _heap->marking_context()->top_at_mark_start(r)) {
485       // Non-generational, marking
486       arraycopy_work<T, false, false, true>(array, count);
487     }
488   } else {
489     // Incremental Update mode, marking
490     T* array = src;
491     HeapWord* array_addr = reinterpret_cast<HeapWord*>(array);
492     ShenandoahHeapRegion* r = _heap->heap_region_containing(array_addr);
493     if (array_addr < _heap->marking_context()->top_at_mark_start(r)) {
494       arraycopy_work<T, false, false, true>(array, count);
495     }
496   }
497 }
498 
499 inline bool ShenandoahBarrierSet::need_bulk_update(HeapWord* ary) {
500   return ary < _heap->heap_region_containing(ary)->get_update_watermark();
501 }
502 
503 template <class T>
504 void ShenandoahBarrierSet::arraycopy_evacuation(T* src, size_t count) {
505   assert(_heap->is_evacuation_in_progress(), "only during evacuation");
506   if (need_bulk_update(reinterpret_cast<HeapWord*>(src))) {
507     ShenandoahEvacOOMScope oom_evac;
508     arraycopy_work<T, true, true, false>(src, count);
509   }
510 }
511 
512 template <class T>
513 void ShenandoahBarrierSet::arraycopy_update(T* src, size_t count) {
514   assert(_heap->is_update_refs_in_progress(), "only during update-refs");
515   if (need_bulk_update(reinterpret_cast<HeapWord*>(src))) {
516     arraycopy_work<T, true, false, false>(src, count);
517   }
518 }
519 
520 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP