diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-10 13:04:27 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-12-04 23:04:26 +0100 |
commit | a813044708c8297e4cbe634c7822c41336fcec87 (patch) | |
tree | 5cc4bf09ddd69ce8aa022427c159e4b8b944c881 /android | |
parent | 46ccb683a3b7c23d09e2e813b9d5c92b98b831c4 (diff) |
android: VM based implementation of DirectBufferAllocator
DirectBufferAllocator is responsible to allocate buffer. We used
Fennec JNI based allocation (and freeing) because of overallocation
bug in some Android versions. With this the VM based allocator
implementation is added and used by default because of bugs that
happen in newer Android versions (specifically when ART is used
as the Android VM).
Change-Id: I07eb364fd1647b3a09d1568d4fef82398a02dfeb
Diffstat (limited to 'android')
-rw-r--r-- | android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java index 7c8f808eb5a2..431ccad97182 100644 --- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java +++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java @@ -11,10 +11,14 @@ package org.libreoffice.kit; // https://code.google.com/p/android/issues/detail?id=16941 // +import android.util.Log; + import java.nio.ByteBuffer; public class DirectBufferAllocator { + private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName(); + private DirectBufferAllocator() { } @@ -23,13 +27,23 @@ public class DirectBufferAllocator { private static native void freeDirectBufferNative(ByteBuffer aBuffer); public static ByteBuffer allocate(int size) { - if (size <= 0) { - throw new IllegalArgumentException("Invalid size " + size); - } + Log.i(LOGTAG, "Buffer size: " + size); + return allocateVM(size); + } + + public static ByteBuffer free(ByteBuffer buffer) { + return freeVM(buffer); + } + private static ByteBuffer allocateJNI(int size) { ByteBuffer directBuffer = allocateDirectBufferNative(size); + if (directBuffer == null) { - throw new OutOfMemoryError("allocateDirectBuffer() returned null"); + if (size <= 0) { + throw new IllegalArgumentException("Invalid allocation size: " + size); + } else { + throw new OutOfMemoryError("allocateDirectBuffer() returned null"); + } } else if (!directBuffer.isDirect()) { throw new AssertionError("allocateDirectBuffer() did not return a direct buffer"); } @@ -37,7 +51,7 @@ public class DirectBufferAllocator { return directBuffer; } - public static ByteBuffer free(ByteBuffer buffer) { + private static ByteBuffer freeJNI(ByteBuffer buffer) { if (buffer == null) { return null; } @@ -49,4 +63,31 @@ public class DirectBufferAllocator { freeDirectBufferNative(buffer); return null; } -}
\ No newline at end of file + + private static ByteBuffer allocateVM(int size) { + ByteBuffer directBuffer = ByteBuffer.allocateDirect(size); + if (directBuffer == null) { + if (size <= 0) { + throw new IllegalArgumentException("Invalid allocation size: " + size); + } else { + throw new OutOfMemoryError("allocateDirectBuffer() returned null"); + } + } else if (!directBuffer.isDirect()) { + throw new AssertionError("allocateDirectBuffer() did not return a direct buffer"); + } + + return directBuffer; + } + + private static ByteBuffer freeVM(ByteBuffer buffer) { + if (buffer == null) { + return null; + } + + if (!buffer.isDirect()) { + throw new IllegalArgumentException("buffer must be direct"); + } + + return null; + } +} |