ART: Add pointer-size template to some reflection functions
The unstarted runtime may run code for a different pointer size,
even when no transaction is active (e.g., during startup). To
retain performance when the runtime is up and executing under
normal conditions, add a template parameter and use sizeof(void*)
in places where it is adequate.
For maintainability, it is necessary to drop the default for
the transaction template parameter. Implicit conversions from
bool to size_t may lead to incorrect code and hard to diagnose
problems. So instead ensure that all callers must give all
template parameter values.
Test: m test-art-host
Change-Id: I3076883422c8553ede4de5642409c5684a5a9aa8
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index 8cdf96d..6ef3999 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -375,10 +375,12 @@
ScopedObjectAccess soa(env);
ArtMethod* m = soa.DecodeMethod(mid);
mirror::AbstractMethod* method;
+ DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), sizeof(void*));
+ DCHECK(!Runtime::Current()->IsActiveTransaction());
if (m->IsConstructor()) {
- method = mirror::Constructor::CreateFromArtMethod(soa.Self(), m);
+ method = mirror::Constructor::CreateFromArtMethod<sizeof(void*), false>(soa.Self(), m);
} else {
- method = mirror::Method::CreateFromArtMethod(soa.Self(), m);
+ method = mirror::Method::CreateFromArtMethod<sizeof(void*), false>(soa.Self(), m);
}
return soa.AddLocalReference<jobject>(method);
}
@@ -387,7 +389,8 @@
CHECK_NON_NULL_ARGUMENT(fid);
ScopedObjectAccess soa(env);
ArtField* f = soa.DecodeField(fid);
- return soa.AddLocalReference<jobject>(mirror::Field::CreateFromArtField(soa.Self(), f, true));
+ return soa.AddLocalReference<jobject>(
+ mirror::Field::CreateFromArtField<sizeof(void*)>(soa.Self(), f, true));
}
static jclass GetObjectClass(JNIEnv* env, jobject java_object) {