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 | |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 21 | void AssertStaticIntMethod(jint expected, const ClassLoader* class_loader, |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 22 | const char* class_name, const char* method, const char* signature, |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 23 | ...) { |
Shih-wei Liao | 303b01e | 2011-09-14 00:46:13 -0700 | [diff] [blame] | 24 | EnsureCompiled(class_loader, class_name, method, signature, false); |
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 | va_list args; |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 27 | va_start(args, signature); |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 28 | jint result = env_->CallStaticIntMethodV(class_, mid_, args); |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 29 | va_end(args); |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 30 | LOG(INFO) << class_name << "." << method << "(...) result is " << result; |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 31 | EXPECT_EQ(expected, result); |
| 32 | #endif // __arm__ |
| 33 | } |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 34 | |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 35 | void AssertStaticLongMethod(jlong expected, const ClassLoader* class_loader, |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 36 | const char* class_name, const char* method, const char* signature, |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 37 | ...) { |
Shih-wei Liao | 303b01e | 2011-09-14 00:46:13 -0700 | [diff] [blame] | 38 | EnsureCompiled(class_loader, class_name, method, signature, false); |
Elliott Hughes | d3a7297 | 2011-09-07 15:31:59 -0700 | [diff] [blame] | 39 | #if defined(__arm__) |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 40 | va_list args; |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 41 | va_start(args, signature); |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 42 | jlong result = env_->CallStaticLongMethodV(class_, mid_, args); |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 43 | va_end(args); |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 44 | LOG(INFO) << class_name << "." << method << "(...) result is " << result; |
buzbee | bafc342 | 2011-08-25 15:22:55 -0700 | [diff] [blame] | 45 | EXPECT_EQ(expected, result); |
| 46 | #endif // __arm__ |
| 47 | } |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 48 | |
| 49 | void CompileAll(const ClassLoader* class_loader) { |
| 50 | compiler_->CompileAll(class_loader); |
| 51 | MakeAllExecutable(class_loader); |
| 52 | } |
| 53 | |
| 54 | void EnsureCompiled(const ClassLoader* class_loader, |
Shih-wei Liao | 303b01e | 2011-09-14 00:46:13 -0700 | [diff] [blame] | 55 | const char* class_name, const char* method, const char* signature, bool is_virtual) { |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 56 | CompileAll(class_loader); |
| 57 | env_ = Thread::Current()->GetJniEnv(); |
| 58 | class_ = env_->FindClass(class_name); |
| 59 | CHECK(class_ != NULL) << "Class not found: " << class_name; |
Shih-wei Liao | 303b01e | 2011-09-14 00:46:13 -0700 | [diff] [blame] | 60 | if (is_virtual) { |
| 61 | mid_ = env_->GetMethodID(class_, method, signature); |
| 62 | } else { |
| 63 | mid_ = env_->GetStaticMethodID(class_, method, signature); |
| 64 | } |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 65 | CHECK(mid_ != NULL) << "Method not found: " << class_name << "." << method << signature; |
| 66 | } |
| 67 | |
| 68 | void MakeAllExecutable(const ClassLoader* class_loader) { |
| 69 | const std::vector<const DexFile*>& class_path = ClassLoader::GetClassPath(class_loader); |
| 70 | for (size_t i = 0; i != class_path.size(); ++i) { |
| 71 | const DexFile* dex_file = class_path[i]; |
| 72 | CHECK(dex_file != NULL); |
| 73 | MakeDexFileExecutable(class_loader, *dex_file); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void MakeDexFileExecutable(const ClassLoader* class_loader, const DexFile& dex_file) { |
| 78 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 79 | for (size_t i = 0; i < dex_file.NumClassDefs(); i++) { |
| 80 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(i); |
| 81 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
| 82 | Class* c = class_linker->FindClass(descriptor, class_loader); |
| 83 | CHECK(c != NULL); |
| 84 | for (size_t i = 0; i < c->NumDirectMethods(); i++) { |
| 85 | MakeMethodExecutable(c->GetDirectMethod(i)); |
| 86 | } |
| 87 | for (size_t i = 0; i < c->NumVirtualMethods(); i++) { |
| 88 | MakeMethodExecutable(c->GetVirtualMethod(i)); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void MakeMethodExecutable(Method* m) { |
| 94 | if (m->GetCodeArray() != NULL) { |
| 95 | MakeExecutable(m->GetCodeArray()); |
| 96 | } else { |
| 97 | LOG(WARNING) << "no code for " << PrettyMethod(m); |
| 98 | } |
| 99 | if (m->GetInvokeStubArray() != NULL) { |
| 100 | MakeExecutable(m->GetInvokeStubArray()); |
| 101 | } else { |
| 102 | LOG(WARNING) << "no invoke stub for " << PrettyMethod(m); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | JNIEnv* env_; |
| 107 | jclass class_; |
| 108 | jmethodID mid_; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 111 | // Disabled due to 10 second runtime on host |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 112 | TEST_F(CompilerTest, DISABLED_LARGE_CompileDexLibCore) { |
| 113 | CompileAll(NULL); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 114 | |
| 115 | // All libcore references should resolve |
| 116 | const DexFile* dex = java_lang_dex_file_.get(); |
| 117 | DexCache* dex_cache = class_linker_->FindDexCache(*dex); |
| 118 | EXPECT_EQ(dex->NumStringIds(), dex_cache->NumStrings()); |
| 119 | for (size_t i = 0; i < dex_cache->NumStrings(); i++) { |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 120 | const String* string = dex_cache->GetResolvedString(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 121 | EXPECT_TRUE(string != NULL) << "string_idx=" << i; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 122 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 123 | EXPECT_EQ(dex->NumTypeIds(), dex_cache->NumResolvedTypes()); |
| 124 | for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) { |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 125 | Class* type = dex_cache->GetResolvedType(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 126 | EXPECT_TRUE(type != NULL) << "type_idx=" << i |
| 127 | << " " << dex->GetTypeDescriptor(dex->GetTypeId(i)); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 128 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 129 | EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumResolvedMethods()); |
| 130 | for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) { |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 131 | Method* method = dex_cache->GetResolvedMethod(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 132 | EXPECT_TRUE(method != NULL) << "method_idx=" << i |
| 133 | << " " << dex->GetMethodClassDescriptor(dex->GetMethodId(i)) |
| 134 | << " " << dex->GetMethodName(dex->GetMethodId(i)); |
Shih-wei Liao | c486c11 | 2011-09-13 16:43:52 -0700 | [diff] [blame] | 135 | EXPECT_TRUE(method->GetCode() != NULL) << "method_idx=" << i |
| 136 | << " " |
| 137 | << dex->GetMethodClassDescriptor(dex->GetMethodId(i)) |
| 138 | << " " << dex->GetMethodName(dex->GetMethodId(i)); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 139 | } |
Brian Carlstrom | 1caa2c2 | 2011-08-28 13:02:33 -0700 | [diff] [blame] | 140 | EXPECT_EQ(dex->NumFieldIds(), dex_cache->NumResolvedFields()); |
| 141 | for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) { |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 142 | Field* field = dex_cache->GetResolvedField(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 143 | EXPECT_TRUE(field != NULL) << "field_idx=" << i |
| 144 | << " " << dex->GetFieldClassDescriptor(dex->GetFieldId(i)) |
| 145 | << " " << dex->GetFieldName(dex->GetFieldId(i)); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 148 | // TODO check Class::IsVerified for all classes |
| 149 | |
| 150 | // TODO: check that all Method::GetCode() values are non-null |
| 151 | |
Brian Carlstrom | 9cc262e | 2011-08-28 12:45:30 -0700 | [diff] [blame] | 152 | EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumCodeAndDirectMethods()); |
| 153 | CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods(); |
| 154 | for (size_t i = 0; i < dex_cache->NumCodeAndDirectMethods(); i++) { |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 155 | Method* method = dex_cache->GetResolvedMethod(i); |
Brian Carlstrom | 7540ff4 | 2011-09-04 16:38:46 -0700 | [diff] [blame] | 156 | if (method->IsDirect()) { |
| 157 | EXPECT_EQ(method->GetCode(), code_and_direct_methods->GetResolvedCode(i)); |
| 158 | EXPECT_EQ(method, code_and_direct_methods->GetResolvedMethod(i)); |
| 159 | } else { |
| 160 | EXPECT_EQ(0U, code_and_direct_methods->GetResolvedCode(i)); |
| 161 | EXPECT_TRUE(code_and_direct_methods->GetResolvedMethod(i) == NULL); |
| 162 | } |
Brian Carlstrom | 83db772 | 2011-08-26 17:32:56 -0700 | [diff] [blame] | 163 | } |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 164 | } |
| 165 | |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 166 | TEST_F(CompilerTest, NullCheckElimination1) { |
| 167 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 168 | AssertStaticIntMethod(2054, LoadDex("ExceptionTest"), "ExceptionTest", "nullCheckTestNoThrow", "(I)I", 1976); |
| 169 | } |
| 170 | |
| 171 | TEST_F(CompilerTest, DISABLED_NullCheckElimination2) { |
| 172 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 173 | AssertStaticIntMethod(2057, LoadDex("ExceptionTest"), "ExceptionTest", "nullCheckTestThrow", "(I)I", 1976); |
| 174 | } |
| 175 | |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 176 | TEST_F(CompilerTest, ByBillion) { |
| 177 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 178 | AssertStaticLongMethod(123, LoadDex("IntMath"), "IntMath", "divideLongByBillion", "(J)J", 123000000000LL); |
| 179 | } |
| 180 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 181 | TEST_F(CompilerTest, BasicCodegen) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 182 | AssertStaticIntMethod(55, LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 10); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 183 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 184 | |
Shih-wei Liao | 303b01e | 2011-09-14 00:46:13 -0700 | [diff] [blame] | 185 | TEST_F(CompilerTest, DISABLED_AbstractMethodErrorStub) { |
| 186 | const ClassLoader* class_loader = LoadDex("AbstractMethod"); |
| 187 | EnsureCompiled(class_loader, "AbstractMethod", "callme", "()V", true); |
| 188 | |
| 189 | // Create a jobj_ of class "B", NOT class "AbstractMethod". |
| 190 | jclass b_class = env_->FindClass("B"); |
| 191 | jmethodID constructor = env_->GetMethodID(b_class, "<init>", "()V"); |
| 192 | jobject jobj_ = env_->NewObject(b_class, constructor); |
| 193 | ASSERT_TRUE(jobj_ != NULL); |
| 194 | |
| 195 | #if defined(__arm__) |
| 196 | // Will throw AbstractMethodError exception. |
| 197 | env_->CallNonvirtualVoidMethod(jobj_, class_, mid_); |
| 198 | #endif // __arm__ |
| 199 | } |
| 200 | |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 201 | // TODO: need stub for InstanceofNonTrivialFromCode |
| 202 | TEST_F(CompilerTest, InstanceTest) { |
| 203 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 204 | AssertStaticIntMethod(1352, LoadDex("IntMath"), "IntMath", "instanceTest", "(I)I", 10); |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // TODO: need check-cast test (when stub complete & we can throw/catch |
| 208 | |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 209 | // TODO: Need invoke-interface test |
| 210 | |
| 211 | TEST_F(CompilerTest, SuperTest) { |
| 212 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 213 | AssertStaticIntMethod(4175, LoadDex("IntMath"), "IntMath", "superTest", "(I)I", 4141); |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 214 | } |
| 215 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 216 | TEST_F(CompilerTest, ConstStringTest) { |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 217 | CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V"); |
| 218 | CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V"); |
| 219 | CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V"); |
| 220 | CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V"); |
| 221 | CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C"); |
| 222 | CompileVirtualMethod(NULL, "java.lang.String", "length", "()I"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 223 | AssertStaticIntMethod(1246, LoadDex("IntMath"), "IntMath", "constStringTest", "(I)I", 1234); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 224 | } |
| 225 | |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 226 | TEST_F(CompilerTest, ConstClassTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 227 | AssertStaticIntMethod(2222, LoadDex("IntMath"), "IntMath", "constClassTest", "(I)I", 1111); |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 230 | TEST_F(CompilerTest, CatchTest) { |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 231 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
| 232 | CompileDirectMethod(NULL, "java.lang.NullPointerException", "<init>", "()V"); |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 233 | CompileDirectMethod(NULL, "java.lang.RuntimeException", "<init>", "()V"); |
| 234 | CompileDirectMethod(NULL, "java.lang.Exception", "<init>", "()V"); |
| 235 | CompileDirectMethod(NULL, "java.lang.Throwable","<init>", "()V"); |
| 236 | CompileDirectMethod(NULL, "java.util.ArrayList","<init>","()V"); |
| 237 | CompileDirectMethod(NULL, "java.util.AbstractList","<init>","()V"); |
| 238 | CompileDirectMethod(NULL, "java.util.AbstractCollection","<init>","()V"); |
| 239 | CompileVirtualMethod(NULL, "java.lang.Throwable","fillInStackTrace","()Ljava/lang/Throwable;"); |
| 240 | CompileDirectMethod(NULL, "java.lang.Throwable","nativeFillInStackTrace","()Ljava/lang/Object;"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 241 | AssertStaticIntMethod(1579, LoadDex("IntMath"), "IntMath", "catchBlock", "(I)I", 1000); |
Ian Rogers | 93dd966 | 2011-09-17 23:21:22 -0700 | [diff] [blame^] | 242 | AssertStaticIntMethod(7777, LoadDex("IntMath"), "IntMath", "catchBlock", "(I)I", 7000); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 243 | } |
| 244 | |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 245 | TEST_F(CompilerTest, CatchTestNoThrow) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 246 | AssertStaticIntMethod(1123, LoadDex("IntMath"), "IntMath", "catchBlockNoThrow", "(I)I", 1000); |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 247 | } |
| 248 | |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 249 | TEST_F(CompilerTest, StaticFieldTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 250 | AssertStaticIntMethod(1404, LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 404); |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 251 | } |
| 252 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 253 | TEST_F(CompilerTest, UnopTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 254 | AssertStaticIntMethod(37, LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 38); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 255 | } |
| 256 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 257 | TEST_F(CompilerTest, ShiftTest1) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 258 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "shiftTest1", "()I"); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 259 | } |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 260 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 261 | TEST_F(CompilerTest, ShiftTest2) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 262 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "shiftTest2", "()I"); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 263 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 264 | |
| 265 | TEST_F(CompilerTest, UnsignedShiftTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 266 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I"); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 267 | } |
| 268 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 269 | TEST_F(CompilerTest, ConvTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 270 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "convTest", "()I"); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 271 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 272 | |
| 273 | TEST_F(CompilerTest, CharSubTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 274 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "charSubTest", "()I"); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 275 | } |
| 276 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 277 | TEST_F(CompilerTest, IntOperTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 278 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 70000, -3); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 279 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 280 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 281 | TEST_F(CompilerTest, Lit16Test) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 282 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 77777); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 283 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 284 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 285 | TEST_F(CompilerTest, Lit8Test) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 286 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", -55555); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 287 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 288 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 289 | TEST_F(CompilerTest, IntShiftTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 290 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0xff00aa01, 8); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 291 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 292 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 293 | TEST_F(CompilerTest, LongOperTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 294 | AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I", |
buzbee | 439c4fa | 2011-08-27 15:59:07 -0700 | [diff] [blame] | 295 | 70000000000LL, -3LL); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 296 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 297 | |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 298 | TEST_F(CompilerTest, LongShiftTest) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 299 | AssertStaticLongMethod(0x96deff00aa010000LL, |
| 300 | LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J", 0xd5aa96deff00aa01LL, 16); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 301 | } |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 302 | |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 303 | TEST_F(CompilerTest, SwitchTest1) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 304 | AssertStaticIntMethod(1234, LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | TEST_F(CompilerTest, IntCompare) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 308 | AssertStaticIntMethod(1111, LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I", |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 309 | -5, 4, 4, 0); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | TEST_F(CompilerTest, LongCompare) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 313 | AssertStaticIntMethod(2222, LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I", |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 314 | -5LL, -4294967287LL, 4LL, 8LL); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | TEST_F(CompilerTest, FloatCompare) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 318 | AssertStaticIntMethod(3333, LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I", |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 319 | -5.0f, 4.0f, 4.0f, |
| 320 | (1.0f/0.0f) / (1.0f/0.0f)); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | TEST_F(CompilerTest, DoubleCompare) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 324 | AssertStaticIntMethod(4444, LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I", |
Brian Carlstrom | bffb155 | 2011-08-25 12:23:53 -0700 | [diff] [blame] | 325 | -5.0, 4.0, 4.0, |
| 326 | (1.0/0.0) / (1.0/0.0)); |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 327 | } |
| 328 | |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 329 | TEST_F(CompilerTest, RecursiveFibonacci) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 330 | AssertStaticIntMethod(55, LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 10); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 331 | } |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 332 | |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 333 | #if 0 // Need to complete try/catch block handling |
| 334 | TEST_F(CompilerTest, ThrowAndCatch) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 335 | AssertStaticIntMethod(4, LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I"); |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 336 | } |
| 337 | #endif |
| 338 | |
| 339 | TEST_F(CompilerTest, ManyArgs) { |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 340 | AssertStaticIntMethod(-1, LoadDex("IntMath"), "IntMath", "manyArgs", |
| 341 | "(IJIJIJIIDFDSICIIBZIIJJIIIII)I", |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 342 | 0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0, |
| 343 | (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18, |
| 344 | 19, 20LL, 21LL, 22, 23, 24, 25, 26); |
| 345 | } |
| 346 | |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 347 | TEST_F(CompilerTest, VirtualCall) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 348 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 349 | AssertStaticIntMethod(6, LoadDex("IntMath"), "IntMath", "staticCall", "(I)I", 3); |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 350 | } |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 351 | |
buzbee | dd3efae | 2011-08-28 14:39:07 -0700 | [diff] [blame] | 352 | TEST_F(CompilerTest, TestIGetPut) { |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 353 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 354 | AssertStaticIntMethod(333, LoadDex("IntMath"), "IntMath", "testIGetPut", "(I)I", 111); |
buzbee | dd3efae | 2011-08-28 14:39:07 -0700 | [diff] [blame] | 355 | } |
| 356 | |
buzbee | 109bd6a | 2011-09-06 13:58:41 -0700 | [diff] [blame] | 357 | TEST_F(CompilerTest, InvokeTest) { |
| 358 | CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V"); |
Elliott Hughes | 7957d54 | 2011-09-09 17:16:01 -0700 | [diff] [blame] | 359 | AssertStaticIntMethod(20664, LoadDex("Invoke"), "Invoke", "test0", "(I)I", 912); |
buzbee | 109bd6a | 2011-09-06 13:58:41 -0700 | [diff] [blame] | 360 | } |
| 361 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 362 | } // namespace art |