< prev index next >

src/hotspot/share/gc/shared/modRefBarrierSet.inline.hpp

Print this page
rev 50331 : 8198285: More consistent Access API for arraycopy


  74   if (result == compare_value) {
  75     bs->template write_ref_field_post<decorators>(addr, new_value);
  76   }
  77   return result;
  78 }
  79 
  80 template <DecoratorSet decorators, typename BarrierSetT>
  81 template <typename T>
  82 inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
  83 oop_atomic_xchg_in_heap(oop new_value, T* addr) {
  84   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
  85   bs->template write_ref_field_pre<decorators>(addr);
  86   oop result = Raw::oop_atomic_xchg(new_value, addr);
  87   bs->template write_ref_field_post<decorators>(addr, new_value);
  88   return result;
  89 }
  90 
  91 template <DecoratorSet decorators, typename BarrierSetT>
  92 template <typename T>
  93 inline bool ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
  94 oop_arraycopy_in_heap(arrayOop src_obj, arrayOop dst_obj, T* src, T* dst, size_t length) {
  95   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
  96 



  97   if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
  98     // Optimized covariant case
  99     bs->write_ref_array_pre(dst, length,
 100                             HasDecorator<decorators, AS_DEST_NOT_INITIALIZED>::value);
 101     Raw::oop_arraycopy(src_obj, dst_obj, src, dst, length);
 102     bs->write_ref_array((HeapWord*)dst, length);
 103   } else {

 104     Klass* bound = objArrayOop(dst_obj)->element_klass();
 105     T* from = src;
 106     T* end = from + length;
 107     for (T* p = dst; from < end; from++, p++) {
 108       T element = *from;
 109       if (oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound)) {
 110         bs->template write_ref_field_pre<decorators>(p);
 111         *p = element;
 112       } else {
 113         // We must do a barrier to cover the partial copy.
 114         const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize);
 115         // pointer delta is scaled to number of elements (length field in
 116         // objArrayOop) which we assume is 32 bit.
 117         assert(pd == (size_t)(int)pd, "length field overflow");
 118         bs->write_ref_array((HeapWord*)dst, pd);
 119         return false;
 120       }
 121     }
 122     bs->write_ref_array((HeapWord*)dst, length);
 123   }
 124   return true;
 125 }
 126 
 127 template <DecoratorSet decorators, typename BarrierSetT>
 128 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
 129 clone_in_heap(oop src, oop dst, size_t size) {
 130   Raw::clone(src, dst, size);
 131   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
 132   bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
 133 }
 134 
 135 #endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP


  74   if (result == compare_value) {
  75     bs->template write_ref_field_post<decorators>(addr, new_value);
  76   }
  77   return result;
  78 }
  79 
  80 template <DecoratorSet decorators, typename BarrierSetT>
  81 template <typename T>
  82 inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
  83 oop_atomic_xchg_in_heap(oop new_value, T* addr) {
  84   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
  85   bs->template write_ref_field_pre<decorators>(addr);
  86   oop result = Raw::oop_atomic_xchg(new_value, addr);
  87   bs->template write_ref_field_post<decorators>(addr, new_value);
  88   return result;
  89 }
  90 
  91 template <DecoratorSet decorators, typename BarrierSetT>
  92 template <typename T>
  93 inline bool ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
  94 oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, const T* src_raw, arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw, size_t length) {
  95   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
  96 
  97   src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
  98   dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
  99 
 100   if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
 101     // Optimized covariant case
 102     bs->write_ref_array_pre(dst_raw, length,
 103                             HasDecorator<decorators, AS_DEST_NOT_INITIALIZED>::value);
 104     Raw::oop_arraycopy(NULL, 0, src_raw, NULL, 0, dst_raw, length);
 105     bs->write_ref_array((HeapWord*)dst_raw, length);
 106   } else {
 107     assert(dst_obj != NULL, "better have an actual oop");
 108     Klass* bound = objArrayOop(dst_obj)->element_klass();
 109     T* from = const_cast<T*>(src_raw);
 110     T* end = from + length;
 111     for (T* p = dst_raw; from < end; from++, p++) {
 112       T element = *from;
 113       if (oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound)) {
 114         bs->template write_ref_field_pre<decorators>(p);
 115         *p = element;
 116       } else {
 117         // We must do a barrier to cover the partial copy.
 118         const size_t pd = pointer_delta(p, dst_raw, (size_t)heapOopSize);
 119         // pointer delta is scaled to number of elements (length field in
 120         // objArrayOop) which we assume is 32 bit.
 121         assert(pd == (size_t)(int)pd, "length field overflow");
 122         bs->write_ref_array((HeapWord*)dst_raw, pd);
 123         return false;
 124       }
 125     }
 126     bs->write_ref_array((HeapWord*)dst_raw, length);
 127   }
 128   return true;
 129 }
 130 
 131 template <DecoratorSet decorators, typename BarrierSetT>
 132 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
 133 clone_in_heap(oop src, oop dst, size_t size) {
 134   Raw::clone(src, dst, size);
 135   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
 136   bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
 137 }
 138 
 139 #endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
< prev index next >