Merge "Pass --top-k-profile-threshold to dex2oat if available."
diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c
index 064ee32..f714836 100644
--- a/cmds/installd/installd.c
+++ b/cmds/installd/installd.c
@@ -489,6 +489,11 @@
         goto fail;
     }
 
+    if (ensure_config_user_dirs(0) == -1) {
+        ALOGE("Failed to setup misc for user 0");
+        goto fail;
+    }
+
     if (version == 2) {
         ALOGD("Upgrading to /data/misc/user directories");
 
@@ -517,12 +522,31 @@
             closedir(dir);
         }
 
-        version = 3;
-    }
+        // Just rename keychain files into user/0; they should already have the right permissions
+        char misc_dir[PATH_MAX];
+        char keychain_added_dir[PATH_MAX];
+        char keychain_removed_dir[PATH_MAX];
+        char config_added_dir[PATH_MAX];
+        char config_removed_dir[PATH_MAX];
 
-    if (ensure_config_user_dirs(0) == -1) {
-        ALOGE("Failed to setup misc for user 0");
-        goto fail;
+        snprintf(misc_dir, PATH_MAX, "%s/misc", android_data_dir.path);
+        snprintf(keychain_added_dir, PATH_MAX, "%s/keychain/cacerts-added", misc_dir);
+        snprintf(keychain_removed_dir, PATH_MAX, "%s/keychain/cacerts-removed", misc_dir);
+        snprintf(config_added_dir, PATH_MAX, "%s/user/0/cacerts-added", misc_dir);
+        snprintf(config_removed_dir, PATH_MAX, "%s/user/0/cacerts-removed", misc_dir);
+
+        if (access(keychain_added_dir, F_OK) == 0) {
+            if (rename(keychain_added_dir, config_added_dir) != 0) {
+                goto fail;
+            }
+        }
+        if (access(keychain_removed_dir, F_OK) == 0) {
+            if (rename(keychain_removed_dir, config_removed_dir) != 0) {
+                goto fail;
+            }
+        }
+
+        version = 3;
     }
 
     // Persist layout version if changed
diff --git a/libs/gui/BitTube.cpp b/libs/gui/BitTube.cpp
index 85a7de7..0282834 100644
--- a/libs/gui/BitTube.cpp
+++ b/libs/gui/BitTube.cpp
@@ -145,7 +145,7 @@
 
     // should never happen because of SOCK_SEQPACKET
     LOG_ALWAYS_FATAL_IF((size >= 0) && (size % objSize),
-            "BitTube::sendObjects(count=%d, size=%d), res=%d (partial events were sent!)",
+            "BitTube::sendObjects(count=%zu, size=%zu), res=%zd (partial events were sent!)",
             count, objSize, size);
 
     //ALOGE_IF(size<0, "error %d sending %d events", size, count);
@@ -160,7 +160,7 @@
 
     // should never happen because of SOCK_SEQPACKET
     LOG_ALWAYS_FATAL_IF((size >= 0) && (size % objSize),
-            "BitTube::recvObjects(count=%d, size=%d), res=%d (partial events were received!)",
+            "BitTube::recvObjects(count=%zu, size=%zu), res=%zd (partial events were received!)",
             count, objSize, size);
 
     //ALOGE_IF(size<0, "error %d receiving %d events", size, count);
diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp
index c4ec857..674ee5a 100644
--- a/libs/gui/ConsumerBase.cpp
+++ b/libs/gui/ConsumerBase.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
+
 #define LOG_TAG "ConsumerBase"
 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
 //#define LOG_NDEBUG 0
@@ -188,7 +190,7 @@
     mSlots[item->mBuf].mFrameNumber = item->mFrameNumber;
     mSlots[item->mBuf].mFence = item->mFence;
 
-    CB_LOGV("acquireBufferLocked: -> slot=%d/%llu",
+    CB_LOGV("acquireBufferLocked: -> slot=%d/%" PRIu64,
             item->mBuf, item->mFrameNumber);
 
     return OK;
@@ -239,7 +241,7 @@
         return OK;
     }
 
-    CB_LOGV("releaseBufferLocked: slot=%d/%llu",
+    CB_LOGV("releaseBufferLocked: slot=%d/%" PRIu64,
             slot, mSlots[slot].mFrameNumber);
     status_t err = mConsumer->releaseBuffer(slot, mSlots[slot].mFrameNumber,
             display, eglFence, mSlots[slot].mFence);
diff --git a/opengl/libs/EGL/getProcAddress.cpp b/opengl/libs/EGL/getProcAddress.cpp
index 5470d81..fc61134 100644
--- a/opengl/libs/EGL/getProcAddress.cpp
+++ b/opengl/libs/EGL/getProcAddress.cpp
@@ -53,9 +53,29 @@
             : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
               [api] "J"(__builtin_offsetof(gl_hooks_t,          \
                                       ext.extensions[_api]))    \
-            :                                                   \
+            : "r12"                                             \
             );
 
+#elif defined(__aarch64__)
+
+    #define API_ENTRY(_api) __attribute__((noinline)) _api
+
+    #define CALL_GL_EXTENSION_API(_api)                             \
+        asm volatile(                                               \
+            "mrs x16, tpidr_el0\n"                                  \
+            "ldr x16, [x16, %[tls]]\n"                              \
+            "cbz x16, 1f\n"                                         \
+            "ldr x16, [x16, %[api]]\n"                              \
+            "cbz x16, 1f\n"                                         \
+            "br  x16\n"                                             \
+            "1:\n"                                                  \
+            :                                                       \
+            : [tls] "i" (TLS_SLOT_OPENGL_API * sizeof(void*)),      \
+              [api] "i" (__builtin_offsetof(gl_hooks_t,             \
+                                        ext.extensions[_api]))      \
+            : "x16"                                                 \
+        );
+
 #elif defined(__i386__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
diff --git a/opengl/libs/GLES2/gl2.cpp b/opengl/libs/GLES2/gl2.cpp
index ab6fb51..e112fec 100644
--- a/opengl/libs/GLES2/gl2.cpp
+++ b/opengl/libs/GLES2/gl2.cpp
@@ -40,7 +40,15 @@
 #undef CALL_GL_API
 #undef CALL_GL_API_RETURN
 
-#if defined(__arm__) && !USE_SLOW_BINDING
+#if USE_SLOW_BINDING
+
+    #define API_ENTRY(_api) _api
+
+    #define CALL_GL_API(_api, ...)                                       \
+        gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
+        if (_c) return _c->_api(__VA_ARGS__);
+
+#elif defined(__arm__)
 
     #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
 
@@ -55,10 +63,28 @@
             :                                                   \
             : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
               [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api))    \
-            :                                                   \
+            : "r12"                                             \
             );
 
-#elif defined(__i386__) && !USE_SLOW_BINDING
+#elif defined(__aarch64__)
+
+    #define API_ENTRY(_api) __attribute__((noinline)) _api
+
+    #define CALL_GL_API(_api, ...)                                  \
+        asm volatile(                                               \
+            "mrs x16, tpidr_el0\n"                                  \
+            "ldr x16, [x16, %[tls]]\n"                              \
+            "cbz x16, 1f\n"                                         \
+            "ldr x16, [x16, %[api]]\n"                              \
+            "br  x16\n"                                             \
+            "1:\n"                                                  \
+            :                                                       \
+            : [tls] "i" (TLS_SLOT_OPENGL_API * sizeof(void*)),      \
+              [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api))   \
+            : "x16"                                                 \
+        );
+
+#elif defined(__i386__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
 
@@ -77,7 +103,7 @@
             : "cc"                                                  \
             );
 
-#elif defined(__x86_64__) && !USE_SLOW_BINDING
+#elif defined(__x86_64__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
 
@@ -96,7 +122,7 @@
             : "cc"                                                  \
             );
 
-#elif defined(__mips__) && !USE_SLOW_BINDING
+#elif defined(__mips__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
 
@@ -128,14 +154,6 @@
             :                                                    \
             );
 
-#else
-
-    #define API_ENTRY(_api) _api
-
-    #define CALL_GL_API(_api, ...)                                       \
-        gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
-        if (_c) return _c->_api(__VA_ARGS__);
-
 #endif
 
 #define CALL_GL_API_RETURN(_api, ...) \
diff --git a/opengl/libs/GLES_CM/gl.cpp b/opengl/libs/GLES_CM/gl.cpp
index 5873391..71fbed1 100644
--- a/opengl/libs/GLES_CM/gl.cpp
+++ b/opengl/libs/GLES_CM/gl.cpp
@@ -92,7 +92,15 @@
 #undef CALL_GL_API
 #undef CALL_GL_API_RETURN
 
-#if defined(__arm__) && !USE_SLOW_BINDING
+#if USE_SLOW_BINDING
+
+    #define API_ENTRY(_api) _api
+
+    #define CALL_GL_API(_api, ...)                                       \
+        gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
+        if (_c) return _c->_api(__VA_ARGS__);
+
+#elif defined(__arm__)
 
     #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
 
@@ -107,10 +115,28 @@
             :                                                   \
             : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
               [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api))    \
-            :                                                   \
+            : "r12"                                             \
             );
 
-#elif defined(__i386__) && !USE_SLOW_BINDING
+#elif defined(__aarch64__)
+
+    #define API_ENTRY(_api) __attribute__((noinline)) _api
+
+    #define CALL_GL_API(_api, ...)                                  \
+        asm volatile(                                               \
+            "mrs x16, tpidr_el0\n"                                  \
+            "ldr x16, [x16, %[tls]]\n"                              \
+            "cbz x16, 1f\n"                                         \
+            "ldr x16, [x16, %[api]]\n"                              \
+            "br  x16\n"                                             \
+            "1:\n"                                                  \
+            :                                                       \
+            : [tls] "i" (TLS_SLOT_OPENGL_API * sizeof(void*)),      \
+              [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api))   \
+            : "x16"                                                 \
+        );
+
+#elif defined(__i386__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
 
@@ -129,7 +155,7 @@
             : "cc"                                                  \
             );
 
-#elif defined(__x86_64__) && !USE_SLOW_BINDING
+#elif defined(__x86_64__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
 
@@ -148,7 +174,7 @@
             : "cc"                                                  \
             );
 
-#elif defined(__mips__) && !USE_SLOW_BINDING
+#elif defined(__mips__)
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
 
@@ -180,14 +206,6 @@
             :                                                    \
             );
 
-#else
-
-    #define API_ENTRY(_api) _api
-
-    #define CALL_GL_API(_api, ...)                                       \
-        gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
-        if (_c) return _c->_api(__VA_ARGS__);
-
 #endif
 
 #define CALL_GL_API_RETURN(_api, ...) \
diff --git a/opengl/tests/hwc/Android.mk b/opengl/tests/hwc/Android.mk
index 2fdfcf8..86e1d46 100644
--- a/opengl/tests/hwc/Android.mk
+++ b/opengl/tests/hwc/Android.mk
@@ -57,7 +57,6 @@
 LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
 
 LOCAL_MODULE:= hwcStress
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativestresstest
 
 LOCAL_MODULE_TAGS := tests
 
@@ -88,7 +87,6 @@
 	$(call include-path-for, opengl-tests-includes)
 
 LOCAL_MODULE:= hwcRects
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativeutil
 
 LOCAL_MODULE_TAGS := tests
 
@@ -119,7 +117,6 @@
 	$(call include-path-for, opengl-tests-includes)
 
 LOCAL_MODULE:= hwcColorEquiv
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativeutil
 
 LOCAL_MODULE_TAGS := tests
 
@@ -150,7 +147,6 @@
 	$(call include-path-for, opengl-tests-includes)
 
 LOCAL_MODULE:= hwcCommit
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativebenchmark
 
 LOCAL_MODULE_TAGS := tests