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