blob: 5766a4f77de693a64fe89e266db2855e98972788 [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
Brian Carlstrom8a487412011-08-29 20:08:52 -070021 void AssertStaticIntMethod(const ClassLoader* class_loader,
22 const char* klass, const char* method, const char* signature,
Brian Carlstrombffb1552011-08-25 12:23:53 -070023 jint expected, ...) {
Brian Carlstrom8a487412011-08-29 20:08:52 -070024 CompileDirectMethod(class_loader, klass, method, signature);
Elliott Hughesd3a72972011-09-07 15:31:59 -070025#if defined(__arm__)
Brian Carlstrombffb1552011-08-25 12:23:53 -070026 JNIEnv* env = Thread::Current()->GetJniEnv();
27 jclass c = env->FindClass(klass);
Brian Carlstrom8a487412011-08-29 20:08:52 -070028 CHECK(c != NULL) << "Class not found " << klass;
Brian Carlstrombffb1552011-08-25 12:23:53 -070029 jmethodID m = env->GetStaticMethodID(c, method, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070030 CHECK(m != NULL) << "Method not found: " << klass << "." << method << signature;
Brian Carlstrombffb1552011-08-25 12:23:53 -070031 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 Carlstrom8a487412011-08-29 20:08:52 -070039 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 Hughesd3a72972011-09-07 15:31:59 -070043#if defined(__arm__)
buzbeebafc3422011-08-25 15:22:55 -070044 JNIEnv* env = Thread::Current()->GetJniEnv();
45 jclass c = env->FindClass(klass);
Brian Carlstrom8a487412011-08-29 20:08:52 -070046 CHECK(c != NULL) << "Class not found " << klass;
buzbeebafc3422011-08-25 15:22:55 -070047 jmethodID m = env->GetStaticMethodID(c, method, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070048 CHECK(m != NULL) << "Method not found: " << klass << "." << method << signature;
buzbeebafc3422011-08-25 15:22:55 -070049 va_list args;
50 va_start(args, expected);
buzbeec5ef0462011-08-25 18:44:49 -070051 jlong result = env->CallStaticLongMethodV(c, m, args);
buzbeebafc3422011-08-25 15:22:55 -070052 va_end(args);
53 LOG(INFO) << klass << "." << method << "(...) result is " << result;
54 EXPECT_EQ(expected, result);
55#endif // __arm__
56 }
buzbeec143c552011-08-20 17:38:58 -070057};
58
Brian Carlstrom7540ff42011-09-04 16:38:46 -070059// Disabled due to 10 second runtime on host
Brian Carlstrom8a487412011-08-29 20:08:52 -070060TEST_F(CompilerTest, DISABLED_CompileDexLibCore) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070061 Compiler compiler;
Brian Carlstrom8a487412011-08-29 20:08:52 -070062 compiler.CompileAll(NULL);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070063
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 Hughescf4c6c42011-09-01 15:16:42 -070069 const String* string = dex_cache->GetResolvedString(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -070070 EXPECT_TRUE(string != NULL) << "string_idx=" << i;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070071 }
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070072 EXPECT_EQ(dex->NumTypeIds(), dex_cache->NumResolvedTypes());
73 for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070074 Class* type = dex_cache->GetResolvedType(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -070075 EXPECT_TRUE(type != NULL) << "type_idx=" << i
76 << " " << dex->GetTypeDescriptor(dex->GetTypeId(i));
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070077 }
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070078 EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumResolvedMethods());
79 for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) {
Brian Carlstrom20cfffa2011-08-26 02:31:27 -070080 Method* method = dex_cache->GetResolvedMethod(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -070081 EXPECT_TRUE(method != NULL) << "method_idx=" << i
82 << " " << dex->GetMethodClassDescriptor(dex->GetMethodId(i))
83 << " " << dex->GetMethodName(dex->GetMethodId(i));
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070084 }
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070085 EXPECT_EQ(dex->NumFieldIds(), dex_cache->NumResolvedFields());
86 for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) {
Brian Carlstrom20cfffa2011-08-26 02:31:27 -070087 Field* field = dex_cache->GetResolvedField(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -070088 EXPECT_TRUE(field != NULL) << "field_idx=" << i
89 << " " << dex->GetFieldClassDescriptor(dex->GetFieldId(i))
90 << " " << dex->GetFieldName(dex->GetFieldId(i));
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070091 }
92
Brian Carlstrom83db7722011-08-26 17:32:56 -070093 // TODO check Class::IsVerified for all classes
94
95 // TODO: check that all Method::GetCode() values are non-null
96
Brian Carlstrom9cc262e2011-08-28 12:45:30 -070097 EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumCodeAndDirectMethods());
98 CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods();
99 for (size_t i = 0; i < dex_cache->NumCodeAndDirectMethods(); i++) {
Brian Carlstrom83db7722011-08-26 17:32:56 -0700100 Method* method = dex_cache->GetResolvedMethod(i);
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700101 if (method->IsDirect()) {
102 EXPECT_EQ(method->GetCode(), code_and_direct_methods->GetResolvedCode(i));
103 EXPECT_EQ(method, code_and_direct_methods->GetResolvedMethod(i));
104 } else {
105 EXPECT_EQ(0U, code_and_direct_methods->GetResolvedCode(i));
106 EXPECT_TRUE(code_and_direct_methods->GetResolvedMethod(i) == NULL);
107 }
Brian Carlstrom83db7722011-08-26 17:32:56 -0700108 }
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700109}
110
buzbeec143c552011-08-20 17:38:58 -0700111TEST_F(CompilerTest, BasicCodegen) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700112 AssertStaticIntMethod(LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 55,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700113 10);
buzbeec143c552011-08-20 17:38:58 -0700114}
buzbee3ea4ec52011-08-22 17:37:19 -0700115
buzbee2a475e72011-09-07 17:19:17 -0700116// TODO: need stub for InstanceofNonTrivialFromCode
117TEST_F(CompilerTest, InstanceTest) {
118 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
119 const ClassLoader* class_loader = LoadDex("IntMath");
120 CompileDirectMethod(class_loader, "IntMath", "<init>", "()V");
121 CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V");
122 AssertStaticIntMethod(class_loader, "IntMath", "instanceTest", "(I)I", 1352, 10);
123}
124
125// TODO: need check-cast test (when stub complete & we can throw/catch
126
buzbee4a3164f2011-09-03 11:25:10 -0700127// TODO: Need invoke-interface test
128
129TEST_F(CompilerTest, SuperTest) {
130 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
131 const ClassLoader* class_loader = LoadDex("IntMath");
132 CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V");
133 CompileVirtualMethod(class_loader, "IntMathBase", "tryThing", "()I");
134 CompileDirectMethod(class_loader, "IntMath", "<init>", "()V");
135 CompileVirtualMethod(class_loader, "IntMath", "tryThing", "()I");
136 AssertStaticIntMethod(class_loader, "IntMath", "superTest", "(I)I", 4175,
137 4141);
138}
139
buzbee1b4c8592011-08-31 10:43:51 -0700140TEST_F(CompilerTest, ConstStringTest) {
buzbee2a475e72011-09-07 17:19:17 -0700141 CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V");
142 CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V");
143 CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V");
144 CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V");
145 CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C");
146 CompileVirtualMethod(NULL, "java.lang.String", "length", "()I");
buzbee1b4c8592011-08-31 10:43:51 -0700147 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constStringTest",
buzbee2a475e72011-09-07 17:19:17 -0700148 "(I)I", 1246, 1234);
buzbee1b4c8592011-08-31 10:43:51 -0700149}
150
buzbee561227c2011-09-02 15:28:19 -0700151TEST_F(CompilerTest, ConstClassTest) {
152 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constClassTest",
153 "(I)I", 2222, 1111);
154}
155
buzbee2a475e72011-09-07 17:19:17 -0700156// TODO: Need native nativeFillInStackTrace()
buzbee1b4c8592011-08-31 10:43:51 -0700157TEST_F(CompilerTest, DISABLED_CatchTest) {
158 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
159 CompileDirectMethod(NULL, "java.lang.NullPointerException", "<init>", "()V");
buzbee2a475e72011-09-07 17:19:17 -0700160 CompileDirectMethod(NULL, "java.lang.RuntimeException", "<init>", "()V");
161 CompileDirectMethod(NULL, "java.lang.Exception", "<init>", "()V");
162 CompileDirectMethod(NULL, "java.lang.Throwable","<init>", "()V");
163 CompileDirectMethod(NULL, "java.util.ArrayList","<init>","()V");
164 CompileDirectMethod(NULL, "java.util.AbstractList","<init>","()V");
165 CompileDirectMethod(NULL, "java.util.AbstractCollection","<init>","()V");
166 CompileVirtualMethod(NULL, "java.lang.Throwable","fillInStackTrace","()Ljava/lang/Throwable;");
167 CompileDirectMethod(NULL, "java.lang.Throwable","nativeFillInStackTrace","()Ljava/lang/Object;");
buzbee1b4c8592011-08-31 10:43:51 -0700168 const ClassLoader* class_loader = LoadDex("IntMath");
169 CompileDirectMethod(class_loader, "IntMath", "throwNullPointerException", "()V");
170 AssertStaticIntMethod(class_loader, "IntMath", "catchBlock", "(I)I", 1579,
171 1000);
172}
173
buzbeee9a72f62011-09-04 17:59:07 -0700174TEST_F(CompilerTest, CatchTestNoThrow) {
175 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
176 const ClassLoader* class_loader = LoadDex("IntMath");
177 AssertStaticIntMethod(class_loader, "IntMath", "catchBlockNoThrow", "(I)I",
178 1123, 1000);
179}
180
buzbeee1931742011-08-28 21:15:53 -0700181TEST_F(CompilerTest, StaticFieldTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700182 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 1404,
buzbeee1931742011-08-28 21:15:53 -0700183 404);
184}
185
buzbee3ea4ec52011-08-22 17:37:19 -0700186TEST_F(CompilerTest, UnopTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700187 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 37,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700188 38);
buzbee3ea4ec52011-08-22 17:37:19 -0700189}
190
buzbee3ea4ec52011-08-22 17:37:19 -0700191TEST_F(CompilerTest, ShiftTest1) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700192 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest1", "()I", 0);
buzbee3ea4ec52011-08-22 17:37:19 -0700193}
buzbeec143c552011-08-20 17:38:58 -0700194
buzbee3ea4ec52011-08-22 17:37:19 -0700195TEST_F(CompilerTest, ShiftTest2) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700196 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest2", "()I", 0);
buzbee3ea4ec52011-08-22 17:37:19 -0700197}
buzbee3ea4ec52011-08-22 17:37:19 -0700198
199TEST_F(CompilerTest, UnsignedShiftTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700200 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I", 0);
buzbee3ea4ec52011-08-22 17:37:19 -0700201}
202
buzbee3ea4ec52011-08-22 17:37:19 -0700203TEST_F(CompilerTest, ConvTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700204 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "convTest", "()I", 0);
buzbee3ea4ec52011-08-22 17:37:19 -0700205}
buzbee3ea4ec52011-08-22 17:37:19 -0700206
207TEST_F(CompilerTest, CharSubTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700208 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "charSubTest", "()I", 0);
buzbee3ea4ec52011-08-22 17:37:19 -0700209}
210
buzbee3ea4ec52011-08-22 17:37:19 -0700211TEST_F(CompilerTest, IntOperTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700212 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 0,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700213 70000, -3);
buzbee3ea4ec52011-08-22 17:37:19 -0700214}
buzbee3ea4ec52011-08-22 17:37:19 -0700215
buzbee3ea4ec52011-08-22 17:37:19 -0700216TEST_F(CompilerTest, Lit16Test) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700217 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 0,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700218 77777);
buzbee3ea4ec52011-08-22 17:37:19 -0700219}
buzbee3ea4ec52011-08-22 17:37:19 -0700220
buzbee3ea4ec52011-08-22 17:37:19 -0700221TEST_F(CompilerTest, Lit8Test) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700222 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", 0,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700223 -55555);
buzbee3ea4ec52011-08-22 17:37:19 -0700224}
buzbee3ea4ec52011-08-22 17:37:19 -0700225
buzbee3ea4ec52011-08-22 17:37:19 -0700226TEST_F(CompilerTest, IntShiftTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700227 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700228 0xff00aa01, 8);
buzbee3ea4ec52011-08-22 17:37:19 -0700229}
buzbee3ea4ec52011-08-22 17:37:19 -0700230
buzbee3ea4ec52011-08-22 17:37:19 -0700231TEST_F(CompilerTest, LongOperTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700232 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I", 0,
buzbee439c4fa2011-08-27 15:59:07 -0700233 70000000000LL, -3LL);
buzbee3ea4ec52011-08-22 17:37:19 -0700234}
buzbee3ea4ec52011-08-22 17:37:19 -0700235
buzbee3ea4ec52011-08-22 17:37:19 -0700236TEST_F(CompilerTest, LongShiftTest) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700237 AssertStaticLongMethod(LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J",
buzbee7b1b86d2011-08-26 18:59:10 -0700238 0x96deff00aa010000LL, 0xd5aa96deff00aa01LL, 16);
buzbee3ea4ec52011-08-22 17:37:19 -0700239}
buzbee3ea4ec52011-08-22 17:37:19 -0700240
buzbee9e0f9b02011-08-24 15:32:46 -0700241TEST_F(CompilerTest, SwitchTest1) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700242 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1234,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700243 1);
buzbee9e0f9b02011-08-24 15:32:46 -0700244}
245
246TEST_F(CompilerTest, IntCompare) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700247 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I", 1111,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700248 -5, 4, 4, 0);
buzbee9e0f9b02011-08-24 15:32:46 -0700249}
250
251TEST_F(CompilerTest, LongCompare) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700252 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I", 2222,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700253 -5LL, -4294967287LL, 4LL, 8LL);
buzbee9e0f9b02011-08-24 15:32:46 -0700254}
255
256TEST_F(CompilerTest, FloatCompare) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700257 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I", 3333,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700258 -5.0f, 4.0f, 4.0f,
259 (1.0f/0.0f) / (1.0f/0.0f));
buzbee9e0f9b02011-08-24 15:32:46 -0700260}
261
262TEST_F(CompilerTest, DoubleCompare) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700263 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I", 4444,
Brian Carlstrombffb1552011-08-25 12:23:53 -0700264 -5.0, 4.0, 4.0,
265 (1.0/0.0) / (1.0/0.0));
buzbee9e0f9b02011-08-24 15:32:46 -0700266}
267
buzbeec5ef0462011-08-25 18:44:49 -0700268TEST_F(CompilerTest, RecursiveFibonacci) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700269 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 55,
buzbeec5ef0462011-08-25 18:44:49 -0700270 10);
271}
buzbeec5ef0462011-08-25 18:44:49 -0700272
buzbee7b1b86d2011-08-26 18:59:10 -0700273#if 0 // Need to complete try/catch block handling
274TEST_F(CompilerTest, ThrowAndCatch) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700275 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I", 4);
buzbee7b1b86d2011-08-26 18:59:10 -0700276}
277#endif
278
279TEST_F(CompilerTest, ManyArgs) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700280 AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "manyArgs",
buzbee7b1b86d2011-08-26 18:59:10 -0700281 "(IJIJIJIIDFDSICIIBZIIJJIIIII)I", -1,
282 0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0,
283 (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18,
284 19, 20LL, 21LL, 22, 23, 24, 25, 26);
285}
286
buzbee7b1b86d2011-08-26 18:59:10 -0700287TEST_F(CompilerTest, VirtualCall) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700288 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
289 const ClassLoader* class_loader = LoadDex("IntMath");
buzbee4a3164f2011-09-03 11:25:10 -0700290 CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V");
Brian Carlstrom8a487412011-08-29 20:08:52 -0700291 CompileDirectMethod(class_loader, "IntMath", "<init>", "()V");
292 CompileVirtualMethod(class_loader, "IntMath", "virtualCall", "(I)I");
293 AssertStaticIntMethod(class_loader, "IntMath", "staticCall", "(I)I", 6,
buzbee7b1b86d2011-08-26 18:59:10 -0700294 3);
295}
buzbee7b1b86d2011-08-26 18:59:10 -0700296
buzbeedd3efae2011-08-28 14:39:07 -0700297TEST_F(CompilerTest, TestIGetPut) {
Brian Carlstrom8a487412011-08-29 20:08:52 -0700298 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
299 const ClassLoader* class_loader = LoadDex("IntMath");
buzbee4a3164f2011-09-03 11:25:10 -0700300 CompileDirectMethod(class_loader, "IntMathBase", "<init>", "()V");
Brian Carlstrom8a487412011-08-29 20:08:52 -0700301 CompileDirectMethod(class_loader, "IntMath", "<init>", "(I)V");
302 CompileDirectMethod(class_loader, "IntMath", "<init>", "()V");
303 CompileVirtualMethod(class_loader, "IntMath", "getFoo", "()I");
304 CompileVirtualMethod(class_loader, "IntMath", "setFoo", "(I)V");
305 AssertStaticIntMethod(class_loader, "IntMath", "testIGetPut", "(I)I", 333,
buzbeedd3efae2011-08-28 14:39:07 -0700306 111);
307}
308
buzbee109bd6a2011-09-06 13:58:41 -0700309TEST_F(CompilerTest, InvokeTest) {
310 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
311 const ClassLoader* class_loader = LoadDex("Invoke");
312 CompileDirectMethod(class_loader, "Invoke", "<init>", "()V");
313 CompileVirtualMethod(class_loader, "Invoke", "virI_I", "(I)I");
314 CompileVirtualMethod(class_loader, "Invoke", "virI_II", "(II)I");
315 CompileVirtualMethod(class_loader, "Invoke", "virI_III", "(III)I");
316 CompileVirtualMethod(class_loader, "Invoke", "virI_IIII", "(IIII)I");
317 CompileVirtualMethod(class_loader, "Invoke", "virI_IIIII", "(IIIII)I");
318 CompileVirtualMethod(class_loader, "Invoke", "virI_IIIIII", "(IIIIII)I");
319 CompileDirectMethod(class_loader, "Invoke", "statI_I", "(I)I");
320 CompileDirectMethod(class_loader, "Invoke", "statI_II", "(II)I");
321 CompileDirectMethod(class_loader, "Invoke", "statI_III", "(III)I");
322 CompileDirectMethod(class_loader, "Invoke", "statI_IIII", "(IIII)I");
323 CompileDirectMethod(class_loader, "Invoke", "statI_IIIII", "(IIIII)I");
324 CompileDirectMethod(class_loader, "Invoke", "statI_IIIIII", "(IIIIII)I");
325 AssertStaticIntMethod(class_loader, "Invoke", "test0", "(I)I", 20664,
326 912);
327}
328
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700329TEST_F(CompilerTest, SystemMethodsTest) {
330 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
331
332 CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V");
333 CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V");
334 CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700335 CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700336 CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C");
337 CompileVirtualMethod(NULL, "java.lang.String", "length", "()I");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700338
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700339 CompileDirectMethod(NULL, "java.lang.AbstractStringBuilder", "<init>", "()V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700340 CompileDirectMethod(NULL, "java.lang.AbstractStringBuilder", "<init>", "(I)V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700341 CompileDirectMethod(NULL, "java.lang.AbstractStringBuilder", "enlargeBuffer", "(I)V");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700342 CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "append0", "(C)V");
343 CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "append0", "(Ljava/lang/String;)V");
344 CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "append0", "([CII)V");
345 CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "appendNull", "()V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700346 CompileVirtualMethod(NULL, "java.lang.AbstractStringBuilder", "toString", "()Ljava/lang/String;");
347
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700348 CompileDirectMethod(NULL, "java.lang.StringBuilder", "<init>", "()V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700349 CompileDirectMethod(NULL, "java.lang.StringBuilder", "<init>", "(I)V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700350 CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(C)Ljava/lang/StringBuilder;");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700351 CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(I)Ljava/lang/StringBuilder;");
352 CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(J)Ljava/lang/StringBuilder;");
353 CompileVirtualMethod(NULL, "java.lang.StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700354 CompileVirtualMethod(NULL, "java.lang.StringBuilder", "toString", "()Ljava/lang/String;");
355
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700356 CompileDirectMethod(NULL, "java.lang.ThreadLocal", "<init>", "()V");
357 CompileVirtualMethod(NULL, "java.lang.ThreadLocal", "get", "()Ljava/lang/Object;");
358
359 CompileDirectMethod(NULL, "java.lang.Long", "toHexString", "(J)Ljava/lang/String;");
360 CompileDirectMethod(NULL, "java.lang.Long", "toString", "(J)Ljava/lang/String;");
buzbee6a0f7f52011-09-05 16:14:20 -0700361 CompileDirectMethod(NULL, "java.lang.Long", "toString", "(JI)Ljava/lang/String;");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700362
363 CompileDirectMethod(NULL, "java.lang.IntegralToString", "<clinit>", "()V");
364 CompileDirectMethod(NULL, "java.lang.IntegralToString", "appendInt", "(Ljava/lang/AbstractStringBuilder;I)V");
365 CompileDirectMethod(NULL, "java.lang.IntegralToString", "appendLong", "(Ljava/lang/AbstractStringBuilder;J)V");
366 CompileDirectMethod(NULL, "java.lang.IntegralToString", "convertInt", "(Ljava/lang/AbstractStringBuilder;I)Ljava/lang/String;");
367 CompileDirectMethod(NULL, "java.lang.IntegralToString", "convertLong", "(Ljava/lang/AbstractStringBuilder;J)Ljava/lang/String;");
368 CompileDirectMethod(NULL, "java.lang.IntegralToString", "intIntoCharArray", "([CII)I");
369 CompileDirectMethod(NULL, "java.lang.IntegralToString", "intToHexString", "(IZI)Ljava/lang/String;");
370 CompileDirectMethod(NULL, "java.lang.IntegralToString", "longToHexString", "(J)Ljava/lang/String;");
371 CompileDirectMethod(NULL, "java.lang.IntegralToString", "longToString", "(J)Ljava/lang/String;");
buzbee6a0f7f52011-09-05 16:14:20 -0700372 CompileDirectMethod(NULL, "java.lang.IntegralToString", "longToString", "(JI)Ljava/lang/String;");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700373 CompileDirectMethod(NULL, "java.lang.IntegralToString", "stringOf", "([C)Ljava/lang/String;");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700374
375 CompileDirectMethod(NULL, "java.lang.System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700376 CompileDirectMethod(NULL, "java.lang.System", "currentTimeMillis", "()J");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700377 CompileDirectMethod(NULL, "java.lang.System", "log", "(CLjava/lang/String;Ljava/lang/Throwable;)V");
378 CompileDirectMethod(NULL, "java.lang.System", "logI", "(Ljava/lang/String;)V");
379 CompileDirectMethod(NULL, "java.lang.System", "logI", "(Ljava/lang/String;Ljava/lang/Throwable;)V");
380
381 CompileDirectMethod(NULL, "java.util.Arrays", "checkOffsetAndCount", "(III)V");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700382
383 const ClassLoader* class_loader = LoadDex("SystemMethods");
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700384
385 CompileDirectMethod(class_loader, "SystemMethods", "<clinit>", "()V");
386
buzbee6a0f7f52011-09-05 16:14:20 -0700387 AssertStaticIntMethod(class_loader, "SystemMethods", "test0", "()I", 123);
388 AssertStaticIntMethod(class_loader, "SystemMethods", "test1", "()I", 123);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700389 AssertStaticIntMethod(class_loader, "SystemMethods", "test2", "()I", 123);
Elliott Hughesf5ecf062011-09-06 17:37:59 -0700390 AssertStaticIntMethod(class_loader, "SystemMethods", "test3", "()I", 123);
391 AssertStaticIntMethod(class_loader, "SystemMethods", "test4", "()I", 123);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700392}
393
buzbee4a3164f2011-09-03 11:25:10 -0700394
buzbeec143c552011-08-20 17:38:58 -0700395} // namespace art