blob: f6158f3b9e5ad2b7ca0988c89f342bb6f65834bc [file] [log] [blame]
Ian Rogers6d4d9fc2011-11-30 16:24:48 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_OBJECT_UTILS_H_
18#define ART_SRC_OBJECT_UTILS_H_
19
20#include "class_linker.h"
21#include "dex_cache.h"
22#include "dex_file.h"
Ian Rogersc2b44472011-12-14 21:17:17 -080023#include "intern_table.h"
Ian Rogers672f5202012-01-12 18:06:40 -080024#include "monitor.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080025#include "object.h"
26#include "runtime.h"
Elliott Hughes91250e02011-12-13 22:30:35 -080027#include "UniquePtr.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080028
29#include <string>
30
31namespace art {
32
Ian Rogers672f5202012-01-12 18:06:40 -080033class ObjectLock {
34 public:
Ian Rogersb726dcb2012-09-05 08:57:23 -070035 explicit ObjectLock(Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers00f7d0e2012-07-19 15:28:27 -070036 : self_(Thread::Current()), obj_(object) {
Ian Rogers672f5202012-01-12 18:06:40 -080037 CHECK(object != NULL);
38 obj_->MonitorEnter(self_);
39 }
40
Ian Rogersb726dcb2012-09-05 08:57:23 -070041 ~ObjectLock() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers672f5202012-01-12 18:06:40 -080042 obj_->MonitorExit(self_);
43 }
44
Ian Rogersb726dcb2012-09-05 08:57:23 -070045 void Wait() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers672f5202012-01-12 18:06:40 -080046 return Monitor::Wait(self_, obj_, 0, 0, false);
47 }
48
Ian Rogersb726dcb2012-09-05 08:57:23 -070049 void Notify() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers672f5202012-01-12 18:06:40 -080050 obj_->Notify();
51 }
52
Ian Rogersb726dcb2012-09-05 08:57:23 -070053 void NotifyAll() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers672f5202012-01-12 18:06:40 -080054 obj_->NotifyAll();
55 }
56
57 private:
Ian Rogers00f7d0e2012-07-19 15:28:27 -070058 Thread* const self_;
Ian Rogers672f5202012-01-12 18:06:40 -080059 Object* obj_;
60 DISALLOW_COPY_AND_ASSIGN(ObjectLock);
61};
62
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080063class ClassHelper {
64 public:
Elliott Hughes91250e02011-12-13 22:30:35 -080065 ClassHelper(const Class* c = NULL, ClassLinker* l = NULL)
Ian Rogersb726dcb2012-09-05 08:57:23 -070066 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Elliott Hughes91250e02011-12-13 22:30:35 -080067 : class_def_(NULL),
68 class_linker_(l),
69 dex_cache_(NULL),
70 dex_file_(NULL),
71 interface_type_list_(NULL),
Brian Carlstrome77be402012-03-30 01:08:38 -070072 klass_(NULL) {
73 if (c != NULL) {
74 ChangeClass(c);
75 }
Elliott Hughes91250e02011-12-13 22:30:35 -080076 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080077
Ian Rogers00f7d0e2012-07-19 15:28:27 -070078 void ChangeClass(const Class* new_c)
Ian Rogersb726dcb2012-09-05 08:57:23 -070079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom01e076e2012-03-30 11:54:16 -070080 CHECK(new_c != NULL) << "klass_=" << klass_; // Log what we were changing from if any
81 CHECK(new_c->IsClass()) << "new_c=" << new_c;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080082 if (dex_cache_ != NULL) {
83 DexCache* new_c_dex_cache = new_c->GetDexCache();
84 if (new_c_dex_cache != dex_cache_) {
85 dex_cache_ = new_c_dex_cache;
86 dex_file_ = NULL;
87 }
88 }
89 klass_ = new_c;
90 interface_type_list_ = NULL;
91 class_def_ = NULL;
92 }
93
Elliott Hughes91250e02011-12-13 22:30:35 -080094 // The returned const char* is only guaranteed to be valid for the lifetime of the ClassHelper.
95 // If you need it longer, copy it into a std::string.
Ian Rogersb726dcb2012-09-05 08:57:23 -070096 const char* GetDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom93235f72012-03-29 22:48:15 -070097 CHECK(klass_ != NULL);
Ian Rogersa68a1cb2012-01-10 10:34:36 -080098 if (UNLIKELY(klass_->IsArrayClass())) {
99 return GetArrayDescriptor();
100 } else if (UNLIKELY(klass_->IsPrimitive())) {
Elliott Hughes91250e02011-12-13 22:30:35 -0800101 return Primitive::Descriptor(klass_->GetPrimitiveType());
Ian Rogersa68a1cb2012-01-10 10:34:36 -0800102 } else if (UNLIKELY(klass_->IsProxyClass())) {
Elliott Hughes91250e02011-12-13 22:30:35 -0800103 descriptor_ = GetClassLinker()->GetDescriptorForProxy(klass_);
104 return descriptor_.c_str();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800105 } else {
106 const DexFile& dex_file = GetDexFile();
107 const DexFile::TypeId& type_id = dex_file.GetTypeId(klass_->GetDexTypeIndex());
108 return dex_file.GetTypeDescriptor(type_id);
109 }
110 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800111
Ian Rogersb726dcb2012-09-05 08:57:23 -0700112 const char* GetArrayDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersa68a1cb2012-01-10 10:34:36 -0800113 std::string result("[");
114 const Class* saved_klass = klass_;
Brian Carlstrom93235f72012-03-29 22:48:15 -0700115 CHECK(saved_klass != NULL);
Ian Rogersa68a1cb2012-01-10 10:34:36 -0800116 ChangeClass(klass_->GetComponentType());
117 result += GetDescriptor();
118 ChangeClass(saved_klass);
119 descriptor_ = result;
120 return descriptor_.c_str();
121 }
122
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700123 const DexFile::ClassDef* GetClassDef()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700124 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800125 const DexFile::ClassDef* result = class_def_;
126 if (result == NULL) {
127 result = GetDexFile().FindClassDef(GetDescriptor());
128 class_def_ = result;
129 }
130 return result;
131 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800132
Ian Rogersb726dcb2012-09-05 08:57:23 -0700133 uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom93235f72012-03-29 22:48:15 -0700134 DCHECK(klass_ != NULL);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800135 if (klass_->IsPrimitive()) {
136 return 0;
137 } else if (klass_->IsArrayClass()) {
138 return 2;
Ian Rogersc2b44472011-12-14 21:17:17 -0800139 } else if (klass_->IsProxyClass()) {
140 return klass_->GetIfTable()->GetLength();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800141 } else {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800142 const DexFile::TypeList* interfaces = GetInterfaceTypeList();
143 if (interfaces == NULL) {
144 return 0;
145 } else {
146 return interfaces->Size();
147 }
148 }
149 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800150
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700151 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700152 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom93235f72012-03-29 22:48:15 -0700153 DCHECK(klass_ != NULL);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800154 DCHECK(!klass_->IsPrimitive());
155 DCHECK(!klass_->IsArrayClass());
156 return GetInterfaceTypeList()->GetTypeItem(idx).type_idx_;
157 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800158
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700159 Class* GetDirectInterface(uint32_t idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700160 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom93235f72012-03-29 22:48:15 -0700161 DCHECK(klass_ != NULL);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800162 DCHECK(!klass_->IsPrimitive());
163 if (klass_->IsArrayClass()) {
164 if (idx == 0) {
165 return GetClassLinker()->FindSystemClass("Ljava/lang/Cloneable;");
166 } else {
167 DCHECK_EQ(1U, idx);
168 return GetClassLinker()->FindSystemClass("Ljava/io/Serializable;");
169 }
Ian Rogersc2b44472011-12-14 21:17:17 -0800170 } else if (klass_->IsProxyClass()) {
171 return klass_->GetIfTable()->Get(idx)->GetInterface();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800172 } else {
Ian Rogersd24e2642012-06-06 21:21:43 -0700173 uint16_t type_idx = GetDirectInterfaceTypeIdx(idx);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800174 Class* interface = GetDexCache()->GetResolvedType(type_idx);
175 if (interface == NULL) {
176 interface = GetClassLinker()->ResolveType(GetDexFile(), type_idx, klass_);
177 CHECK(interface != NULL || Thread::Current()->IsExceptionPending());
178 }
179 return interface;
180 }
181 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800182
Ian Rogersb726dcb2012-09-05 08:57:23 -0700183 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughes95572412011-12-13 18:14:20 -0800184 std::string descriptor(GetDescriptor());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800185 const DexFile& dex_file = GetDexFile();
186 const DexFile::ClassDef* dex_class_def = dex_file.FindClassDef(descriptor);
Elliott Hughes12c51e32012-01-17 20:25:05 -0800187 CHECK(dex_class_def != NULL);
188 return dex_file.GetSourceFile(*dex_class_def);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800189 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800190
Ian Rogersb726dcb2012-09-05 08:57:23 -0700191 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700192 DexCache* dex_cache = GetDexCache();
193 if (dex_cache != NULL && !klass_->IsProxyClass()) {
194 return dex_cache->GetLocation()->ToModifiedUtf8();
195 } else {
196 // Arrays and proxies are generated and have no corresponding dex file location.
197 return "generated class";
198 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800199 }
200
Ian Rogersb726dcb2012-09-05 08:57:23 -0700201 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800202 const DexFile* result = dex_file_;
203 if (result == NULL) {
204 const DexCache* dex_cache = GetDexCache();
205 result = &GetClassLinker()->FindDexFile(dex_cache);
206 dex_file_ = result;
207 }
208 return *result;
209 }
210
Ian Rogersb726dcb2012-09-05 08:57:23 -0700211 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700212 DexCache* result = dex_cache_;
213 if (result == NULL) {
214 DCHECK(klass_ != NULL);
215 result = klass_->GetDexCache();
216 dex_cache_ = result;
217 }
218 return result;
219 }
220
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800221 private:
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700222 const DexFile::TypeList* GetInterfaceTypeList()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800224 const DexFile::TypeList* result = interface_type_list_;
225 if (result == NULL) {
226 const DexFile::ClassDef* class_def = GetClassDef();
227 if (class_def != NULL) {
228 result = GetDexFile().GetInterfacesList(*class_def);
229 interface_type_list_ = result;
230 }
231 }
232 return result;
233 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800234
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800235 ClassLinker* GetClassLinker() {
236 ClassLinker* result = class_linker_;
237 if (result == NULL) {
238 result = Runtime::Current()->GetClassLinker();
239 class_linker_ = result;
240 }
241 return result;
242 }
243
244 const DexFile::ClassDef* class_def_;
245 ClassLinker* class_linker_;
246 DexCache* dex_cache_;
247 const DexFile* dex_file_;
248 const DexFile::TypeList* interface_type_list_;
249 const Class* klass_;
Elliott Hughes91250e02011-12-13 22:30:35 -0800250 std::string descriptor_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800251
252 DISALLOW_COPY_AND_ASSIGN(ClassHelper);
253};
254
255class FieldHelper {
256 public:
257 FieldHelper() : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), field_(NULL) {}
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800258 explicit FieldHelper(const Field* f) : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), field_(f) {}
Ian Rogersca190662012-06-26 15:45:57 -0700259 FieldHelper(const Field* f, ClassLinker* l)
260 : class_linker_(l), dex_cache_(NULL), dex_file_(NULL), field_(f) {}
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800261
262 void ChangeField(const Field* new_f) {
263 DCHECK(new_f != NULL);
264 if (dex_cache_ != NULL) {
265 DexCache* new_f_dex_cache = new_f->GetDeclaringClass()->GetDexCache();
266 if (new_f_dex_cache != dex_cache_) {
267 dex_cache_ = new_f_dex_cache;
268 dex_file_ = NULL;
269 }
270 }
271 field_ = new_f;
272 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700273 const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800274 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700275 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800276 const DexFile& dex_file = GetDexFile();
277 return dex_file.GetFieldName(dex_file.GetFieldId(field_index));
278 } else {
Ian Rogersc2b44472011-12-14 21:17:17 -0800279 DCHECK(field_->IsStatic());
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700280 DCHECK_LT(field_index, 2U);
281 return field_index == 0 ? "interfaces" : "throws";
Ian Rogersc2b44472011-12-14 21:17:17 -0800282 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800283 }
284 String* GetNameAsString() {
Ian Rogersc2b44472011-12-14 21:17:17 -0800285 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700286 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800287 const DexFile& dex_file = GetDexFile();
288 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
289 return GetClassLinker()->ResolveString(dex_file, field_id.name_idx_, GetDexCache());
290 } else {
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700291 return Runtime::Current()->GetInternTable()->InternStrong(GetName());
Ian Rogersc2b44472011-12-14 21:17:17 -0800292 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800293 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700294 Class* GetType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800295 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700296 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800297 const DexFile& dex_file = GetDexFile();
298 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
299 Class* type = GetDexCache()->GetResolvedType(field_id.type_idx_);
300 if (type == NULL) {
301 type = GetClassLinker()->ResolveType(field_id.type_idx_, field_);
302 CHECK(type != NULL || Thread::Current()->IsExceptionPending());
303 }
304 return type;
305 } else {
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700306 return GetClassLinker()->FindSystemClass(GetTypeDescriptor());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800307 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800308 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700309 const char* GetTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800310 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700311 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800312 const DexFile& dex_file = GetDexFile();
313 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
314 return dex_file.GetFieldTypeDescriptor(field_id);
315 } else {
Ian Rogersc2b44472011-12-14 21:17:17 -0800316 DCHECK(field_->IsStatic());
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700317 DCHECK_LT(field_index, 2U);
318 // 0 == Class[] interfaces; 1 == Class[][] throws;
319 return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;";
Ian Rogersc2b44472011-12-14 21:17:17 -0800320 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800321 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700322 Primitive::Type GetTypeAsPrimitiveType()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800324 return Primitive::GetType(GetTypeDescriptor()[0]);
325 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700326 bool IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800327 Primitive::Type type = GetTypeAsPrimitiveType();
328 return type != Primitive::kPrimNot;
329 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700330 size_t FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800331 Primitive::Type type = GetTypeAsPrimitiveType();
332 return Primitive::FieldSize(type);
333 }
Ian Rogersc2b44472011-12-14 21:17:17 -0800334
335 // The returned const char* is only guaranteed to be valid for the lifetime of the FieldHelper.
336 // If you need it longer, copy it into a std::string.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700337 const char* GetDeclaringClassDescriptor()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800339 uint16_t type_idx = field_->GetDeclaringClass()->GetDexTypeIndex();
Ian Rogersc2b44472011-12-14 21:17:17 -0800340 if (type_idx != DexFile::kDexNoIndex16) {
341 const DexFile& dex_file = GetDexFile();
342 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx));
343 } else {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700344 // Most likely a proxy class.
Ian Rogersc2b44472011-12-14 21:17:17 -0800345 ClassHelper kh(field_->GetDeclaringClass());
346 declaring_class_descriptor_ = kh.GetDescriptor();
347 return declaring_class_descriptor_.c_str();
348 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800349 }
350
351 private:
Ian Rogersb726dcb2012-09-05 08:57:23 -0700352 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800353 DexCache* result = dex_cache_;
354 if (result == NULL) {
355 result = field_->GetDeclaringClass()->GetDexCache();
356 dex_cache_ = result;
357 }
358 return result;
359 }
360 ClassLinker* GetClassLinker() {
361 ClassLinker* result = class_linker_;
362 if (result == NULL) {
363 result = Runtime::Current()->GetClassLinker();
364 class_linker_ = result;
365 }
366 return result;
367 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700368 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800369 const DexFile* result = dex_file_;
370 if (result == NULL) {
371 const DexCache* dex_cache = GetDexCache();
372 result = &GetClassLinker()->FindDexFile(dex_cache);
373 dex_file_ = result;
374 }
375 return *result;
376 }
377
378 ClassLinker* class_linker_;
379 DexCache* dex_cache_;
380 const DexFile* dex_file_;
381 const Field* field_;
Ian Rogersc2b44472011-12-14 21:17:17 -0800382 std::string declaring_class_descriptor_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800383
384 DISALLOW_COPY_AND_ASSIGN(FieldHelper);
385};
386
387class MethodHelper {
388 public:
Ian Rogersca190662012-06-26 15:45:57 -0700389 MethodHelper()
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700390 : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL),
391 shorty_len_(0) {}
Ian Rogersca190662012-06-26 15:45:57 -0700392
393 explicit MethodHelper(const Method* m)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogersca190662012-06-26 15:45:57 -0700395 : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL),
396 shorty_len_(0) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800397 SetMethod(m);
398 }
Ian Rogersca190662012-06-26 15:45:57 -0700399
400 MethodHelper(const Method* m, ClassLinker* l)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogersca190662012-06-26 15:45:57 -0700402 : class_linker_(l), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL),
403 shorty_len_(0) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800404 SetMethod(m);
405 }
406
Ian Rogersb726dcb2012-09-05 08:57:23 -0700407 void ChangeMethod(Method* new_m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800408 DCHECK(new_m != NULL);
409 if (dex_cache_ != NULL) {
410 Class* klass = new_m->GetDeclaringClass();
411 if (klass->IsProxyClass()) {
412 dex_cache_ = NULL;
413 dex_file_ = NULL;
414 } else {
415 DexCache* new_m_dex_cache = klass->GetDexCache();
416 if (new_m_dex_cache != dex_cache_) {
417 dex_cache_ = new_m_dex_cache;
418 dex_file_ = NULL;
419 }
420 }
421 }
422 SetMethod(new_m);
423 shorty_ = NULL;
424 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700425
Ian Rogersb726dcb2012-09-05 08:57:23 -0700426 const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800427 const DexFile& dex_file = GetDexFile();
Ian Rogers19846512012-02-24 11:42:47 -0800428 uint32_t dex_method_idx = method_->GetDexMethodIndex();
429 if (dex_method_idx != DexFile::kDexNoIndex16) {
430 return dex_file.GetMethodName(dex_file.GetMethodId(dex_method_idx));
431 } else {
432 Runtime* runtime = Runtime::Current();
433 if (method_ == runtime->GetResolutionMethod()) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700434 return "<runtime internal resolution method>";
Ian Rogers19846512012-02-24 11:42:47 -0800435 } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700436 return "<runtime internal callee-save all registers method>";
Ian Rogers19846512012-02-24 11:42:47 -0800437 } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700438 return "<runtime internal callee-save reference registers method>";
Ian Rogers19846512012-02-24 11:42:47 -0800439 } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700440 return "<runtime internal callee-save reference and argument registers method>";
Ian Rogers19846512012-02-24 11:42:47 -0800441 } else {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700442 return "<unknown runtime internal method>";
Ian Rogers19846512012-02-24 11:42:47 -0800443 }
444 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800445 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700446
Ian Rogersb726dcb2012-09-05 08:57:23 -0700447 String* GetNameAsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800448 const DexFile& dex_file = GetDexFile();
Ian Rogers19846512012-02-24 11:42:47 -0800449 uint32_t dex_method_idx = method_->GetDexMethodIndex();
450 const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800451 return GetClassLinker()->ResolveString(dex_file, method_id.name_idx_, GetDexCache());
452 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700453
Ian Rogersb726dcb2012-09-05 08:57:23 -0700454 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800456 const char* result = shorty_;
457 if (result == NULL) {
458 const DexFile& dex_file = GetDexFile();
459 result = dex_file.GetMethodShorty(dex_file.GetMethodId(method_->GetDexMethodIndex()),
460 &shorty_len_);
461 shorty_ = result;
462 }
463 return result;
464 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700465
Ian Rogersb726dcb2012-09-05 08:57:23 -0700466 uint32_t GetShortyLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800467 if (shorty_ == NULL) {
468 GetShorty();
469 }
470 return shorty_len_;
471 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700472
Ian Rogersb726dcb2012-09-05 08:57:23 -0700473 const std::string GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800474 const DexFile& dex_file = GetDexFile();
Ian Rogers19846512012-02-24 11:42:47 -0800475 uint32_t dex_method_idx = method_->GetDexMethodIndex();
476 if (dex_method_idx != DexFile::kDexNoIndex16) {
477 return dex_file.GetMethodSignature(dex_file.GetMethodId(dex_method_idx));
478 } else {
479 return "<no signature>";
480 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800481 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700482
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700483 const DexFile::ProtoId& GetPrototype()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800485 const DexFile& dex_file = GetDexFile();
486 return dex_file.GetMethodPrototype(dex_file.GetMethodId(method_->GetDexMethodIndex()));
487 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700488
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700489 const DexFile::TypeList* GetParameterTypeList()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800491 const DexFile::ProtoId& proto = GetPrototype();
492 return GetDexFile().GetProtoParameters(proto);
493 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700494
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700495 ObjectArray<Class>* GetParameterTypes()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700496 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800497 const DexFile::TypeList* params = GetParameterTypeList();
498 Class* array_class = GetClassLinker()->FindSystemClass("[Ljava/lang/Class;");
499 uint32_t num_params = params == NULL ? 0 : params->Size();
500 ObjectArray<Class>* result = ObjectArray<Class>::Alloc(array_class, num_params);
501 for (uint32_t i = 0; i < num_params; i++) {
502 Class* param_type = GetClassFromTypeIdx(params->GetTypeItem(i).type_idx_);
jeffhao441d9122012-03-21 17:29:10 -0700503 if (param_type == NULL) {
504 DCHECK(Thread::Current()->IsExceptionPending());
505 return NULL;
506 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800507 result->Set(i, param_type);
508 }
509 return result;
510 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700511
Ian Rogersb726dcb2012-09-05 08:57:23 -0700512 Class* GetReturnType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800513 const DexFile& dex_file = GetDexFile();
514 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_->GetDexMethodIndex());
515 const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id);
516 uint16_t return_type_idx = proto_id.return_type_idx_;
517 return GetClassFromTypeIdx(return_type_idx);
518 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700519
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700520 const char* GetReturnTypeDescriptor()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800522 const DexFile& dex_file = GetDexFile();
523 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_->GetDexMethodIndex());
524 const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id);
525 uint16_t return_type_idx = proto_id.return_type_idx_;
526 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(return_type_idx));
527 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700528
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700529 int32_t GetLineNumFromDexPC(uint32_t dex_pc)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700530 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700531 if (dex_pc == DexFile::kDexNoIndex) {
532 return method_->IsNative() ? -2 : -1;
533 } else {
534 const DexFile& dex_file = GetDexFile();
535 return dex_file.GetLineNumFromPC(method_, dex_pc);
536 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800537 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700538
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700539 const char* GetDeclaringClassDescriptor()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700540 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800541 Class* klass = method_->GetDeclaringClass();
Ian Rogersc2b44472011-12-14 21:17:17 -0800542 DCHECK(!klass->IsProxyClass());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800543 uint16_t type_idx = klass->GetDexTypeIndex();
544 const DexFile& dex_file = GetDexFile();
545 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx));
546 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700547
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700548 const char* GetDeclaringClassSourceFile()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700549 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800550 const char* descriptor = GetDeclaringClassDescriptor();
551 const DexFile& dex_file = GetDexFile();
552 const DexFile::ClassDef* dex_class_def = dex_file.FindClassDef(descriptor);
Elliott Hughes12c51e32012-01-17 20:25:05 -0800553 CHECK(dex_class_def != NULL);
554 return dex_file.GetSourceFile(*dex_class_def);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800555 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700556
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700557 uint32_t GetClassDefIndex()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700558 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700559 const char* descriptor = GetDeclaringClassDescriptor();
560 const DexFile& dex_file = GetDexFile();
561 uint32_t index;
562 CHECK(dex_file.FindClassDefIndex(descriptor, index));
563 return index;
564 }
565
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700566 ClassLoader* GetClassLoader()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700568 return method_->GetDeclaringClass()->GetClassLoader();
569 }
570
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700571 bool IsStatic()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700572 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800573 return method_->IsStatic();
574 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700575
Ian Rogersb726dcb2012-09-05 08:57:23 -0700576 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800577 return IsStatic() && StringPiece(GetName()) == "<clinit>";
578 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700579
Ian Rogersb726dcb2012-09-05 08:57:23 -0700580 size_t NumArgs() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800581 // "1 +" because the first in Args is the receiver.
582 // "- 1" because we don't count the return type.
583 return (IsStatic() ? 0 : 1) + GetShortyLength() - 1;
584 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700585
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800586 // Is the specified parameter a long or double, where parameter 0 is 'this' for instance methods
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700587 bool IsParamALongOrDouble(size_t param)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700588 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800589 CHECK_LT(param, NumArgs());
590 if (IsStatic()) {
591 param++; // 0th argument must skip return value at start of the shorty
592 } else if (param == 0) {
593 return false; // this argument
594 }
595 char ch = GetShorty()[param];
596 return (ch == 'J' || ch == 'D');
597 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700598
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800599 // Is the specified parameter a reference, where parameter 0 is 'this' for instance methods
Ian Rogersb726dcb2012-09-05 08:57:23 -0700600 bool IsParamAReference(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800601 CHECK_LT(param, NumArgs());
602 if (IsStatic()) {
603 param++; // 0th argument must skip return value at start of the shorty
604 } else if (param == 0) {
605 return true; // this argument
606 }
607 return GetShorty()[param] == 'L'; // An array also has a shorty character of 'L' (not '[')
608 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700609
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700610 bool HasSameNameAndSignature(MethodHelper* other)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800612 if (GetDexCache() == other->GetDexCache()) {
613 const DexFile& dex_file = GetDexFile();
614 const DexFile::MethodId& mid = dex_file.GetMethodId(method_->GetDexMethodIndex());
615 const DexFile::MethodId& other_mid =
616 dex_file.GetMethodId(other->method_->GetDexMethodIndex());
Ian Rogers7b0c5b42012-02-16 15:29:07 -0800617 return mid.name_idx_ == other_mid.name_idx_ && mid.proto_idx_ == other_mid.proto_idx_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800618 }
Ian Rogers7b0c5b42012-02-16 15:29:07 -0800619 StringPiece name(GetName());
620 StringPiece other_name(other->GetName());
621 return name == other_name && GetSignature() == other->GetSignature();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800622 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700623
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700624 const DexFile::CodeItem* GetCodeItem()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700625 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800626 return GetDexFile().GetCodeItem(method_->GetCodeItemOffset());
627 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700628
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700629 bool IsResolvedTypeIdx(uint16_t type_idx) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700630 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6f1dfe42011-12-08 17:28:34 -0800631 return method_->GetDexCacheResolvedTypes()->Get(type_idx) != NULL;
632 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700633
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700634 Class* GetClassFromTypeIdx(uint16_t type_idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700635 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800636 Class* type = method_->GetDexCacheResolvedTypes()->Get(type_idx);
637 if (type == NULL) {
638 type = GetClassLinker()->ResolveType(type_idx, method_);
639 CHECK(type != NULL || Thread::Current()->IsExceptionPending());
640 }
641 return type;
642 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700643
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700644 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700645 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800646 const DexFile& dex_file = GetDexFile();
647 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx));
648 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700649
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700650 Class* GetDexCacheResolvedType(uint16_t type_idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700651 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800652 return GetDexCache()->GetResolvedType(type_idx);
653 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700654
Ian Rogersb726dcb2012-09-05 08:57:23 -0700655 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800656 const DexFile* result = dex_file_;
657 if (result == NULL) {
658 const DexCache* dex_cache = GetDexCache();
659 result = &GetClassLinker()->FindDexFile(dex_cache);
660 dex_file_ = result;
661 }
662 return *result;
663 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700664
Ian Rogersb726dcb2012-09-05 08:57:23 -0700665 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700666 DexCache* result = dex_cache_;
667 if (result == NULL) {
668 Class* klass = method_->GetDeclaringClass();
669 result = klass->GetDexCache();
670 dex_cache_ = result;
671 }
672 return result;
673 }
Elliott Hughesa21039c2012-06-21 12:09:25 -0700674
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800675 private:
676 // Set the method_ field, for proxy methods looking up the interface method via the resolved
677 // methods table.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700678 void SetMethod(const Method* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700679 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800680 if (method != NULL) {
681 Class* klass = method->GetDeclaringClass();
682 if (klass->IsProxyClass()) {
Ian Rogers19846512012-02-24 11:42:47 -0800683 Method* interface_method =
684 method->GetDexCacheResolvedMethods()->Get(method->GetDexMethodIndex());
685 CHECK(interface_method != NULL);
686 CHECK(interface_method == GetClassLinker()->FindMethodForProxy(klass, method));
687 method = interface_method;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800688 }
689 }
690 method_ = method;
691 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700692
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800693 ClassLinker* GetClassLinker() {
694 ClassLinker* result = class_linker_;
695 if (result == NULL) {
696 result = Runtime::Current()->GetClassLinker();
697 class_linker_ = result;
698 }
699 return result;
700 }
701
702 ClassLinker* class_linker_;
703 DexCache* dex_cache_;
704 const DexFile* dex_file_;
705 const Method* method_;
706 const char* shorty_;
Elliott Hughes45651fd2012-02-21 15:48:20 -0800707 uint32_t shorty_len_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800708
709 DISALLOW_COPY_AND_ASSIGN(MethodHelper);
710};
711
712} // namespace art
713
714#endif // ART_SRC_OBJECT_UTILS_H_