blob: 4b02c0ff60807f130c473ed36aaa8967ed44bcc5 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -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#include "class.h"
18
Brian Carlstromea46f952013-07-30 01:26:50 -070019#include "art_field-inl.h"
20#include "art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "class-inl.h"
22#include "class_linker.h"
23#include "class_loader.h"
24#include "dex_cache.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070025#include "dex_file-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070026#include "gc/accounting/card_table-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027#include "object-inl.h"
28#include "object_array-inl.h"
29#include "object_utils.h"
30#include "runtime.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070031#include "handle_scope-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "thread.h"
33#include "throwable.h"
34#include "utils.h"
35#include "well_known_classes.h"
36
37namespace art {
38namespace mirror {
39
40Class* Class::java_lang_Class_ = NULL;
41
42void Class::SetClassClass(Class* java_lang_Class) {
43 CHECK(java_lang_Class_ == NULL) << java_lang_Class_ << " " << java_lang_Class;
44 CHECK(java_lang_Class != NULL);
45 java_lang_Class_ = java_lang_Class;
46}
47
48void Class::ResetClass() {
49 CHECK(java_lang_Class_ != NULL);
50 java_lang_Class_ = NULL;
51}
52
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080053void Class::VisitRoots(RootCallback* callback, void* arg) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -080054 if (java_lang_Class_ != nullptr) {
Mathieu Chartier815873e2014-02-13 18:02:13 -080055 callback(reinterpret_cast<mirror::Object**>(&java_lang_Class_), arg, 0, kRootStickyClass);
Mathieu Chartierc528dba2013-11-26 12:00:11 -080056 }
57}
58
Ian Rogers7dfb28c2013-08-22 08:18:36 -070059void Class::SetStatus(Status new_status, Thread* self) {
60 Status old_status = GetStatus();
Mathieu Chartier590fee92013-09-13 13:46:47 -070061 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
62 bool class_linker_initialized = class_linker != nullptr && class_linker->IsInitialized();
Ian Rogers7dfb28c2013-08-22 08:18:36 -070063 if (LIKELY(class_linker_initialized)) {
64 if (UNLIKELY(new_status <= old_status && new_status != kStatusError)) {
Ian Rogers8f3c9ae2013-08-20 17:26:41 -070065 LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(this) << " "
Ian Rogers7dfb28c2013-08-22 08:18:36 -070066 << old_status << " -> " << new_status;
Ian Rogers8f3c9ae2013-08-20 17:26:41 -070067 }
Ian Rogers7dfb28c2013-08-22 08:18:36 -070068 if (new_status >= kStatusResolved || old_status >= kStatusResolved) {
69 // When classes are being resolved the resolution code should hold the lock.
Ian Rogersd9c4fc92013-10-01 19:45:43 -070070 CHECK_EQ(GetLockOwnerThreadId(), self->GetThreadId())
Ian Rogers7dfb28c2013-08-22 08:18:36 -070071 << "Attempt to change status of class while not holding its lock: "
72 << PrettyClass(this) << " " << old_status << " -> " << new_status;
73 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 }
Ian Rogers98379392014-02-24 16:53:16 -080075 if (UNLIKELY(new_status == kStatusError)) {
Ian Rogers8f3c9ae2013-08-20 17:26:41 -070076 CHECK_NE(GetStatus(), kStatusError)
77 << "Attempt to set as erroneous an already erroneous class " << PrettyClass(this);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078
Ian Rogers62d6c772013-02-27 08:32:07 -080079 // Stash current exception.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070080 StackHandleScope<3> hs(self);
81 ThrowLocation old_throw_location;
82 Handle<mirror::Throwable> old_exception(hs.NewHandle(self->GetException(&old_throw_location)));
83 CHECK(old_exception.Get() != nullptr);
84 Handle<mirror::Object> old_throw_this_object(hs.NewHandle(old_throw_location.GetThis()));
85 Handle<mirror::ArtMethod> old_throw_method(hs.NewHandle(old_throw_location.GetMethod()));
86 uint32_t old_throw_dex_pc = old_throw_location.GetDexPc();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087
88 // clear exception to call FindSystemClass
89 self->ClearException();
90 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogers98379392014-02-24 16:53:16 -080091 Class* eiie_class = class_linker->FindSystemClass(self,
92 "Ljava/lang/ExceptionInInitializerError;");
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 CHECK(!self->IsExceptionPending());
94
Ian Rogers62d6c772013-02-27 08:32:07 -080095 // Only verification errors, not initialization problems, should set a verify error.
96 // This is to ensure that ThrowEarlierClassFailure will throw NoClassDefFoundError in that case.
97 Class* exception_class = old_exception->GetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 if (!eiie_class->IsAssignableFrom(exception_class)) {
99 SetVerifyErrorClass(exception_class);
100 }
101
Ian Rogers62d6c772013-02-27 08:32:07 -0800102 // Restore exception.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700103 ThrowLocation gc_safe_throw_location(old_throw_this_object.Get(), old_throw_method.Get(),
Ian Rogers62d6c772013-02-27 08:32:07 -0800104 old_throw_dex_pc);
105
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700106 self->SetException(gc_safe_throw_location, old_exception.Get());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800107 }
Ian Rogers03dbc042014-06-02 14:24:56 -0700108 COMPILE_ASSERT(sizeof(Status) == sizeof(uint32_t), size_of_status_not_uint32);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100109 if (Runtime::Current()->IsActiveTransaction()) {
Ian Rogers03dbc042014-06-02 14:24:56 -0700110 SetField32Volatile<true>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100111 } else {
Ian Rogers03dbc042014-06-02 14:24:56 -0700112 SetField32Volatile<false>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100113 }
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700114 // Classes that are being resolved or initialized need to notify waiters that the class status
115 // changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass.
116 if ((old_status >= kStatusResolved || new_status >= kStatusResolved) &&
117 class_linker_initialized) {
118 NotifyAll(self);
119 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120}
121
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122void Class::SetDexCache(DexCache* new_dex_cache) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700123 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124}
125
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126void Class::SetClassSize(uint32_t new_class_size) {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700127 if (kIsDebugBuild && (new_class_size < GetClassSize())) {
128 DumpClass(LOG(ERROR), kDumpClassFullDetail);
129 CHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this);
130 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100131 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700132 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800133}
134
135// Return the class' name. The exact format is bizarre, but it's the specified behavior for
136// Class.getName: keywords for primitive types, regular "[I" form for primitive arrays (so "int"
137// but "[I"), and arrays of reference types written between "L" and ";" but with dots rather than
138// slashes (so "java.lang.String" but "[Ljava.lang.String;"). Madness.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700139String* Class::ComputeName(Handle<Class> h_this) {
140 String* name = h_this->GetName();
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800141 if (name != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142 return name;
143 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700144 std::string descriptor(h_this->GetDescriptor());
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800145 Thread* self = Thread::Current();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 if ((descriptor[0] != 'L') && (descriptor[0] != '[')) {
147 // The descriptor indicates that this is the class for
148 // a primitive type; special-case the return value.
149 const char* c_name = NULL;
150 switch (descriptor[0]) {
151 case 'Z': c_name = "boolean"; break;
152 case 'B': c_name = "byte"; break;
153 case 'C': c_name = "char"; break;
154 case 'S': c_name = "short"; break;
155 case 'I': c_name = "int"; break;
156 case 'J': c_name = "long"; break;
157 case 'F': c_name = "float"; break;
158 case 'D': c_name = "double"; break;
159 case 'V': c_name = "void"; break;
160 default:
161 LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]);
162 }
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800163 name = String::AllocFromModifiedUtf8(self, c_name);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164 } else {
165 // Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package
166 // components.
167 if (descriptor.size() > 2 && descriptor[0] == 'L' && descriptor[descriptor.size() - 1] == ';') {
168 descriptor.erase(0, 1);
169 descriptor.erase(descriptor.size() - 1);
170 }
171 std::replace(descriptor.begin(), descriptor.end(), '/', '.');
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800172 name = String::AllocFromModifiedUtf8(self, descriptor.c_str());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700174 h_this->SetName(name);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175 return name;
176}
177
Ian Rogersef7d42f2014-01-06 12:55:46 -0800178void Class::DumpClass(std::ostream& os, int flags) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 if ((flags & kDumpClassFullDetail) == 0) {
180 os << PrettyClass(this);
181 if ((flags & kDumpClassClassLoader) != 0) {
182 os << ' ' << GetClassLoader();
183 }
184 if ((flags & kDumpClassInitialized) != 0) {
185 os << ' ' << GetStatus();
186 }
187 os << "\n";
188 return;
189 }
190
Mathieu Chartierf8322842014-05-16 10:59:25 -0700191 Thread* self = Thread::Current();
192 StackHandleScope<2> hs(self);
193 Handle<mirror::Class> h_this(hs.NewHandle(this));
194 Handle<mirror::Class> h_super(hs.NewHandle(GetSuperClass()));
195
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 os << "----- " << (IsInterface() ? "interface" : "class") << " "
Mathieu Chartierf8322842014-05-16 10:59:25 -0700197 << "'" << GetDescriptor() << "' cl=" << GetClassLoader() << " -----\n",
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198 os << " objectSize=" << SizeOf() << " "
Mathieu Chartierf8322842014-05-16 10:59:25 -0700199 << "(" << (h_super.Get() != NULL ? h_super->SizeOf() : -1) << " from super)\n",
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 os << StringPrintf(" access=0x%04x.%04x\n",
201 GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask);
Mathieu Chartierf8322842014-05-16 10:59:25 -0700202 if (h_super.Get() != NULL) {
203 os << " super='" << PrettyClass(h_super.Get()) << "' (cl=" << h_super->GetClassLoader()
204 << ")\n";
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 }
206 if (IsArrayClass()) {
207 os << " componentType=" << PrettyClass(GetComponentType()) << "\n";
208 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700209 const size_t num_direct_interfaces = NumDirectInterfaces();
210 if (num_direct_interfaces > 0) {
211 os << " interfaces (" << num_direct_interfaces << "):\n";
212 for (size_t i = 0; i < num_direct_interfaces; ++i) {
213 Class* interface = GetDirectInterface(self, h_this, i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 const ClassLoader* cl = interface->GetClassLoader();
215 os << StringPrintf(" %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl);
216 }
217 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700218 // After this point, this may have moved due to GetDirectInterface.
219 os << " vtable (" << h_this->NumVirtualMethods() << " entries, "
220 << (h_super.Get() != NULL ? h_super->NumVirtualMethods() : 0) << " in super):\n";
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221 for (size_t i = 0; i < NumVirtualMethods(); ++i) {
Mathieu Chartierf8322842014-05-16 10:59:25 -0700222 os << StringPrintf(" %2zd: %s\n", i,
223 PrettyMethod(h_this->GetVirtualMethodDuringLinking(i)).c_str());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700225 os << " direct methods (" << h_this->NumDirectMethods() << " entries):\n";
226 for (size_t i = 0; i < h_this->NumDirectMethods(); ++i) {
227 os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(h_this->GetDirectMethod(i)).c_str());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800228 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700229 if (h_this->NumStaticFields() > 0) {
230 os << " static fields (" << h_this->NumStaticFields() << " entries):\n";
231 if (h_this->IsResolved() || h_this->IsErroneous()) {
232 for (size_t i = 0; i < h_this->NumStaticFields(); ++i) {
233 os << StringPrintf(" %2zd: %s\n", i, PrettyField(h_this->GetStaticField(i)).c_str());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800234 }
235 } else {
236 os << " <not yet available>";
237 }
238 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700239 if (h_this->NumInstanceFields() > 0) {
240 os << " instance fields (" << h_this->NumInstanceFields() << " entries):\n";
241 if (h_this->IsResolved() || h_this->IsErroneous()) {
242 for (size_t i = 0; i < h_this->NumInstanceFields(); ++i) {
243 os << StringPrintf(" %2zd: %s\n", i, PrettyField(h_this->GetInstanceField(i)).c_str());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800244 }
245 } else {
246 os << " <not yet available>";
247 }
248 }
249}
250
251void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) {
252 if (new_reference_offsets != CLASS_WALK_SUPER) {
253 // Sanity check that the number of bits set in the reference offset bitmap
254 // agrees with the number of references
255 size_t count = 0;
256 for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
257 count += c->NumReferenceInstanceFieldsDuringLinking();
258 }
Vladimir Marko81949632014-05-02 11:53:22 +0100259 CHECK_EQ((size_t)POPCOUNT(new_reference_offsets), count);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100261 // Not called within a transaction.
262 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700263 new_reference_offsets);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800264}
265
266void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) {
267 if (new_reference_offsets != CLASS_WALK_SUPER) {
268 // Sanity check that the number of bits set in the reference offset bitmap
269 // agrees with the number of references
Vladimir Marko81949632014-05-02 11:53:22 +0100270 CHECK_EQ((size_t)POPCOUNT(new_reference_offsets),
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800271 NumReferenceStaticFieldsDuringLinking());
272 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100273 // Not called within a transaction.
274 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700275 new_reference_offsets);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800276}
277
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800278bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) {
279 size_t i = 0;
280 while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) {
281 ++i;
282 }
283 if (descriptor1.find('/', i) != StringPiece::npos ||
284 descriptor2.find('/', i) != StringPiece::npos) {
285 return false;
286 } else {
287 return true;
288 }
289}
290
Ian Rogersef7d42f2014-01-06 12:55:46 -0800291bool Class::IsInSamePackage(Class* that) {
292 Class* klass1 = this;
293 Class* klass2 = that;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294 if (klass1 == klass2) {
295 return true;
296 }
297 // Class loaders must match.
298 if (klass1->GetClassLoader() != klass2->GetClassLoader()) {
299 return false;
300 }
301 // Arrays are in the same package when their element classes are.
302 while (klass1->IsArrayClass()) {
303 klass1 = klass1->GetComponentType();
304 }
305 while (klass2->IsArrayClass()) {
306 klass2 = klass2->GetComponentType();
307 }
Anwar Ghuloum9fa3f202013-03-26 14:32:54 -0700308 // trivial check again for array types
309 if (klass1 == klass2) {
310 return true;
311 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312 // Compare the package part of the descriptor string.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700313 return IsInSamePackage(klass1->GetDescriptor().c_str(), klass2->GetDescriptor().c_str());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314}
315
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800316bool Class::IsStringClass() const {
317 return this == String::GetJavaLangString();
318}
319
Ian Rogersef7d42f2014-01-06 12:55:46 -0800320bool Class::IsThrowableClass() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321 return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this);
322}
323
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800324void Class::SetClassLoader(ClassLoader* new_class_loader) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100325 if (Runtime::Current()->IsActiveTransaction()) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700326 SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100327 } else {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700328 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100329 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800330}
331
Ian Rogersef7d42f2014-01-06 12:55:46 -0800332ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const Signature& signature) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333 // Check the current class before checking the interfaces.
Brian Carlstromea46f952013-07-30 01:26:50 -0700334 ArtMethod* method = FindDeclaredVirtualMethod(name, signature);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800335 if (method != NULL) {
336 return method;
337 }
338
339 int32_t iftable_count = GetIfTableCount();
340 IfTable* iftable = GetIfTable();
341 for (int32_t i = 0; i < iftable_count; i++) {
342 method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature);
343 if (method != NULL) {
344 return method;
345 }
346 }
347 return NULL;
348}
349
Ian Rogersef7d42f2014-01-06 12:55:46 -0800350ArtMethod* Class::FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351 // Check the current class before checking the interfaces.
Brian Carlstromea46f952013-07-30 01:26:50 -0700352 ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800353 if (method != NULL) {
354 return method;
355 }
356
357 int32_t iftable_count = GetIfTableCount();
358 IfTable* iftable = GetIfTable();
359 for (int32_t i = 0; i < iftable_count; i++) {
360 method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
361 if (method != NULL) {
362 return method;
363 }
364 }
365 return NULL;
366}
367
Ian Rogersef7d42f2014-01-06 12:55:46 -0800368ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800369 MethodHelper mh;
370 for (size_t i = 0; i < NumDirectMethods(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700371 ArtMethod* method = GetDirectMethod(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372 mh.ChangeMethod(method);
Ian Rogersdfb325e2013-10-30 01:00:44 -0700373 if (name == mh.GetName() && mh.GetSignature() == signature) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700374 return method;
375 }
376 }
377 return NULL;
378}
379
Ian Rogersef7d42f2014-01-06 12:55:46 -0800380ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700381 MethodHelper mh;
382 for (size_t i = 0; i < NumDirectMethods(); ++i) {
383 ArtMethod* method = GetDirectMethod(i);
384 mh.ChangeMethod(method);
Ian Rogersdfb325e2013-10-30 01:00:44 -0700385 if (name == mh.GetName() && signature == mh.GetSignature()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386 return method;
387 }
388 }
389 return NULL;
390}
391
Ian Rogersef7d42f2014-01-06 12:55:46 -0800392ArtMethod* Class::FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800393 if (GetDexCache() == dex_cache) {
394 for (size_t i = 0; i < NumDirectMethods(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700395 ArtMethod* method = GetDirectMethod(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800396 if (method->GetDexMethodIndex() == dex_method_idx) {
397 return method;
398 }
399 }
400 }
401 return NULL;
402}
403
Ian Rogersef7d42f2014-01-06 12:55:46 -0800404ArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature) {
405 for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700406 ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407 if (method != NULL) {
408 return method;
409 }
410 }
411 return NULL;
412}
413
Ian Rogersef7d42f2014-01-06 12:55:46 -0800414ArtMethod* Class::FindDirectMethod(const StringPiece& name, const Signature& signature) {
415 for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700416 ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature);
417 if (method != NULL) {
418 return method;
419 }
420 }
421 return NULL;
422}
423
Ian Rogersef7d42f2014-01-06 12:55:46 -0800424ArtMethod* Class::FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
425 for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700426 ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 if (method != NULL) {
428 return method;
429 }
430 }
431 return NULL;
432}
433
Ian Rogersef7d42f2014-01-06 12:55:46 -0800434ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700435 MethodHelper mh;
436 for (size_t i = 0; i < NumVirtualMethods(); ++i) {
437 ArtMethod* method = GetVirtualMethod(i);
438 mh.ChangeMethod(method);
Ian Rogersdfb325e2013-10-30 01:00:44 -0700439 if (name == mh.GetName() && mh.GetSignature() == signature) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700440 return method;
441 }
442 }
443 return NULL;
444}
445
Brian Carlstromea46f952013-07-30 01:26:50 -0700446ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800447 const Signature& signature) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800448 MethodHelper mh;
449 for (size_t i = 0; i < NumVirtualMethods(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700450 ArtMethod* method = GetVirtualMethod(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451 mh.ChangeMethod(method);
Ian Rogersdfb325e2013-10-30 01:00:44 -0700452 if (name == mh.GetName() && signature == mh.GetSignature()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453 return method;
454 }
455 }
456 return NULL;
457}
458
Ian Rogersef7d42f2014-01-06 12:55:46 -0800459ArtMethod* Class::FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800460 if (GetDexCache() == dex_cache) {
461 for (size_t i = 0; i < NumVirtualMethods(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700462 ArtMethod* method = GetVirtualMethod(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800463 if (method->GetDexMethodIndex() == dex_method_idx) {
464 return method;
465 }
466 }
467 }
468 return NULL;
469}
470
Ian Rogersef7d42f2014-01-06 12:55:46 -0800471ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const StringPiece& signature) {
472 for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700473 ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474 if (method != NULL) {
475 return method;
476 }
477 }
478 return NULL;
479}
480
Ian Rogersef7d42f2014-01-06 12:55:46 -0800481ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const Signature& signature) {
482 for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700483 ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature);
484 if (method != NULL) {
485 return method;
486 }
487 }
488 return NULL;
489}
490
Ian Rogersef7d42f2014-01-06 12:55:46 -0800491ArtMethod* Class::FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
492 for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700493 ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800494 if (method != NULL) {
495 return method;
496 }
497 }
498 return NULL;
499}
500
Ian Rogersef7d42f2014-01-06 12:55:46 -0800501ArtMethod* Class::FindClassInitializer() {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700502 for (size_t i = 0; i < NumDirectMethods(); ++i) {
503 ArtMethod* method = GetDirectMethod(i);
504 if (method->IsConstructor() && method->IsStatic()) {
505 if (kIsDebugBuild) {
506 MethodHelper mh(method);
Ian Rogers241b5de2013-10-09 17:58:57 -0700507 CHECK(mh.IsClassInitializer());
Ian Rogersd91d6d62013-09-25 20:26:14 -0700508 CHECK_STREQ(mh.GetName(), "<clinit>");
509 CHECK_STREQ(mh.GetSignature().ToString().c_str(), "()V");
510 }
511 return method;
512 }
513 }
514 return NULL;
515}
516
Brian Carlstromea46f952013-07-30 01:26:50 -0700517ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800518 // Is the field in this class?
519 // Interfaces are not relevant because they can't contain instance fields.
520 FieldHelper fh;
521 for (size_t i = 0; i < NumInstanceFields(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700522 ArtField* f = GetInstanceField(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800523 fh.ChangeField(f);
Ian Rogersdfb325e2013-10-30 01:00:44 -0700524 if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800525 return f;
526 }
527 }
528 return NULL;
529}
530
Brian Carlstromea46f952013-07-30 01:26:50 -0700531ArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800532 if (GetDexCache() == dex_cache) {
533 for (size_t i = 0; i < NumInstanceFields(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700534 ArtField* f = GetInstanceField(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800535 if (f->GetDexFieldIndex() == dex_field_idx) {
536 return f;
537 }
538 }
539 }
540 return NULL;
541}
542
Brian Carlstromea46f952013-07-30 01:26:50 -0700543ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800544 // Is the field in this class, or any of its superclasses?
545 // Interfaces are not relevant because they can't contain instance fields.
546 for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700547 ArtField* f = c->FindDeclaredInstanceField(name, type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800548 if (f != NULL) {
549 return f;
550 }
551 }
552 return NULL;
553}
554
Brian Carlstromea46f952013-07-30 01:26:50 -0700555ArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800556 // Is the field in this class, or any of its superclasses?
557 // Interfaces are not relevant because they can't contain instance fields.
558 for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700559 ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800560 if (f != NULL) {
561 return f;
562 }
563 }
564 return NULL;
565}
566
Brian Carlstromea46f952013-07-30 01:26:50 -0700567ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800568 DCHECK(type != NULL);
569 FieldHelper fh;
570 for (size_t i = 0; i < NumStaticFields(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700571 ArtField* f = GetStaticField(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800572 fh.ChangeField(f);
Ian Rogersdfb325e2013-10-30 01:00:44 -0700573 if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800574 return f;
575 }
576 }
577 return NULL;
578}
579
Brian Carlstromea46f952013-07-30 01:26:50 -0700580ArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800581 if (dex_cache == GetDexCache()) {
582 for (size_t i = 0; i < NumStaticFields(); ++i) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700583 ArtField* f = GetStaticField(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800584 if (f->GetDexFieldIndex() == dex_field_idx) {
585 return f;
586 }
587 }
588 }
589 return NULL;
590}
591
Mathieu Chartierf8322842014-05-16 10:59:25 -0700592ArtField* Class::FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
593 const StringPiece& type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800594 // Is the field in this class (or its interfaces), or any of its
595 // superclasses (or their interfaces)?
Mathieu Chartierf8322842014-05-16 10:59:25 -0700596 for (Class* k = klass.Get(); k != nullptr; k = k->GetSuperClass()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800597 // Is the field in this class?
Brian Carlstromea46f952013-07-30 01:26:50 -0700598 ArtField* f = k->FindDeclaredStaticField(name, type);
Mathieu Chartierf8322842014-05-16 10:59:25 -0700599 if (f != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800600 return f;
601 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700602 // Wrap k incase it moves during GetDirectInterface.
603 StackHandleScope<1> hs(self);
604 HandleWrapper<mirror::Class> h_k(hs.NewHandleWrapper(&k));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605 // Is this field in any of this class' interfaces?
Mathieu Chartierf8322842014-05-16 10:59:25 -0700606 for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) {
607 StackHandleScope<1> hs(self);
608 Handle<mirror::Class> interface(hs.NewHandle(GetDirectInterface(self, h_k, i)));
609 f = FindStaticField(self, interface, name, type);
610 if (f != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800611 return f;
612 }
613 }
614 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700615 return nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800616}
617
Mathieu Chartierf8322842014-05-16 10:59:25 -0700618ArtField* Class::FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
619 uint32_t dex_field_idx) {
620 for (Class* k = klass.Get(); k != nullptr; k = k->GetSuperClass()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800621 // Is the field in this class?
Brian Carlstromea46f952013-07-30 01:26:50 -0700622 ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800623 if (f != NULL) {
624 return f;
625 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700626 // Wrap k incase it moves during GetDirectInterface.
627 StackHandleScope<1> hs(self);
628 HandleWrapper<mirror::Class> h_k(hs.NewHandleWrapper(&k));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800629 // Is this field in any of this class' interfaces?
Mathieu Chartierf8322842014-05-16 10:59:25 -0700630 for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) {
631 StackHandleScope<1> hs(self);
632 Handle<mirror::Class> interface(hs.NewHandle(GetDirectInterface(self, h_k, i)));
633 f = FindStaticField(self, interface, dex_cache, dex_field_idx);
634 if (f != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800635 return f;
636 }
637 }
638 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700639 return nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800640}
641
Mathieu Chartierf8322842014-05-16 10:59:25 -0700642ArtField* Class::FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
643 const StringPiece& type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800644 // Find a field using the JLS field resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700645 for (Class* k = klass.Get(); k != NULL; k = k->GetSuperClass()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800646 // Is the field in this class?
Brian Carlstromea46f952013-07-30 01:26:50 -0700647 ArtField* f = k->FindDeclaredInstanceField(name, type);
Mathieu Chartierf8322842014-05-16 10:59:25 -0700648 if (f != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800649 return f;
650 }
651 f = k->FindDeclaredStaticField(name, type);
Mathieu Chartierf8322842014-05-16 10:59:25 -0700652 if (f != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800653 return f;
654 }
655 // Is this field in any of this class' interfaces?
Mathieu Chartierf8322842014-05-16 10:59:25 -0700656 StackHandleScope<1> hs(self);
657 HandleWrapper<mirror::Class> h_k(hs.NewHandleWrapper(&k));
658 for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) {
659 StackHandleScope<1> hs(self);
660 Handle<mirror::Class> interface(hs.NewHandle(GetDirectInterface(self, h_k, i)));
661 f = interface->FindStaticField(self, interface, name, type);
662 if (f != nullptr) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800663 return f;
664 }
665 }
666 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700667 return nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800668}
669
Brian Carlstromea46f952013-07-30 01:26:50 -0700670static void SetPreverifiedFlagOnMethods(mirror::ObjectArray<mirror::ArtMethod>* methods)
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200671 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
672 if (methods != NULL) {
673 for (int32_t index = 0, end = methods->GetLength(); index < end; ++index) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700674 mirror::ArtMethod* method = methods->GetWithoutChecks(index);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200675 DCHECK(method != NULL);
Ian Rogers1eb512d2013-10-18 15:42:20 -0700676 if (!method->IsNative() && !method->IsAbstract()) {
677 method->SetPreverified();
678 }
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200679 }
680 }
681}
682
683void Class::SetPreverifiedFlagOnAllMethods() {
684 DCHECK(IsVerified());
685 SetPreverifiedFlagOnMethods(GetDirectMethods());
686 SetPreverifiedFlagOnMethods(GetVirtualMethods());
687}
688
Mathieu Chartierf8322842014-05-16 10:59:25 -0700689std::string Class::GetDescriptor() {
690 if (UNLIKELY(IsArrayClass())) {
691 return GetArrayDescriptor();
692 } else if (UNLIKELY(IsPrimitive())) {
693 return Primitive::Descriptor(GetPrimitiveType());
694 } else if (UNLIKELY(IsProxyClass())) {
695 return Runtime::Current()->GetClassLinker()->GetDescriptorForProxy(this);
696 } else {
697 const DexFile& dex_file = GetDexFile();
698 const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_);
699 return dex_file.GetTypeDescriptor(type_id);
700 }
701}
702
703std::string Class::GetArrayDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
704 return "[" + GetComponentType()->GetDescriptor();
705}
706
707const DexFile::ClassDef* Class::GetClassDef() {
708 uint16_t class_def_idx = GetDexClassDefIndex();
709 if (class_def_idx == DexFile::kDexNoIndex16) {
710 return nullptr;
711 }
712 return &GetDexFile().GetClassDef(class_def_idx);
713}
714
715uint32_t Class::NumDirectInterfaces() {
716 if (IsPrimitive()) {
717 return 0;
718 } else if (IsArrayClass()) {
719 return 2;
720 } else if (IsProxyClass()) {
721 mirror::SynthesizedProxyClass* proxy_class=
722 reinterpret_cast<mirror::SynthesizedProxyClass*>(this);
723 mirror::ObjectArray<mirror::Class>* interfaces = proxy_class->GetInterfaces();
724 return interfaces != nullptr ? interfaces->GetLength() : 0;
725 } else {
726 const DexFile::TypeList* interfaces = GetInterfaceTypeList();
727 if (interfaces == nullptr) {
728 return 0;
729 } else {
730 return interfaces->Size();
731 }
732 }
733}
734
735uint16_t Class::GetDirectInterfaceTypeIdx(uint32_t idx) {
736 DCHECK(!IsPrimitive());
737 DCHECK(!IsArrayClass());
738 return GetInterfaceTypeList()->GetTypeItem(idx).type_idx_;
739}
740
741mirror::Class* Class::GetDirectInterface(Thread* self, Handle<mirror::Class> klass, uint32_t idx) {
742 DCHECK(klass.Get() != nullptr);
743 DCHECK(!klass->IsPrimitive());
744 if (klass->IsArrayClass()) {
745 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
746 if (idx == 0) {
747 return class_linker->FindSystemClass(self, "Ljava/lang/Cloneable;");
748 } else {
749 DCHECK_EQ(1U, idx);
750 return class_linker->FindSystemClass(self, "Ljava/io/Serializable;");
751 }
752 } else if (klass->IsProxyClass()) {
753 mirror::SynthesizedProxyClass* proxy_class =
754 reinterpret_cast<mirror::SynthesizedProxyClass*>(klass.Get());
755 mirror::ObjectArray<mirror::Class>* interfaces = proxy_class->GetInterfaces();
756 DCHECK(interfaces != nullptr);
757 return interfaces->Get(idx);
758 } else {
759 uint16_t type_idx = klass->GetDirectInterfaceTypeIdx(idx);
760 mirror::Class* interface = klass->GetDexCache()->GetResolvedType(type_idx);
761 if (interface == nullptr) {
762 interface = Runtime::Current()->GetClassLinker()->ResolveType(klass->GetDexFile(), type_idx,
763 klass.Get());
764 CHECK(interface != nullptr || self->IsExceptionPending());
765 }
766 return interface;
767 }
768}
769
770const char* Class::GetSourceFile() {
771 std::string descriptor(GetDescriptor());
772 const DexFile& dex_file = GetDexFile();
773 const DexFile::ClassDef* dex_class_def = GetClassDef();
774 CHECK(dex_class_def != nullptr) << "No class def for class " << PrettyClass(this);
775 return dex_file.GetSourceFile(*dex_class_def);
776}
777
778std::string Class::GetLocation() {
779 mirror::DexCache* dex_cache = GetDexCache();
780 if (dex_cache != nullptr && !IsProxyClass()) {
781 return dex_cache->GetLocation()->ToModifiedUtf8();
782 }
783 // Arrays and proxies are generated and have no corresponding dex file location.
784 return "generated class";
785}
786
787const DexFile::TypeList* Class::GetInterfaceTypeList() {
788 const DexFile::ClassDef* class_def = GetClassDef();
789 if (class_def == nullptr) {
790 return nullptr;
791 }
792 return GetDexFile().GetInterfacesList(*class_def);
793}
794
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800795} // namespace mirror
796} // namespace art