compiler_driver_test.cc revision 1240dade91d6c4bbf4e367ca608fcdc15348da45
1c143c55718342519db5398e41dda31422cf16c79buzbee// Copyright 2011 Google Inc. All Rights Reserved.
2c143c55718342519db5398e41dda31422cf16c79buzbee
390a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes#include "compiler.h"
490a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes
590a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes#include <stdint.h>
690a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes#include <stdio.h>
790a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes
890a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes#include "UniquePtr.h"
9c143c55718342519db5398e41dda31422cf16c79buzbee#include "class_linker.h"
10c143c55718342519db5398e41dda31422cf16c79buzbee#include "common_test.h"
119ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom#include "dex_cache.h"
12c143c55718342519db5398e41dda31422cf16c79buzbee#include "dex_file.h"
13c143c55718342519db5398e41dda31422cf16c79buzbee#include "heap.h"
14c143c55718342519db5398e41dda31422cf16c79buzbee#include "object.h"
15c143c55718342519db5398e41dda31422cf16c79buzbee
16c143c55718342519db5398e41dda31422cf16c79buzbeenamespace art {
17c143c55718342519db5398e41dda31422cf16c79buzbee
18c143c55718342519db5398e41dda31422cf16c79buzbeeclass CompilerTest : public CommonTest {
19bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom protected:
208a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom
218a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  void AssertStaticIntMethod(const ClassLoader* class_loader,
221240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes                             const char* class_name, const char* method, const char* signature,
23bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                             jint expected, ...) {
241240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    EnsureCompiled(class_loader, class_name, method, signature);
25d3a729707671111ddd6a1aebbf8f986ce477642eElliott Hughes#if defined(__arm__)
26bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom    va_list args;
27bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom    va_start(args, expected);
281240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    jint result = env_->CallStaticIntMethodV(class_, mid_, args);
29bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom    va_end(args);
301240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    LOG(INFO) << class_name << "." << method << "(...) result is " << result;
31bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom    EXPECT_EQ(expected, result);
32bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom#endif // __arm__
33bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom  }
341240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
358a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  void AssertStaticLongMethod(const ClassLoader* class_loader,
361240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes                              const char* class_name, const char* method, const char* signature,
378a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom                              jlong expected, ...) {
381240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    EnsureCompiled(class_loader, class_name, method, signature);
39d3a729707671111ddd6a1aebbf8f986ce477642eElliott Hughes#if defined(__arm__)
40bafc342a37e423a19ac05f14800006ea9d67a941buzbee    va_list args;
41bafc342a37e423a19ac05f14800006ea9d67a941buzbee    va_start(args, expected);
421240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    jlong result = env_->CallStaticLongMethodV(class_, mid_, args);
43bafc342a37e423a19ac05f14800006ea9d67a941buzbee    va_end(args);
441240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    LOG(INFO) << class_name << "." << method << "(...) result is " << result;
45bafc342a37e423a19ac05f14800006ea9d67a941buzbee    EXPECT_EQ(expected, result);
46bafc342a37e423a19ac05f14800006ea9d67a941buzbee#endif // __arm__
47bafc342a37e423a19ac05f14800006ea9d67a941buzbee  }
481240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
491240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  void CompileAll(const ClassLoader* class_loader) {
501240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    compiler_->CompileAll(class_loader);
511240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    MakeAllExecutable(class_loader);
521240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  }
531240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
541240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  void EnsureCompiled(const ClassLoader* class_loader,
551240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      const char* class_name, const char* method, const char* signature) {
561240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    CompileAll(class_loader);
571240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    env_ = Thread::Current()->GetJniEnv();
581240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    class_ = env_->FindClass(class_name);
591240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    CHECK(class_ != NULL) << "Class not found: " << class_name;
601240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    mid_ = env_->GetStaticMethodID(class_, method, signature);
611240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    CHECK(mid_ != NULL) << "Method not found: " << class_name << "." << method << signature;
621240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  }
631240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
641240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  void MakeAllExecutable(const ClassLoader* class_loader) {
651240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    const std::vector<const DexFile*>& class_path = ClassLoader::GetClassPath(class_loader);
661240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    for (size_t i = 0; i != class_path.size(); ++i) {
671240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      const DexFile* dex_file = class_path[i];
681240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      CHECK(dex_file != NULL);
691240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      MakeDexFileExecutable(class_loader, *dex_file);
701240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    }
711240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  }
721240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
731240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  void MakeDexFileExecutable(const ClassLoader* class_loader, const DexFile& dex_file) {
741240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
751240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
761240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      const DexFile::ClassDef& class_def = dex_file.GetClassDef(i);
771240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      const char* descriptor = dex_file.GetClassDescriptor(class_def);
781240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      Class* c = class_linker->FindClass(descriptor, class_loader);
791240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      CHECK(c != NULL);
801240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      for (size_t i = 0; i < c->NumDirectMethods(); i++) {
811240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes        MakeMethodExecutable(c->GetDirectMethod(i));
821240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      }
831240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      for (size_t i = 0; i < c->NumVirtualMethods(); i++) {
841240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes        MakeMethodExecutable(c->GetVirtualMethod(i));
851240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      }
861240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    }
871240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  }
881240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
891240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  void MakeMethodExecutable(Method* m) {
901240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    if (m->GetCodeArray() != NULL) {
911240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      MakeExecutable(m->GetCodeArray());
921240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    } else {
931240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      LOG(WARNING) << "no code for " << PrettyMethod(m);
941240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    }
951240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    if (m->GetInvokeStubArray() != NULL) {
961240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      MakeExecutable(m->GetInvokeStubArray());
971240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    } else {
981240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes      LOG(WARNING) << "no invoke stub for " << PrettyMethod(m);
991240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes    }
1001240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  }
1011240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes
1021240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  JNIEnv* env_;
1031240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  jclass class_;
1041240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  jmethodID mid_;
105c143c55718342519db5398e41dda31422cf16c79buzbee};
106c143c55718342519db5398e41dda31422cf16c79buzbee
1077540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom// Disabled due to 10 second runtime on host
1081240dade91d6c4bbf4e367ca608fcdc15348da45Elliott HughesTEST_F(CompilerTest, DISABLED_LARGE_CompileDexLibCore) {
1091240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  CompileAll(NULL);
1109ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom
1119ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  // All libcore references should resolve
1129ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  const DexFile* dex = java_lang_dex_file_.get();
1139ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  DexCache* dex_cache = class_linker_->FindDexCache(*dex);
1149ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  EXPECT_EQ(dex->NumStringIds(), dex_cache->NumStrings());
1159ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  for (size_t i = 0; i < dex_cache->NumStrings(); i++) {
116cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes    const String* string = dex_cache->GetResolvedString(i);
1177540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    EXPECT_TRUE(string != NULL) << "string_idx=" << i;
1189ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  }
1191caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(dex->NumTypeIds(), dex_cache->NumResolvedTypes());
1201caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) {
1219ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom    Class* type = dex_cache->GetResolvedType(i);
1227540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    EXPECT_TRUE(type != NULL) << "type_idx=" << i
1237540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom                              << " " << dex->GetTypeDescriptor(dex->GetTypeId(i));
1249ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  }
1251caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumResolvedMethods());
1261caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) {
12720cfffabdc9e02b2df798bc4e6b6035d14bf4e36Brian Carlstrom    Method* method = dex_cache->GetResolvedMethod(i);
1287540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    EXPECT_TRUE(method != NULL) << "method_idx=" << i
1297540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom                                << " " << dex->GetMethodClassDescriptor(dex->GetMethodId(i))
1307540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom                                << " " << dex->GetMethodName(dex->GetMethodId(i));
1319ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  }
1321caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(dex->NumFieldIds(), dex_cache->NumResolvedFields());
1331caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) {
13420cfffabdc9e02b2df798bc4e6b6035d14bf4e36Brian Carlstrom    Field* field = dex_cache->GetResolvedField(i);
1357540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    EXPECT_TRUE(field != NULL) << "field_idx=" << i
1367540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom                               << " " << dex->GetFieldClassDescriptor(dex->GetFieldId(i))
1377540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom                               << " " << dex->GetFieldName(dex->GetFieldId(i));
1389ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom  }
1399ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom
14083db7721aef15df6919c0ec072e087bef6041e2dBrian Carlstrom  // TODO check Class::IsVerified for all classes
14183db7721aef15df6919c0ec072e087bef6041e2dBrian Carlstrom
14283db7721aef15df6919c0ec072e087bef6041e2dBrian Carlstrom  // TODO: check that all Method::GetCode() values are non-null
14383db7721aef15df6919c0ec072e087bef6041e2dBrian Carlstrom
1449cc262e2ad5cb507c21cc83b8dc954e9354a469cBrian Carlstrom  EXPECT_EQ(dex->NumMethodIds(), dex_cache->NumCodeAndDirectMethods());
1459cc262e2ad5cb507c21cc83b8dc954e9354a469cBrian Carlstrom  CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods();
1469cc262e2ad5cb507c21cc83b8dc954e9354a469cBrian Carlstrom  for (size_t i = 0; i < dex_cache->NumCodeAndDirectMethods(); i++) {
14783db7721aef15df6919c0ec072e087bef6041e2dBrian Carlstrom    Method* method = dex_cache->GetResolvedMethod(i);
1487540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    if (method->IsDirect()) {
1497540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom      EXPECT_EQ(method->GetCode(), code_and_direct_methods->GetResolvedCode(i));
1507540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom      EXPECT_EQ(method,            code_and_direct_methods->GetResolvedMethod(i));
1517540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    } else {
1527540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom      EXPECT_EQ(0U, code_and_direct_methods->GetResolvedCode(i));
1537540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom      EXPECT_TRUE(code_and_direct_methods->GetResolvedMethod(i) == NULL);
1547540ff4b6ad0ff5d8c5f60658b66155caf3a7cbcBrian Carlstrom    }
15583db7721aef15df6919c0ec072e087bef6041e2dBrian Carlstrom  }
1569ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom}
1579ea1cb1a22be5b85dc2622e3836c46a1c48e3f25Brian Carlstrom
158c143c55718342519db5398e41dda31422cf16c79buzbeeTEST_F(CompilerTest, BasicCodegen) {
1591240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("Fibonacci"), "Fibonacci", "fibonacci", "(I)I", 55, 10);
160c143c55718342519db5398e41dda31422cf16c79buzbee}
1613ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
1622a475e7b93d754e0a7525bb5c7059386307ea63abuzbee// TODO: need stub for InstanceofNonTrivialFromCode
1632a475e7b93d754e0a7525bb5c7059386307ea63abuzbeeTEST_F(CompilerTest, InstanceTest) {
1642a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
1651240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "instanceTest", "(I)I", 1352, 10);
1662a475e7b93d754e0a7525bb5c7059386307ea63abuzbee}
1672a475e7b93d754e0a7525bb5c7059386307ea63abuzbee
1682a475e7b93d754e0a7525bb5c7059386307ea63abuzbee// TODO: need check-cast test (when stub complete & we can throw/catch
1692a475e7b93d754e0a7525bb5c7059386307ea63abuzbee
1704a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbee// TODO: Need invoke-interface test
1714a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbee
1724a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbeeTEST_F(CompilerTest, SuperTest) {
1734a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbee  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
1741240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "superTest", "(I)I", 4175, 4141);
1754a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbee}
1764a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbee
1771b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbeeTEST_F(CompilerTest, ConstStringTest) {
1782a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.String", "<clinit>", "()V");
1792a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.String", "<init>", "(II[C)V");
1802a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.String", "<init>", "([CII)V");
1812a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileVirtualMethod(NULL, "java.lang.String", "_getChars", "(II[CI)V");
1822a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileVirtualMethod(NULL, "java.lang.String", "charAt", "(I)C");
1832a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileVirtualMethod(NULL, "java.lang.String", "length", "()I");
1841240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constStringTest", "(I)I", 1246, 1234);
1851b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbee}
1861b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbee
187561227c80077bbb4147f778043f1a836af6b9248buzbeeTEST_F(CompilerTest, ConstClassTest) {
1881240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "constClassTest", "(I)I", 2222, 1111);
189561227c80077bbb4147f778043f1a836af6b9248buzbee}
190561227c80077bbb4147f778043f1a836af6b9248buzbee
1912a475e7b93d754e0a7525bb5c7059386307ea63abuzbee// TODO: Need native nativeFillInStackTrace()
1921b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbeeTEST_F(CompilerTest, DISABLED_CatchTest) {
1931b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbee  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
1941b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbee  CompileDirectMethod(NULL, "java.lang.NullPointerException", "<init>", "()V");
1952a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.RuntimeException", "<init>", "()V");
1962a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.Exception", "<init>", "()V");
1972a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.Throwable","<init>", "()V");
1982a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.util.ArrayList","<init>","()V");
1992a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.util.AbstractList","<init>","()V");
2002a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.util.AbstractCollection","<init>","()V");
2012a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileVirtualMethod(NULL, "java.lang.Throwable","fillInStackTrace","()Ljava/lang/Throwable;");
2022a475e7b93d754e0a7525bb5c7059386307ea63abuzbee  CompileDirectMethod(NULL, "java.lang.Throwable","nativeFillInStackTrace","()Ljava/lang/Object;");
2031240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "catchBlock", "(I)I", 1579, 1000);
2041b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbee}
2051b4c85959b3d9a4a33bc2160c46c1bbde67350c7buzbee
206e9a72f6a1a84f4d9af0b07dd289b89e45ffb32d5buzbeeTEST_F(CompilerTest, CatchTestNoThrow) {
2071240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "catchBlockNoThrow", "(I)I", 1123, 1000);
208e9a72f6a1a84f4d9af0b07dd289b89e45ffb32d5buzbee}
209e9a72f6a1a84f4d9af0b07dd289b89e45ffb32d5buzbee
210e1931749814dbb80c5a756f9842e9c261bb2e8f6buzbeeTEST_F(CompilerTest, StaticFieldTest) {
2111240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "staticFieldTest", "(I)I", 1404, 404);
212e1931749814dbb80c5a756f9842e9c261bb2e8f6buzbee}
213e1931749814dbb80c5a756f9842e9c261bb2e8f6buzbee
2143ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, UnopTest) {
2151240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unopTest", "(I)I", 37, 38);
2163ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2173ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2183ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, ShiftTest1) {
2198a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest1", "()I", 0);
2203ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2213ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2223ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, ShiftTest2) {
2238a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "shiftTest2", "()I", 0);
2243ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2253ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2263ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, UnsignedShiftTest) {
2278a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "unsignedShiftTest", "()I", 0);
2283ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2293ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2303ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, ConvTest) {
2318a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "convTest", "()I", 0);
2323ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2333ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2343ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, CharSubTest) {
2358a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "charSubTest", "()I", 0);
2363ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2373ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2383ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, IntOperTest) {
2391240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intOperTest", "(II)I", 0, 70000, -3);
2403ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2413ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2423ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, Lit16Test) {
2431240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit16Test", "(I)I", 0, 77777);
2443ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2453ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2463ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, Lit8Test) {
2471240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "lit8Test", "(I)I", 0, -55555);
2483ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2493ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2503ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, IntShiftTest) {
2511240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "intShiftTest", "(II)I", 0, 0xff00aa01, 8);
2523ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2533ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2543ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, LongOperTest) {
2558a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "longOperTest", "(JJ)I", 0,
256439c4fa0db980fb19e4a585723a64a3461e4c278buzbee                        70000000000LL, -3LL);
2573ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
2583ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee
2593ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbeeTEST_F(CompilerTest, LongShiftTest) {
2608a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticLongMethod(LoadDex("IntMath"), "IntMath", "longShiftTest", "(JI)J",
2617b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee                         0x96deff00aa010000LL, 0xd5aa96deff00aa01LL, 16);
2623ea4ec5629613013ad9b0d7a69abdb94491ac46fbuzbee}
263c143c55718342519db5398e41dda31422cf16c79buzbee
2649e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbeeTEST_F(CompilerTest, SwitchTest1) {
2651240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "switchTest", "(I)I", 1234, 1);
2669e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee}
2679e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee
2689e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbeeTEST_F(CompilerTest, IntCompare) {
2698a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testIntCompare", "(IIII)I", 1111,
270bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                        -5, 4, 4, 0);
2719e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee}
2729e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee
2739e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbeeTEST_F(CompilerTest, LongCompare) {
2748a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testLongCompare", "(JJJJ)I", 2222,
275bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                        -5LL, -4294967287LL, 4LL, 8LL);
2769e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee}
2779e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee
2789e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbeeTEST_F(CompilerTest, FloatCompare) {
2798a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testFloatCompare", "(FFFF)I", 3333,
280bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                        -5.0f, 4.0f, 4.0f,
281bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                        (1.0f/0.0f) / (1.0f/0.0f));
2829e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee}
2839e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee
2849e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbeeTEST_F(CompilerTest, DoubleCompare) {
2858a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testDoubleCompare", "(DDDD)I", 4444,
286bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                                    -5.0, 4.0, 4.0,
287bffb15585b8fd43d3ca534ddbb85e7f591595951Brian Carlstrom                                    (1.0/0.0) / (1.0/0.0));
2889e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee}
2899e0f9b0d3e2cd78092e5c4b66ce1edcd79c951eabuzbee
290c5ef046ba4a484b08d0286393574396669a57c03buzbeeTEST_F(CompilerTest, RecursiveFibonacci) {
2911240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "fibonacci", "(I)I", 55, 10);
292c5ef046ba4a484b08d0286393574396669a57c03buzbee}
293c5ef046ba4a484b08d0286393574396669a57c03buzbee
2947b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee#if 0 // Need to complete try/catch block handling
2957b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbeeTEST_F(CompilerTest, ThrowAndCatch) {
2968a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "throwAndCatch", "()I", 4);
2977b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee}
2987b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee#endif
2997b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee
3007b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbeeTEST_F(CompilerTest, ManyArgs) {
3018a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "manyArgs",
3027b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee                        "(IJIJIJIIDFDSICIIBZIIJJIIIII)I", -1,
3037b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee                        0, 1LL, 2, 3LL, 4, 5LL, 6, 7, 8.0, 9.0f, 10.0,
3047b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee                        (short)11, 12, (char)13, 14, 15, (int8_t)-16, true, 18,
3057b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee                        19, 20LL, 21LL, 22, 23, 24, 25, 26);
3067b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee}
3077b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee
3087b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbeeTEST_F(CompilerTest, VirtualCall) {
3098a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
3101240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "staticCall", "(I)I", 6, 3);
3117b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee}
3127b1b86d68244b0bb4ea3f43505eb45fdd46814d6buzbee
313dd3efae34ee77935cbd275d09c0ad35e5b79daeebuzbeeTEST_F(CompilerTest, TestIGetPut) {
3148a48741b96ca9cc5835cac72ac133c4ca480930fBrian Carlstrom  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
3151240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("IntMath"), "IntMath", "testIGetPut", "(I)I", 333, 111);
316dd3efae34ee77935cbd275d09c0ad35e5b79daeebuzbee}
317dd3efae34ee77935cbd275d09c0ad35e5b79daeebuzbee
318109bd6a38d0cd7c4b7797a9f2db8324c797d1368buzbeeTEST_F(CompilerTest, InvokeTest) {
319109bd6a38d0cd7c4b7797a9f2db8324c797d1368buzbee  CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
3201240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("Invoke"), "Invoke", "test0", "(I)I", 20664, 912);
3210f4c41d75c821162184501cd4b510a93f6eb580fElliott Hughes}
3220f4c41d75c821162184501cd4b510a93f6eb580fElliott Hughes
3231240dade91d6c4bbf4e367ca608fcdc15348da45Elliott HughesTEST_F(CompilerTest, DISABLED_LARGE_SystemMethodsTest) {
3241240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  CompileAll(NULL); // This test calls a bunch of stuff from libcore.
3251240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes  AssertStaticIntMethod(LoadDex("SystemMethods"), "SystemMethods", "test5", "()I", 123);
3261240dade91d6c4bbf4e367ca608fcdc15348da45Elliott Hughes}
3274a3164faefd255b1c1e911e7ad7c3d57749caaf6buzbee
328c143c55718342519db5398e41dda31422cf16c79buzbee}  // namespace art
329