< prev index next >

src/hotspot/share/prims/jni.cpp

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

@@ -2463,11 +2463,12 @@
     buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
     /* JNI Specification states return NULL on OOM */
     if (buf != NULL) {
       if (s_len > 0) {
         if (!is_latin1) {
-          memcpy(buf, s_value->char_at_addr(0), sizeof(jchar)*s_len);
+          HeapAccess<>::arraycopy<jchar>(s_value, (size_t) typeArrayOopDesc::element_offset<jchar>(0), NULL,
+                                         NULL, 0, buf, s_len);
         } else {
           for (int i = 0; i < s_len; i++) {
             buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
           }
         }

@@ -2719,11 +2720,12 @@
   } else { \
     /* JNI Specification states return NULL on OOM */                    \
     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
     if (result != NULL) {                                                \
       /* copy the array to the c chunk */                                \
-      memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len);      \
+      HeapAccess<>::arraycopy<ElementType>(a, typeArrayOopDesc::element_offset<ElementType>(0), NULL, \
+                                           NULL, 0, result, len);        \
       if (isCopy) {                                                      \
         *isCopy = JNI_TRUE;                                              \
       }                                                                  \
     }                                                                    \
   } \

@@ -2768,11 +2770,11 @@
   EntryProbe; \
   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
   int len = a->length(); \
   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
     if ((mode == 0) || (mode == JNI_COMMIT)) { \
-      memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \
+      HeapAccess<>::arraycopy<ElementType>(NULL, 0, buf, a, typeArrayOopDesc::element_offset<ElementType>(0), NULL, len); \
     } \
     if ((mode == 0) || (mode == JNI_ABORT)) { \
       FreeHeap(buf); \
     } \
   } \

@@ -2819,14 +2821,11 @@
   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
   if (start < 0 || len < 0 || (start > src->length() - len)) { \
     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
   } else { \
     if (len > 0) { \
-      int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \
-      memcpy((u_char*) buf, \
-             (u_char*) src->Tag##_at_addr(start), \
-             len << sc);                          \
+      HeapAccess<>::arraycopy<ElementType>(src, typeArrayOopDesc::element_offset<ElementType>(start), NULL, NULL, 0, buf, len); \
     } \
   } \
 JNI_END
 
 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool

@@ -2869,14 +2868,11 @@
   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
   if (start < 0 || len < 0 || (start > dst->length() - len)) { \
     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
   } else { \
     if (len > 0) { \
-      int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \
-      memcpy((u_char*) dst->Tag##_at_addr(start), \
-             (u_char*) buf, \
-             len << sc);    \
+      HeapAccess<>::arraycopy<ElementType>(NULL, 0, buf, dst, typeArrayOopDesc::element_offset<ElementType>(start), NULL, len); \
     } \
   } \
 JNI_END
 
 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool

@@ -3108,11 +3104,12 @@
   } else {
     if (len > 0) {
       typeArrayOop s_value = java_lang_String::value(s);
       bool is_latin1 = java_lang_String::is_latin1(s);
       if (!is_latin1) {
-        memcpy(buf, s_value->char_at_addr(start), sizeof(jchar)*len);
+        HeapAccess<>::arraycopy<jchar>(s_value, typeArrayOopDesc::element_offset<jchar>(start), NULL,
+                                       NULL, 0, buf, len);
       } else {
         for (int i = 0; i < len; i++) {
           buf[i] = ((jchar) s_value->byte_at(i + start)) & 0xff;
         }
       }
< prev index next >