Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. // Either oop or narrowOop depending on UseCompressedOops.
  2. template <class T> void objArrayKlass::do_copy(arrayOop s, T* src,
  3.                                arrayOop d, T* dst, int length, TRAPS) {
  4.  
  5.   BarrierSet* bs = Universe::heap()->barrier_set();
  6.   // For performance reasons, we assume we are that the write barrier we
  7.   // are using has optimized modes for arrays of references.  At least one
  8.   // of the asserts below will fail if this is not the case.
  9.   assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
  10.   assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
  11.  
  12.   if (s == d) {
  13.     // since source and destination are equal we do not need conversion checks.
  14.     assert(length > 0, "sanity check");
  15.     bs->write_ref_array_pre(dst, length);
  16.     Copy::conjoint_oops_atomic(src, dst, length);
  17.   } else {
  18.     // We have to make sure all elements conform to the destination array
  19.     klassOop bound = objArrayKlass::cast(d->klass())->element_klass();
  20.     klassOop stype = objArrayKlass::cast(s->klass())->element_klass();
  21.     if (stype == bound || Klass::cast(stype)->is_subtype_of(bound)) {
  22.       // elements are guaranteed to be subtypes, so no check necessary
  23.       bs->write_ref_array_pre(dst, length);
  24.       Copy::conjoint_oops_atomic(src, dst, length);
  25.     } else {
  26.       // slow case: need individual subtype checks
  27.       // note: don't use obj_at_put below because it includes a redundant store check
  28.       T* from = src;
  29.       T* end = from + length;
  30.       for (T* p = dst; from < end; from++, p++) {
  31.         // XXX this is going to be slow.
  32.         T element = *from;
  33.         // even slower now
  34.         bool element_is_null = oopDesc::is_null(element);
  35.         oop new_val = element_is_null ? oop(NULL)
  36.                                       : oopDesc::decode_heap_oop_not_null(element);
  37.         if (element_is_null ||
  38.             Klass::cast((new_val->klass()))->is_subtype_of(bound)) {
  39.           bs->write_ref_field_pre(p, new_val);
  40.           *p = *from;
  41.         } else {
  42.           // We must do a barrier to cover the partial copy.
  43.           const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize);
  44.           // pointer delta is scaled to number of elements (length field in
  45.           // objArrayOop) which we assume is 32 bit.
  46.           assert(pd == (size_t)(int)pd, "length field overflow");
  47.           bs->write_ref_array((HeapWord*)dst, pd);
  48.           THROW(vmSymbols::java_lang_ArrayStoreException());
  49.           return;
  50.         }
  51.       }
  52.     }
  53.   }
  54.   bs->write_ref_array((HeapWord*)dst, length);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement