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/proxy_test.cc b/runtime/proxy_test.cc
index 4d9ca6d..1ce7e48 100644
--- a/runtime/proxy_test.cc
+++ b/runtime/proxy_test.cc
@@ -60,29 +60,31 @@
jsize array_index = 0;
// Fill the method array
+ DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), sizeof(void*));
ArtMethod* method = javaLangObject->FindDeclaredVirtualMethod(
"equals", "(Ljava/lang/Object;)Z", sizeof(void*));
CHECK(method != nullptr);
+ DCHECK(!Runtime::Current()->IsActiveTransaction());
soa.Env()->SetObjectArrayElement(
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
- mirror::Method::CreateFromArtMethod(soa.Self(), method)));
+ mirror::Method::CreateFromArtMethod<sizeof(void*), false>(soa.Self(), method)));
method = javaLangObject->FindDeclaredVirtualMethod("hashCode", "()I", sizeof(void*));
CHECK(method != nullptr);
soa.Env()->SetObjectArrayElement(
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
- mirror::Method::CreateFromArtMethod(soa.Self(), method)));
+ mirror::Method::CreateFromArtMethod<sizeof(void*), false>(soa.Self(), method)));
method = javaLangObject->FindDeclaredVirtualMethod(
"toString", "()Ljava/lang/String;", sizeof(void*));
CHECK(method != nullptr);
soa.Env()->SetObjectArrayElement(
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
- mirror::Method::CreateFromArtMethod(soa.Self(), method)));
+ mirror::Method::CreateFromArtMethod<sizeof(void*), false>(soa.Self(), method)));
// Now adds all interfaces virtual methods.
for (mirror::Class* interface : interfaces) {
for (auto& m : interface->GetDeclaredVirtualMethods(sizeof(void*))) {
soa.Env()->SetObjectArrayElement(
proxyClassMethods, array_index++, soa.AddLocalReference<jobject>(
- mirror::Method::CreateFromArtMethod(soa.Self(), &m)));
+ mirror::Method::CreateFromArtMethod<sizeof(void*), false>(soa.Self(), &m)));
}
}
CHECK_EQ(array_index, methods_count);
@@ -226,14 +228,20 @@
EXPECT_EQ(static_fields1->At(0).GetDeclaringClass(), proxyClass1.Get());
EXPECT_EQ(static_fields1->At(1).GetDeclaringClass(), proxyClass1.Get());
+ ASSERT_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), sizeof(void*));
+ ASSERT_FALSE(Runtime::Current()->IsActiveTransaction());
Handle<mirror::Field> field00 =
- hs.NewHandle(mirror::Field::CreateFromArtField(soa.Self(), &static_fields0->At(0), true));
+ hs.NewHandle(mirror::Field::CreateFromArtField<sizeof(void*), false>(
+ soa.Self(), &static_fields0->At(0), true));
Handle<mirror::Field> field01 =
- hs.NewHandle(mirror::Field::CreateFromArtField(soa.Self(), &static_fields0->At(1), true));
+ hs.NewHandle(mirror::Field::CreateFromArtField<sizeof(void*), false>(
+ soa.Self(), &static_fields0->At(1), true));
Handle<mirror::Field> field10 =
- hs.NewHandle(mirror::Field::CreateFromArtField(soa.Self(), &static_fields1->At(0), true));
+ hs.NewHandle(mirror::Field::CreateFromArtField<sizeof(void*), false>(
+ soa.Self(), &static_fields1->At(0), true));
Handle<mirror::Field> field11 =
- hs.NewHandle(mirror::Field::CreateFromArtField(soa.Self(), &static_fields1->At(1), true));
+ hs.NewHandle(mirror::Field::CreateFromArtField<sizeof(void*), false>(
+ soa.Self(), &static_fields1->At(1), true));
EXPECT_EQ(field00->GetArtField(), &static_fields0->At(0));
EXPECT_EQ(field01->GetArtField(), &static_fields0->At(1));
EXPECT_EQ(field10->GetArtField(), &static_fields1->At(0));