blob: d140d4063dfc8ec0b62edce1d8398e85de2352b4 [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"
Brian Carlstrom33f741e2011-10-03 11:24:05 -070020#include "os.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070021#include "runtime.h"
Elliott Hughes14134a12011-09-30 16:55:51 -070022#include "stl_util.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070023#include "stringprintf.h"
24#include "thread.h"
Elliott Hughes0af55432011-08-17 18:37:28 -070025#include "unicode/uclean.h"
26#include "unicode/uvernum.h"
27
Brian Carlstrom934486c2011-07-12 23:42:50 -070028namespace art {
29
Brian Carlstrom9f30b382011-08-28 22:41:38 -070030static inline const DexFile* OpenDexFileBase64(const char* base64,
31 const std::string& location) {
Brian Carlstrom33f741e2011-10-03 11:24:05 -070032 // decode base64
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070033 CHECK(base64 != NULL);
34 size_t length;
Brian Carlstromf615a612011-07-23 12:50:34 -070035 byte* dex_bytes = DecodeBase64(base64, &length);
36 CHECK(dex_bytes != NULL);
Brian Carlstrom33f741e2011-10-03 11:24:05 -070037
38 // write to provided file
39 UniquePtr<File> file(OS::OpenFile(location.c_str(), true));
40 CHECK(file.get() != NULL);
41 if (!file->WriteFully(dex_bytes, length)) {
42 PLOG(FATAL) << "Failed to write base64 as dex file";
43 }
44 file.reset();
45
46 // read dex file
Brian Carlstrom58ae9412011-10-04 00:56:06 -070047 const DexFile* dex_file = DexFile::Open(location, "");
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070048 CHECK(dex_file != NULL);
Brian Carlstromf615a612011-07-23 12:50:34 -070049 return dex_file;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070050}
51
Brian Carlstromdb4d5402011-08-09 12:18:28 -070052class ScratchFile {
53 public:
54 ScratchFile() {
Elliott Hughes34023802011-08-30 12:06:17 -070055 filename_ = getenv("ANDROID_DATA");
56 filename_ += "/TmpFile-XXXXXX";
57 fd_ = mkstemp(&filename_[0]);
Brian Carlstromdb4d5402011-08-09 12:18:28 -070058 CHECK_NE(-1, fd_);
Elliott Hughes234da572011-11-03 22:13:06 -070059 file_.reset(OS::FileFromFd(GetFilename(), fd_));
Brian Carlstromdb4d5402011-08-09 12:18:28 -070060 }
61
62 ~ScratchFile() {
Elliott Hughes34023802011-08-30 12:06:17 -070063 int unlink_result = unlink(filename_.c_str());
Brian Carlstromdb4d5402011-08-09 12:18:28 -070064 CHECK_EQ(0, unlink_result);
65 int close_result = close(fd_);
66 CHECK_EQ(0, close_result);
67 }
68
69 const char* GetFilename() const {
Elliott Hughes34023802011-08-30 12:06:17 -070070 return filename_.c_str();
Brian Carlstromdb4d5402011-08-09 12:18:28 -070071 }
72
Elliott Hughes234da572011-11-03 22:13:06 -070073 File* GetFile() const {
74 return file_.get();
75 }
76
Brian Carlstromdb4d5402011-08-09 12:18:28 -070077 int GetFd() const {
78 return fd_;
79 }
80
81 private:
Elliott Hughes34023802011-08-30 12:06:17 -070082 std::string filename_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070083 int fd_;
Elliott Hughes234da572011-11-03 22:13:06 -070084 UniquePtr<File> file_;
Brian Carlstromdb4d5402011-08-09 12:18:28 -070085};
86
Brian Carlstromf734cf52011-08-17 16:28:14 -070087class CommonTest : public testing::Test {
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -070088 public:
Brian Carlstrom3320cf42011-10-04 14:58:28 -070089
90 static void MakeExecutable(const ByteArray* code_array) {
91 CHECK(code_array != NULL);
92 MakeExecutable(code_array->GetData(), code_array->GetLength());
93 }
94
95 static void MakeExecutable(const std::vector<uint8_t>& code) {
96 CHECK_NE(code.size(), 0U);
97 MakeExecutable(&code[0], code.size());
98 }
99
Brian Carlstromae826982011-11-09 01:33:42 -0800100 // Create an OatMethod based on pointers (for unit tests)
101 OatFile::OatMethod CreateOatMethod(const void* code,
102 const size_t frame_size_in_bytes,
103 const uint32_t core_spill_mask,
104 const uint32_t fp_spill_mask,
105 const uint32_t* mapping_table,
106 const uint16_t* vmap_table,
107 const Method::InvokeStub* invoke_stub) {
108 return OatFile::OatMethod(NULL,
109 reinterpret_cast<uint32_t>(code),
110 frame_size_in_bytes,
111 core_spill_mask,
112 fp_spill_mask,
113 reinterpret_cast<uint32_t>(mapping_table),
114 reinterpret_cast<uint32_t>(vmap_table),
115 reinterpret_cast<uint32_t>(invoke_stub));
116 }
117
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700118 void MakeExecutable(Method* method) {
119 CHECK(method != NULL);
120
Ian Rogers0571d352011-11-03 19:51:38 -0700121 const CompiledInvokeStub* compiled_invoke_stub =
122 compiler_->FindInvokeStub(method->IsStatic(),
123 method->GetShorty()->ToModifiedUtf8().c_str());
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700124 CHECK(compiled_invoke_stub != NULL) << PrettyMethod(method);
125 const std::vector<uint8_t>& invoke_stub = compiled_invoke_stub->GetCode();
126 MakeExecutable(invoke_stub);
127 const Method::InvokeStub* method_invoke_stub
128 = reinterpret_cast<const Method::InvokeStub*>(&invoke_stub[0]);
129 LOG(INFO) << "MakeExecutable " << PrettyMethod(method)
130 << " invoke_stub=" << reinterpret_cast<void*>(method_invoke_stub);
131
132 if (!method->IsAbstract()) {
Ian Rogers0571d352011-11-03 19:51:38 -0700133 const DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache();
134 const DexFile& dex_file = Runtime::Current()->GetClassLinker()->FindDexFile(dex_cache);
135 const CompiledMethod* compiled_method =
136 compiler_->GetCompiledMethod(Compiler::MethodReference(&dex_file,
137 method->GetDexMethodIndex()));
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700138 CHECK(compiled_method != NULL) << PrettyMethod(method);
139 const std::vector<uint8_t>& code = compiled_method->GetCode();
140 MakeExecutable(code);
141 const void* method_code
142 = CompiledMethod::CodePointer(&code[0], compiled_method->GetInstructionSet());
143 LOG(INFO) << "MakeExecutable " << PrettyMethod(method) << " code=" << method_code;
Brian Carlstromae826982011-11-09 01:33:42 -0800144 OatFile::OatMethod oat_method = CreateOatMethod(method_code,
145 compiled_method->GetFrameSizeInBytes(),
146 compiled_method->GetCoreSpillMask(),
147 compiled_method->GetFpSpillMask(),
148 &compiled_method->GetMappingTable()[0],
149 &compiled_method->GetVmapTable()[0],
150 method_invoke_stub);
151 oat_method.LinkMethodPointers(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700152 } else {
153 MakeExecutable(runtime_->GetAbstractMethodErrorStubArray());
154 const void* method_code = runtime_->GetAbstractMethodErrorStubArray()->GetData();
155 LOG(INFO) << "MakeExecutable " << PrettyMethod(method) << " code=" << method_code;
Brian Carlstromae826982011-11-09 01:33:42 -0800156 OatFile::OatMethod oat_method = CreateOatMethod(method_code,
157 kStackAlignment,
158 0,
159 0,
160 NULL,
161 NULL,
162 method_invoke_stub);
163 oat_method.LinkMethodPointers(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700164 }
165 }
166
167 static void MakeExecutable(const void* code_start, size_t code_length) {
168 CHECK(code_start != NULL);
169 CHECK_NE(code_length, 0U);
170 uintptr_t data = reinterpret_cast<uintptr_t>(code_start);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700171 uintptr_t base = RoundDown(data, kPageSize);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700172 uintptr_t limit = RoundUp(data + code_length, kPageSize);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700173 uintptr_t len = limit - base;
174 int result = mprotect(reinterpret_cast<void*>(base), len, PROT_READ | PROT_WRITE | PROT_EXEC);
Ian Rogers16341552011-10-10 11:33:06 -0700175 // Flush instruction cache
176 __builtin___clear_cache(reinterpret_cast<void*>(base), reinterpret_cast<void*>(base + len));
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700177 CHECK_EQ(result, 0);
178 }
179
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700180 protected:
181 virtual void SetUp() {
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700182 is_host_ = getenv("ANDROID_BUILD_TOP") != NULL;
183
Elliott Hughes0af55432011-08-17 18:37:28 -0700184 if (is_host_) {
185 // $ANDROID_ROOT is set on the device, but not on the host.
186 // We need to set this so that icu4c can find its locale data.
187 std::string root;
188 root += getenv("ANDROID_BUILD_TOP");
189 root += "/out/host/linux-x86";
190 setenv("ANDROID_ROOT", root.c_str(), 1);
191 }
192
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700193 // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of art-cache
194 android_data_ = (is_host_ ? "/tmp/art-data-XXXXXX" : "/data/art-cache/art-data-XXXXXX");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700195 if (mkdtemp(&android_data_[0]) == NULL) {
196 PLOG(FATAL) << "mkdtemp(\"" << &android_data_[0] << "\") failed";
197 }
Elliott Hughes34023802011-08-30 12:06:17 -0700198 setenv("ANDROID_DATA", android_data_.c_str(), 1);
199 art_cache_.append(android_data_.c_str());
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700200 art_cache_.append("/art-cache");
201 int mkdir_result = mkdir(art_cache_.c_str(), 0700);
202 ASSERT_EQ(mkdir_result, 0);
203
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700204 java_lang_dex_file_.reset(GetLibCoreDex());
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700205
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700206 std::string boot_class_path;
207 boot_class_path += "-Xbootclasspath:";
208 boot_class_path += GetLibCoreDexFileName();
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700209
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700210 Runtime::Options options;
Brian Carlstroma4a7b482011-10-16 15:29:16 -0700211 options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL)));
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700212 options.push_back(std::make_pair(boot_class_path.c_str(), reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700213 options.push_back(std::make_pair("-Xcheck:jni", reinterpret_cast<void*>(NULL)));
Brian Carlstrome24fa612011-09-29 00:53:55 -0700214 options.push_back(std::make_pair("-Xms64m", reinterpret_cast<void*>(NULL)));
215 options.push_back(std::make_pair("-Xmx64m", reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700216 runtime_.reset(Runtime::Create(options, false));
Elliott Hughes90a33692011-08-30 13:27:07 -0700217 ASSERT_TRUE(runtime_.get() != NULL);
Carl Shapiro7a909592011-07-24 19:21:59 -0700218 class_linker_ = runtime_->GetClassLinker();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700219
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700220 InstructionSet instruction_set = kNone;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700221#if defined(__i386__)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700222 instruction_set = kX86;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700223#elif defined(__arm__)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700224 instruction_set = kThumb2;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700225#endif
Ian Rogers169c9a72011-11-13 20:13:17 -0800226 runtime_->SetJniDlsymLookupStub(Compiler::CreateJniDlysmLookupStub(instruction_set));
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700227 runtime_->SetAbstractMethodErrorStubArray(Compiler::CreateAbstractMethodErrorStub(instruction_set));
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700228 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700229 Runtime::TrampolineType type = Runtime::TrampolineType(i);
230 if (!runtime_->HasResolutionStubArray(type)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700231 runtime_->SetResolutionStubArray(
232 Compiler::CreateResolutionStub(instruction_set, type), type);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700233 }
234 }
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700235 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700236 Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i);
237 if (!runtime_->HasCalleeSaveMethod(type)) {
238 runtime_->SetCalleeSaveMethod(
239 runtime_->CreateCalleeSaveMethod(instruction_set, type), type);
240 }
241 }
Brian Carlstromae826982011-11-09 01:33:42 -0800242 compiler_.reset(new Compiler(instruction_set, false, NULL));
Ian Rogers2c8f6532011-09-02 17:16:34 -0700243
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700244 Heap::VerifyHeap(); // Check for heap corruption before the test
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700245 }
246
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700247 virtual void TearDown() {
248 const char* android_data = getenv("ANDROID_DATA");
249 ASSERT_TRUE(android_data != NULL);
250 DIR* dir = opendir(art_cache_.c_str());
251 ASSERT_TRUE(dir != NULL);
252 while (true) {
253 struct dirent entry;
254 struct dirent* entry_ptr;
255 int readdir_result = readdir_r(dir, &entry, &entry_ptr);
256 ASSERT_EQ(0, readdir_result);
257 if (entry_ptr == NULL) {
258 break;
259 }
260 if ((strcmp(entry_ptr->d_name, ".") == 0) || (strcmp(entry_ptr->d_name, "..") == 0)) {
261 continue;
262 }
263 std::string filename(art_cache_);
264 filename.push_back('/');
265 filename.append(entry_ptr->d_name);
266 int unlink_result = unlink(filename.c_str());
267 ASSERT_EQ(0, unlink_result);
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400268 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700269 closedir(dir);
270 int rmdir_cache_result = rmdir(art_cache_.c_str());
271 ASSERT_EQ(0, rmdir_cache_result);
Elliott Hughes34023802011-08-30 12:06:17 -0700272 int rmdir_data_result = rmdir(android_data_.c_str());
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700273 ASSERT_EQ(0, rmdir_data_result);
Elliott Hughes0af55432011-08-17 18:37:28 -0700274
275 // icu4c has a fixed 10-element array "gCommonICUDataArray".
276 // If we run > 10 tests, we fill that array and u_setCommonData fails.
277 // There's a function to clear the array, but it's not public...
278 typedef void (*IcuCleanupFn)();
279 void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT);
280 CHECK(sym != NULL);
281 IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym);
282 (*icu_cleanup_fn)();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700283
Ian Rogers0e073f72011-09-09 10:45:46 -0700284 compiler_.reset();
Ian Rogers2c8f6532011-09-02 17:16:34 -0700285
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700286 Heap::VerifyHeap(); // Check for heap corruption after the test
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700287 }
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400288
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700289 std::string GetLibCoreDexFileName() {
290 if (is_host_) {
291 const char* host_dir = getenv("ANDROID_HOST_OUT");
292 CHECK(host_dir != NULL);
293 return StringPrintf("%s/framework/core-hostdex.jar", host_dir);
294 }
295 return std::string("/system/framework/core.jar");
296 }
297
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700298 const DexFile* GetLibCoreDex() {
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700299 std::string libcore_dex_file_name = GetLibCoreDexFileName();
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700300 return DexFile::Open(libcore_dex_file_name, "");
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400301 }
302
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700303 const DexFile* OpenTestDexFile(const char* name) {
304 CHECK(name != NULL);
305 std::string filename;
306 if (is_host_) {
307 // on the host, just read target dex file
308 filename += getenv("ANDROID_PRODUCT_OUT");
309 }
Brian Carlstrom47a0d5a2011-10-12 21:20:05 -0700310 filename += "/data/art-test/art-test-dex-";
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700311 filename += name;
312 filename += ".jar";
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700313 const DexFile* dex_file = DexFile::Open(filename, "");
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700314 CHECK(dex_file != NULL) << "Failed to open " << filename;
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700315 return dex_file;
316 }
317
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700318 ClassLoader* LoadDex(const char* dex_name) {
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700319 const DexFile* dex_file = OpenTestDexFile(dex_name);
320 CHECK(dex_file != NULL);
321 loaded_dex_files_.push_back(dex_file);
322 class_linker_->RegisterDexFile(*dex_file);
323 std::vector<const DexFile*> class_path;
324 class_path.push_back(dex_file);
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700325 SirtRef<ClassLoader> class_loader(PathClassLoader::AllocCompileTime(class_path));
326 CHECK(class_loader.get() != NULL);
327 Thread::Current()->SetClassLoaderOverride(class_loader.get());
328 return class_loader.get();
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700329 }
330
Brian Carlstromaded5f72011-10-07 17:15:04 -0700331 void CompileClass(const ClassLoader* class_loader, const char* class_name) {
332 std::string class_descriptor = DotToDescriptor(class_name);
333 Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
334 CHECK(klass != NULL) << "Class not found " << class_name;
335 for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
336 CompileMethod(klass->GetDirectMethod(i));
337 }
338 for (size_t i = 0; i < klass->NumVirtualMethods(); i++) {
339 CompileMethod(klass->GetVirtualMethod(i));
340 }
341 }
342
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700343 void CompileMethod(Method* method) {
344 CHECK(method != NULL);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700345 compiler_->CompileOne(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700346 MakeExecutable(method);
347
Ian Rogers169c9a72011-11-13 20:13:17 -0800348 MakeExecutable(runtime_->GetJniDlsymLookupStub());
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700349 }
350
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700351 void CompileDirectMethod(ClassLoader* class_loader,
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700352 const char* class_name,
353 const char* method_name,
354 const char* signature) {
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700355 std::string class_descriptor = DotToDescriptor(class_name);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700356 Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
357 CHECK(klass != NULL) << "Class not found " << class_name;
358 Method* method = klass->FindDirectMethod(method_name, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700359 CHECK(method != NULL) << "Direct method not found: "
360 << class_name << "." << method_name << signature;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700361 CompileMethod(method);
362 }
363
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700364 void CompileVirtualMethod(ClassLoader* class_loader,
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700365 const char* class_name,
366 const char* method_name,
367 const char* signature) {
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700368 std::string class_descriptor = DotToDescriptor(class_name);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700369 Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
370 CHECK(klass != NULL) << "Class not found " << class_name;
371 Method* method = klass->FindVirtualMethod(method_name, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700372 CHECK(method != NULL) << "Virtual method not found: "
373 << class_name << "." << method_name << signature;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700374 CompileMethod(method);
375 }
376
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700377 bool is_host_;
Elliott Hughes34023802011-08-30 12:06:17 -0700378 std::string android_data_;
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700379 std::string art_cache_;
Elliott Hughes90a33692011-08-30 13:27:07 -0700380 UniquePtr<const DexFile> java_lang_dex_file_;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700381 std::vector<const DexFile*> boot_class_path_;
Elliott Hughes90a33692011-08-30 13:27:07 -0700382 UniquePtr<Runtime> runtime_;
Ian Rogers0e073f72011-09-09 10:45:46 -0700383 // Owned by the runtime
Carl Shapiro7a909592011-07-24 19:21:59 -0700384 ClassLinker* class_linker_;
Ian Rogers0e073f72011-09-09 10:45:46 -0700385 UniquePtr<Compiler> compiler_;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700386
387 private:
388 std::vector<const DexFile*> loaded_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700389};
390
Brian Carlstrom934486c2011-07-12 23:42:50 -0700391} // namespace art
Elliott Hughes34023802011-08-30 12:06:17 -0700392
393namespace std {
394
395// TODO: isn't gtest supposed to be able to print STL types for itself?
396template <typename T>
397std::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) {
Elliott Hughes14134a12011-09-30 16:55:51 -0700398 os << ::art::ToString(rhs);
Elliott Hughes34023802011-08-30 12:06:17 -0700399 return os;
400}
401
402} // namespace std