Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_OBJECT_UTILS_H_ |
| 18 | #define ART_RUNTIME_OBJECT_UTILS_H_ |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 19 | |
Ian Rogers | d8274bc | 2013-05-15 15:54:45 -0700 | [diff] [blame] | 20 | #include "class_linker-inl.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 21 | #include "dex_file.h" |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 22 | #include "monitor.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 23 | #include "mirror/art_field.h" |
| 24 | #include "mirror/art_method.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "mirror/class.h" |
| 26 | #include "mirror/dex_cache.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "mirror/iftable.h" |
| 28 | #include "mirror/string.h" |
| 29 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 30 | #include "runtime.h" |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 31 | #include "sirt_ref.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 32 | |
| 33 | #include <string> |
| 34 | |
| 35 | namespace art { |
| 36 | |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 37 | class ObjectLock { |
| 38 | public: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | explicit ObjectLock(Thread* self, mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 40 | : self_(self), obj_(object) { |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 41 | CHECK(object != NULL); |
| 42 | obj_->MonitorEnter(self_); |
| 43 | } |
| 44 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 45 | ~ObjectLock() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 46 | obj_->MonitorExit(self_); |
| 47 | } |
| 48 | |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 49 | void WaitIgnoringInterrupts() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 50 | Monitor::Wait(self_, obj_, 0, 0, false, kWaiting); |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 53 | void Notify() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 54 | obj_->Notify(self_); |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 57 | void NotifyAll() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 58 | obj_->NotifyAll(self_); |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | private: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 62 | Thread* const self_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | mirror::Object* obj_; |
Ian Rogers | 672f520 | 2012-01-12 18:06:40 -0800 | [diff] [blame] | 64 | DISALLOW_COPY_AND_ASSIGN(ObjectLock); |
| 65 | }; |
| 66 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 67 | class ClassHelper { |
| 68 | public: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | ClassHelper(const mirror::Class* c = NULL, ClassLinker* l = NULL) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 70 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 71 | : class_linker_(l), |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 72 | dex_cache_(NULL), |
| 73 | dex_file_(NULL), |
| 74 | interface_type_list_(NULL), |
Brian Carlstrom | e77be40 | 2012-03-30 01:08:38 -0700 | [diff] [blame] | 75 | klass_(NULL) { |
| 76 | if (c != NULL) { |
| 77 | ChangeClass(c); |
| 78 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 79 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 80 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 81 | void ChangeClass(const mirror::Class* new_c) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 82 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 01e076e | 2012-03-30 11:54:16 -0700 | [diff] [blame] | 83 | CHECK(new_c != NULL) << "klass_=" << klass_; // Log what we were changing from if any |
| 84 | CHECK(new_c->IsClass()) << "new_c=" << new_c; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 85 | if (dex_cache_ != NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 86 | mirror::DexCache* new_c_dex_cache = new_c->GetDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 87 | if (new_c_dex_cache != dex_cache_) { |
| 88 | dex_cache_ = new_c_dex_cache; |
| 89 | dex_file_ = NULL; |
| 90 | } |
| 91 | } |
| 92 | klass_ = new_c; |
| 93 | interface_type_list_ = NULL; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 96 | // The returned const char* is only guaranteed to be valid for the lifetime of the ClassHelper. |
| 97 | // If you need it longer, copy it into a std::string. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 98 | const char* GetDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 93235f7 | 2012-03-29 22:48:15 -0700 | [diff] [blame] | 99 | CHECK(klass_ != NULL); |
Ian Rogers | a68a1cb | 2012-01-10 10:34:36 -0800 | [diff] [blame] | 100 | if (UNLIKELY(klass_->IsArrayClass())) { |
| 101 | return GetArrayDescriptor(); |
| 102 | } else if (UNLIKELY(klass_->IsPrimitive())) { |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 103 | return Primitive::Descriptor(klass_->GetPrimitiveType()); |
Ian Rogers | a68a1cb | 2012-01-10 10:34:36 -0800 | [diff] [blame] | 104 | } else if (UNLIKELY(klass_->IsProxyClass())) { |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 105 | descriptor_ = GetClassLinker()->GetDescriptorForProxy(klass_); |
| 106 | return descriptor_.c_str(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 107 | } else { |
| 108 | const DexFile& dex_file = GetDexFile(); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 109 | const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 110 | return dex_file.GetTypeDescriptor(type_id); |
| 111 | } |
| 112 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 113 | |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 114 | StringPiece GetDescriptorAsStringPiece() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 115 | CHECK(klass_ != NULL); |
| 116 | if (UNLIKELY(klass_->IsArrayClass() || klass_->IsPrimitive() || klass_->IsProxyClass())) { |
| 117 | return StringPiece(GetDescriptor()); |
| 118 | } else { |
| 119 | const DexFile& dex_file = GetDexFile(); |
| 120 | const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_); |
| 121 | return dex_file.StringDataAsStringPieceByIdx(type_id.descriptor_idx_); |
| 122 | } |
| 123 | } |
| 124 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 125 | const char* GetArrayDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | a68a1cb | 2012-01-10 10:34:36 -0800 | [diff] [blame] | 126 | std::string result("["); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 127 | const mirror::Class* saved_klass = klass_; |
Brian Carlstrom | 93235f7 | 2012-03-29 22:48:15 -0700 | [diff] [blame] | 128 | CHECK(saved_klass != NULL); |
Ian Rogers | a68a1cb | 2012-01-10 10:34:36 -0800 | [diff] [blame] | 129 | ChangeClass(klass_->GetComponentType()); |
| 130 | result += GetDescriptor(); |
| 131 | ChangeClass(saved_klass); |
| 132 | descriptor_ = result; |
| 133 | return descriptor_.c_str(); |
| 134 | } |
| 135 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 136 | const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 137 | DCHECK(klass_ != nullptr); |
| 138 | uint16_t class_def_idx = klass_->GetDexClassDefIndex(); |
| 139 | if (class_def_idx == DexFile::kDexNoIndex16) { |
| 140 | return nullptr; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 141 | } |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 142 | return &GetDexFile().GetClassDef(class_def_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 143 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 144 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 145 | uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 93235f7 | 2012-03-29 22:48:15 -0700 | [diff] [blame] | 146 | DCHECK(klass_ != NULL); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 147 | if (klass_->IsPrimitive()) { |
| 148 | return 0; |
| 149 | } else if (klass_->IsArrayClass()) { |
| 150 | return 2; |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 151 | } else if (klass_->IsProxyClass()) { |
| 152 | return klass_->GetIfTable()->GetLength(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 153 | } else { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 154 | const DexFile::TypeList* interfaces = GetInterfaceTypeList(); |
| 155 | if (interfaces == NULL) { |
| 156 | return 0; |
| 157 | } else { |
| 158 | return interfaces->Size(); |
| 159 | } |
| 160 | } |
| 161 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 162 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 163 | uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 164 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 93235f7 | 2012-03-29 22:48:15 -0700 | [diff] [blame] | 165 | DCHECK(klass_ != NULL); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 166 | DCHECK(!klass_->IsPrimitive()); |
| 167 | DCHECK(!klass_->IsArrayClass()); |
| 168 | return GetInterfaceTypeList()->GetTypeItem(idx).type_idx_; |
| 169 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 170 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | mirror::Class* GetDirectInterface(uint32_t idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 172 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 93235f7 | 2012-03-29 22:48:15 -0700 | [diff] [blame] | 173 | DCHECK(klass_ != NULL); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 174 | DCHECK(!klass_->IsPrimitive()); |
| 175 | if (klass_->IsArrayClass()) { |
| 176 | if (idx == 0) { |
| 177 | return GetClassLinker()->FindSystemClass("Ljava/lang/Cloneable;"); |
| 178 | } else { |
| 179 | DCHECK_EQ(1U, idx); |
| 180 | return GetClassLinker()->FindSystemClass("Ljava/io/Serializable;"); |
| 181 | } |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 182 | } else if (klass_->IsProxyClass()) { |
Ian Rogers | 9bc8191 | 2012-10-11 21:43:36 -0700 | [diff] [blame] | 183 | return klass_->GetIfTable()->GetInterface(idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 184 | } else { |
Ian Rogers | d24e264 | 2012-06-06 21:21:43 -0700 | [diff] [blame] | 185 | uint16_t type_idx = GetDirectInterfaceTypeIdx(idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 186 | mirror::Class* interface = GetDexCache()->GetResolvedType(type_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 187 | if (interface == NULL) { |
| 188 | interface = GetClassLinker()->ResolveType(GetDexFile(), type_idx, klass_); |
| 189 | CHECK(interface != NULL || Thread::Current()->IsExceptionPending()); |
| 190 | } |
| 191 | return interface; |
| 192 | } |
| 193 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 194 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 195 | const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 196 | std::string descriptor(GetDescriptorAsStringPiece().as_string()); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 197 | const DexFile& dex_file = GetDexFile(); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 198 | const DexFile::ClassDef* dex_class_def = GetClassDef(); |
Elliott Hughes | 12c51e3 | 2012-01-17 20:25:05 -0800 | [diff] [blame] | 199 | CHECK(dex_class_def != NULL); |
| 200 | return dex_file.GetSourceFile(*dex_class_def); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 201 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 202 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 203 | std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 204 | mirror::DexCache* dex_cache = GetDexCache(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 205 | if (dex_cache != NULL && !klass_->IsProxyClass()) { |
| 206 | return dex_cache->GetLocation()->ToModifiedUtf8(); |
| 207 | } else { |
| 208 | // Arrays and proxies are generated and have no corresponding dex file location. |
| 209 | return "generated class"; |
| 210 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 213 | const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 214 | if (dex_file_ == NULL) { |
| 215 | dex_file_ = GetDexCache()->GetDexFile(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 216 | } |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 217 | return *dex_file_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 220 | mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 221 | mirror::DexCache* result = dex_cache_; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 222 | if (result == NULL) { |
| 223 | DCHECK(klass_ != NULL); |
| 224 | result = klass_->GetDexCache(); |
| 225 | dex_cache_ = result; |
| 226 | } |
| 227 | return result; |
| 228 | } |
| 229 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 230 | private: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 231 | const DexFile::TypeList* GetInterfaceTypeList() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 232 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 233 | const DexFile::TypeList* result = interface_type_list_; |
| 234 | if (result == NULL) { |
| 235 | const DexFile::ClassDef* class_def = GetClassDef(); |
| 236 | if (class_def != NULL) { |
| 237 | result = GetDexFile().GetInterfacesList(*class_def); |
| 238 | interface_type_list_ = result; |
| 239 | } |
| 240 | } |
| 241 | return result; |
| 242 | } |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 243 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 244 | ClassLinker* GetClassLinker() { |
| 245 | ClassLinker* result = class_linker_; |
| 246 | if (result == NULL) { |
| 247 | result = Runtime::Current()->GetClassLinker(); |
| 248 | class_linker_ = result; |
| 249 | } |
| 250 | return result; |
| 251 | } |
| 252 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 253 | ClassLinker* class_linker_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 254 | mirror::DexCache* dex_cache_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 255 | const DexFile* dex_file_; |
| 256 | const DexFile::TypeList* interface_type_list_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 257 | const mirror::Class* klass_; |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 258 | std::string descriptor_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 259 | |
| 260 | DISALLOW_COPY_AND_ASSIGN(ClassHelper); |
| 261 | }; |
| 262 | |
| 263 | class FieldHelper { |
| 264 | public: |
| 265 | FieldHelper() : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), field_(NULL) {} |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 266 | explicit FieldHelper(const mirror::ArtField* f) : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), field_(f) {} |
| 267 | FieldHelper(const mirror::ArtField* f, ClassLinker* l) |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 268 | : class_linker_(l), dex_cache_(NULL), dex_file_(NULL), field_(f) {} |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 269 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 270 | void ChangeField(const mirror::ArtField* new_f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 271 | DCHECK(new_f != NULL); |
| 272 | if (dex_cache_ != NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 273 | mirror::DexCache* new_f_dex_cache = new_f->GetDeclaringClass()->GetDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 274 | if (new_f_dex_cache != dex_cache_) { |
| 275 | dex_cache_ = new_f_dex_cache; |
| 276 | dex_file_ = NULL; |
| 277 | } |
| 278 | } |
| 279 | field_ = new_f; |
| 280 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 281 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 282 | const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 283 | uint32_t field_index = field_->GetDexFieldIndex(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 284 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 285 | DCHECK(field_->IsStatic()); |
Elliott Hughes | 2ed52c4 | 2012-03-21 16:56:56 -0700 | [diff] [blame] | 286 | DCHECK_LT(field_index, 2U); |
| 287 | return field_index == 0 ? "interfaces" : "throws"; |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 288 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 289 | const DexFile& dex_file = GetDexFile(); |
| 290 | return dex_file.GetFieldName(dex_file.GetFieldId(field_index)); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 291 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 292 | |
| 293 | StringPiece GetNameAsStringPiece() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 294 | uint32_t field_index = field_->GetDexFieldIndex(); |
| 295 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
| 296 | return StringPiece(GetName()); |
| 297 | } |
| 298 | const DexFile& dex_file = GetDexFile(); |
| 299 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 300 | return dex_file.StringDataAsStringPieceByIdx(field_id.name_idx_); |
| 301 | } |
| 302 | |
Ian Rogers | 50239c7 | 2013-06-17 14:53:22 -0700 | [diff] [blame] | 303 | mirror::Class* GetType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 304 | uint32_t field_index = field_->GetDexFieldIndex(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 305 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
Elliott Hughes | 2ed52c4 | 2012-03-21 16:56:56 -0700 | [diff] [blame] | 306 | return GetClassLinker()->FindSystemClass(GetTypeDescriptor()); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 307 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 308 | const DexFile& dex_file = GetDexFile(); |
| 309 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 310 | mirror::Class* type = GetDexCache()->GetResolvedType(field_id.type_idx_); |
| 311 | if (resolve && (type == NULL)) { |
| 312 | type = GetClassLinker()->ResolveType(field_id.type_idx_, field_); |
| 313 | CHECK(type != NULL || Thread::Current()->IsExceptionPending()); |
| 314 | } |
| 315 | return type; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 316 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 317 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 318 | const char* GetTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 319 | uint32_t field_index = field_->GetDexFieldIndex(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 320 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 321 | DCHECK(field_->IsStatic()); |
Elliott Hughes | 2ed52c4 | 2012-03-21 16:56:56 -0700 | [diff] [blame] | 322 | DCHECK_LT(field_index, 2U); |
| 323 | // 0 == Class[] interfaces; 1 == Class[][] throws; |
| 324 | return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;"; |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 325 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 326 | const DexFile& dex_file = GetDexFile(); |
| 327 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 328 | return dex_file.GetFieldTypeDescriptor(field_id); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 329 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 330 | |
| 331 | StringPiece GetTypeDescriptorAsStringPiece() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 332 | uint32_t field_index = field_->GetDexFieldIndex(); |
| 333 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
| 334 | return StringPiece(GetTypeDescriptor()); |
| 335 | } |
| 336 | const DexFile& dex_file = GetDexFile(); |
| 337 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 338 | const DexFile::TypeId& type_id = dex_file.GetTypeId(field_id.type_idx_); |
| 339 | return dex_file.StringDataAsStringPieceByIdx(type_id.descriptor_idx_); |
| 340 | } |
| 341 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 342 | Primitive::Type GetTypeAsPrimitiveType() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 343 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 344 | return Primitive::GetType(GetTypeDescriptor()[0]); |
| 345 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 346 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 347 | bool IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 348 | Primitive::Type type = GetTypeAsPrimitiveType(); |
| 349 | return type != Primitive::kPrimNot; |
| 350 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 351 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 352 | size_t FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 353 | Primitive::Type type = GetTypeAsPrimitiveType(); |
| 354 | return Primitive::FieldSize(type); |
| 355 | } |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 356 | |
| 357 | // The returned const char* is only guaranteed to be valid for the lifetime of the FieldHelper. |
| 358 | // If you need it longer, copy it into a std::string. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 359 | const char* GetDeclaringClassDescriptor() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 360 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 361 | uint32_t field_index = field_->GetDexFieldIndex(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 362 | if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 363 | DCHECK(field_->IsStatic()); |
| 364 | DCHECK_LT(field_index, 2U); |
| 365 | // 0 == Class[] interfaces; 1 == Class[][] throws; |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 366 | ClassHelper kh(field_->GetDeclaringClass()); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 367 | declaring_class_descriptor_ = kh.GetDescriptorAsStringPiece().as_string(); |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 368 | return declaring_class_descriptor_.c_str(); |
| 369 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 370 | const DexFile& dex_file = GetDexFile(); |
| 371 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 372 | return dex_file.GetFieldDeclaringClassDescriptor(field_id); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | private: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 376 | mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 377 | mirror::DexCache* result = dex_cache_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 378 | if (result == NULL) { |
| 379 | result = field_->GetDeclaringClass()->GetDexCache(); |
| 380 | dex_cache_ = result; |
| 381 | } |
| 382 | return result; |
| 383 | } |
| 384 | ClassLinker* GetClassLinker() { |
| 385 | ClassLinker* result = class_linker_; |
| 386 | if (result == NULL) { |
| 387 | result = Runtime::Current()->GetClassLinker(); |
| 388 | class_linker_ = result; |
| 389 | } |
| 390 | return result; |
| 391 | } |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 392 | const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 393 | if (dex_file_ == NULL) { |
| 394 | dex_file_ = GetDexCache()->GetDexFile(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 395 | } |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 396 | return *dex_file_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | ClassLinker* class_linker_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 400 | mirror::DexCache* dex_cache_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 401 | const DexFile* dex_file_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 402 | const mirror::ArtField* field_; |
Ian Rogers | c2b4447 | 2011-12-14 21:17:17 -0800 | [diff] [blame] | 403 | std::string declaring_class_descriptor_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 404 | |
| 405 | DISALLOW_COPY_AND_ASSIGN(FieldHelper); |
| 406 | }; |
| 407 | |
| 408 | class MethodHelper { |
| 409 | public: |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 410 | MethodHelper() |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 411 | : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL), |
| 412 | shorty_len_(0) {} |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 413 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 414 | explicit MethodHelper(const mirror::ArtMethod* m) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 415 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 416 | : class_linker_(NULL), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL), |
| 417 | shorty_len_(0) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 418 | SetMethod(m); |
| 419 | } |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 420 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 421 | MethodHelper(const mirror::ArtMethod* m, ClassLinker* l) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 422 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 423 | : class_linker_(l), dex_cache_(NULL), dex_file_(NULL), method_(NULL), shorty_(NULL), |
| 424 | shorty_len_(0) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 425 | SetMethod(m); |
| 426 | } |
| 427 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 428 | void ChangeMethod(mirror::ArtMethod* new_m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 429 | DCHECK(new_m != NULL); |
| 430 | if (dex_cache_ != NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 431 | mirror::Class* klass = new_m->GetDeclaringClass(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 432 | if (klass->IsProxyClass()) { |
| 433 | dex_cache_ = NULL; |
| 434 | dex_file_ = NULL; |
| 435 | } else { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 436 | mirror::DexCache* new_m_dex_cache = klass->GetDexCache(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 437 | if (new_m_dex_cache != dex_cache_) { |
| 438 | dex_cache_ = new_m_dex_cache; |
| 439 | dex_file_ = NULL; |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | SetMethod(new_m); |
| 444 | shorty_ = NULL; |
| 445 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 446 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 447 | const mirror::ArtMethod* GetMethod() const { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 448 | return method_; |
| 449 | } |
| 450 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 451 | const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 452 | const DexFile& dex_file = GetDexFile(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 453 | uint32_t dex_method_idx = method_->GetDexMethodIndex(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 454 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 455 | return dex_file.GetMethodName(dex_file.GetMethodId(dex_method_idx)); |
| 456 | } else { |
| 457 | Runtime* runtime = Runtime::Current(); |
| 458 | if (method_ == runtime->GetResolutionMethod()) { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 459 | return "<runtime internal resolution method>"; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 460 | } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 461 | return "<runtime internal callee-save all registers method>"; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 462 | } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 463 | return "<runtime internal callee-save reference registers method>"; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 464 | } else if (method_ == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 465 | return "<runtime internal callee-save reference and argument registers method>"; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 466 | } else { |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 467 | return "<unknown runtime internal method>"; |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 468 | } |
| 469 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 470 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 471 | |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 472 | StringPiece GetNameAsStringPiece() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 473 | const DexFile& dex_file = GetDexFile(); |
| 474 | uint32_t dex_method_idx = method_->GetDexMethodIndex(); |
| 475 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 476 | return StringPiece(GetName()); |
| 477 | } |
| 478 | const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx); |
| 479 | return dex_file.StringDataAsStringPieceByIdx(method_id.name_idx_); |
| 480 | } |
| 481 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 482 | mirror::String* GetNameAsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 483 | const DexFile& dex_file = GetDexFile(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 484 | uint32_t dex_method_idx = method_->GetDexMethodIndex(); |
| 485 | const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 486 | return GetClassLinker()->ResolveString(dex_file, method_id.name_idx_, GetDexCache()); |
| 487 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 488 | |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 489 | const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 490 | const char* result = shorty_; |
| 491 | if (result == NULL) { |
| 492 | const DexFile& dex_file = GetDexFile(); |
| 493 | result = dex_file.GetMethodShorty(dex_file.GetMethodId(method_->GetDexMethodIndex()), |
| 494 | &shorty_len_); |
| 495 | shorty_ = result; |
| 496 | } |
| 497 | return result; |
| 498 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 499 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 500 | uint32_t GetShortyLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 501 | if (shorty_ == NULL) { |
| 502 | GetShorty(); |
| 503 | } |
| 504 | return shorty_len_; |
| 505 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 506 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 507 | const std::string GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 508 | const DexFile& dex_file = GetDexFile(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 509 | uint32_t dex_method_idx = method_->GetDexMethodIndex(); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 510 | if (dex_method_idx != DexFile::kDexNoIndex) { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 511 | return dex_file.GetMethodSignature(dex_file.GetMethodId(dex_method_idx)); |
| 512 | } else { |
| 513 | return "<no signature>"; |
| 514 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 515 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 516 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 517 | const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 518 | const DexFile& dex_file = GetDexFile(); |
| 519 | return dex_file.GetMethodPrototype(dex_file.GetMethodId(method_->GetDexMethodIndex())); |
| 520 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 521 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 522 | const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 523 | const DexFile::ProtoId& proto = GetPrototype(); |
| 524 | return GetDexFile().GetProtoParameters(proto); |
| 525 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 526 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 527 | mirror::Class* GetReturnType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 528 | const DexFile& dex_file = GetDexFile(); |
| 529 | const DexFile::MethodId& method_id = dex_file.GetMethodId(method_->GetDexMethodIndex()); |
| 530 | const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id); |
| 531 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 532 | return GetClassFromTypeIdx(return_type_idx); |
| 533 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 534 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 535 | const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 536 | const DexFile& dex_file = GetDexFile(); |
| 537 | const DexFile::MethodId& method_id = dex_file.GetMethodId(method_->GetDexMethodIndex()); |
| 538 | const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(method_id); |
| 539 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 540 | return dex_file.GetTypeDescriptor(dex_file.GetTypeId(return_type_idx)); |
| 541 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 542 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 543 | int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 544 | if (dex_pc == DexFile::kDexNoIndex) { |
| 545 | return method_->IsNative() ? -2 : -1; |
| 546 | } else { |
| 547 | const DexFile& dex_file = GetDexFile(); |
| 548 | return dex_file.GetLineNumFromPC(method_, dex_pc); |
| 549 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 550 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 551 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 552 | const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 553 | const DexFile& dex_file = GetDexFile(); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 554 | uint32_t dex_method_idx = method_->GetDexMethodIndex(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 555 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 556 | return "<runtime method>"; |
| 557 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 558 | return dex_file.GetMethodDeclaringClassDescriptor(dex_file.GetMethodId(dex_method_idx)); |
| 559 | } |
| 560 | |
| 561 | StringPiece GetDeclaringClassDescriptorAsStringPiece() |
| 562 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 563 | const DexFile& dex_file = GetDexFile(); |
| 564 | uint32_t dex_method_idx = method_->GetDexMethodIndex(); |
| 565 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 566 | return StringPiece("<runtime method>"); |
| 567 | } |
| 568 | const DexFile::MethodId& mid = dex_file.GetMethodId(dex_method_idx); |
| 569 | const DexFile::TypeId& type_id = dex_file.GetTypeId(mid.class_idx_); |
| 570 | return dex_file.StringDataAsStringPieceByIdx(type_id.descriptor_idx_); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 571 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 572 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 573 | const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 574 | return ClassHelper(method_->GetDeclaringClass()).GetSourceFile(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 575 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 576 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 577 | uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 578 | return method_->GetDeclaringClass()->GetDexClassDefIndex(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 581 | const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 582 | return GetDexFile().GetClassDef(GetClassDefIndex()); |
| 583 | } |
| 584 | |
| 585 | mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 586 | return method_->GetDeclaringClass()->GetClassLoader(); |
| 587 | } |
| 588 | |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 589 | bool IsStatic() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 590 | return method_->IsStatic(); |
| 591 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 592 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 593 | bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 594 | return IsStatic() && GetNameAsStringPiece() == "<clinit>"; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 595 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 596 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 597 | size_t NumArgs() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 598 | // "1 +" because the first in Args is the receiver. |
| 599 | // "- 1" because we don't count the return type. |
| 600 | return (IsStatic() ? 0 : 1) + GetShortyLength() - 1; |
| 601 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 602 | |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 603 | // Get the primitive type associated with the given parameter. |
| 604 | Primitive::Type GetParamPrimitiveType(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 605 | CHECK_LT(param, NumArgs()); |
| 606 | if (IsStatic()) { |
| 607 | param++; // 0th argument must skip return value at start of the shorty |
| 608 | } else if (param == 0) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 609 | return Primitive::kPrimNot; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 610 | } |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 611 | return Primitive::GetType(GetShorty()[param]); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 612 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 613 | |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 614 | // Is the specified parameter a long or double, where parameter 0 is 'this' for instance methods. |
| 615 | bool IsParamALongOrDouble(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 616 | Primitive::Type type = GetParamPrimitiveType(param); |
| 617 | return type == Primitive::kPrimLong || type == Primitive::kPrimDouble; |
| 618 | } |
| 619 | |
| 620 | // Is the specified parameter a reference, where parameter 0 is 'this' for instance methods. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 621 | bool IsParamAReference(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 622 | return GetParamPrimitiveType(param) == Primitive::kPrimNot; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 623 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 624 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 625 | bool HasSameNameAndSignature(MethodHelper* other) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 626 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 627 | const DexFile& dex_file = GetDexFile(); |
| 628 | const DexFile::MethodId& mid = dex_file.GetMethodId(method_->GetDexMethodIndex()); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 629 | if (GetDexCache() == other->GetDexCache()) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 630 | const DexFile::MethodId& other_mid = |
| 631 | dex_file.GetMethodId(other->method_->GetDexMethodIndex()); |
Ian Rogers | 7b0c5b4 | 2012-02-16 15:29:07 -0800 | [diff] [blame] | 632 | return mid.name_idx_ == other_mid.name_idx_ && mid.proto_idx_ == other_mid.proto_idx_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 633 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame^] | 634 | const DexFile& other_dex_file = other->GetDexFile(); |
| 635 | const DexFile::MethodId& other_mid = |
| 636 | other_dex_file.GetMethodId(other->method_->GetDexMethodIndex()); |
| 637 | if (dex_file.StringDataAsStringPieceByIdx(mid.name_idx_) != |
| 638 | other_dex_file.StringDataAsStringPieceByIdx(other_mid.name_idx_)) { |
| 639 | return false; // Name mismatch. |
| 640 | } |
| 641 | const DexFile::ProtoId& proto_id = dex_file.GetMethodPrototype(mid); |
| 642 | const DexFile::ProtoId& other_proto_id = other_dex_file.GetMethodPrototype(other_mid); |
| 643 | if (dex_file.StringDataAsStringPieceByIdx(proto_id.shorty_idx_) != |
| 644 | other_dex_file.StringDataAsStringPieceByIdx(other_proto_id.shorty_idx_)) { |
| 645 | return false; // Shorty mismatch. |
| 646 | } |
| 647 | const DexFile::TypeId& return_type_id = dex_file.GetTypeId(proto_id.return_type_idx_); |
| 648 | const DexFile::TypeId& other_return_type_id = |
| 649 | other_dex_file.GetTypeId(other_proto_id.return_type_idx_); |
| 650 | if (dex_file.StringDataAsStringPieceByIdx(return_type_id.descriptor_idx_) != |
| 651 | other_dex_file.StringDataAsStringPieceByIdx(other_return_type_id.descriptor_idx_)) { |
| 652 | return false; // Return type mismatch. |
| 653 | } |
| 654 | const DexFile::TypeList* params = dex_file.GetProtoParameters(proto_id); |
| 655 | const DexFile::TypeList* other_params = other_dex_file.GetProtoParameters(other_proto_id); |
| 656 | if (params == nullptr) { |
| 657 | return other_params == nullptr; // Check both lists are empty. |
| 658 | } |
| 659 | if (other_params == nullptr) { |
| 660 | return false; // Parameter list size mismatch. |
| 661 | } |
| 662 | uint32_t params_size = params->Size(); |
| 663 | uint32_t other_params_size = other_params->Size(); |
| 664 | if (params_size != other_params_size) { |
| 665 | return false; // Parameter list size mismatch. |
| 666 | } |
| 667 | for (uint32_t i = 0; i < params_size; ++i) { |
| 668 | const DexFile::TypeId& param_id = dex_file.GetTypeId(params->GetTypeItem(i).type_idx_); |
| 669 | const DexFile::TypeId& other_param_id = |
| 670 | other_dex_file.GetTypeId(other_params->GetTypeItem(i).type_idx_); |
| 671 | if (dex_file.StringDataAsStringPieceByIdx(param_id.descriptor_idx_) != |
| 672 | other_dex_file.StringDataAsStringPieceByIdx(other_param_id.descriptor_idx_)) { |
| 673 | return false; // Parameter type mismatch. |
| 674 | } |
| 675 | } |
| 676 | return true; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 677 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 678 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 679 | const DexFile::CodeItem* GetCodeItem() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 680 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 681 | return GetDexFile().GetCodeItem(method_->GetCodeItemOffset()); |
| 682 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 683 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 684 | bool IsResolvedTypeIdx(uint16_t type_idx) const |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 685 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6f1dfe4 | 2011-12-08 17:28:34 -0800 | [diff] [blame] | 686 | return method_->GetDexCacheResolvedTypes()->Get(type_idx) != NULL; |
| 687 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 688 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 689 | mirror::Class* GetClassFromTypeIdx(uint16_t type_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 690 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 691 | mirror::Class* type = method_->GetDexCacheResolvedTypes()->Get(type_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 692 | if (type == NULL) { |
| 693 | type = GetClassLinker()->ResolveType(type_idx, method_); |
| 694 | CHECK(type != NULL || Thread::Current()->IsExceptionPending()); |
| 695 | } |
| 696 | return type; |
| 697 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 698 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 699 | const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 700 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 701 | const DexFile& dex_file = GetDexFile(); |
| 702 | return dex_file.GetTypeDescriptor(dex_file.GetTypeId(type_idx)); |
| 703 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 704 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 705 | mirror::Class* GetDexCacheResolvedType(uint16_t type_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 706 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 707 | return method_->GetDexCacheResolvedTypes()->Get(type_idx); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 708 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 709 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 710 | const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 711 | const DexFile* result = dex_file_; |
| 712 | if (result == NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 713 | const mirror::DexCache* dex_cache = GetDexCache(); |
Ian Rogers | 4445a7e | 2012-10-05 17:19:13 -0700 | [diff] [blame] | 714 | result = dex_file_ = dex_cache->GetDexFile(); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 715 | } |
| 716 | return *result; |
| 717 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 718 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 719 | mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 720 | mirror::DexCache* result = dex_cache_; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 721 | if (result == NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 722 | mirror::Class* klass = method_->GetDeclaringClass(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 723 | result = klass->GetDexCache(); |
| 724 | dex_cache_ = result; |
| 725 | } |
| 726 | return result; |
| 727 | } |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 728 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 729 | mirror::String* ResolveString(uint32_t string_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 730 | mirror::String* s = method_->GetDexCacheStrings()->Get(string_idx); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 731 | if (UNLIKELY(s == NULL)) { |
| 732 | s = GetClassLinker()->ResolveString(GetDexFile(), string_idx, GetDexCache()); |
| 733 | } |
| 734 | return s; |
| 735 | } |
| 736 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 737 | private: |
| 738 | // Set the method_ field, for proxy methods looking up the interface method via the resolved |
| 739 | // methods table. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 740 | void SetMethod(const mirror::ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 741 | if (method != NULL) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 742 | mirror::Class* klass = method->GetDeclaringClass(); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 743 | if (UNLIKELY(klass->IsProxyClass())) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 744 | mirror::ArtMethod* interface_method = |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 745 | method->GetDexCacheResolvedMethods()->Get(method->GetDexMethodIndex()); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 746 | DCHECK(interface_method != NULL); |
| 747 | DCHECK(interface_method == GetClassLinker()->FindMethodForProxy(klass, method)); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 748 | method = interface_method; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | method_ = method; |
| 752 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 753 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 754 | ClassLinker* GetClassLinker() { |
| 755 | ClassLinker* result = class_linker_; |
| 756 | if (result == NULL) { |
| 757 | result = Runtime::Current()->GetClassLinker(); |
| 758 | class_linker_ = result; |
| 759 | } |
| 760 | return result; |
| 761 | } |
| 762 | |
| 763 | ClassLinker* class_linker_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 764 | mirror::DexCache* dex_cache_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 765 | const DexFile* dex_file_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 766 | const mirror::ArtMethod* method_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 767 | const char* shorty_; |
Elliott Hughes | 45651fd | 2012-02-21 15:48:20 -0800 | [diff] [blame] | 768 | uint32_t shorty_len_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 769 | |
| 770 | DISALLOW_COPY_AND_ASSIGN(MethodHelper); |
| 771 | }; |
| 772 | |
| 773 | } // namespace art |
| 774 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 775 | #endif // ART_RUNTIME_OBJECT_UTILS_H_ |