src/hotspot/share/oops/objArrayKlass.cpp
changeset 50389 7e8c0409a747
parent 50304 d5331b94f821
child 50601 3fbae7b9ddb5
--- a/src/hotspot/share/oops/objArrayKlass.cpp	Mon Jun 04 22:03:10 2018 +0200
+++ b/src/hotspot/share/oops/objArrayKlass.cpp	Mon Jun 04 23:01:48 2018 +0200
@@ -218,23 +218,23 @@
 }
 
 // Either oop or narrowOop depending on UseCompressedOops.
-template <class T> void ObjArrayKlass::do_copy(arrayOop s, T* src,
-                               arrayOop d, T* dst, int length, TRAPS) {
+void ObjArrayKlass::do_copy(arrayOop s, size_t src_offset,
+                            arrayOop d, size_t dst_offset, int length, TRAPS) {
   if (oopDesc::equals(s, d)) {
     // since source and destination are equal we do not need conversion checks.
     assert(length > 0, "sanity check");
-    HeapAccess<>::oop_arraycopy(s, d, src, dst, length);
+    ArrayAccess<>::oop_arraycopy(s, src_offset, d, dst_offset, length);
   } else {
     // We have to make sure all elements conform to the destination array
     Klass* bound = ObjArrayKlass::cast(d->klass())->element_klass();
     Klass* stype = ObjArrayKlass::cast(s->klass())->element_klass();
     if (stype == bound || stype->is_subtype_of(bound)) {
       // elements are guaranteed to be subtypes, so no check necessary
-      HeapAccess<ARRAYCOPY_DISJOINT>::oop_arraycopy(s, d, src, dst, length);
+      ArrayAccess<ARRAYCOPY_DISJOINT>::oop_arraycopy(s, src_offset, d, dst_offset, length);
     } else {
       // slow case: need individual subtype checks
       // note: don't use obj_at_put below because it includes a redundant store check
-      if (!HeapAccess<ARRAYCOPY_DISJOINT | ARRAYCOPY_CHECKCAST>::oop_arraycopy(s, d, src, dst, length)) {
+      if (!ArrayAccess<ARRAYCOPY_DISJOINT | ARRAYCOPY_CHECKCAST>::oop_arraycopy(s, src_offset, d, dst_offset, length)) {
         THROW(vmSymbols::java_lang_ArrayStoreException());
       }
     }
@@ -289,13 +289,21 @@
     return;
   }
   if (UseCompressedOops) {
-    narrowOop* const src = objArrayOop(s)->obj_at_addr<narrowOop>(src_pos);
-    narrowOop* const dst = objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos);
-    do_copy<narrowOop>(s, src, d, dst, length, CHECK);
+    size_t src_offset = (size_t) objArrayOopDesc::obj_at_offset<narrowOop>(src_pos);
+    size_t dst_offset = (size_t) objArrayOopDesc::obj_at_offset<narrowOop>(dst_pos);
+    assert(arrayOopDesc::obj_offset_to_raw<narrowOop>(s, src_offset, NULL) ==
+           objArrayOop(s)->obj_at_addr<narrowOop>(src_pos), "sanity");
+    assert(arrayOopDesc::obj_offset_to_raw<narrowOop>(d, dst_offset, NULL) ==
+           objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos), "sanity");
+    do_copy(s, src_offset, d, dst_offset, length, CHECK);
   } else {
-    oop* const src = objArrayOop(s)->obj_at_addr<oop>(src_pos);
-    oop* const dst = objArrayOop(d)->obj_at_addr<oop>(dst_pos);
-    do_copy<oop> (s, src, d, dst, length, CHECK);
+    size_t src_offset = (size_t) objArrayOopDesc::obj_at_offset<oop>(src_pos);
+    size_t dst_offset = (size_t) objArrayOopDesc::obj_at_offset<oop>(dst_pos);
+    assert(arrayOopDesc::obj_offset_to_raw<oop>(s, src_offset, NULL) ==
+           objArrayOop(s)->obj_at_addr<oop>(src_pos), "sanity");
+    assert(arrayOopDesc::obj_offset_to_raw<oop>(d, dst_offset, NULL) ==
+           objArrayOop(d)->obj_at_addr<oop>(dst_pos), "sanity");
+    do_copy(s, src_offset, d, dst_offset, length, CHECK);
   }
 }