@@ -414,14 +414,11 @@ void ShenandoahBarrierSet::arraycopy_work(T* src, size_t count) {
414414template <class T >
415415void ShenandoahBarrierSet::arraycopy_barrier (T* src, T* dst, size_t count) {
416416 if (count == 0 ) {
417- return ;
418- }
419- int gc_state = _heap->gc_state ();
420- if ((gc_state & ShenandoahHeap::YOUNG_MARKING) != 0 ) {
421- arraycopy_marking (src, dst, count, false );
417+ // No elements to copy, no need for barrier
422418 return ;
423419 }
424420
421+ int gc_state = _heap->gc_state ();
425422 if ((gc_state & ShenandoahHeap::EVACUATION) != 0 ) {
426423 arraycopy_evacuation (src, count);
427424 } else if ((gc_state & ShenandoahHeap::UPDATEREFS) != 0 ) {
@@ -430,12 +427,14 @@ void ShenandoahBarrierSet::arraycopy_barrier(T* src, T* dst, size_t count) {
430427
431428 if (_heap->mode ()->is_generational ()) {
432429 assert (ShenandoahSATBBarrier, " Generational mode assumes SATB mode" );
430+ if ((gc_state & ShenandoahHeap::YOUNG_MARKING) != 0 ) {
431+ arraycopy_marking (src, dst, count, false );
432+ }
433433 if ((gc_state & ShenandoahHeap::OLD_MARKING) != 0 ) {
434- // Note that we can't do the arraycopy marking using the 'src' array when
435- // SATB mode is enabled (so we can't do this as part of the iteration for
436- // evacuation or update references).
437434 arraycopy_marking (src, dst, count, true );
438435 }
436+ } else if ((gc_state & ShenandoahHeap::MARKING) != 0 ) {
437+ arraycopy_marking (src, dst, count, false );
439438 }
440439}
441440
0 commit comments