blob: b62c40bb5c04bcef98bd98c6f84d8e6151a1386b [file] [log] [blame]
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "compiler.h"
4
Brian Carlstrom27ec9612011-09-19 20:20:38 -07005#include <sys/mman.h>
6
Brian Carlstrom2cc022b2011-08-25 10:05:39 -07007#include "assembler.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07008#include "class_linker.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -07009#include "class_loader.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070010#include "dex_cache.h"
Brian Carlstrom2cc022b2011-08-25 10:05:39 -070011#include "jni_compiler.h"
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -070012#include "jni_internal.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070013#include "oat_file.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070014#include "runtime.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070015#include "stl_util.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070016
Brian Carlstrom3320cf42011-10-04 14:58:28 -070017extern art::CompiledMethod* oatCompileMethod(const art::Compiler& compiler,
18 const art::Method*,
19 art::InstructionSet);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070020
21namespace art {
22
Shih-wei Liaoc486c112011-09-13 16:43:52 -070023namespace arm {
Ian Rogersbdb03912011-09-14 00:55:44 -070024 ByteArray* CreateAbstractMethodErrorStub();
Brian Carlstrom3320cf42011-10-04 14:58:28 -070025 CompiledInvokeStub* ArmCreateInvokeStub(const Method* method);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070026 ByteArray* ArmCreateResolutionTrampoline(Runtime::TrampolineType type);
Shih-wei Liaoc486c112011-09-13 16:43:52 -070027}
Shih-wei Liaoc486c112011-09-13 16:43:52 -070028namespace x86 {
Ian Rogersbdb03912011-09-14 00:55:44 -070029 ByteArray* CreateAbstractMethodErrorStub();
Brian Carlstrom3320cf42011-10-04 14:58:28 -070030 CompiledInvokeStub* X86CreateInvokeStub(const Method* method);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070031 ByteArray* X86CreateResolutionTrampoline(Runtime::TrampolineType type);
Brian Carlstrome24fa612011-09-29 00:53:55 -070032}
33
Brian Carlstromaded5f72011-10-07 17:15:04 -070034Compiler::Compiler(InstructionSet instruction_set, bool image)
35 : instruction_set_(instruction_set),
36 jni_compiler_(instruction_set),
37 image_(image),
38 verbose_(false) {
Brian Carlstrom25c33252011-09-18 15:58:35 -070039 CHECK(!Runtime::Current()->IsStarted());
Shih-wei Liaoc486c112011-09-13 16:43:52 -070040}
41
Brian Carlstrom3320cf42011-10-04 14:58:28 -070042Compiler::~Compiler() {
43 STLDeleteValues(&compiled_methods_);
44 STLDeleteValues(&compiled_invoke_stubs_);
45}
46
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070047ByteArray* Compiler::CreateResolutionStub(InstructionSet instruction_set,
48 Runtime::TrampolineType type) {
Ian Rogersad25ac52011-10-04 19:13:33 -070049 if (instruction_set == kX86) {
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070050 return x86::X86CreateResolutionTrampoline(type);
Ian Rogersad25ac52011-10-04 19:13:33 -070051 } else {
52 CHECK(instruction_set == kArm || instruction_set == kThumb2);
53 // Generates resolution stub using ARM instruction set
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070054 return arm::ArmCreateResolutionTrampoline(type);
Ian Rogersad25ac52011-10-04 19:13:33 -070055 }
56}
57
58ByteArray* Compiler::CreateAbstractMethodErrorStub(InstructionSet instruction_set) {
59 if (instruction_set == kX86) {
60 return x86::CreateAbstractMethodErrorStub();
61 } else {
62 CHECK(instruction_set == kArm || instruction_set == kThumb2);
63 // Generates resolution stub using ARM instruction set
64 return arm::CreateAbstractMethodErrorStub();
65 }
66}
67
Brian Carlstrom8a487412011-08-29 20:08:52 -070068void Compiler::CompileAll(const ClassLoader* class_loader) {
Brian Carlstrom25c33252011-09-18 15:58:35 -070069 DCHECK(!Runtime::Current()->IsStarted());
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070070 Resolve(class_loader);
jeffhao98eacac2011-09-14 16:11:53 -070071 Verify(class_loader);
Brian Carlstroma5a97a22011-09-15 14:08:49 -070072 InitializeClassesWithoutClinit(class_loader);
Brian Carlstrom83db7722011-08-26 17:32:56 -070073 Compile(class_loader);
Brian Carlstrom9cc262e2011-08-28 12:45:30 -070074 SetCodeAndDirectMethods(class_loader);
Brian Carlstrom8a487412011-08-29 20:08:52 -070075}
76
Brian Carlstrom3320cf42011-10-04 14:58:28 -070077void Compiler::CompileOne(const Method* method) {
Brian Carlstrom25c33252011-09-18 15:58:35 -070078 DCHECK(!Runtime::Current()->IsStarted());
Brian Carlstrom8a487412011-08-29 20:08:52 -070079 const ClassLoader* class_loader = method->GetDeclaringClass()->GetClassLoader();
80 Resolve(class_loader);
jeffhao98eacac2011-09-14 16:11:53 -070081 Verify(class_loader);
Brian Carlstroma5a97a22011-09-15 14:08:49 -070082 InitializeClassesWithoutClinit(class_loader);
Brian Carlstrom8a487412011-08-29 20:08:52 -070083 CompileMethod(method);
84 SetCodeAndDirectMethods(class_loader);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070085}
86
87void Compiler::Resolve(const ClassLoader* class_loader) {
Brian Carlstromaded5f72011-10-07 17:15:04 -070088 const std::vector<const DexFile*>& class_path
89 = ClassLoader::GetCompileTimeClassPath(class_loader);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070090 for (size_t i = 0; i != class_path.size(); ++i) {
91 const DexFile* dex_file = class_path[i];
92 CHECK(dex_file != NULL);
93 ResolveDexFile(class_loader, *dex_file);
94 }
95}
96
97void Compiler::ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
98 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Brian Carlstromaded5f72011-10-07 17:15:04 -070099 DexCache* dex_cache = class_linker->FindDexCache(dex_file);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700100
101 // Strings are easy, they always are simply resolved to literals in the same file
Brian Carlstromaded5f72011-10-07 17:15:04 -0700102 if (IsImage()) { // Only resolve when we'll have an image, so compiler won't choose fast path
103 for (size_t string_idx = 0; string_idx < dex_cache->NumStrings(); string_idx++) {
104 class_linker->ResolveString(dex_file, string_idx, dex_cache);
105 }
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700106 }
107
Brian Carlstrom845490b2011-09-19 15:56:53 -0700108 // Class derived values are more complicated, they require the linker and loader.
Brian Carlstromffca45d2011-09-16 12:10:49 -0700109 for (size_t type_idx = 0; type_idx < dex_cache->NumResolvedTypes(); type_idx++) {
110 Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader);
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700111 if (klass == NULL) {
112 Thread::Current()->ClearException();
113 }
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700114 }
Brian Carlstrom845490b2011-09-19 15:56:53 -0700115
116 // Method and Field are the worst. We can't resolve without either
117 // context from the code use (to disambiguate virtual vs direct
118 // method and instance vs static field) or from class
119 // definitions. While the compiler will resolve what it can as it
120 // needs it, here we try to resolve fields and methods used in class
121 // definitions, since many of them many never be referenced by
122 // generated code.
123 for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) {
124 const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
125
126 // Note the class_data pointer advances through the headers,
127 // static fields, instance fields, direct methods, and virtual
128 // methods.
129 const byte* class_data = dex_file.GetClassData(class_def);
130
131 DexFile::ClassDataHeader header = dex_file.ReadClassDataHeader(&class_data);
132 size_t num_static_fields = header.static_fields_size_;
133 size_t num_instance_fields = header.instance_fields_size_;
134 size_t num_direct_methods = header.direct_methods_size_;
135 size_t num_virtual_methods = header.virtual_methods_size_;
136
137 if (num_static_fields != 0) {
138 uint32_t last_idx = 0;
139 for (size_t i = 0; i < num_static_fields; ++i) {
140 DexFile::Field dex_field;
141 dex_file.dexReadClassDataField(&class_data, &dex_field, &last_idx);
Brian Carlstrom65ca0772011-09-24 16:03:08 -0700142 Field* field = class_linker->ResolveField(dex_file, dex_field.field_idx_, dex_cache,
143 class_loader, true);
144 if (field == NULL) {
145 Thread* self = Thread::Current();
146 CHECK(self->IsExceptionPending());
147 self->ClearException();
148 }
Brian Carlstrom845490b2011-09-19 15:56:53 -0700149 }
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700150 }
Brian Carlstrom845490b2011-09-19 15:56:53 -0700151 if (num_instance_fields != 0) {
152 uint32_t last_idx = 0;
153 for (size_t i = 0; i < num_instance_fields; ++i) {
154 DexFile::Field dex_field;
155 dex_file.dexReadClassDataField(&class_data, &dex_field, &last_idx);
Brian Carlstrom65ca0772011-09-24 16:03:08 -0700156 Field* field = class_linker->ResolveField(dex_file, dex_field.field_idx_, dex_cache,
157 class_loader, false);
158 if (field == NULL) {
159 Thread* self = Thread::Current();
160 CHECK(self->IsExceptionPending());
161 self->ClearException();
162 }
Brian Carlstrom845490b2011-09-19 15:56:53 -0700163 }
164 }
165 if (num_direct_methods != 0) {
166 uint32_t last_idx = 0;
167 for (size_t i = 0; i < num_direct_methods; ++i) {
168 DexFile::Method dex_method;
169 dex_file.dexReadClassDataMethod(&class_data, &dex_method, &last_idx);
Brian Carlstrom65ca0772011-09-24 16:03:08 -0700170 Method* method = class_linker->ResolveMethod(dex_file, dex_method.method_idx_, dex_cache,
171 class_loader, true);
172 if (method == NULL) {
173 Thread* self = Thread::Current();
174 CHECK(self->IsExceptionPending());
175 self->ClearException();
176 }
Brian Carlstrom845490b2011-09-19 15:56:53 -0700177 }
178 }
179 if (num_virtual_methods != 0) {
180 uint32_t last_idx = 0;
181 for (size_t i = 0; i < num_virtual_methods; ++i) {
182 DexFile::Method dex_method;
183 dex_file.dexReadClassDataMethod(&class_data, &dex_method, &last_idx);
Brian Carlstrom65ca0772011-09-24 16:03:08 -0700184 Method* method = class_linker->ResolveMethod(dex_file, dex_method.method_idx_, dex_cache,
185 class_loader, false);
186 if (method == NULL) {
187 Thread* self = Thread::Current();
188 CHECK(self->IsExceptionPending());
189 self->ClearException();
190 }
Brian Carlstrom845490b2011-09-19 15:56:53 -0700191 }
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700192 }
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700193 }
194}
195
jeffhao98eacac2011-09-14 16:11:53 -0700196void Compiler::Verify(const ClassLoader* class_loader) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700197 const std::vector<const DexFile*>& class_path
198 = ClassLoader::GetCompileTimeClassPath(class_loader);
jeffhao98eacac2011-09-14 16:11:53 -0700199 for (size_t i = 0; i != class_path.size(); ++i) {
200 const DexFile* dex_file = class_path[i];
201 CHECK(dex_file != NULL);
202 VerifyDexFile(class_loader, *dex_file);
203 }
204}
205
206void Compiler::VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
jeffhaob4df5142011-09-19 20:25:32 -0700207 dex_file.ChangePermissions(PROT_READ | PROT_WRITE);
jeffhao98eacac2011-09-14 16:11:53 -0700208 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Brian Carlstromffca45d2011-09-16 12:10:49 -0700209 for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) {
210 const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
jeffhao98eacac2011-09-14 16:11:53 -0700211 const char* descriptor = dex_file.GetClassDescriptor(class_def);
212 Class* klass = class_linker->FindClass(descriptor, class_loader);
Brian Carlstrom65ca0772011-09-24 16:03:08 -0700213 if (klass == NULL) {
214 Thread* self = Thread::Current();
215 CHECK(self->IsExceptionPending());
216 self->ClearException();
217 continue;
218 }
219 CHECK(klass->IsResolved()) << PrettyClass(klass);
jeffhao98eacac2011-09-14 16:11:53 -0700220 class_linker->VerifyClass(klass);
Elliott Hughesd9cdfe92011-10-06 16:09:04 -0700221
222 if (klass->IsErroneous()) {
223 // ClassLinker::VerifyClass throws, which isn't useful in the compiler.
224 CHECK(Thread::Current()->IsExceptionPending());
225 Thread::Current()->ClearException();
226 // We want to try verification again at run-time, so move back into the resolved state.
227 klass->SetStatus(Class::kStatusResolved);
228 }
229
jeffhao5cfd6fb2011-09-27 13:54:29 -0700230 CHECK(klass->IsVerified() || klass->IsResolved()) << PrettyClass(klass);
231 CHECK(!Thread::Current()->IsExceptionPending()) << PrettyTypeOf(Thread::Current()->GetException());
Brian Carlstroma5a97a22011-09-15 14:08:49 -0700232 }
jeffhaob4df5142011-09-19 20:25:32 -0700233 dex_file.ChangePermissions(PROT_READ);
Brian Carlstroma5a97a22011-09-15 14:08:49 -0700234}
235
236void Compiler::InitializeClassesWithoutClinit(const ClassLoader* class_loader) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700237 const std::vector<const DexFile*>& class_path
238 = ClassLoader::GetCompileTimeClassPath(class_loader);
Brian Carlstroma5a97a22011-09-15 14:08:49 -0700239 for (size_t i = 0; i != class_path.size(); ++i) {
240 const DexFile* dex_file = class_path[i];
241 CHECK(dex_file != NULL);
242 InitializeClassesWithoutClinit(class_loader, *dex_file);
243 }
244}
245
246void Compiler::InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file) {
247 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Brian Carlstromffca45d2011-09-16 12:10:49 -0700248 for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) {
249 const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
Brian Carlstroma5a97a22011-09-15 14:08:49 -0700250 const char* descriptor = dex_file.GetClassDescriptor(class_def);
251 Class* klass = class_linker->FindClass(descriptor, class_loader);
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700252 if (klass != NULL) {
253 class_linker->EnsureInitialized(klass, false);
254 }
255 // clear any class not found or verification exceptions
256 Thread::Current()->ClearException();
Brian Carlstromffca45d2011-09-16 12:10:49 -0700257 }
258
259 DexCache* dex_cache = class_linker->FindDexCache(dex_file);
260 for (size_t type_idx = 0; type_idx < dex_cache->NumResolvedTypes(); type_idx++) {
261 Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader);
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700262 if (klass == NULL) {
263 Thread::Current()->ClearException();
264 } else if (klass->IsInitialized()) {
Brian Carlstromffca45d2011-09-16 12:10:49 -0700265 dex_cache->GetInitializedStaticStorage()->Set(type_idx, klass);
266 }
jeffhao98eacac2011-09-14 16:11:53 -0700267 }
268}
269
Brian Carlstrom83db7722011-08-26 17:32:56 -0700270void Compiler::Compile(const ClassLoader* class_loader) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700271 const std::vector<const DexFile*>& class_path
272 = ClassLoader::GetCompileTimeClassPath(class_loader);
Brian Carlstrom83db7722011-08-26 17:32:56 -0700273 for (size_t i = 0; i != class_path.size(); ++i) {
274 const DexFile* dex_file = class_path[i];
275 CHECK(dex_file != NULL);
276 CompileDexFile(class_loader, *dex_file);
277 }
278}
279
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700280void Compiler::CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file) {
281 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Brian Carlstromffca45d2011-09-16 12:10:49 -0700282 for (size_t class_def_index = 0; class_def_index < dex_file.NumClassDefs(); class_def_index++) {
283 const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700284 const char* descriptor = dex_file.GetClassDescriptor(class_def);
285 Class* klass = class_linker->FindClass(descriptor, class_loader);
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700286 if (klass == NULL) {
287 // previous verification error will cause FindClass to throw
288 Thread* self = Thread::Current();
Brian Carlstrom65ca0772011-09-24 16:03:08 -0700289 CHECK(self->IsExceptionPending());
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700290 self->ClearException();
291 } else {
292 CompileClass(klass);
293 }
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700294 }
295}
296
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700297void Compiler::CompileClass(const Class* klass) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700298 for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
299 CompileMethod(klass->GetDirectMethod(i));
300 }
301 for (size_t i = 0; i < klass->NumVirtualMethods(); i++) {
302 CompileMethod(klass->GetVirtualMethod(i));
303 }
304}
305
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700306void Compiler::CompileMethod(const Method* method) {
Brian Carlstrom2cc022b2011-08-25 10:05:39 -0700307 if (method->IsNative()) {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700308 CompiledMethod* compiled_method = jni_compiler_.Compile(method);
309 CHECK(compiled_method != NULL);
310 compiled_methods_[method] = compiled_method;
311 DCHECK_EQ(1U, compiled_methods_.count(method));
312 DCHECK(GetCompiledMethod(method) != NULL) << PrettyMethod(method);
Brian Carlstrom2cc022b2011-08-25 10:05:39 -0700313 } else if (method->IsAbstract()) {
Brian Carlstrom2cc022b2011-08-25 10:05:39 -0700314 } else {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700315 CompiledMethod* compiled_method = oatCompileMethod(*this, method, kThumb2);
316 CHECK(compiled_method != NULL);
317 compiled_methods_[method] = compiled_method;
318 DCHECK_EQ(1U, compiled_methods_.count(method));
319 DCHECK(GetCompiledMethod(method) != NULL) << PrettyMethod(method);
Brian Carlstrom2cc022b2011-08-25 10:05:39 -0700320 }
Brian Carlstrom9baa4ae2011-09-01 21:14:14 -0700321
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700322 CompiledInvokeStub* compiled_invoke_stub = NULL;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700323 if (instruction_set_ == kX86) {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700324 compiled_invoke_stub = art::x86::X86CreateInvokeStub(method);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700325 } else {
326 CHECK(instruction_set_ == kArm || instruction_set_ == kThumb2);
327 // Generates invocation stub using ARM instruction set
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700328 compiled_invoke_stub = art::arm::ArmCreateInvokeStub(method);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700329 }
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700330 CHECK(compiled_invoke_stub != NULL);
331 compiled_invoke_stubs_[method] = compiled_invoke_stub;
332}
333
334const CompiledMethod* Compiler::GetCompiledMethod(const Method* method) const {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700335 MethodTable::const_iterator it = compiled_methods_.find(method);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700336 if (it == compiled_methods_.end()) {
337 return NULL;
338 }
339 CHECK(it->second != NULL);
340 return it->second;
341}
342
343const CompiledInvokeStub* Compiler::GetCompiledInvokeStub(const Method* method) const {
344 InvokeStubTable::const_iterator it = compiled_invoke_stubs_.find(method);
345 if (it == compiled_invoke_stubs_.end()) {
346 return NULL;
347 }
348 CHECK(it->second != NULL);
349 return it->second;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700350}
351
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700352void Compiler::SetCodeAndDirectMethods(const ClassLoader* class_loader) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700353 const std::vector<const DexFile*>& class_path
354 = ClassLoader::GetCompileTimeClassPath(class_loader);
Brian Carlstrom83db7722011-08-26 17:32:56 -0700355 for (size_t i = 0; i != class_path.size(); ++i) {
356 const DexFile* dex_file = class_path[i];
357 CHECK(dex_file != NULL);
Brian Carlstrom8a487412011-08-29 20:08:52 -0700358 SetCodeAndDirectMethodsDexFile(*dex_file);
Brian Carlstrom83db7722011-08-26 17:32:56 -0700359 }
360}
361
Brian Carlstrom8a487412011-08-29 20:08:52 -0700362void Compiler::SetCodeAndDirectMethodsDexFile(const DexFile& dex_file) {
Ian Rogersad25ac52011-10-04 19:13:33 -0700363 Runtime* runtime = Runtime::Current();
364 ClassLinker* class_linker = runtime->GetClassLinker();
Brian Carlstrom83db7722011-08-26 17:32:56 -0700365 DexCache* dex_cache = class_linker->FindDexCache(dex_file);
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700366 CodeAndDirectMethods* code_and_direct_methods = dex_cache->GetCodeAndDirectMethods();
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700367 for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) {
Brian Carlstrom83db7722011-08-26 17:32:56 -0700368 Method* method = dex_cache->GetResolvedMethod(i);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700369 if (method == NULL || method->IsDirect()) {
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700370 Runtime::TrampolineType type = Runtime::GetTrampolineType(method);
371 ByteArray* res_trampoline = runtime->GetResolutionStubArray(type);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700372 code_and_direct_methods->SetResolvedDirectMethodTrampoline(i, res_trampoline);
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700373 } else {
374 // TODO: we currently leave the entry blank for resolved
375 // non-direct methods. we could put in an error stub.
Brian Carlstrom83db7722011-08-26 17:32:56 -0700376 }
377 }
378}
379
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700380} // namespace art