JNI optimization tweaks to Paint high-frequency methods

Bug: 22378829

Use fast-jni for getFontMetrics, drops from 35us -> 30us
Note the "heavy" part of the method, getMetricsInternal, is
already called by other fast-jni methods.

Use critical array access for getRunAdvance_* methods. This
will avoid the copy and the access is appropriately scoped
and fast enough to not significantly block the moving GC.
Improves from 88us -> 79us on short text

Change-Id: I7c1481c23f6dba3420fbcf48220f6335cf9f6d10
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index bff1885..c66cdfe 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -1065,12 +1065,11 @@
             jint contextEnd, jboolean isRtl, jint offset) {
         const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
         TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
-        // TODO performance: optimize JNI array access
-        jchar* textArray = env->GetCharArrayElements(text, NULL);
+        jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL);
         jfloat result = doRunAdvance(paint, typeface, textArray + contextStart,
                 start - contextStart, end - start, contextEnd - contextStart, isRtl,
                 offset - contextStart);
-        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
+        env->ReleasePrimitiveArrayCritical(text, textArray, JNI_ABORT);
         return result;
     }
 
@@ -1086,12 +1085,11 @@
             jint contextEnd, jboolean isRtl, jfloat advance) {
         const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
         TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
-        // TODO performance: optimize JNI array access
-        jchar* textArray = env->GetCharArrayElements(text, NULL);
+        jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL);
         jint result = doOffsetForAdvance(paint, typeface, textArray + contextStart,
                 start - contextStart, end - start, contextEnd - contextStart, isRtl, advance);
         result += contextStart;
-        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
+        env->ReleasePrimitiveArrayCritical(text, textArray, JNI_ABORT);
         return result;
     }
 
@@ -1158,9 +1156,9 @@
     {"ascent","!()F", (void*) PaintGlue::ascent},
     {"descent","!()F", (void*) PaintGlue::descent},
 
-    {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F",
+    {"getFontMetrics", "!(Landroid/graphics/Paint$FontMetrics;)F",
             (void*)PaintGlue::getFontMetrics},
-    {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I",
+    {"getFontMetricsInt", "!(Landroid/graphics/Paint$FontMetricsInt;)I",
             (void*)PaintGlue::getFontMetricsInt},
     {"native_measureText","([CIII)F", (void*) PaintGlue::measureText_CIII},
     {"native_measureText","(Ljava/lang/String;I)F", (void*) PaintGlue::measureText_StringI},