Avoid using dex cache array pointers in libart.
In preparation for making dex cache arrays native, avoid
using them in Java code.
This causes a performance regression for our reflection
benchmarks. Class_getDeclaredMethod and Class_getMethod
take an up to 30% hit, measured using the Quick compiler.
We accept this hit at this stage and we will tune the
performance after we're done with the larger effort.
Companion libcore/ change:
https://android-review.googlesource.com/146069
Bug: 20134538
Change-Id: Ibbef3b50043a1311cd40723ed42e1f1c609b8fc1
diff --git a/runtime/native/java_lang_DexCache.cc b/runtime/native/java_lang_DexCache.cc
index 27eae46..8944270 100644
--- a/runtime/native/java_lang_DexCache.cc
+++ b/runtime/native/java_lang_DexCache.cc
@@ -48,8 +48,38 @@
args);
}
+static jobject DexCache_getResolvedType(JNIEnv* env, jobject javaDexCache, jint type_index) {
+ ScopedFastNativeObjectAccess soa(env);
+ mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ return soa.AddLocalReference<jobject>(dex_cache->GetResolvedType(type_index));
+}
+
+static jobject DexCache_getResolvedString(JNIEnv* env, jobject javaDexCache, jint string_index) {
+ ScopedFastNativeObjectAccess soa(env);
+ mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ return soa.AddLocalReference<jobject>(dex_cache->GetResolvedString(string_index));
+}
+
+static void DexCache_setResolvedType(JNIEnv* env, jobject javaDexCache, jint type_index,
+ jobject type) {
+ ScopedFastNativeObjectAccess soa(env);
+ mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ dex_cache->SetResolvedType(type_index, soa.Decode<mirror::Class*>(type));
+}
+
+static void DexCache_setResolvedString(JNIEnv* env, jobject javaDexCache, jint string_index,
+ jobject string) {
+ ScopedFastNativeObjectAccess soa(env);
+ mirror::DexCache* dex_cache = soa.Decode<mirror::DexCache*>(javaDexCache);
+ dex_cache->SetResolvedString(string_index, soa.Decode<mirror::String*>(string));
+}
+
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(DexCache, getDexNative, "!()Lcom/android/dex/Dex;"),
+ NATIVE_METHOD(DexCache, getResolvedType, "!(I)Ljava/lang/Class;"),
+ NATIVE_METHOD(DexCache, getResolvedString, "!(I)Ljava/lang/String;"),
+ NATIVE_METHOD(DexCache, setResolvedType, "!(ILjava/lang/Class;)V"),
+ NATIVE_METHOD(DexCache, setResolvedString, "!(ILjava/lang/String;)V"),
};
void register_java_lang_DexCache(JNIEnv* env) {