buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 3 | #include "compiler.h" |
| 4 | |
| 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "UniquePtr.h" |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 9 | #include "class_linker.h" |
| 10 | #include "common_test.h" |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 11 | #include "dex_cache.h" |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 12 | #include "dex_file.h" |
| 13 | #include "heap.h" |
| 14 | #include "object.h" |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 15 | |
| 16 | namespace art { |
| 17 | |
| 18 | class CompilerTest : public CommonTest { |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 19 | protected: |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 20 | |
| 21 | const ClassLoader* LoadDex(const char* dex_name) { |
| 22 | dex_file_.reset(OpenTestDexFile(dex_name)); |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 23 | class_linker_->RegisterDexFile(*dex_file_.get()); |
| 24 | std::vector<const DexFile*> class_path; |
| 25 | class_path.push_back(dex_file_.get()); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 26 | const ClassLoader* class_loader = PathClassLoader::Alloc(class_path); |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 27 | Thread::Current()->SetClassLoaderOverride(class_loader); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 28 | return class_loader; |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 31 | |
| 32 | void CompileDex(const char* dex_name) { |
| 33 | Compile(LoadDex(dex_name)); |
| 34 | } |
| 35 | |
| 36 | void CompileSystem() { |
| 37 | Compile(NULL); |
| 38 | } |
| 39 | |
| 40 | void Compile(const ClassLoader* class_loader) { |
| 41 | Compiler compiler; |
| 42 | compiler.CompileAll(NULL); |
| 43 | } |
| 44 | |
| 45 | std::string ConvertClassNameToClassDescriptor(const char* class_name) { |
| 46 | std::string desc; |
| 47 | desc += "L"; |
| 48 | desc += class_name; |
| 49 | desc += ";"; |
| 50 | std::replace(desc.begin(), desc.end(), '.', '/'); |
| 51 | return desc; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | void CompileDirectMethod(const ClassLoader* class_loader, |
| 56 | const char* class_name, |
| 57 | const char* method_name, |
| 58 | const char* signature) { |
| 59 | std::string class_descriptor = ConvertClassNameToClassDescriptor(class_name); |
| 60 | Class* klass = class_linker_->FindClass(class_descriptor, class_loader); |
| 61 | CHECK(klass != NULL) << "Class not found " << class_name; |
| 62 | Method* method = klass->FindDirectMethod(method_name, signature); |
| 63 | CHECK(method != NULL) << "Method not found " << method_name; |
| 64 | Compiler compiler; |
| 65 | compiler.CompileOne(method); |
| 66 | } |
| 67 | |
| 68 | void CompileVirtualMethod(const ClassLoader* class_loader, |
| 69 | const char* class_name, |
| 70 | const char* method_name, |
| 71 | const char* signature) { |
| 72 | std::string class_descriptor = ConvertClassNameToClassDescriptor(class_name); |
| 73 | Class* klass = class_linker_->FindClass(class_descriptor, class_loader); |
| 74 | CHECK(klass != NULL) << "Class not found " << class_name; |
| 75 | Method* method = klass->FindVirtualMethod(method_name, signature); |
| 76 | CHECK(method != NULL) << "Method not found " << method_name; |
| 77 | Compiler compiler; |
| 78 | compiler.CompileOne(method); |
| 79 | } |
| 80 | |
| 81 | void AssertStaticIntMethod(const ClassLoader* class_loader, |
| 82 | const char* klass, const char* method, const char* signature, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 83 | jint expected, ...) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 84 | CompileDirectMethod(class_loader, klass, method, signature); |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 85 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 86 | jclass c = env->FindClass(klass); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 87 | CHECK(c != NULL) << "Class not found " << klass; |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 88 | jmethodID m = env->GetStaticMethodID(c, method, signature); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 89 | CHECK(m != NULL) << "Method not found " << method; |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 90 | #if defined(__arm__) |
| 91 | va_list args; |
| 92 | va_start(args, expected); |
| 93 | jint result = env->CallStaticIntMethodV(c, m, args); |
| 94 | va_end(args); |
| 95 | LOG(INFO) << klass << "." << method << "(...) result is " << result; |
| 96 | EXPECT_EQ(expected, result); |
| 97 | #endif // __arm__ |
| 98 | } |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 99 | void AssertStaticLongMethod(const ClassLoader* class_loader, |
| 100 | const char* klass, const char* method, const char* signature, |
| 101 | jlong expected, ...) { |
| 102 | CompileDirectMethod(class_loader, klass, method, signature); |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 103 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 104 | jclass c = env->FindClass(klass); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 105 | CHECK(c != NULL) << "Class not found " << klass; |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 106 | jmethodID m = env->GetStaticMethodID(c, method, signature); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 107 | CHECK(m != NULL) << "Method not found " << method; |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 108 | #if defined(__arm__) |
| 109 | va_list args; |
| 110 | va_start(args, expected); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 111 | jlong result = env->CallStaticLongMethodV(c, m, args); |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 112 | va_end(args); |
| 113 | LOG(INFO) << klass << "." << method << "(...) result is " << result; |
| 114 | EXPECT_EQ(expected, result); |
| 115 | #endif // __arm__ |
| 116 | } |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 117 | private: |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 118 | UniquePtr<const DexFile> dex_file_; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 121 | // TODO renenable when compiler can handle libcore |
| 122 | TEST_F(CompilerTest, DISABLED_CompileDexLibCore) { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 123 | Compiler compiler; |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 124 | compiler.CompileAll(NULL); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 125 | |
| 126 | // All libcore references should resolve |
| 127 | const DexFile* dex = java_lang_dex_file_.get(); |
| 128 | DexCache* dex_cache = class_linker_->FindDexCache(*dex); |
| 129 | EXPECT_EQ(dex->NumStringIds(), dex_cache->NumStrings()); |
| 130 | for (size_t i = 0; i < dex_cache->NumStrings(); i++) { |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 131 | const String* string = dex_cache->GetResolvedString(i); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 132 | EXPECT_TRUE(string != NULL); |
| 133 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 134 | EXPECT_EQ(dex->NumTypeIds(), dex_cache->NumResolvedTypes()); |
| 135 | for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 136 | Class* type = dex_cache->GetResolvedType(i); |
| 137 | EXPECT_TRUE(type != NULL); |
| 138 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 139 | EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumResolvedMethods()); |
| 140 | for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) { |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 141 | Method* method = dex_cache->GetResolvedMethod(i); |
| 142 | EXPECT_TRUE(method != NULL); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 143 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 144 | EXPECT_EQ(dex->NumFieldIds(), dex_cache->NumResolvedFields()); |
| 145 | for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) { |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 146 | Field* field = dex_cache->GetResolvedField(i); |
| 147 | EXPECT_TRUE(field != NULL); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 150 | // TODO check Class::IsVerified for all classes |
| 151 | |
| 152 | // TODO: check that all Method::GetCode() values are non-null |
| 153 | |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 154 | EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumCodeAndDirectMethods()); |
| 155 | CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods(); |
| 156 | for (size_t i = 0; i < dex_cache->NumCodeAndDirectMethods(); i++) { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 157 | Method* method = dex_cache->GetResolvedMethod(i); |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 158 | EXPECT_EQ(method->GetCode(), code_and_direct_methods->GetResolvedCode(i)); |
| 159 | EXPECT_EQ(method, code_and_direct_methods->GetResolvedMethod(i)); |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 160 | } |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 161 | } |
| 162 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 163 | TEST_F(CompilerTest, BasicCodegen) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 164 | AssertStaticIntMethod(LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 55, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 165 | 10); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 166 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 167 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 168 | TEST_F(CompilerTest, ConstStringTest) { |
| 169 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constStringTest", |
| 170 | "(I)I", 2468, 1234); |
| 171 | } |
| 172 | |
| 173 | TEST_F(CompilerTest, DISABLED_CatchTest) { |
| 174 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 175 | CompileDirectMethod(NULL, "java.lang.NullPointerException", "<init>", "()V"); |
| 176 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 177 | CompileDirectMethod(class_loader, "IntMath", "throwNullPointerException", "()V"); |
| 178 | AssertStaticIntMethod(class_loader, "IntMath", "catchBlock", "(I)I", 1579, |
| 179 | 1000); |
| 180 | } |
| 181 | |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 182 | TEST_F(CompilerTest, StaticFieldTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 183 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 1404, |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 184 | 404); |
| 185 | } |
| 186 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 187 | TEST_F(CompilerTest, UnopTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 188 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 37, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 189 | 38); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 190 | } |
| 191 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 192 | TEST_F(CompilerTest, ShiftTest1) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 193 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest1", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 194 | } |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 195 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 196 | TEST_F(CompilerTest, ShiftTest2) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 197 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest2", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 198 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 199 | |
| 200 | TEST_F(CompilerTest, UnsignedShiftTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 201 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 202 | } |
| 203 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 204 | TEST_F(CompilerTest, ConvTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 205 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "convTest", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 206 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 207 | |
| 208 | TEST_F(CompilerTest, CharSubTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 209 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "charSubTest", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 210 | } |
| 211 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 212 | TEST_F(CompilerTest, IntOperTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 213 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 214 | 70000, -3); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 215 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 216 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 217 | TEST_F(CompilerTest, Lit16Test) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 218 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 219 | 77777); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 220 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 221 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 222 | TEST_F(CompilerTest, Lit8Test) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 223 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 224 | -55555); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 225 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 226 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 227 | TEST_F(CompilerTest, IntShiftTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 228 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 229 | 0xff00aa01, 8); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 230 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 231 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 232 | TEST_F(CompilerTest, LongOperTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 233 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I", 0, |
buzbee | 439c4fa | 2011-08-27 15:59:07 -0700 | [diff] [blame] | 234 | 70000000000LL, -3LL); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 235 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 236 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 237 | TEST_F(CompilerTest, LongShiftTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 238 | AssertStaticLongMethod(LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J", |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 239 | 0x96deff00aa010000LL, 0xd5aa96deff00aa01LL, 16); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 240 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 241 | |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 242 | TEST_F(CompilerTest, SwitchTest1) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 243 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1234, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 244 | 1); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | TEST_F(CompilerTest, IntCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 248 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I", 1111, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 249 | -5, 4, 4, 0); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | TEST_F(CompilerTest, LongCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 253 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I", 2222, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 254 | -5LL, -4294967287LL, 4LL, 8LL); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | TEST_F(CompilerTest, FloatCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 258 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I", 3333, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 259 | -5.0f, 4.0f, 4.0f, |
| 260 | (1.0f/0.0f) / (1.0f/0.0f)); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | TEST_F(CompilerTest, DoubleCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 264 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I", 4444, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 265 | -5.0, 4.0, 4.0, |
| 266 | (1.0/0.0) / (1.0/0.0)); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 267 | } |
| 268 | |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 269 | TEST_F(CompilerTest, RecursiveFibonacci) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 270 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 55, |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 271 | 10); |
| 272 | } |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 273 | |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 274 | #if 0 // Need to complete try/catch block handling |
| 275 | TEST_F(CompilerTest, ThrowAndCatch) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 276 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I", 4); |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 277 | } |
| 278 | #endif |
| 279 | |
| 280 | TEST_F(CompilerTest, ManyArgs) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 281 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "manyArgs", |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 282 | "(IJIJIJIIDFDSICIIBZIIJJIIIII)I", -1, |
| 283 | 0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0, |
| 284 | (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18, |
| 285 | 19, 20LL, 21LL, 22, 23, 24, 25, 26); |
| 286 | } |
| 287 | |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 288 | TEST_F(CompilerTest, VirtualCall) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 289 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 290 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 291 | CompileDirectMethod(class_loader, "IntMath", "<init>", "()V"); |
| 292 | CompileVirtualMethod(class_loader, "IntMath", "virtualCall", "(I)I"); |
| 293 | AssertStaticIntMethod(class_loader, "IntMath", "staticCall", "(I)I", 6, |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 294 | 3); |
| 295 | } |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 296 | |
buzbee | dd3efae | 2011-08-28 14:39:07 -0700 | [diff] [blame] | 297 | TEST_F(CompilerTest, TestIGetPut) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 298 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 299 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 300 | CompileDirectMethod(class_loader, "IntMath", "<init>", "(I)V"); |
| 301 | CompileDirectMethod(class_loader, "IntMath", "<init>", "()V"); |
| 302 | CompileVirtualMethod(class_loader, "IntMath", "getFoo", "()I"); |
| 303 | CompileVirtualMethod(class_loader, "IntMath", "setFoo", "(I)V"); |
| 304 | AssertStaticIntMethod(class_loader, "IntMath", "testIGetPut", "(I)I", 333, |
buzbee | dd3efae | 2011-08-28 14:39:07 -0700 | [diff] [blame] | 305 | 111); |
| 306 | } |
| 307 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 308 | } // namespace art |