Materialize method descriptors when instantiating method objects.
Previously, when comparing method descriptors, one had to piecewise
compare the leaves of a method structure for equality.
With this change a flat method descriptor is computed and associated
to an object. This will simplify comparisons for descriptor equality
used during verification and reflective method retrieval.
Change-Id: I91e5ac76fb3816a36716b34fe43d05cd7364897b
diff --git a/src/jni_compiler_test.cc b/src/jni_compiler_test.cc
index 7dcfdc2..3041927 100644
--- a/src/jni_compiler_test.cc
+++ b/src/jni_compiler_test.cc
@@ -205,8 +205,12 @@
TEST_F(JniCompilerTest, CompileAndRunNoArgMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("foo"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod("foo", "()V");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -230,8 +234,12 @@
TEST_F(JniCompilerTest, CompileAndRunIntMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("fooI"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod("fooI", "(I)I");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -257,8 +265,12 @@
TEST_F(JniCompilerTest, CompileAndRunIntIntMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("fooII"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod("fooII", "(II)I");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -287,8 +299,12 @@
TEST_F(JniCompilerTest, CompileAndRunDoubleDoubleMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("fooDD"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod("fooDD", "(DD)D");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -316,8 +332,14 @@
TEST_F(JniCompilerTest, CompileAndRunIntObjectObjectMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("fooIOO"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod(
+ "fooIOO",
+ "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -371,8 +393,14 @@
TEST_F(JniCompilerTest, CompileAndRunStaticIntObjectObjectMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindDirectMethod(String::AllocFromAscii("fooSIOO"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindDirectMethod(
+ "fooSIOO",
+ "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -423,8 +451,14 @@
TEST_F(JniCompilerTest, CompileAndRunStaticSynchronizedIntObjectObjectMethod) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindDirectMethod(String::AllocFromAscii("fooSSIOO"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindDirectMethod(
+ "fooSSIOO",
+ "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -481,8 +515,12 @@
TEST_F(JniCompilerTest, SuspendCountAcknolewdgement) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("fooI"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod("fooI", "(I)I");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;
@@ -522,8 +560,12 @@
TEST_F(JniCompilerTest, ExceptionHandling) {
scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassNativesDex));
class_linker_->RegisterDexFile(dex.get());
+
Class* klass = class_linker_->FindClass("LMyClass;", NULL, dex.get());
- Method* method = klass->FindVirtualMethod(String::AllocFromAscii("foo"));
+ ASSERT_TRUE(klass != NULL);
+
+ Method* method = klass->FindVirtualMethod("foo", "()V");
+ ASSERT_TRUE(method != NULL);
Assembler jni_asm;
JniCompiler jni_compiler;