blob: c89527cbdb632cab9460a8d0882d195f3bc0a181 [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);
Shih-wei Liao24782c62012-01-08 12:46:11 -0800176
Ian Rogers16341552011-10-10 11:33:06 -0700177 // Flush instruction cache
Shih-wei Liao24782c62012-01-08 12:46:11 -0800178 // Only uses __builtin___clear_cache if GCC >= 4.3.3
179#if GCC_VERSION >= 40303
Ian Rogers16341552011-10-10 11:33:06 -0700180 __builtin___clear_cache(reinterpret_cast<void*>(base), reinterpret_cast<void*>(base + len));
Shih-wei Liao24782c62012-01-08 12:46:11 -0800181#else
182 // Currently, only Mac OS builds use GCC 4.2.*. Those host builds do not
183 // need to generate clear_cache on x86.
184#endif
185
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700186 CHECK_EQ(result, 0);
187 }
188
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700189 protected:
190 virtual void SetUp() {
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700191 is_host_ = getenv("ANDROID_BUILD_TOP") != NULL;
192
Elliott Hughes0af55432011-08-17 18:37:28 -0700193 if (is_host_) {
194 // $ANDROID_ROOT is set on the device, but not on the host.
195 // We need to set this so that icu4c can find its locale data.
196 std::string root;
197 root += getenv("ANDROID_BUILD_TOP");
198 root += "/out/host/linux-x86";
199 setenv("ANDROID_ROOT", root.c_str(), 1);
200 }
201
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700202 // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of art-cache
203 android_data_ = (is_host_ ? "/tmp/art-data-XXXXXX" : "/data/art-cache/art-data-XXXXXX");
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700204 if (mkdtemp(&android_data_[0]) == NULL) {
205 PLOG(FATAL) << "mkdtemp(\"" << &android_data_[0] << "\") failed";
206 }
Elliott Hughes34023802011-08-30 12:06:17 -0700207 setenv("ANDROID_DATA", android_data_.c_str(), 1);
208 art_cache_.append(android_data_.c_str());
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700209 art_cache_.append("/art-cache");
210 int mkdir_result = mkdir(art_cache_.c_str(), 0700);
211 ASSERT_EQ(mkdir_result, 0);
212
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700213 java_lang_dex_file_.reset(GetLibCoreDex());
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700214
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700215 std::string boot_class_path;
216 boot_class_path += "-Xbootclasspath:";
217 boot_class_path += GetLibCoreDexFileName();
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700218
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700219 Runtime::Options options;
Brian Carlstroma4a7b482011-10-16 15:29:16 -0700220 options.push_back(std::make_pair("compiler", reinterpret_cast<void*>(NULL)));
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700221 options.push_back(std::make_pair(boot_class_path.c_str(), reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700222 options.push_back(std::make_pair("-Xcheck:jni", reinterpret_cast<void*>(NULL)));
Brian Carlstrome24fa612011-09-29 00:53:55 -0700223 options.push_back(std::make_pair("-Xms64m", reinterpret_cast<void*>(NULL)));
224 options.push_back(std::make_pair("-Xmx64m", reinterpret_cast<void*>(NULL)));
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700225 runtime_.reset(Runtime::Create(options, false));
Elliott Hughes90a33692011-08-30 13:27:07 -0700226 ASSERT_TRUE(runtime_.get() != NULL);
Carl Shapiro7a909592011-07-24 19:21:59 -0700227 class_linker_ = runtime_->GetClassLinker();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700228
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700229 InstructionSet instruction_set = kNone;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700230#if defined(__i386__)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700231 instruction_set = kX86;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700232#elif defined(__arm__)
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700233 instruction_set = kThumb2;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700234#endif
Ian Rogers169c9a72011-11-13 20:13:17 -0800235 runtime_->SetJniDlsymLookupStub(Compiler::CreateJniDlysmLookupStub(instruction_set));
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700236 runtime_->SetAbstractMethodErrorStubArray(Compiler::CreateAbstractMethodErrorStub(instruction_set));
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700237 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700238 Runtime::TrampolineType type = Runtime::TrampolineType(i);
239 if (!runtime_->HasResolutionStubArray(type)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700240 runtime_->SetResolutionStubArray(
241 Compiler::CreateResolutionStub(instruction_set, type), type);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700242 }
243 }
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700244 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700245 Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i);
246 if (!runtime_->HasCalleeSaveMethod(type)) {
247 runtime_->SetCalleeSaveMethod(
248 runtime_->CreateCalleeSaveMethod(instruction_set, type), type);
249 }
250 }
Brian Carlstromae826982011-11-09 01:33:42 -0800251 compiler_.reset(new Compiler(instruction_set, false, NULL));
Ian Rogers2c8f6532011-09-02 17:16:34 -0700252
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700253 Heap::VerifyHeap(); // Check for heap corruption before the test
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700254 }
255
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700256 virtual void TearDown() {
257 const char* android_data = getenv("ANDROID_DATA");
258 ASSERT_TRUE(android_data != NULL);
259 DIR* dir = opendir(art_cache_.c_str());
260 ASSERT_TRUE(dir != NULL);
261 while (true) {
262 struct dirent entry;
263 struct dirent* entry_ptr;
264 int readdir_result = readdir_r(dir, &entry, &entry_ptr);
265 ASSERT_EQ(0, readdir_result);
266 if (entry_ptr == NULL) {
267 break;
268 }
269 if ((strcmp(entry_ptr->d_name, ".") == 0) || (strcmp(entry_ptr->d_name, "..") == 0)) {
270 continue;
271 }
272 std::string filename(art_cache_);
273 filename.push_back('/');
274 filename.append(entry_ptr->d_name);
275 int unlink_result = unlink(filename.c_str());
276 ASSERT_EQ(0, unlink_result);
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400277 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700278 closedir(dir);
279 int rmdir_cache_result = rmdir(art_cache_.c_str());
280 ASSERT_EQ(0, rmdir_cache_result);
Elliott Hughes34023802011-08-30 12:06:17 -0700281 int rmdir_data_result = rmdir(android_data_.c_str());
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700282 ASSERT_EQ(0, rmdir_data_result);
Elliott Hughes0af55432011-08-17 18:37:28 -0700283
284 // icu4c has a fixed 10-element array "gCommonICUDataArray".
285 // If we run > 10 tests, we fill that array and u_setCommonData fails.
286 // There's a function to clear the array, but it's not public...
287 typedef void (*IcuCleanupFn)();
288 void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT);
289 CHECK(sym != NULL);
290 IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym);
291 (*icu_cleanup_fn)();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700292
Ian Rogers0e073f72011-09-09 10:45:46 -0700293 compiler_.reset();
Ian Rogers2c8f6532011-09-02 17:16:34 -0700294
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700295 Heap::VerifyHeap(); // Check for heap corruption after the test
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700296 }
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400297
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700298 std::string GetLibCoreDexFileName() {
299 if (is_host_) {
300 const char* host_dir = getenv("ANDROID_HOST_OUT");
301 CHECK(host_dir != NULL);
302 return StringPrintf("%s/framework/core-hostdex.jar", host_dir);
303 }
304 return std::string("/system/framework/core.jar");
305 }
306
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700307 const DexFile* GetLibCoreDex() {
Elliott Hughes95572412011-12-13 18:14:20 -0800308 std::string libcore_dex_file_name(GetLibCoreDexFileName());
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700309 return DexFile::Open(libcore_dex_file_name, "");
Jesse Wilsonac5b9e22011-07-27 15:11:13 -0400310 }
311
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700312 const DexFile* OpenTestDexFile(const char* name) {
313 CHECK(name != NULL);
314 std::string filename;
315 if (is_host_) {
316 // on the host, just read target dex file
317 filename += getenv("ANDROID_PRODUCT_OUT");
318 }
Brian Carlstrom47a0d5a2011-10-12 21:20:05 -0700319 filename += "/data/art-test/art-test-dex-";
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700320 filename += name;
321 filename += ".jar";
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700322 const DexFile* dex_file = DexFile::Open(filename, "");
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700323 CHECK(dex_file != NULL) << "Failed to open " << filename;
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700324 return dex_file;
325 }
326
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700327 ClassLoader* LoadDex(const char* dex_name) {
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700328 const DexFile* dex_file = OpenTestDexFile(dex_name);
329 CHECK(dex_file != NULL);
330 loaded_dex_files_.push_back(dex_file);
331 class_linker_->RegisterDexFile(*dex_file);
332 std::vector<const DexFile*> class_path;
333 class_path.push_back(dex_file);
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700334 SirtRef<ClassLoader> class_loader(PathClassLoader::AllocCompileTime(class_path));
335 CHECK(class_loader.get() != NULL);
336 Thread::Current()->SetClassLoaderOverride(class_loader.get());
337 return class_loader.get();
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700338 }
339
Brian Carlstromaded5f72011-10-07 17:15:04 -0700340 void CompileClass(const ClassLoader* class_loader, const char* class_name) {
Elliott Hughes95572412011-12-13 18:14:20 -0800341 std::string class_descriptor(DotToDescriptor(class_name));
Elliott Hughesc3b77c72011-12-15 20:56:48 -0800342 Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700343 CHECK(klass != NULL) << "Class not found " << class_name;
344 for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
345 CompileMethod(klass->GetDirectMethod(i));
346 }
347 for (size_t i = 0; i < klass->NumVirtualMethods(); i++) {
348 CompileMethod(klass->GetVirtualMethod(i));
349 }
350 }
351
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700352 void CompileMethod(Method* method) {
353 CHECK(method != NULL);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700354 compiler_->CompileOne(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700355 MakeExecutable(method);
356
Ian Rogers169c9a72011-11-13 20:13:17 -0800357 MakeExecutable(runtime_->GetJniDlsymLookupStub());
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700358 }
359
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700360 void CompileDirectMethod(ClassLoader* class_loader,
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700361 const char* class_name,
362 const char* method_name,
363 const char* signature) {
Elliott Hughes95572412011-12-13 18:14:20 -0800364 std::string class_descriptor(DotToDescriptor(class_name));
Elliott Hughesc3b77c72011-12-15 20:56:48 -0800365 Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700366 CHECK(klass != NULL) << "Class not found " << class_name;
367 Method* method = klass->FindDirectMethod(method_name, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700368 CHECK(method != NULL) << "Direct method not found: "
369 << class_name << "." << method_name << signature;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700370 CompileMethod(method);
371 }
372
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700373 void CompileVirtualMethod(ClassLoader* class_loader,
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700374 const char* class_name,
375 const char* method_name,
376 const char* signature) {
Elliott Hughes95572412011-12-13 18:14:20 -0800377 std::string class_descriptor(DotToDescriptor(class_name));
Elliott Hughesc3b77c72011-12-15 20:56:48 -0800378 Class* klass = class_linker_->FindClass(class_descriptor.c_str(), class_loader);
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700379 CHECK(klass != NULL) << "Class not found " << class_name;
380 Method* method = klass->FindVirtualMethod(method_name, signature);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700381 CHECK(method != NULL) << "Virtual method not found: "
382 << class_name << "." << method_name << signature;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700383 CompileMethod(method);
384 }
385
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700386 bool is_host_;
Elliott Hughes34023802011-08-30 12:06:17 -0700387 std::string android_data_;
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700388 std::string art_cache_;
Elliott Hughes90a33692011-08-30 13:27:07 -0700389 UniquePtr<const DexFile> java_lang_dex_file_;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700390 std::vector<const DexFile*> boot_class_path_;
Elliott Hughes90a33692011-08-30 13:27:07 -0700391 UniquePtr<Runtime> runtime_;
Ian Rogers0e073f72011-09-09 10:45:46 -0700392 // Owned by the runtime
Carl Shapiro7a909592011-07-24 19:21:59 -0700393 ClassLinker* class_linker_;
Ian Rogers0e073f72011-09-09 10:45:46 -0700394 UniquePtr<Compiler> compiler_;
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700395
396 private:
397 std::vector<const DexFile*> loaded_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700398};
399
Brian Carlstrom934486c2011-07-12 23:42:50 -0700400} // namespace art
Elliott Hughes34023802011-08-30 12:06:17 -0700401
402namespace std {
403
404// TODO: isn't gtest supposed to be able to print STL types for itself?
405template <typename T>
406std::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) {
Elliott Hughes14134a12011-09-30 16:55:51 -0700407 os << ::art::ToString(rhs);
Elliott Hughes34023802011-08-30 12:06:17 -0700408 return os;
409}
410
411} // namespace std