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); |
Elliott Hughes | d3a7297 | 2011-09-07 15:31:59 -0700 | [diff] [blame] | 25 | #if defined(__arm__) |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 26 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 27 | jclass c = env->FindClass(klass); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 28 | CHECK(c != NULL) << "Class not found " << klass; |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 29 | jmethodID m = env->GetStaticMethodID(c, method, signature); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 30 | CHECK(m != NULL) << "Method not found: " << klass << "." << method << signature; |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 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); |
Elliott Hughes | d3a7297 | 2011-09-07 15:31:59 -0700 | [diff] [blame] | 43 | #if defined(__arm__) |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 44 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 45 | jclass c = env->FindClass(klass); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 46 | CHECK(c != NULL) << "Class not found " << klass; |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 47 | jmethodID m = env->GetStaticMethodID(c, method, signature); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 48 | CHECK(m != NULL) << "Method not found: " << klass << "." << method << signature; |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 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 | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 59 | // Disabled due to 10 second runtime on host |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 60 | TEST_F(CompilerTest, DISABLED_CompileDexLibCore) { |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 61 | compiler_->CompileAll(NULL); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 62 | |
| 63 | // All libcore references should resolve |
| 64 | const DexFile* dex = java_lang_dex_file_.get(); |
| 65 | DexCache* dex_cache = class_linker_->FindDexCache(*dex); |
| 66 | EXPECT_EQ(dex->NumStringIds(), dex_cache->NumStrings()); |
| 67 | for (size_t i = 0; i < dex_cache->NumStrings(); i++) { |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 68 | const String* string = dex_cache->GetResolvedString(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 69 | EXPECT_TRUE(string != NULL) << "string_idx=" << i; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 70 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 71 | EXPECT_EQ(dex->NumTypeIds(), dex_cache->NumResolvedTypes()); |
| 72 | for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 73 | Class* type = dex_cache->GetResolvedType(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 74 | EXPECT_TRUE(type != NULL) << "type_idx=" << i |
| 75 | << " " << dex->GetTypeDescriptor(dex->GetTypeId(i)); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 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); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 80 | EXPECT_TRUE(method != NULL) << "method_idx=" << i |
| 81 | << " " << dex->GetMethodClassDescriptor(dex->GetMethodId(i)) |
| 82 | << " " << dex->GetMethodName(dex->GetMethodId(i)); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 83 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 84 | EXPECT_EQ(dex->NumFieldIds(), dex_cache->NumResolvedFields()); |
| 85 | for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) { |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 86 | Field* field = dex_cache->GetResolvedField(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 87 | EXPECT_TRUE(field != NULL) << "field_idx=" << i |
| 88 | << " " << dex->GetFieldClassDescriptor(dex->GetFieldId(i)) |
| 89 | << " " << dex->GetFieldName(dex->GetFieldId(i)); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 92 | // TODO check Class::IsVerified for all classes |
| 93 | |
| 94 | // TODO: check that all Method::GetCode() values are non-null |
| 95 | |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 96 | EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumCodeAndDirectMethods()); |
| 97 | CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods(); |
| 98 | for (size_t i = 0; i < dex_cache->NumCodeAndDirectMethods(); i++) { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 99 | Method* method = dex_cache->GetResolvedMethod(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 100 | if (method->IsDirect()) { |
| 101 | EXPECT_EQ(method->GetCode(), code_and_direct_methods->GetResolvedCode(i)); |
| 102 | EXPECT_EQ(method, code_and_direct_methods->GetResolvedMethod(i)); |
| 103 | } else { |
| 104 | EXPECT_EQ(0U, code_and_direct_methods->GetResolvedCode(i)); |
| 105 | EXPECT_TRUE(code_and_direct_methods->GetResolvedMethod(i) == NULL); |
| 106 | } |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 107 | } |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 108 | } |
| 109 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 110 | TEST_F(CompilerTest, BasicCodegen) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 111 | AssertStaticIntMethod(LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 55, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 112 | 10); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 113 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 114 | |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 115 | // TODO: need stub for InstanceofNonTrivialFromCode |
| 116 | TEST_F(CompilerTest, InstanceTest) { |
| 117 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 118 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 119 | CompileDirectMethod(class_loader, "IntMath", "<init>", "()V"); |
| 120 | CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V"); |
| 121 | AssertStaticIntMethod(class_loader, "IntMath", "instanceTest", "(I)I", 1352, 10); |
| 122 | } |
| 123 | |
| 124 | // TODO: need check-cast test (when stub complete & we can throw/catch |
| 125 | |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 126 | // TODO: Need invoke-interface test |
| 127 | |
| 128 | TEST_F(CompilerTest, SuperTest) { |
| 129 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 130 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 131 | CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V"); |
| 132 | CompileVirtualMethod(class_loader, "IntMathBase", "tryThing", "()I"); |
| 133 | CompileDirectMethod(class_loader, "IntMath", "<init>", "()V"); |
| 134 | CompileVirtualMethod(class_loader, "IntMath", "tryThing", "()I"); |
| 135 | AssertStaticIntMethod(class_loader, "IntMath", "superTest", "(I)I", 4175, |
| 136 | 4141); |
| 137 | } |
| 138 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 139 | TEST_F(CompilerTest, ConstStringTest) { |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 140 | CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V"); |
| 141 | CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V"); |
| 142 | CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V"); |
| 143 | CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V"); |
| 144 | CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C"); |
| 145 | CompileVirtualMethod(NULL, "java.lang.String", "length", "()I"); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 146 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constStringTest", |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 147 | "(I)I", 1246, 1234); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 148 | } |
| 149 | |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 150 | TEST_F(CompilerTest, ConstClassTest) { |
| 151 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constClassTest", |
| 152 | "(I)I", 2222, 1111); |
| 153 | } |
| 154 | |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 155 | // TODO: Need native nativeFillInStackTrace() |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 156 | TEST_F(CompilerTest, DISABLED_CatchTest) { |
| 157 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 158 | CompileDirectMethod(NULL, "java.lang.NullPointerException", "<init>", "()V"); |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 159 | CompileDirectMethod(NULL, "java.lang.RuntimeException", "<init>", "()V"); |
| 160 | CompileDirectMethod(NULL, "java.lang.Exception", "<init>", "()V"); |
| 161 | CompileDirectMethod(NULL, "java.lang.Throwable","<init>", "()V"); |
| 162 | CompileDirectMethod(NULL, "java.util.ArrayList","<init>","()V"); |
| 163 | CompileDirectMethod(NULL, "java.util.AbstractList","<init>","()V"); |
| 164 | CompileDirectMethod(NULL, "java.util.AbstractCollection","<init>","()V"); |
| 165 | CompileVirtualMethod(NULL, "java.lang.Throwable","fillInStackTrace","()Ljava/lang/Throwable;"); |
| 166 | CompileDirectMethod(NULL, "java.lang.Throwable","nativeFillInStackTrace","()Ljava/lang/Object;"); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 167 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 168 | CompileDirectMethod(class_loader, "IntMath", "throwNullPointerException", "()V"); |
| 169 | AssertStaticIntMethod(class_loader, "IntMath", "catchBlock", "(I)I", 1579, |
| 170 | 1000); |
| 171 | } |
| 172 | |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 173 | TEST_F(CompilerTest, CatchTestNoThrow) { |
| 174 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 175 | const ClassLoader* class_loader = LoadDex("IntMath"); |
| 176 | AssertStaticIntMethod(class_loader, "IntMath", "catchBlockNoThrow", "(I)I", |
| 177 | 1123, 1000); |
| 178 | } |
| 179 | |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 180 | TEST_F(CompilerTest, StaticFieldTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 181 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 1404, |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 182 | 404); |
| 183 | } |
| 184 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 185 | TEST_F(CompilerTest, UnopTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 186 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 37, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 187 | 38); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 188 | } |
| 189 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 190 | TEST_F(CompilerTest, ShiftTest1) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 191 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest1", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 192 | } |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 193 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 194 | TEST_F(CompilerTest, ShiftTest2) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 195 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest2", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 196 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 197 | |
| 198 | TEST_F(CompilerTest, UnsignedShiftTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 199 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 200 | } |
| 201 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 202 | TEST_F(CompilerTest, ConvTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 203 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "convTest", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 204 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 205 | |
| 206 | TEST_F(CompilerTest, CharSubTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 207 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "charSubTest", "()I", 0); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 208 | } |
| 209 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 210 | TEST_F(CompilerTest, IntOperTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 211 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 212 | 70000, -3); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 213 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 214 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 215 | TEST_F(CompilerTest, Lit16Test) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 216 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 217 | 77777); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 218 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 219 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 220 | TEST_F(CompilerTest, Lit8Test) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 221 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 222 | -55555); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 223 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 224 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 225 | TEST_F(CompilerTest, IntShiftTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 226 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 227 | 0xff00aa01, 8); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 228 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 229 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 230 | TEST_F(CompilerTest, LongOperTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 231 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I", 0, |
buzbee | 439c4fa | 2011-08-27 15:59:07 -0700 | [diff] [blame] | 232 | 70000000000LL, -3LL); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 233 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 234 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 235 | TEST_F(CompilerTest, LongShiftTest) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 236 | AssertStaticLongMethod(LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J", |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 237 | 0x96deff00aa010000LL, 0xd5aa96deff00aa01LL, 16); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 238 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 239 | |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 240 | TEST_F(CompilerTest, SwitchTest1) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 241 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1234, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 242 | 1); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | TEST_F(CompilerTest, IntCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 246 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I", 1111, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 247 | -5, 4, 4, 0); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(CompilerTest, LongCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 251 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I", 2222, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 252 | -5LL, -4294967287LL, 4LL, 8LL); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST_F(CompilerTest, FloatCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 256 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I", 3333, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 257 | -5.0f, 4.0f, 4.0f, |
| 258 | (1.0f/0.0f) / (1.0f/0.0f)); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | TEST_F(CompilerTest, DoubleCompare) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 262 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I", 4444, |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 263 | -5.0, 4.0, 4.0, |
| 264 | (1.0/0.0) / (1.0/0.0)); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 265 | } |
| 266 | |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 267 | TEST_F(CompilerTest, RecursiveFibonacci) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 268 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 55, |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 269 | 10); |
| 270 | } |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 271 | |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 272 | #if 0 // Need to complete try/catch block handling |
| 273 | TEST_F(CompilerTest, ThrowAndCatch) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 274 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I", 4); |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 275 | } |
| 276 | #endif |
| 277 | |
| 278 | TEST_F(CompilerTest, ManyArgs) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 279 | AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "manyArgs", |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 280 | "(IJIJIJIIDFDSICIIBZIIJJIIIII)I", -1, |
| 281 | 0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0, |
| 282 | (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18, |
| 283 | 19, 20LL, 21LL, 22, 23, 24, 25, 26); |
| 284 | } |
| 285 | |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 286 | TEST_F(CompilerTest, VirtualCall) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 287 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 288 | const ClassLoader* class_loader = LoadDex("IntMath"); |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 289 | CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V"); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 290 | CompileDirectMethod(class_loader, "IntMath", "<init>", "()V"); |
| 291 | CompileVirtualMethod(class_loader, "IntMath", "virtualCall", "(I)I"); |
| 292 | AssertStaticIntMethod(class_loader, "IntMath", "staticCall", "(I)I", 6, |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 293 | 3); |
| 294 | } |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 295 | |
buzbee | dd3efae | 2011-08-28 14:39:07 -0700 | [diff] [blame] | 296 | TEST_F(CompilerTest, TestIGetPut) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 297 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 298 | const ClassLoader* class_loader = LoadDex("IntMath"); |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 299 | CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V"); |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 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 | 109bd6a | 2011-09-06 13:58:41 -0700 | [diff] [blame] | 308 | TEST_F(CompilerTest, InvokeTest) { |
| 309 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 310 | const ClassLoader* class_loader = LoadDex("Invoke"); |
| 311 | CompileDirectMethod(class_loader, "Invoke", "<init>", "()V"); |
| 312 | CompileVirtualMethod(class_loader, "Invoke", "virI_I", "(I)I"); |
| 313 | CompileVirtualMethod(class_loader, "Invoke", "virI_II", "(II)I"); |
| 314 | CompileVirtualMethod(class_loader, "Invoke", "virI_III", "(III)I"); |
| 315 | CompileVirtualMethod(class_loader, "Invoke", "virI_IIII", "(IIII)I"); |
| 316 | CompileVirtualMethod(class_loader, "Invoke", "virI_IIIII", "(IIIII)I"); |
| 317 | CompileVirtualMethod(class_loader, "Invoke", "virI_IIIIII", "(IIIIII)I"); |
| 318 | CompileDirectMethod(class_loader, "Invoke", "statI_I", "(I)I"); |
| 319 | CompileDirectMethod(class_loader, "Invoke", "statI_II", "(II)I"); |
| 320 | CompileDirectMethod(class_loader, "Invoke", "statI_III", "(III)I"); |
| 321 | CompileDirectMethod(class_loader, "Invoke", "statI_IIII", "(IIII)I"); |
| 322 | CompileDirectMethod(class_loader, "Invoke", "statI_IIIII", "(IIIII)I"); |
| 323 | CompileDirectMethod(class_loader, "Invoke", "statI_IIIIII", "(IIIIII)I"); |
| 324 | AssertStaticIntMethod(class_loader, "Invoke", "test0", "(I)I", 20664, |
| 325 | 912); |
| 326 | } |
| 327 | |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 328 | TEST_F(CompilerTest, SystemMethodsTest) { |
| 329 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 330 | |
| 331 | CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V"); |
| 332 | CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V"); |
| 333 | CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 334 | CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 335 | CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C"); |
| 336 | CompileVirtualMethod(NULL, "java.lang.String", "length", "()I"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 337 | |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 338 | CompileDirectMethod(NULL, "java.lang.AbstractStringBuilder", "<init>", "()V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 339 | CompileDirectMethod(NULL, "java.lang.AbstractStringBuilder", "<init>", "(I)V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 340 | CompileDirectMethod(NULL, "java.lang.AbstractStringBuilder", "enlargeBuffer", "(I)V"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 341 | CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "append0", "(C)V"); |
| 342 | CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "append0", "(Ljava/lang/String;)V"); |
| 343 | CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "append0", "([CII)V"); |
| 344 | CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "appendNull", "()V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 345 | CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "toString", "()Ljava/lang/String;"); |
| 346 | |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 347 | CompileDirectMethod(NULL, "java.lang.StringBuilder", "<init>", "()V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 348 | CompileDirectMethod(NULL, "java.lang.StringBuilder", "<init>", "(I)V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 349 | CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(C)Ljava/lang/StringBuilder;"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 350 | CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(I)Ljava/lang/StringBuilder;"); |
| 351 | CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(J)Ljava/lang/StringBuilder;"); |
| 352 | CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 353 | CompileVirtualMethod(NULL, "java.lang.StringBuilder", "toString", "()Ljava/lang/String;"); |
| 354 | |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 355 | CompileDirectMethod(NULL, "java.lang.ThreadLocal", "<init>", "()V"); |
| 356 | CompileVirtualMethod(NULL, "java.lang.ThreadLocal", "get", "()Ljava/lang/Object;"); |
| 357 | |
| 358 | CompileDirectMethod(NULL, "java.lang.Long", "toHexString", "(J)Ljava/lang/String;"); |
| 359 | CompileDirectMethod(NULL, "java.lang.Long", "toString", "(J)Ljava/lang/String;"); |
buzbee | 6a0f7f5 | 2011-09-05 16:14:20 -0700 | [diff] [blame] | 360 | CompileDirectMethod(NULL, "java.lang.Long", "toString", "(JI)Ljava/lang/String;"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 361 | |
| 362 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "<clinit>", "()V"); |
| 363 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "appendInt", "(Ljava/lang/AbstractStringBuilder;I)V"); |
| 364 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "appendLong", "(Ljava/lang/AbstractStringBuilder;J)V"); |
| 365 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "convertInt", "(Ljava/lang/AbstractStringBuilder;I)Ljava/lang/String;"); |
| 366 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "convertLong", "(Ljava/lang/AbstractStringBuilder;J)Ljava/lang/String;"); |
| 367 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "intIntoCharArray", "([CII)I"); |
| 368 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "intToHexString", "(IZI)Ljava/lang/String;"); |
| 369 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "longToHexString", "(J)Ljava/lang/String;"); |
| 370 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "longToString", "(J)Ljava/lang/String;"); |
buzbee | 6a0f7f5 | 2011-09-05 16:14:20 -0700 | [diff] [blame] | 371 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "longToString", "(JI)Ljava/lang/String;"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 372 | CompileDirectMethod(NULL, "java.lang.IntegralToString", "stringOf", "([C)Ljava/lang/String;"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 373 | |
| 374 | CompileDirectMethod(NULL, "java.lang.System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 375 | CompileDirectMethod(NULL, "java.lang.System", "currentTimeMillis", "()J"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 376 | CompileDirectMethod(NULL, "java.lang.System", "log", "(CLjava/lang/String;Ljava/lang/Throwable;)V"); |
| 377 | CompileDirectMethod(NULL, "java.lang.System", "logI", "(Ljava/lang/String;)V"); |
| 378 | CompileDirectMethod(NULL, "java.lang.System", "logI", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); |
| 379 | |
| 380 | CompileDirectMethod(NULL, "java.util.Arrays", "checkOffsetAndCount", "(III)V"); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 381 | |
| 382 | const ClassLoader* class_loader = LoadDex("SystemMethods"); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 383 | |
| 384 | CompileDirectMethod(class_loader, "SystemMethods", "<clinit>", "()V"); |
| 385 | |
buzbee | 6a0f7f5 | 2011-09-05 16:14:20 -0700 | [diff] [blame] | 386 | AssertStaticIntMethod(class_loader, "SystemMethods", "test0", "()I", 123); |
| 387 | AssertStaticIntMethod(class_loader, "SystemMethods", "test1", "()I", 123); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 388 | AssertStaticIntMethod(class_loader, "SystemMethods", "test2", "()I", 123); |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 389 | AssertStaticIntMethod(class_loader, "SystemMethods", "test3", "()I", 123); |
| 390 | AssertStaticIntMethod(class_loader, "SystemMethods", "test4", "()I", 123); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 391 | } |
| 392 | |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 393 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 394 | } // namespace art |