blob: 396cda5ee83c9437f99c7b946300114a5647f6fd [file] [log] [blame]
Brian Carlstrom934486c2011-07-12 23:42:50 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Brian Carlstromb0460ea2011-07-29 10:08:05 -07003#include <dirent.h>
Elliott Hughes0af55432011-08-17 18:37:28 -07004#include <dlfcn.h>
Brian Carlstrom27ec9612011-09-19 20:20:38 -07005#include <sys/mman.h>
Brian Carlstromb0460ea2011-07-29 10:08:05 -07006#include <sys/stat.h>
7#include <sys/types.h>
8
Elliott Hughes90a33692011-08-30 13:27:07 -07009#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070010#include "base64.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070011#include "class_linker.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070012#include "class_loader.h"
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -070013#include "compiler.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -070014#include "constants.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070015#include "dex_file.h"
Brian Carlstrom33f741e2011-10-03 11:24:05 -070016#include "file.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070017#include "gtest/gtest.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070018#include "heap.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070019#include "oat_file.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080020#include "object_utils.h"
Brian Carlstrom33f741e2011-10-03 11:24:05 -070021#include "os.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070022#include "runtime.h"
Elliott Hughes14134a12011-09-30 16:55:51 -070023#include "stl_util.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070024#include "stringprintf.h"
25#include "thread.h"
Elliott Hughes0af55432011-08-17 18:37:28 -070026#include "unicode/uclean.h"
27#include "unicode/uvernum.h"
28
Brian Carlstrom934486c2011-07-12 23:42:50 -070029namespace art {
30
Brian Carlstrom9f30b382011-08-28 22:41:38 -070031static inline const DexFile* OpenDexFileBase64(const char* base64,
32 const std::string& location) {
Brian Carlstrom33f741e2011-10-03 11:24:05 -070033 // decode base64
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070034 CHECK(base64 != NULL);
35 size_t length;
Brian Carlstromf615a612011-07-23 12:50:34 -070036 byte* dex_bytes = DecodeBase64(base64, &length);
37 CHECK(dex_bytes != NULL);
Brian Carlstrom33f741e2011-10-03 11:24:05 -070038
39 // write to provided file
40 UniquePtr<File> file(OS::OpenFile(location.c_str(), true));
41 CHECK(file.get() != NULL);
42 if (!file->WriteFully(dex_bytes, length)) {
43 PLOG(FATAL) << "Failed to write base64 as dex file";
44 }
45 file.reset();
46
47 // read dex file
Brian Carlstrom58ae9412011-10-04 00:56:06 -070048 const DexFile* dex_file = DexFile::Open(location, "");
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070049 CHECK(dex_file != NULL);
Brian Carlstromf615a612011-07-23 12:50:34 -070050 return dex_file;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070051}
52
Brian Carlstromdb4d5402011-08-09 12:18:28 -070053class ScratchFile {
54 public:
55 ScratchFile() {
Elliott Hughes34023802011-08-30 12:06:17 -070056 filename_ = getenv("ANDROID_DATA");
57 filename_ += "/TmpFile-XXXXXX";
58 fd_ = mkstemp(&filename_[0]);
Brian Carlstromdb4d5402011-08-09 12:18:28 -070059 CHECK_NE(-1, fd_);
Elliott Hughes234da572011-11-03 22:13:06 -070060 file_.reset(OS::FileFromFd(GetFilename(), fd_));
Brian Carlstromdb4d5402011-08-09 12:18:28 -070061 }
62
63 ~ScratchFile() {
Elliott Hughes34023802011-08-30 12:06:17 -070064 int unlink_result = unlink(filename_.c_str());
Brian Carlstromdb4d5402011-08-09 12:18:28 -070065 CHECK_EQ(0, unlink_result);
66 int close_result = close(fd_);
67 CHECK_EQ(0, close_result);
68 }
69
70 const char* GetFilename() const {
Elliott Hughes34023802011-08-30 12:06:17 -070071 return filename_.c_str();
Brian Carlstromdb4d5402011-08-09 12:18:28 -070072 }
73
Elliott Hughes234da572011-11-03 22:13:06 -070074 File* GetFile() const {
75 return file_.get();
76 }
77
Brian Carlstromdb4d5402011-08-09 12:18:28 -070078 int GetFd() const {
79 return fd_;
80 }
81
82 private:
Elliott Hughes34023802011-08-30 12:06:17 -070083 std::string filename_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070084 int fd_;
Elliott Hughes234da572011-11-03 22:13:06 -070085 UniquePtr<File> file_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070086};
87
Brian Carlstromf734cf52011-08-17 16:28:14 -070088class CommonTest : public testing::Test {
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -070089 public:
Brian Carlstrom3320cf42011-10-04 14:58:28 -070090
91 static void MakeExecutable(const ByteArray* code_array) {
92 CHECK(code_array != NULL);
93 MakeExecutable(code_array->GetData(), code_array->GetLength());
94 }
95
96 static void MakeExecutable(const std::vector<uint8_t>& code) {
97 CHECK_NE(code.size(), 0U);
98 MakeExecutable(&code[0], code.size());
99 }
100
Brian Carlstromae826982011-11-09 01:33:42 -0800101 // Create an OatMethod based on pointers (for unit tests)
102 OatFile::OatMethod CreateOatMethod(const void* code,
103 const size_t frame_size_in_bytes,
104 const uint32_t core_spill_mask,
105 const uint32_t fp_spill_mask,
106 const uint32_t* mapping_table,
107 const uint16_t* vmap_table,
108 const Method::InvokeStub* invoke_stub) {
109 return OatFile::OatMethod(NULL,
110 reinterpret_cast<uint32_t>(code),
111 frame_size_in_bytes,
112 core_spill_mask,
113 fp_spill_mask,
114 reinterpret_cast<uint32_t>(mapping_table),
115 reinterpret_cast<uint32_t>(vmap_table),
116 reinterpret_cast<uint32_t>(invoke_stub));
117 }
118
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700119 void MakeExecutable(Method* method) {
120 CHECK(method != NULL);
121
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800122 MethodHelper mh(method);
Ian Rogers0571d352011-11-03 19:51:38 -0700123 const CompiledInvokeStub* compiled_invoke_stub =
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800124 compiler_->FindInvokeStub(mh.IsStatic(), mh.GetShorty());
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700125 CHECK(compiled_invoke_stub != NULL) << PrettyMethod(method);
126 const std::vector<uint8_t>& invoke_stub = compiled_invoke_stub->GetCode();
127 MakeExecutable(invoke_stub);
128 const Method::InvokeStub* method_invoke_stub
129 = reinterpret_cast<const Method::InvokeStub*>(&invoke_stub[0]);
130 LOG(INFO) << "MakeExecutable " << PrettyMethod(method)
131 << " invoke_stub=" << reinterpret_cast<void*>(method_invoke_stub);
132
133 if (!method->IsAbstract()) {
Ian Rogers0571d352011-11-03 19:51:38 -0700134 const DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache();
135 const DexFile& dex_file = Runtime::Current()->GetClassLinker()->FindDexFile(dex_cache);
136 const CompiledMethod* compiled_method =
137 compiler_->GetCompiledMethod(Compiler::MethodReference(&dex_file,
138 method->GetDexMethodIndex()));
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700139 CHECK(compiled_method != NULL) << PrettyMethod(method);
140 const std::vector<uint8_t>& code = compiled_method->GetCode();
141 MakeExecutable(code);
142 const void* method_code
143 = CompiledMethod::CodePointer(&code[0], compiled_method->GetInstructionSet());
144 LOG(INFO) << "MakeExecutable " << PrettyMethod(method) << " code=" << method_code;
Brian Carlstromae826982011-11-09 01:33:42 -0800145 OatFile::OatMethod oat_method = CreateOatMethod(method_code,
146 compiled_method->GetFrameSizeInBytes(),
147 compiled_method->GetCoreSpillMask(),
148 compiled_method->GetFpSpillMask(),
149 &compiled_method->GetMappingTable()[0],
150 &compiled_method->GetVmapTable()[0],
151 method_invoke_stub);
152 oat_method.LinkMethodPointers(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700153 } else {
154 MakeExecutable(runtime_->GetAbstractMethodErrorStubArray());
155 const void* method_code = runtime_->GetAbstractMethodErrorStubArray()->GetData();
156 LOG(INFO) << "MakeExecutable " << PrettyMethod(method) << " code=" << method_code;
Brian Carlstromae826982011-11-09 01:33:42 -0800157 OatFile::OatMethod oat_method = CreateOatMethod(method_code,
158 kStackAlignment,
159 0,
160 0,
161 NULL,
162 NULL,
163 method_invoke_stub);
164 oat_method.LinkMethodPointers(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700165 }
166 }
167
168 static void MakeExecutable(const void* code_start, size_t code_length) {
169 CHECK(code_start != NULL);
170 CHECK_NE(code_length, 0U);
171 uintptr_t data = reinterpret_cast<uintptr_t>(code_start);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700172 uintptr_t base = RoundDown(data, kPageSize);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700173 uintptr_t limit = RoundUp(data + code_length, kPageSize);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700174 uintptr_t len = limit - base;
175 int result = mprotect(reinterpret_cast<void*>(base), len, PROT_READ | PROT_WRITE | PROT_EXEC);
Ian Rogers16341552011-10-10 11:33:06 -0700176 // Flush instruction cache
177 __builtin___clear_cache(reinterpret_cast<void*>(base), reinterpret_cast<void*>(base + len));
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700178 CHECK_EQ(result, 0);
179 }
180
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700181 protected:
182 virtual void SetUp() {
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700183 is_host_ = getenv("ANDROID_BUILD_TOP") != NULL;
184
Elliott Hughes0af55432011-08-17 18:37:28 -0700185 if (is_host_) {
186 // $ANDROID_ROOT is set on the device, but not on the host.
187 // We need to set this so that icu4c can find its locale data.
188 std::string root;
189 root += getenv("ANDROID_BUILD_TOP");
190 root += "/out/host/linux-x86";
191 setenv("ANDROID_ROOT", root.c_str(), 1);
192 }
193
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700194 // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of art-cache
195 android_data_ = (is_host_ ? "/tmp/art-data-XXXXXX" : "/data/art-cache/art-data-XXXXXX");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700196 if (mkdtemp(&android_data_[0]) == NULL) {
197 PLOG(FATAL) << "mkdtemp(\"" << &android_data_[0] << "\") failed";
198 }
Elliott Hughes34023802011-08-30 12:06:17 -0700199 setenv("ANDROID_DATA", android_data_.c_str(), 1);
200 art_cache_.append(android_data_.c_str());
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700201 art_cache_.append("/art-cache");
202 int mkdir_result = mkdir(art_cache_.c_str(), 0700);
203 ASSERT_EQ(mkdir_result, 0);
204
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700205 java_lang_dex_file_.reset(GetLibCoreDex());
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700206
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700207 std::string boot_class_path;
208 boot_class_path += "-Xbootclasspath:";
209 boot_class_path += GetLibCoreDexFileName();
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700210
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700211 Runtime::Options options;
Brian Carlstroma4a7b482011-10-16 15:29:16 -0700212 options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL)));
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700213 options.push_back(std::make_pair(boot_class_path.c_str(), reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700214 options.push_back(std::make_pair("-Xcheck:jni", reinterpret_cast<void*>(NULL)));
Brian Carlstrome24fa612011-09-29 00:53:55 -0700215 options.push_back(std::make_pair("-Xms64m", reinterpret_cast<void*>(NULL)));
216 options.push_back(std::make_pair("-Xmx64m", reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700217 runtime_.reset(Runtime::Create(options, false));
Elliott Hughes90a33692011-08-30 13:27:07 -0700218 ASSERT_TRUE(runtime_.get() != NULL);
Carl Shapiro7a909592011-07-24 19:21:59 -0700219 class_linker_ = runtime_->GetClassLinker();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700220
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700221 InstructionSet instruction_set = kNone;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700222#if defined(__i386__)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700223 instruction_set = kX86;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700224#elif defined(__arm__)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700225 instruction_set = kThumb2;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700226#endif
Ian Rogers169c9a72011-11-13 20:13:17 -0800227 runtime_->SetJniDlsymLookupStub(Compiler::CreateJniDlysmLookupStub(instruction_set));
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700228 runtime_->SetAbstractMethodErrorStubArray(Compiler::CreateAbstractMethodErrorStub(instruction_set));
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700229 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700230 Runtime::TrampolineType type = Runtime::TrampolineType(i);
231 if (!runtime_->HasResolutionStubArray(type)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700232 runtime_->SetResolutionStubArray(
233 Compiler::CreateResolutionStub(instruction_set, type), type);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700234 }
235 }
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700236 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700237 Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i);
238 if (!runtime_->HasCalleeSaveMethod(type)) {
239 runtime_->SetCalleeSaveMethod(
240 runtime_->CreateCalleeSaveMethod(instruction_set, type), type);
241 }
242 }
Brian Carlstromae826982011-11-09 01:33:42 -0800243 compiler_.reset(new Compiler(instruction_set, false, NULL));
Ian Rogers2c8f6532011-09-02 17:16:34 -0700244
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700245 Heap::VerifyHeap(); // Check for heap corruption before the test
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700246 }
247
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700248 virtual void TearDown() {
249 const char* android_data = getenv("ANDROID_DATA");
250 ASSERT_TRUE(android_data != NULL);
251 DIR* dir = opendir(art_cache_.c_str());
252 ASSERT_TRUE(dir != NULL);
253 while (true) {
254 struct dirent entry;
255 struct dirent* entry_ptr;
256 int readdir_result = readdir_r(dir, &entry, &entry_ptr);
257 ASSERT_EQ(0, readdir_result);
258 if (entry_ptr == NULL) {
259 break;
260 }
261 if ((strcmp(entry_ptr->d_name, ".") == 0) || (strcmp(entry_ptr->d_name, "..") == 0)) {
262 continue;
263 }
264 std::string filename(art_cache_);
265 filename.push_back('/');
266 filename.append(entry_ptr->d_name);
267 int unlink_result = unlink(filename.c_str());
268 ASSERT_EQ(0, unlink_result);
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400269 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700270 closedir(dir);
271 int rmdir_cache_result = rmdir(art_cache_.c_str());
272 ASSERT_EQ(0, rmdir_cache_result);
Elliott Hughes34023802011-08-30 12:06:17 -0700273 int rmdir_data_result = rmdir(android_data_.c_str());
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700274 ASSERT_EQ(0, rmdir_data_result);
Elliott Hughes0af55432011-08-17 18:37:28 -0700275
276 // icu4c has a fixed 10-element array "gCommonICUDataArray".
277 // If we run > 10 tests, we fill that array and u_setCommonData fails.
278 // There's a function to clear the array, but it's not public...
279 typedef void (*IcuCleanupFn)();
280 void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT);
281 CHECK(sym != NULL);
282 IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym);
283 (*icu_cleanup_fn)();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700284
Ian Rogers0e073f72011-09-09 10:45:46 -0700285 compiler_.reset();
Ian Rogers2c8f6532011-09-02 17:16:34 -0700286
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700287 Heap::VerifyHeap(); // Check for heap corruption after the test
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700288 }
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400289
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700290 std::string GetLibCoreDexFileName() {
291 if (is_host_) {
292 const char* host_dir = getenv("ANDROID_HOST_OUT");
293 CHECK(host_dir != NULL);
294 return StringPrintf("%s/framework/core-hostdex.jar", host_dir);
295 }
296 return std::string("/system/framework/core.jar");
297 }
298
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700299 const DexFile* GetLibCoreDex() {
Elliott Hughes95572412011-12-13 18:14:20 -0800300 std::string libcore_dex_file_name(GetLibCoreDexFileName());
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700301 return DexFile::Open(libcore_dex_file_name, "");
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400302 }
303
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700304 const DexFile* OpenTestDexFile(const char* name) {
305 CHECK(name != NULL);
306 std::string filename;
307 if (is_host_) {
308 // on the host, just read target dex file
309 filename += getenv("ANDROID_PRODUCT_OUT");
310 }
Brian Carlstrom47a0d5a2011-10-12 21:20:05 -0700311 filename += "/data/art-test/art-test-dex-";
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700312 filename += name;
313 filename += ".jar";
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700314 const DexFile* dex_file = DexFile::Open(filename, "");
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700315 CHECK(dex_file != NULL) << "Failed to open " << filename;
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700316 return dex_file;
317 }
318
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700319 ClassLoader* LoadDex(const char* dex_name) {
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700320 const DexFile* dex_file = OpenTestDexFile(dex_name);
321 CHECK(dex_file != NULL);
322 loaded_dex_files_.push_back(dex_file);
323 class_linker_->RegisterDexFile(*dex_file);
324 std::vector<const DexFile*> class_path;
325 class_path.push_back(dex_file);
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700326 SirtRef<ClassLoader> class_loader(PathClassLoader::AllocCompileTime(class_path));
327 CHECK(class_loader.get() != NULL);
328 Thread::Current()->SetClassLoaderOverride(class_loader.get());
329 return class_loader.get();
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700330 }
331
Brian Carlstromaded5f72011-10-07 17:15:04 -0700332 void CompileClass(const ClassLoader* class_loader, const char* class_name) {
Elliott Hughes95572412011-12-13 18:14:20 -0800333 std::string class_descriptor(DotToDescriptor(class_name));
Elliott Hughesc3b77c72011-12-15 20:56:48 -0800334 Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700335 CHECK(klass != NULL) << "Class not found " << class_name;
336 for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
337 CompileMethod(klass->GetDirectMethod(i));
338 }
339 for (size_t i = 0; i < klass->NumVirtualMethods(); i++) {
340 CompileMethod(klass->GetVirtualMethod(i));
341 }
342 }
343
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700344 void CompileMethod(Method* method) {
345 CHECK(method != NULL);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700346 compiler_->CompileOne(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700347 MakeExecutable(method);
348
Ian Rogers169c9a72011-11-13 20:13:17 -0800349 MakeExecutable(runtime_->GetJniDlsymLookupStub());
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700350 }
351
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700352 void CompileDirectMethod(ClassLoader* class_loader,
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700353 const char* class_name,
354 const char* method_name,
355 const char* signature) {
Elliott Hughes95572412011-12-13 18:14:20 -0800356 std::string class_descriptor(DotToDescriptor(class_name));
Elliott Hughesc3b77c72011-12-15 20:56:48 -0800357 Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700358 CHECK(klass != NULL) << "Class not found " << class_name;
359 Method* method = klass->FindDirectMethod(method_name, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700360 CHECK(method != NULL) << "Direct method not found: "
361 << class_name << "." << method_name << signature;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700362 CompileMethod(method);
363 }
364
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700365 void CompileVirtualMethod(ClassLoader* class_loader,
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700366 const char* class_name,
367 const char* method_name,
368 const char* signature) {
Elliott Hughes95572412011-12-13 18:14:20 -0800369 std::string class_descriptor(DotToDescriptor(class_name));
Elliott Hughesc3b77c72011-12-15 20:56:48 -0800370 Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700371 CHECK(klass != NULL) << "Class not found " << class_name;
372 Method* method = klass->FindVirtualMethod(method_name, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700373 CHECK(method != NULL) << "Virtual method not found: "
374 << class_name << "." << method_name << signature;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700375 CompileMethod(method);
376 }
377
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700378 bool is_host_;
Elliott Hughes34023802011-08-30 12:06:17 -0700379 std::string android_data_;
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700380 std::string art_cache_;
Elliott Hughes90a33692011-08-30 13:27:07 -0700381 UniquePtr<const DexFile> java_lang_dex_file_;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700382 std::vector<const DexFile*> boot_class_path_;
Elliott Hughes90a33692011-08-30 13:27:07 -0700383 UniquePtr<Runtime> runtime_;
Ian Rogers0e073f72011-09-09 10:45:46 -0700384 // Owned by the runtime
Carl Shapiro7a909592011-07-24 19:21:59 -0700385 ClassLinker* class_linker_;
Ian Rogers0e073f72011-09-09 10:45:46 -0700386 UniquePtr<Compiler> compiler_;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700387
388 private:
389 std::vector<const DexFile*> loaded_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700390};
391
Brian Carlstrom934486c2011-07-12 23:42:50 -0700392} // namespace art
Elliott Hughes34023802011-08-30 12:06:17 -0700393
394namespace std {
395
396// TODO: isn't gtest supposed to be able to print STL types for itself?
397template <typename T>
398std::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) {
Elliott Hughes14134a12011-09-30 16:55:51 -0700399 os << ::art::ToString(rhs);
Elliott Hughes34023802011-08-30 12:06:17 -0700400 return os;
401}
402
403} // namespace std