Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad984f19 authored by Bjorn Bringert's avatar Bjorn Bringert
Browse files

Use JNI region calls in MemoryFile read and write.

This will reduce copying or pinning, depending on GC policies, which should
improve performance. See dalvik/docs/jni-tips.html#RegionCalls for more information.

Fixes http://b/issue?id=1887911
parent 641bb3d8
Loading
Loading
Loading
Loading
+2 −6
Original line number Original line Diff line number Diff line
@@ -82,9 +82,7 @@ static jint android_os_MemoryFile_read(JNIEnv* env, jobject clazz,
        return -1;
        return -1;
    }
    }


    jbyte* bytes = env->GetByteArrayElements(buffer, 0);
    env->SetByteArrayRegion(buffer, destOffset, count, (const jbyte *)address + srcOffset);
    memcpy(bytes + destOffset, (const char *)address + srcOffset, count);
    env->ReleaseByteArrayElements(buffer, bytes, 0);


    if (unpinned) {
    if (unpinned) {
        ashmem_unpin_region(fd, 0, 0);
        ashmem_unpin_region(fd, 0, 0);
@@ -103,9 +101,7 @@ static jint android_os_MemoryFile_write(JNIEnv* env, jobject clazz,
        return -1;
        return -1;
    }
    }


    jbyte* bytes = env->GetByteArrayElements(buffer, 0);
    env->GetByteArrayRegion(buffer, srcOffset, count, (jbyte *)address + destOffset);
    memcpy((char *)address + destOffset, bytes + srcOffset, count);
    env->ReleaseByteArrayElements(buffer, bytes, 0);


    if (unpinned) {
    if (unpinned) {
        ashmem_unpin_region(fd, 0, 0);
        ashmem_unpin_region(fd, 0, 0);