blob: 884f7a7df9e31b88bcfe1678737edd3ddf4058c9 [file] [log] [blame]
buzbeec143c552011-08-20 17:38:58 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Elliott Hughes90a33692011-08-30 13:27:07 -07003#include "compiler.h"
4
5#include <stdint.h>
6#include <stdio.h>
7
8#include "UniquePtr.h"
buzbeec143c552011-08-20 17:38:58 -07009#include "class_linker.h"
10#include "common_test.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070011#include "dex_cache.h"
buzbeec143c552011-08-20 17:38:58 -070012#include "dex_file.h"
13#include "heap.h"
14#include "object.h"
buzbeec143c552011-08-20 17:38:58 -070015
16namespace art {
17
18class CompilerTest : public CommonTest {
Brian Carlstrombffb1552011-08-25 12:23:53 -070019 protected:
Brian Carlstrom8a487412011-08-29 20:08:52 -070020
Elliott Hughes7957d542011-09-09 17:16:01 -070021 void AssertStaticIntMethod(jint expected, const ClassLoader* class_loader,
Elliott Hughes1240dad2011-09-09 16:24:50 -070022 const char* class_name, const char* method, const char* signature,
Elliott Hughes7957d542011-09-09 17:16:01 -070023 ...) {
Elliott Hughes1240dad2011-09-09 16:24:50 -070024 EnsureCompiled(class_loader, class_name, method, signature);
Elliott Hughesd3a72972011-09-07 15:31:59 -070025#if defined(__arm__)
Brian Carlstrombffb1552011-08-25 12:23:53 -070026 va_list args;
Elliott Hughes7957d542011-09-09 17:16:01 -070027 va_start(args, signature);
Elliott Hughes1240dad2011-09-09 16:24:50 -070028 jint result = env_->CallStaticIntMethodV(class_, mid_, args);
Brian Carlstrombffb1552011-08-25 12:23:53 -070029 va_end(args);
Elliott Hughes1240dad2011-09-09 16:24:50 -070030 LOG(INFO) << class_name << "." << method << "(...) result is " << result;
Brian Carlstrombffb1552011-08-25 12:23:53 -070031 EXPECT_EQ(expected, result);
32#endif // __arm__
33 }
Elliott Hughes1240dad2011-09-09 16:24:50 -070034
Elliott Hughes7957d542011-09-09 17:16:01 -070035 void AssertStaticLongMethod(jlong expected, const ClassLoader* class_loader,
Elliott Hughes1240dad2011-09-09 16:24:50 -070036 const char* class_name, const char* method, const char* signature,
Elliott Hughes7957d542011-09-09 17:16:01 -070037 ...) {
Elliott Hughes1240dad2011-09-09 16:24:50 -070038 EnsureCompiled(class_loader, class_name, method, signature);
Elliott Hughesd3a72972011-09-07 15:31:59 -070039#if defined(__arm__)
buzbeebafc3422011-08-25 15:22:55 -070040 va_list args;
Elliott Hughes7957d542011-09-09 17:16:01 -070041 va_start(args, signature);
Elliott Hughes1240dad2011-09-09 16:24:50 -070042 jlong result = env_->CallStaticLongMethodV(class_, mid_, args);
buzbeebafc3422011-08-25 15:22:55 -070043 va_end(args);
Elliott Hughes1240dad2011-09-09 16:24:50 -070044 LOG(INFO) << class_name << "." << method << "(...) result is " << result;
buzbeebafc3422011-08-25 15:22:55 -070045 EXPECT_EQ(expected, result);
46#endif // __arm__
47 }
Elliott Hughes1240dad2011-09-09 16:24:50 -070048
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,
55 const char* class_name, const char* method, const char* signature) {
56 CompileAll(class_loader);
57 env_ = Thread::Current()->GetJniEnv();
58 class_ = env_->FindClass(class_name);
59 CHECK(class_ != NULL) << "Class not found: " << class_name;
60 mid_ = env_->GetStaticMethodID(class_, method, signature);
61 CHECK(mid_ != NULL) << "Method not found: " << class_name << "." << method << signature;
62 }
63
64 void MakeAllExecutable(const ClassLoader* class_loader) {
65 const std::vector<const DexFile*>& class_path = ClassLoader::GetClassPath(class_loader);
66 for (size_t i = 0; i != class_path.size(); ++i) {
67 const DexFile* dex_file = class_path[i];
68 CHECK(dex_file != NULL);
69 MakeDexFileExecutable(class_loader, *dex_file);
70 }
71 }
72
73 void MakeDexFileExecutable(const ClassLoader* class_loader, const DexFile& dex_file) {
74 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
75 for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
76 const DexFile::ClassDef& class_def = dex_file.GetClassDef(i);
77 const char* descriptor = dex_file.GetClassDescriptor(class_def);
78 Class* c = class_linker->FindClass(descriptor, class_loader);
79 CHECK(c != NULL);
80 for (size_t i = 0; i < c->NumDirectMethods(); i++) {
81 MakeMethodExecutable(c->GetDirectMethod(i));
82 }
83 for (size_t i = 0; i < c->NumVirtualMethods(); i++) {
84 MakeMethodExecutable(c->GetVirtualMethod(i));
85 }
86 }
87 }
88
89 void MakeMethodExecutable(Method* m) {
90 if (m->GetCodeArray() != NULL) {
91 MakeExecutable(m->GetCodeArray());
92 } else {
93 LOG(WARNING) << "no code for " << PrettyMethod(m);
94 }
95 if (m->GetInvokeStubArray() != NULL) {
96 MakeExecutable(m->GetInvokeStubArray());
97 } else {
98 LOG(WARNING) << "no invoke stub for " << PrettyMethod(m);
99 }
100 }
101
102 JNIEnv* env_;
103 jclass class_;
104 jmethodID mid_;
buzbeec143c552011-08-20 17:38:58 -0700105};
106
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700107// Disabled due to 10 second runtime on host
Elliott Hughes1240dad2011-09-09 16:24:50 -0700108TEST_F(CompilerTest, DISABLED_LARGE_CompileDexLibCore) {
109 CompileAll(NULL);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700110
111 // All libcore references should resolve
112 const DexFile* dex = java_lang_dex_file_.get();
113 DexCache* dex_cache = class_linker_->FindDexCache(*dex);
114 EXPECT_EQ(dex->NumStringIds(), dex_cache->NumStrings());
115 for (size_t i = 0; i < dex_cache->NumStrings(); i++) {
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700116 const String* string = dex_cache->GetResolvedString(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700117 EXPECT_TRUE(string != NULL) << "string_idx=" << i;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700118 }
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700119 EXPECT_EQ(dex->NumTypeIds(), dex_cache->NumResolvedTypes());
120 for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700121 Class* type = dex_cache->GetResolvedType(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700122 EXPECT_TRUE(type != NULL) << "type_idx=" << i
123 << " " << dex->GetTypeDescriptor(dex->GetTypeId(i));
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700124 }
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700125 EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumResolvedMethods());
126 for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) {
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700127 Method* method = dex_cache->GetResolvedMethod(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700128 EXPECT_TRUE(method != NULL) << "method_idx=" << i
129 << " " << dex->GetMethodClassDescriptor(dex->GetMethodId(i))
130 << " " << dex->GetMethodName(dex->GetMethodId(i));
Shih-wei Liaoc486c112011-09-13 16:43:52 -0700131 EXPECT_TRUE(method->GetCode() != NULL) << "method_idx=" << i
132 << " "
133 << dex->GetMethodClassDescriptor(dex->GetMethodId(i))
134 << " " << dex->GetMethodName(dex->GetMethodId(i));
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700135 }
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700136 EXPECT_EQ(dex->NumFieldIds(), dex_cache->NumResolvedFields());
137 for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) {
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700138 Field* field = dex_cache->GetResolvedField(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700139 EXPECT_TRUE(field != NULL) << "field_idx=" << i
140 << " " << dex->GetFieldClassDescriptor(dex->GetFieldId(i))
141 << " " << dex->GetFieldName(dex->GetFieldId(i));
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700142 }
143
Brian Carlstrom83db7722011-08-26 17:32:56 -0700144 // TODO check Class::IsVerified for all classes
145
146 // TODO: check that all Method::GetCode() values are non-null
147
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700148 EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumCodeAndDirectMethods());
149 CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods();
150 for (size_t i = 0; i < dex_cache->NumCodeAndDirectMethods(); i++) {
Brian Carlstrom83db7722011-08-26 17:32:56 -0700151 Method* method = dex_cache->GetResolvedMethod(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700152 if (method->IsDirect()) {
153 EXPECT_EQ(method->GetCode(), code_and_direct_methods->GetResolvedCode(i));
154 EXPECT_EQ(method, code_and_direct_methods->GetResolvedMethod(i));
155 } else {
156 EXPECT_EQ(0U, code_and_direct_methods->GetResolvedCode(i));
157 EXPECT_TRUE(code_and_direct_methods->GetResolvedMethod(i) == NULL);
158 }
Brian Carlstrom83db7722011-08-26 17:32:56 -0700159 }
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700160}
161
buzbeef0cde542011-09-13 14:55:02 -0700162TEST_F(CompilerTest, ByBillion) {
163 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
164 AssertStaticLongMethod(123, LoadDex("IntMath"), "IntMath", "divideLongByBillion", "(J)J", 123000000000LL);
165}
166
buzbeec143c552011-08-20 17:38:58 -0700167TEST_F(CompilerTest, BasicCodegen) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700168 AssertStaticIntMethod(55, LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 10);
buzbeec143c552011-08-20 17:38:58 -0700169}
buzbee3ea4ec52011-08-22 17:37:19 -0700170
buzbee2a475e72011-09-07 17:19:17 -0700171// TODO: need stub for InstanceofNonTrivialFromCode
172TEST_F(CompilerTest, InstanceTest) {
173 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
Elliott Hughes7957d542011-09-09 17:16:01 -0700174 AssertStaticIntMethod(1352, LoadDex("IntMath"), "IntMath", "instanceTest", "(I)I", 10);
buzbee2a475e72011-09-07 17:19:17 -0700175}
176
177// TODO: need check-cast test (when stub complete & we can throw/catch
178
buzbee4a3164f2011-09-03 11:25:10 -0700179// TODO: Need invoke-interface test
180
181TEST_F(CompilerTest, SuperTest) {
182 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
Elliott Hughes7957d542011-09-09 17:16:01 -0700183 AssertStaticIntMethod(4175, LoadDex("IntMath"), "IntMath", "superTest", "(I)I", 4141);
buzbee4a3164f2011-09-03 11:25:10 -0700184}
185
buzbee1b4c8592011-08-31 10:43:51 -0700186TEST_F(CompilerTest, ConstStringTest) {
buzbee2a475e72011-09-07 17:19:17 -0700187 CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V");
188 CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V");
189 CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V");
190 CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V");
191 CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C");
192 CompileVirtualMethod(NULL, "java.lang.String", "length", "()I");
Elliott Hughes7957d542011-09-09 17:16:01 -0700193 AssertStaticIntMethod(1246, LoadDex("IntMath"), "IntMath", "constStringTest", "(I)I", 1234);
buzbee1b4c8592011-08-31 10:43:51 -0700194}
195
buzbee561227c2011-09-02 15:28:19 -0700196TEST_F(CompilerTest, ConstClassTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700197 AssertStaticIntMethod(2222, LoadDex("IntMath"), "IntMath", "constClassTest", "(I)I", 1111);
buzbee561227c2011-09-02 15:28:19 -0700198}
199
buzbee2a475e72011-09-07 17:19:17 -0700200// TODO: Need native nativeFillInStackTrace()
buzbee1b4c8592011-08-31 10:43:51 -0700201TEST_F(CompilerTest, DISABLED_CatchTest) {
202 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
203 CompileDirectMethod(NULL, "java.lang.NullPointerException", "<init>", "()V");
buzbee2a475e72011-09-07 17:19:17 -0700204 CompileDirectMethod(NULL, "java.lang.RuntimeException", "<init>", "()V");
205 CompileDirectMethod(NULL, "java.lang.Exception", "<init>", "()V");
206 CompileDirectMethod(NULL, "java.lang.Throwable","<init>", "()V");
207 CompileDirectMethod(NULL, "java.util.ArrayList","<init>","()V");
208 CompileDirectMethod(NULL, "java.util.AbstractList","<init>","()V");
209 CompileDirectMethod(NULL, "java.util.AbstractCollection","<init>","()V");
210 CompileVirtualMethod(NULL, "java.lang.Throwable","fillInStackTrace","()Ljava/lang/Throwable;");
211 CompileDirectMethod(NULL, "java.lang.Throwable","nativeFillInStackTrace","()Ljava/lang/Object;");
Elliott Hughes7957d542011-09-09 17:16:01 -0700212 AssertStaticIntMethod(1579, LoadDex("IntMath"), "IntMath", "catchBlock", "(I)I", 1000);
buzbee1b4c8592011-08-31 10:43:51 -0700213}
214
buzbeee9a72f62011-09-04 17:59:07 -0700215TEST_F(CompilerTest, CatchTestNoThrow) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700216 AssertStaticIntMethod(1123, LoadDex("IntMath"), "IntMath", "catchBlockNoThrow", "(I)I", 1000);
buzbeee9a72f62011-09-04 17:59:07 -0700217}
218
buzbeee1931742011-08-28 21:15:53 -0700219TEST_F(CompilerTest, StaticFieldTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700220 AssertStaticIntMethod(1404, LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 404);
buzbeee1931742011-08-28 21:15:53 -0700221}
222
buzbee3ea4ec52011-08-22 17:37:19 -0700223TEST_F(CompilerTest, UnopTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700224 AssertStaticIntMethod(37, LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 38);
buzbee3ea4ec52011-08-22 17:37:19 -0700225}
226
buzbee3ea4ec52011-08-22 17:37:19 -0700227TEST_F(CompilerTest, ShiftTest1) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700228 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "shiftTest1", "()I");
buzbee3ea4ec52011-08-22 17:37:19 -0700229}
buzbeec143c552011-08-20 17:38:58 -0700230
buzbee3ea4ec52011-08-22 17:37:19 -0700231TEST_F(CompilerTest, ShiftTest2) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700232 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "shiftTest2", "()I");
buzbee3ea4ec52011-08-22 17:37:19 -0700233}
buzbee3ea4ec52011-08-22 17:37:19 -0700234
235TEST_F(CompilerTest, UnsignedShiftTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700236 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I");
buzbee3ea4ec52011-08-22 17:37:19 -0700237}
238
buzbee3ea4ec52011-08-22 17:37:19 -0700239TEST_F(CompilerTest, ConvTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700240 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "convTest", "()I");
buzbee3ea4ec52011-08-22 17:37:19 -0700241}
buzbee3ea4ec52011-08-22 17:37:19 -0700242
243TEST_F(CompilerTest, CharSubTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700244 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "charSubTest", "()I");
buzbee3ea4ec52011-08-22 17:37:19 -0700245}
246
buzbee3ea4ec52011-08-22 17:37:19 -0700247TEST_F(CompilerTest, IntOperTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700248 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 70000, -3);
buzbee3ea4ec52011-08-22 17:37:19 -0700249}
buzbee3ea4ec52011-08-22 17:37:19 -0700250
buzbee3ea4ec52011-08-22 17:37:19 -0700251TEST_F(CompilerTest, Lit16Test) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700252 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 77777);
buzbee3ea4ec52011-08-22 17:37:19 -0700253}
buzbee3ea4ec52011-08-22 17:37:19 -0700254
buzbee3ea4ec52011-08-22 17:37:19 -0700255TEST_F(CompilerTest, Lit8Test) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700256 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", -55555);
buzbee3ea4ec52011-08-22 17:37:19 -0700257}
buzbee3ea4ec52011-08-22 17:37:19 -0700258
buzbee3ea4ec52011-08-22 17:37:19 -0700259TEST_F(CompilerTest, IntShiftTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700260 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0xff00aa01, 8);
buzbee3ea4ec52011-08-22 17:37:19 -0700261}
buzbee3ea4ec52011-08-22 17:37:19 -0700262
buzbee3ea4ec52011-08-22 17:37:19 -0700263TEST_F(CompilerTest, LongOperTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700264 AssertStaticIntMethod(0, LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I",
buzbee439c4fa2011-08-27 15:59:07 -0700265 70000000000LL, -3LL);
buzbee3ea4ec52011-08-22 17:37:19 -0700266}
buzbee3ea4ec52011-08-22 17:37:19 -0700267
buzbee3ea4ec52011-08-22 17:37:19 -0700268TEST_F(CompilerTest, LongShiftTest) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700269 AssertStaticLongMethod(0x96deff00aa010000LL,
270 LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J", 0xd5aa96deff00aa01LL, 16);
buzbee3ea4ec52011-08-22 17:37:19 -0700271}
buzbee3ea4ec52011-08-22 17:37:19 -0700272
buzbee9e0f9b02011-08-24 15:32:46 -0700273TEST_F(CompilerTest, SwitchTest1) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700274 AssertStaticIntMethod(1234, LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1);
buzbee9e0f9b02011-08-24 15:32:46 -0700275}
276
277TEST_F(CompilerTest, IntCompare) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700278 AssertStaticIntMethod(1111, LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I",
Brian Carlstrombffb1552011-08-25 12:23:53 -0700279 -5, 4, 4, 0);
buzbee9e0f9b02011-08-24 15:32:46 -0700280}
281
282TEST_F(CompilerTest, LongCompare) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700283 AssertStaticIntMethod(2222, LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I",
Brian Carlstrombffb1552011-08-25 12:23:53 -0700284 -5LL, -4294967287LL, 4LL, 8LL);
buzbee9e0f9b02011-08-24 15:32:46 -0700285}
286
287TEST_F(CompilerTest, FloatCompare) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700288 AssertStaticIntMethod(3333, LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I",
Brian Carlstrombffb1552011-08-25 12:23:53 -0700289 -5.0f, 4.0f, 4.0f,
290 (1.0f/0.0f) / (1.0f/0.0f));
buzbee9e0f9b02011-08-24 15:32:46 -0700291}
292
293TEST_F(CompilerTest, DoubleCompare) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700294 AssertStaticIntMethod(4444, LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I",
Brian Carlstrombffb1552011-08-25 12:23:53 -0700295 -5.0, 4.0, 4.0,
296 (1.0/0.0) / (1.0/0.0));
buzbee9e0f9b02011-08-24 15:32:46 -0700297}
298
buzbeec5ef0462011-08-25 18:44:49 -0700299TEST_F(CompilerTest, RecursiveFibonacci) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700300 AssertStaticIntMethod(55, LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 10);
buzbeec5ef0462011-08-25 18:44:49 -0700301}
buzbeec5ef0462011-08-25 18:44:49 -0700302
buzbee7b1b86d2011-08-26 18:59:10 -0700303#if 0 // Need to complete try/catch block handling
304TEST_F(CompilerTest, ThrowAndCatch) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700305 AssertStaticIntMethod(4, LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I");
buzbee7b1b86d2011-08-26 18:59:10 -0700306}
307#endif
308
309TEST_F(CompilerTest, ManyArgs) {
Elliott Hughes7957d542011-09-09 17:16:01 -0700310 AssertStaticIntMethod(-1, LoadDex("IntMath"), "IntMath", "manyArgs",
311 "(IJIJIJIIDFDSICIIBZIIJJIIIII)I",
buzbee7b1b86d2011-08-26 18:59:10 -0700312 0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0,
313 (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18,
314 19, 20LL, 21LL, 22, 23, 24, 25, 26);
315}
316
buzbee7b1b86d2011-08-26 18:59:10 -0700317TEST_F(CompilerTest, VirtualCall) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700318 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
Elliott Hughes7957d542011-09-09 17:16:01 -0700319 AssertStaticIntMethod(6, LoadDex("IntMath"), "IntMath", "staticCall", "(I)I", 3);
buzbee7b1b86d2011-08-26 18:59:10 -0700320}
buzbee7b1b86d2011-08-26 18:59:10 -0700321
buzbeedd3efae2011-08-28 14:39:07 -0700322TEST_F(CompilerTest, TestIGetPut) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700323 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
Elliott Hughes7957d542011-09-09 17:16:01 -0700324 AssertStaticIntMethod(333, LoadDex("IntMath"), "IntMath", "testIGetPut", "(I)I", 111);
buzbeedd3efae2011-08-28 14:39:07 -0700325}
326
buzbee109bd6a2011-09-06 13:58:41 -0700327TEST_F(CompilerTest, InvokeTest) {
328 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
Elliott Hughes7957d542011-09-09 17:16:01 -0700329 AssertStaticIntMethod(20664, LoadDex("Invoke"), "Invoke", "test0", "(I)I", 912);
buzbee109bd6a2011-09-06 13:58:41 -0700330}
331
Elliott Hughes1240dad2011-09-09 16:24:50 -0700332TEST_F(CompilerTest, DISABLED_LARGE_SystemMethodsTest) {
333 CompileAll(NULL); // This test calls a bunch of stuff from libcore.
Elliott Hughes7957d542011-09-09 17:16:01 -0700334 AssertStaticIntMethod(123, LoadDex("SystemMethods"), "SystemMethods", "test5", "()I");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700335}
336
buzbeec143c552011-08-20 17:38:58 -0700337} // namespace art