blob: 035f689ae5cef78ab5f7bf8d88c1b8e64b085381 [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_) {
Mathieu Chartier66f19252012-09-18 08:57:04 -0700202 if (dex_file_ == NULL) {
203 dex_file_ = GetDexCache()->GetDexFile();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800204 }
Mathieu Chartier66f19252012-09-18 08:57:04 -0700205 return *dex_file_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800206 }
207
Ian Rogersb726dcb2012-09-05 08:57:23 -0700208 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700209 DexCache* result = dex_cache_;
210 if (result == NULL) {
211 DCHECK(klass_ != NULL);
212 result = klass_->GetDexCache();
213 dex_cache_ = result;
214 }
215 return result;
216 }
217
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800218 private:
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700219 const DexFile::TypeList* GetInterfaceTypeList()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700220 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800221 const DexFile::TypeList* result = interface_type_list_;
222 if (result == NULL) {
223 const DexFile::ClassDef* class_def = GetClassDef();
224 if (class_def != NULL) {
225 result = GetDexFile().GetInterfacesList(*class_def);
226 interface_type_list_ = result;
227 }
228 }
229 return result;
230 }
Elliott Hughes91250e02011-12-13 22:30:35 -0800231
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800232 ClassLinker* GetClassLinker() {
233 ClassLinker* result = class_linker_;
234 if (result == NULL) {
235 result = Runtime::Current()->GetClassLinker();
236 class_linker_ = result;
237 }
238 return result;
239 }
240
241 const DexFile::ClassDef* class_def_;
242 ClassLinker* class_linker_;
243 DexCache* dex_cache_;
244 const DexFile* dex_file_;
245 const DexFile::TypeList* interface_type_list_;
246 const Class* klass_;
Elliott Hughes91250e02011-12-13 22:30:35 -0800247 std::string descriptor_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800248
249 DISALLOW_COPY_AND_ASSIGN(ClassHelper);
250};
251
252class FieldHelper {
253 public:
254 FieldHelper() : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), field_(NULL) {}
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800255 explicit FieldHelper(const Field* f) : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), field_(f) {}
Ian Rogersca190662012-06-26 15:45:57 -0700256 FieldHelper(const Field* f, ClassLinker* l)
257 : class_linker_(l), dex_cache_(NULL), dex_file_(NULL), field_(f) {}
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800258
259 void ChangeField(const Field* new_f) {
260 DCHECK(new_f != NULL);
261 if (dex_cache_ != NULL) {
262 DexCache* new_f_dex_cache = new_f->GetDeclaringClass()->GetDexCache();
263 if (new_f_dex_cache != dex_cache_) {
264 dex_cache_ = new_f_dex_cache;
265 dex_file_ = NULL;
266 }
267 }
268 field_ = new_f;
269 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700270 const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800271 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700272 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800273 const DexFile& dex_file = GetDexFile();
274 return dex_file.GetFieldName(dex_file.GetFieldId(field_index));
275 } else {
Ian Rogersc2b44472011-12-14 21:17:17 -0800276 DCHECK(field_->IsStatic());
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700277 DCHECK_LT(field_index, 2U);
278 return field_index == 0 ? "interfaces" : "throws";
Ian Rogersc2b44472011-12-14 21:17:17 -0800279 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800280 }
281 String* GetNameAsString() {
Ian Rogersc2b44472011-12-14 21:17:17 -0800282 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700283 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800284 const DexFile& dex_file = GetDexFile();
285 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
286 return GetClassLinker()->ResolveString(dex_file, field_id.name_idx_, GetDexCache());
287 } else {
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700288 return Runtime::Current()->GetInternTable()->InternStrong(GetName());
Ian Rogersc2b44472011-12-14 21:17:17 -0800289 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800290 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700291 Class* GetType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800292 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700293 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800294 const DexFile& dex_file = GetDexFile();
295 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
296 Class* type = GetDexCache()->GetResolvedType(field_id.type_idx_);
297 if (type == NULL) {
298 type = GetClassLinker()->ResolveType(field_id.type_idx_, field_);
299 CHECK(type != NULL || Thread::Current()->IsExceptionPending());
300 }
301 return type;
302 } else {
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700303 return GetClassLinker()->FindSystemClass(GetTypeDescriptor());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800304 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800305 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700306 const char* GetTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800307 uint32_t field_index = field_->GetDexFieldIndex();
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700308 if (!field_->GetDeclaringClass()->IsProxyClass()) {
Ian Rogersc2b44472011-12-14 21:17:17 -0800309 const DexFile& dex_file = GetDexFile();
310 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
311 return dex_file.GetFieldTypeDescriptor(field_id);
312 } else {
Ian Rogersc2b44472011-12-14 21:17:17 -0800313 DCHECK(field_->IsStatic());
Elliott Hughes2ed52c42012-03-21 16:56:56 -0700314 DCHECK_LT(field_index, 2U);
315 // 0 == Class[] interfaces; 1 == Class[][] throws;
316 return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;";
Ian Rogersc2b44472011-12-14 21:17:17 -0800317 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800318 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700319 Primitive::Type GetTypeAsPrimitiveType()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800321 return Primitive::GetType(GetTypeDescriptor()[0]);
322 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700323 bool IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800324 Primitive::Type type = GetTypeAsPrimitiveType();
325 return type != Primitive::kPrimNot;
326 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700327 size_t FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800328 Primitive::Type type = GetTypeAsPrimitiveType();
329 return Primitive::FieldSize(type);
330 }
Ian Rogersc2b44472011-12-14 21:17:17 -0800331
332 // The returned const char* is only guaranteed to be valid for the lifetime of the FieldHelper.
333 // If you need it longer, copy it into a std::string.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700334 const char* GetDeclaringClassDescriptor()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800336 uint16_t type_idx = field_->GetDeclaringClass()->GetDexTypeIndex();
Ian Rogersc2b44472011-12-14 21:17:17 -0800337 if (type_idx != DexFile::kDexNoIndex16) {
338 const DexFile& dex_file = GetDexFile();
339 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx));
340 } else {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700341 // Most likely a proxy class.
Ian Rogersc2b44472011-12-14 21:17:17 -0800342 ClassHelper kh(field_->GetDeclaringClass());
343 declaring_class_descriptor_ = kh.GetDescriptor();
344 return declaring_class_descriptor_.c_str();
345 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800346 }
347
348 private:
Ian Rogersb726dcb2012-09-05 08:57:23 -0700349 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800350 DexCache* result = dex_cache_;
351 if (result == NULL) {
352 result = field_->GetDeclaringClass()->GetDexCache();
353 dex_cache_ = result;
354 }
355 return result;
356 }
357 ClassLinker* GetClassLinker() {
358 ClassLinker* result = class_linker_;
359 if (result == NULL) {
360 result = Runtime::Current()->GetClassLinker();
361 class_linker_ = result;
362 }
363 return result;
364 }
Ian Rogersb726dcb2012-09-05 08:57:23 -0700365 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier66f19252012-09-18 08:57:04 -0700366 if (dex_file_ == NULL) {
367 dex_file_ = GetDexCache()->GetDexFile();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800368 }
Mathieu Chartier66f19252012-09-18 08:57:04 -0700369 return *dex_file_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800370 }
371
372 ClassLinker* class_linker_;
373 DexCache* dex_cache_;
374 const DexFile* dex_file_;
375 const Field* field_;
Ian Rogersc2b44472011-12-14 21:17:17 -0800376 std::string declaring_class_descriptor_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800377
378 DISALLOW_COPY_AND_ASSIGN(FieldHelper);
379};
380
381class MethodHelper {
382 public:
Ian Rogersca190662012-06-26 15:45:57 -0700383 MethodHelper()
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700384 : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL),
385 shorty_len_(0) {}
Ian Rogersca190662012-06-26 15:45:57 -0700386
Mathieu Chartier66f19252012-09-18 08:57:04 -0700387 explicit MethodHelper(const AbstractMethod* m)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogersca190662012-06-26 15:45:57 -0700389 : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL),
390 shorty_len_(0) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800391 SetMethod(m);
392 }
Ian Rogersca190662012-06-26 15:45:57 -0700393
Mathieu Chartier66f19252012-09-18 08:57:04 -0700394 MethodHelper(const AbstractMethod* m, ClassLinker* l)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700395 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogersca190662012-06-26 15:45:57 -0700396 : class_linker_(l), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL),
397 shorty_len_(0) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800398 SetMethod(m);
399 }
400
Mathieu Chartier66f19252012-09-18 08:57:04 -0700401 void ChangeMethod(AbstractMethod* new_m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800402 DCHECK(new_m != NULL);
403 if (dex_cache_ != NULL) {
404 Class* klass = new_m->GetDeclaringClass();
405 if (klass->IsProxyClass()) {
406 dex_cache_ = NULL;
407 dex_file_ = NULL;
408 } else {
409 DexCache* new_m_dex_cache = klass->GetDexCache();
410 if (new_m_dex_cache != dex_cache_) {
411 dex_cache_ = new_m_dex_cache;
412 dex_file_ = NULL;
413 }
414 }
415 }
416 SetMethod(new_m);
417 shorty_ = NULL;
418 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700419
Ian Rogersb726dcb2012-09-05 08:57:23 -0700420 const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800421 const DexFile& dex_file = GetDexFile();
Ian Rogers19846512012-02-24 11:42:47 -0800422 uint32_t dex_method_idx = method_->GetDexMethodIndex();
423 if (dex_method_idx != DexFile::kDexNoIndex16) {
424 return dex_file.GetMethodName(dex_file.GetMethodId(dex_method_idx));
425 } else {
426 Runtime* runtime = Runtime::Current();
427 if (method_ == runtime->GetResolutionMethod()) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700428 return "<runtime internal resolution method>";
Ian Rogers19846512012-02-24 11:42:47 -0800429 } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700430 return "<runtime internal callee-save all registers method>";
Ian Rogers19846512012-02-24 11:42:47 -0800431 } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700432 return "<runtime internal callee-save reference registers method>";
Ian Rogers19846512012-02-24 11:42:47 -0800433 } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700434 return "<runtime internal callee-save reference and argument registers method>";
Ian Rogers19846512012-02-24 11:42:47 -0800435 } else {
Elliott Hughes81ff3182012-03-23 20:35:56 -0700436 return "<unknown runtime internal method>";
Ian Rogers19846512012-02-24 11:42:47 -0800437 }
438 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800439 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700440
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 String* GetNameAsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800442 const DexFile& dex_file = GetDexFile();
Ian Rogers19846512012-02-24 11:42:47 -0800443 uint32_t dex_method_idx = method_->GetDexMethodIndex();
444 const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800445 return GetClassLinker()->ResolveString(dex_file, method_id.name_idx_, GetDexCache());
446 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700447
Ian Rogersb726dcb2012-09-05 08:57:23 -0700448 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
449 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800450 const char* result = shorty_;
451 if (result == NULL) {
452 const DexFile& dex_file = GetDexFile();
453 result = dex_file.GetMethodShorty(dex_file.GetMethodId(method_->GetDexMethodIndex()),
454 &shorty_len_);
455 shorty_ = result;
456 }
457 return result;
458 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700459
Ian Rogersb726dcb2012-09-05 08:57:23 -0700460 uint32_t GetShortyLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800461 if (shorty_ == NULL) {
462 GetShorty();
463 }
464 return shorty_len_;
465 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700466
Ian Rogersb726dcb2012-09-05 08:57:23 -0700467 const std::string GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800468 const DexFile& dex_file = GetDexFile();
Ian Rogers19846512012-02-24 11:42:47 -0800469 uint32_t dex_method_idx = method_->GetDexMethodIndex();
470 if (dex_method_idx != DexFile::kDexNoIndex16) {
471 return dex_file.GetMethodSignature(dex_file.GetMethodId(dex_method_idx));
472 } else {
473 return "<no signature>";
474 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800475 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700476
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700477 const DexFile::ProtoId& GetPrototype()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700478 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800479 const DexFile& dex_file = GetDexFile();
480 return dex_file.GetMethodPrototype(dex_file.GetMethodId(method_->GetDexMethodIndex()));
481 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700482
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700483 const DexFile::TypeList* GetParameterTypeList()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800485 const DexFile::ProtoId& proto = GetPrototype();
486 return GetDexFile().GetProtoParameters(proto);
487 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700488
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700489 ObjectArray<Class>* GetParameterTypes()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800491 const DexFile::TypeList* params = GetParameterTypeList();
492 Class* array_class = GetClassLinker()->FindSystemClass("[Ljava/lang/Class;");
493 uint32_t num_params = params == NULL ? 0 : params->Size();
494 ObjectArray<Class>* result = ObjectArray<Class>::Alloc(array_class, num_params);
495 for (uint32_t i = 0; i < num_params; i++) {
496 Class* param_type = GetClassFromTypeIdx(params->GetTypeItem(i).type_idx_);
jeffhao441d9122012-03-21 17:29:10 -0700497 if (param_type == NULL) {
498 DCHECK(Thread::Current()->IsExceptionPending());
499 return NULL;
500 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800501 result->Set(i, param_type);
502 }
503 return result;
504 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700505
Ian Rogersb726dcb2012-09-05 08:57:23 -0700506 Class* GetReturnType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800507 const DexFile& dex_file = GetDexFile();
508 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_->GetDexMethodIndex());
509 const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id);
510 uint16_t return_type_idx = proto_id.return_type_idx_;
511 return GetClassFromTypeIdx(return_type_idx);
512 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700513
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700514 const char* GetReturnTypeDescriptor()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700515 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800516 const DexFile& dex_file = GetDexFile();
517 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_->GetDexMethodIndex());
518 const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id);
519 uint16_t return_type_idx = proto_id.return_type_idx_;
520 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(return_type_idx));
521 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700522
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700523 int32_t GetLineNumFromDexPC(uint32_t dex_pc)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700525 if (dex_pc == DexFile::kDexNoIndex) {
526 return method_->IsNative() ? -2 : -1;
527 } else {
528 const DexFile& dex_file = GetDexFile();
529 return dex_file.GetLineNumFromPC(method_, dex_pc);
530 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800531 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700532
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700533 const char* GetDeclaringClassDescriptor()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700534 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800535 Class* klass = method_->GetDeclaringClass();
Ian Rogersc2b44472011-12-14 21:17:17 -0800536 DCHECK(!klass->IsProxyClass());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800537 uint16_t type_idx = klass->GetDexTypeIndex();
538 const DexFile& dex_file = GetDexFile();
539 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx));
540 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700541
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700542 const char* GetDeclaringClassSourceFile()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700543 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800544 const char* descriptor = GetDeclaringClassDescriptor();
545 const DexFile& dex_file = GetDexFile();
546 const DexFile::ClassDef* dex_class_def = dex_file.FindClassDef(descriptor);
Elliott Hughes12c51e32012-01-17 20:25:05 -0800547 CHECK(dex_class_def != NULL);
548 return dex_file.GetSourceFile(*dex_class_def);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800549 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700550
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700551 uint32_t GetClassDefIndex()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700552 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700553 const char* descriptor = GetDeclaringClassDescriptor();
554 const DexFile& dex_file = GetDexFile();
555 uint32_t index;
556 CHECK(dex_file.FindClassDefIndex(descriptor, index));
557 return index;
558 }
559
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700560 ClassLoader* GetClassLoader()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700562 return method_->GetDeclaringClass()->GetClassLoader();
563 }
564
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700565 bool IsStatic()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800567 return method_->IsStatic();
568 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700569
Ian Rogersb726dcb2012-09-05 08:57:23 -0700570 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800571 return IsStatic() && StringPiece(GetName()) == "<clinit>";
572 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700573
Ian Rogersb726dcb2012-09-05 08:57:23 -0700574 size_t NumArgs() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800575 // "1 +" because the first in Args is the receiver.
576 // "- 1" because we don't count the return type.
577 return (IsStatic() ? 0 : 1) + GetShortyLength() - 1;
578 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700579
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800580 // Is the specified parameter a long or double, where parameter 0 is 'this' for instance methods
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700581 bool IsParamALongOrDouble(size_t param)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700582 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800583 CHECK_LT(param, NumArgs());
584 if (IsStatic()) {
585 param++; // 0th argument must skip return value at start of the shorty
586 } else if (param == 0) {
587 return false; // this argument
588 }
589 char ch = GetShorty()[param];
590 return (ch == 'J' || ch == 'D');
591 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700592
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800593 // Is the specified parameter a reference, where parameter 0 is 'this' for instance methods
Ian Rogersb726dcb2012-09-05 08:57:23 -0700594 bool IsParamAReference(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800595 CHECK_LT(param, NumArgs());
596 if (IsStatic()) {
597 param++; // 0th argument must skip return value at start of the shorty
598 } else if (param == 0) {
599 return true; // this argument
600 }
601 return GetShorty()[param] == 'L'; // An array also has a shorty character of 'L' (not '[')
602 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700603
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700604 bool HasSameNameAndSignature(MethodHelper* other)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700605 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800606 if (GetDexCache() == other->GetDexCache()) {
607 const DexFile& dex_file = GetDexFile();
608 const DexFile::MethodId& mid = dex_file.GetMethodId(method_->GetDexMethodIndex());
609 const DexFile::MethodId& other_mid =
610 dex_file.GetMethodId(other->method_->GetDexMethodIndex());
Ian Rogers7b0c5b42012-02-16 15:29:07 -0800611 return mid.name_idx_ == other_mid.name_idx_ && mid.proto_idx_ == other_mid.proto_idx_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800612 }
Ian Rogers7b0c5b42012-02-16 15:29:07 -0800613 StringPiece name(GetName());
614 StringPiece other_name(other->GetName());
615 return name == other_name && GetSignature() == other->GetSignature();
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800616 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700617
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700618 const DexFile::CodeItem* GetCodeItem()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700619 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800620 return GetDexFile().GetCodeItem(method_->GetCodeItemOffset());
621 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700622
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700623 bool IsResolvedTypeIdx(uint16_t type_idx) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700624 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6f1dfe42011-12-08 17:28:34 -0800625 return method_->GetDexCacheResolvedTypes()->Get(type_idx) != NULL;
626 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700627
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700628 Class* GetClassFromTypeIdx(uint16_t type_idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700629 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800630 Class* type = method_->GetDexCacheResolvedTypes()->Get(type_idx);
631 if (type == NULL) {
632 type = GetClassLinker()->ResolveType(type_idx, method_);
633 CHECK(type != NULL || Thread::Current()->IsExceptionPending());
634 }
635 return type;
636 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700637
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700638 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700639 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800640 const DexFile& dex_file = GetDexFile();
641 return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx));
642 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700643
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700644 Class* GetDexCacheResolvedType(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 return GetDexCache()->GetResolvedType(type_idx);
647 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700648
Ian Rogersb726dcb2012-09-05 08:57:23 -0700649 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800650 const DexFile* result = dex_file_;
651 if (result == NULL) {
652 const DexCache* dex_cache = GetDexCache();
653 result = &GetClassLinker()->FindDexFile(dex_cache);
654 dex_file_ = result;
655 }
656 return *result;
657 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700658
Ian Rogersb726dcb2012-09-05 08:57:23 -0700659 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersad0b3a32012-04-16 14:50:24 -0700660 DexCache* result = dex_cache_;
661 if (result == NULL) {
662 Class* klass = method_->GetDeclaringClass();
663 result = klass->GetDexCache();
664 dex_cache_ = result;
665 }
666 return result;
667 }
Elliott Hughesa21039c2012-06-21 12:09:25 -0700668
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800669 private:
670 // Set the method_ field, for proxy methods looking up the interface method via the resolved
671 // methods table.
Mathieu Chartier66f19252012-09-18 08:57:04 -0700672 void SetMethod(const AbstractMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700673 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800674 if (method != NULL) {
675 Class* klass = method->GetDeclaringClass();
676 if (klass->IsProxyClass()) {
Mathieu Chartier66f19252012-09-18 08:57:04 -0700677 AbstractMethod* interface_method =
Ian Rogers19846512012-02-24 11:42:47 -0800678 method->GetDexCacheResolvedMethods()->Get(method->GetDexMethodIndex());
679 CHECK(interface_method != NULL);
680 CHECK(interface_method == GetClassLinker()->FindMethodForProxy(klass, method));
681 method = interface_method;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800682 }
683 }
684 method_ = method;
685 }
Ian Rogersad0b3a32012-04-16 14:50:24 -0700686
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800687 ClassLinker* GetClassLinker() {
688 ClassLinker* result = class_linker_;
689 if (result == NULL) {
690 result = Runtime::Current()->GetClassLinker();
691 class_linker_ = result;
692 }
693 return result;
694 }
695
696 ClassLinker* class_linker_;
697 DexCache* dex_cache_;
698 const DexFile* dex_file_;
Mathieu Chartier66f19252012-09-18 08:57:04 -0700699 const AbstractMethod* method_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800700 const char* shorty_;
Elliott Hughes45651fd2012-02-21 15:48:20 -0800701 uint32_t shorty_len_;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800702
703 DISALLOW_COPY_AND_ASSIGN(MethodHelper);
704};
705
706} // namespace art
707
708#endif // ART_SRC_OBJECT_UTILS_H_