Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java

Issue 1127313006: Fix alignment issue on old ART runtime. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/android/system/core_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
diff --git a/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java b/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
index 86ad0cd8689465cd455a5fc7726b09d78a534945..0cc2b8c4d992b6c7563909cfe4143d01bbad7337 100644
--- a/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
+++ b/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
@@ -59,7 +59,12 @@ public class CoreImpl implements Core, AsyncWaiter {
/**
* The run loop for the current thread.
*/
- private ThreadLocal<BaseRunLoop> mCurrentRunLoop = new ThreadLocal<BaseRunLoop>();
+ private final ThreadLocal<BaseRunLoop> mCurrentRunLoop = new ThreadLocal<BaseRunLoop>();
+
+ /**
+ * The offset needed to get an aligned buffer.
+ */
+ private final int mByteBufferOffset;
/**
* @return the instance.
@@ -68,7 +73,12 @@ public class CoreImpl implements Core, AsyncWaiter {
return LazyHolder.INSTANCE;
}
- private CoreImpl() {}
+ private CoreImpl() {
+ // Fix for the ART runtime, before:
+ // https://android.googlesource.com/platform/libcore/+/fb6c80875a8a8d0a9628562f89c250b6a962e824%5E!/
+ // This assumes consistent allocation.
+ mByteBufferOffset = nativeGetNativeBufferOffset(ByteBuffer.allocateDirect(8), 8);
+ }
/**
* @see Core#getTimeTicksNow()
@@ -476,10 +486,13 @@ public class CoreImpl implements Core, AsyncWaiter {
return code;
}
- private static ByteBuffer allocateDirectBuffer(int capacity) {
- ByteBuffer buffer = ByteBuffer.allocateDirect(capacity);
- buffer.order(ByteOrder.nativeOrder());
- return buffer;
+ private ByteBuffer allocateDirectBuffer(int capacity) {
+ ByteBuffer buffer = ByteBuffer.allocateDirect(capacity + mByteBufferOffset);
+ if (mByteBufferOffset != 0) {
+ buffer.position(mByteBufferOffset);
+ buffer = buffer.slice();
+ }
+ return buffer.order(ByteOrder.nativeOrder());
}
/**
@@ -618,4 +631,6 @@ public class CoreImpl implements Core, AsyncWaiter {
int mojoHandle, int signals, long deadline, AsyncWaiter.Callback callback);
private native void nativeCancelAsyncWait(long mId, long dataPtr);
+
+ private native int nativeGetNativeBufferOffset(ByteBuffer buffer, int alignment);
}
« no previous file with comments | « mojo/android/system/core_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698