class.cc revision 967a0adf8b93a23d2a8fef82e06bd913db94ac19
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
17#include "class.h"
18
19#include "art_field-inl.h"
20#include "art_method-inl.h"
21#include "class-inl.h"
22#include "class_linker.h"
23#include "class_loader.h"
24#include "dex_cache.h"
25#include "dex_file-inl.h"
26#include "gc/accounting/card_table-inl.h"
27#include "object-inl.h"
28#include "object_array-inl.h"
29#include "object_utils.h"
30#include "runtime.h"
31#include "sirt_ref.h"
32#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
53void Class::SetStatus(Status new_status, Thread* self) {
54  Status old_status = GetStatus();
55  bool class_linker_initialized = Runtime::Current()->GetClassLinker() != nullptr;
56  if (LIKELY(class_linker_initialized)) {
57    if (UNLIKELY(new_status <= old_status && new_status != kStatusError)) {
58      LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(this) << " "
59          << old_status << " -> " << new_status;
60    }
61    if (new_status >= kStatusResolved || old_status >= kStatusResolved) {
62      // When classes are being resolved the resolution code should hold the lock.
63      CHECK_EQ(GetThinLockId(), self->GetThinLockId())
64            << "Attempt to change status of class while not holding its lock: "
65            << PrettyClass(this) << " " << old_status << " -> " << new_status;
66    }
67  }
68  if (new_status == kStatusError) {
69    CHECK_NE(GetStatus(), kStatusError)
70        << "Attempt to set as erroneous an already erroneous class " << PrettyClass(this);
71
72    // Stash current exception.
73    SirtRef<mirror::Object> old_throw_this_object(self, NULL);
74    SirtRef<mirror::ArtMethod> old_throw_method(self, NULL);
75    SirtRef<mirror::Throwable> old_exception(self, NULL);
76    uint32_t old_throw_dex_pc;
77    {
78      ThrowLocation old_throw_location;
79      mirror::Throwable* old_exception_obj = self->GetException(&old_throw_location);
80      old_throw_this_object.reset(old_throw_location.GetThis());
81      old_throw_method.reset(old_throw_location.GetMethod());
82      old_exception.reset(old_exception_obj);
83      old_throw_dex_pc = old_throw_location.GetDexPc();
84      self->ClearException();
85    }
86    CHECK(old_exception.get() != NULL);
87
88    // clear exception to call FindSystemClass
89    self->ClearException();
90    ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
91    Class* eiie_class = class_linker->FindSystemClass("Ljava/lang/ExceptionInInitializerError;");
92    CHECK(!self->IsExceptionPending());
93
94    // Only verification errors, not initialization problems, should set a verify error.
95    // This is to ensure that ThrowEarlierClassFailure will throw NoClassDefFoundError in that case.
96    Class* exception_class = old_exception->GetClass();
97    if (!eiie_class->IsAssignableFrom(exception_class)) {
98      SetVerifyErrorClass(exception_class);
99    }
100
101    // Restore exception.
102    ThrowLocation gc_safe_throw_location(old_throw_this_object.get(), old_throw_method.get(),
103                                         old_throw_dex_pc);
104
105    self->SetException(gc_safe_throw_location, old_exception.get());
106  }
107  CHECK(sizeof(Status) == sizeof(uint32_t)) << PrettyClass(this);
108  SetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false);
109  // Classes that are being resolved or initialized need to notify waiters that the class status
110  // changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass.
111  if ((old_status >= kStatusResolved || new_status >= kStatusResolved) &&
112      class_linker_initialized) {
113    NotifyAll(self);
114  }
115}
116
117void Class::SetDexCache(DexCache* new_dex_cache) {
118  SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache, false);
119}
120
121void Class::SetClassSize(size_t new_class_size) {
122  DCHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this);
123  SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false);
124}
125
126// Return the class' name. The exact format is bizarre, but it's the specified behavior for
127// Class.getName: keywords for primitive types, regular "[I" form for primitive arrays (so "int"
128// but "[I"), and arrays of reference types written between "L" and ";" but with dots rather than
129// slashes (so "java.lang.String" but "[Ljava.lang.String;"). Madness.
130String* Class::ComputeName() {
131  String* name = GetName();
132  if (name != NULL) {
133    return name;
134  }
135  std::string descriptor(ClassHelper(this).GetDescriptor());
136  if ((descriptor[0] != 'L') && (descriptor[0] != '[')) {
137    // The descriptor indicates that this is the class for
138    // a primitive type; special-case the return value.
139    const char* c_name = NULL;
140    switch (descriptor[0]) {
141    case 'Z': c_name = "boolean"; break;
142    case 'B': c_name = "byte";    break;
143    case 'C': c_name = "char";    break;
144    case 'S': c_name = "short";   break;
145    case 'I': c_name = "int";     break;
146    case 'J': c_name = "long";    break;
147    case 'F': c_name = "float";   break;
148    case 'D': c_name = "double";  break;
149    case 'V': c_name = "void";    break;
150    default:
151      LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]);
152    }
153    name = String::AllocFromModifiedUtf8(Thread::Current(), c_name);
154  } else {
155    // Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package
156    // components.
157    if (descriptor.size() > 2 && descriptor[0] == 'L' && descriptor[descriptor.size() - 1] == ';') {
158      descriptor.erase(0, 1);
159      descriptor.erase(descriptor.size() - 1);
160    }
161    std::replace(descriptor.begin(), descriptor.end(), '/', '.');
162    name = String::AllocFromModifiedUtf8(Thread::Current(), descriptor.c_str());
163  }
164  SetName(name);
165  return name;
166}
167
168void Class::DumpClass(std::ostream& os, int flags) const {
169  if ((flags & kDumpClassFullDetail) == 0) {
170    os << PrettyClass(this);
171    if ((flags & kDumpClassClassLoader) != 0) {
172      os << ' ' << GetClassLoader();
173    }
174    if ((flags & kDumpClassInitialized) != 0) {
175      os << ' ' << GetStatus();
176    }
177    os << "\n";
178    return;
179  }
180
181  Class* super = GetSuperClass();
182  ClassHelper kh(this);
183  os << "----- " << (IsInterface() ? "interface" : "class") << " "
184     << "'" << kh.GetDescriptor() << "' cl=" << GetClassLoader() << " -----\n",
185  os << "  objectSize=" << SizeOf() << " "
186     << "(" << (super != NULL ? super->SizeOf() : -1) << " from super)\n",
187  os << StringPrintf("  access=0x%04x.%04x\n",
188      GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask);
189  if (super != NULL) {
190    os << "  super='" << PrettyClass(super) << "' (cl=" << super->GetClassLoader() << ")\n";
191  }
192  if (IsArrayClass()) {
193    os << "  componentType=" << PrettyClass(GetComponentType()) << "\n";
194  }
195  if (kh.NumDirectInterfaces() > 0) {
196    os << "  interfaces (" << kh.NumDirectInterfaces() << "):\n";
197    for (size_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
198      Class* interface = kh.GetDirectInterface(i);
199      const ClassLoader* cl = interface->GetClassLoader();
200      os << StringPrintf("    %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl);
201    }
202  }
203  os << "  vtable (" << NumVirtualMethods() << " entries, "
204     << (super != NULL ? super->NumVirtualMethods() : 0) << " in super):\n";
205  for (size_t i = 0; i < NumVirtualMethods(); ++i) {
206    os << StringPrintf("    %2zd: %s\n", i, PrettyMethod(GetVirtualMethodDuringLinking(i)).c_str());
207  }
208  os << "  direct methods (" << NumDirectMethods() << " entries):\n";
209  for (size_t i = 0; i < NumDirectMethods(); ++i) {
210    os << StringPrintf("    %2zd: %s\n", i, PrettyMethod(GetDirectMethod(i)).c_str());
211  }
212  if (NumStaticFields() > 0) {
213    os << "  static fields (" << NumStaticFields() << " entries):\n";
214    if (IsResolved() || IsErroneous()) {
215      for (size_t i = 0; i < NumStaticFields(); ++i) {
216        os << StringPrintf("    %2zd: %s\n", i, PrettyField(GetStaticField(i)).c_str());
217      }
218    } else {
219      os << "    <not yet available>";
220    }
221  }
222  if (NumInstanceFields() > 0) {
223    os << "  instance fields (" << NumInstanceFields() << " entries):\n";
224    if (IsResolved() || IsErroneous()) {
225      for (size_t i = 0; i < NumInstanceFields(); ++i) {
226        os << StringPrintf("    %2zd: %s\n", i, PrettyField(GetInstanceField(i)).c_str());
227      }
228    } else {
229      os << "    <not yet available>";
230    }
231  }
232}
233
234void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) {
235  if (new_reference_offsets != CLASS_WALK_SUPER) {
236    // Sanity check that the number of bits set in the reference offset bitmap
237    // agrees with the number of references
238    size_t count = 0;
239    for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
240      count += c->NumReferenceInstanceFieldsDuringLinking();
241    }
242    CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), count);
243  }
244  SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_),
245             new_reference_offsets, false);
246}
247
248void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) {
249  if (new_reference_offsets != CLASS_WALK_SUPER) {
250    // Sanity check that the number of bits set in the reference offset bitmap
251    // agrees with the number of references
252    CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets),
253             NumReferenceStaticFieldsDuringLinking());
254  }
255  SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_),
256             new_reference_offsets, false);
257}
258
259bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) {
260  size_t i = 0;
261  while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) {
262    ++i;
263  }
264  if (descriptor1.find('/', i) != StringPiece::npos ||
265      descriptor2.find('/', i) != StringPiece::npos) {
266    return false;
267  } else {
268    return true;
269  }
270}
271
272bool Class::IsInSamePackage(const Class* that) const {
273  const Class* klass1 = this;
274  const Class* klass2 = that;
275  if (klass1 == klass2) {
276    return true;
277  }
278  // Class loaders must match.
279  if (klass1->GetClassLoader() != klass2->GetClassLoader()) {
280    return false;
281  }
282  // Arrays are in the same package when their element classes are.
283  while (klass1->IsArrayClass()) {
284    klass1 = klass1->GetComponentType();
285  }
286  while (klass2->IsArrayClass()) {
287    klass2 = klass2->GetComponentType();
288  }
289  // trivial check again for array types
290  if (klass1 == klass2) {
291    return true;
292  }
293  // Compare the package part of the descriptor string.
294  if (LIKELY(!klass1->IsProxyClass() && !klass2->IsProxyClass())) {
295    ClassHelper kh(klass1);
296    const DexFile* dex_file1 = &kh.GetDexFile();
297    const DexFile::TypeId* type_id1 = &dex_file1->GetTypeId(klass1->GetDexTypeIndex());
298    const char* descriptor1 = dex_file1->GetTypeDescriptor(*type_id1);
299    kh.ChangeClass(klass2);
300    const DexFile* dex_file2 = &kh.GetDexFile();
301    const DexFile::TypeId* type_id2 = &dex_file2->GetTypeId(klass2->GetDexTypeIndex());
302    const char* descriptor2 = dex_file2->GetTypeDescriptor(*type_id2);
303    return IsInSamePackage(descriptor1, descriptor2);
304  }
305  ClassHelper kh(klass1);
306  std::string descriptor1(kh.GetDescriptor());
307  kh.ChangeClass(klass2);
308  std::string descriptor2(kh.GetDescriptor());
309  return IsInSamePackage(descriptor1, descriptor2);
310}
311
312bool Class::IsClassClass() const {
313  Class* java_lang_Class = GetClass()->GetClass();
314  return this == java_lang_Class;
315}
316
317bool Class::IsStringClass() const {
318  return this == String::GetJavaLangString();
319}
320
321bool Class::IsThrowableClass() const {
322  return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this);
323}
324
325bool Class::IsArtFieldClass() const {
326  Class* java_lang_Class = GetClass();
327  Class* java_lang_reflect_ArtField = java_lang_Class->GetInstanceField(0)->GetClass();
328  return this == java_lang_reflect_ArtField;
329}
330
331bool Class::IsArtMethodClass() const {
332  return this == ArtMethod::GetJavaLangReflectArtMethod();
333}
334
335void Class::SetClassLoader(ClassLoader* new_class_loader) {
336  SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false);
337}
338
339ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const StringPiece& signature) const {
340  // Check the current class before checking the interfaces.
341  ArtMethod* method = FindDeclaredVirtualMethod(name, signature);
342  if (method != NULL) {
343    return method;
344  }
345
346  int32_t iftable_count = GetIfTableCount();
347  IfTable* iftable = GetIfTable();
348  for (int32_t i = 0; i < iftable_count; i++) {
349    method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature);
350    if (method != NULL) {
351      return method;
352    }
353  }
354  return NULL;
355}
356
357ArtMethod* Class::FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
358  // Check the current class before checking the interfaces.
359  ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
360  if (method != NULL) {
361    return method;
362  }
363
364  int32_t iftable_count = GetIfTableCount();
365  IfTable* iftable = GetIfTable();
366  for (int32_t i = 0; i < iftable_count; i++) {
367    method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
368    if (method != NULL) {
369      return method;
370    }
371  }
372  return NULL;
373}
374
375
376ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const {
377  MethodHelper mh;
378  for (size_t i = 0; i < NumDirectMethods(); ++i) {
379    ArtMethod* method = GetDirectMethod(i);
380    mh.ChangeMethod(method);
381    if (name == mh.GetName() && signature == mh.GetSignature()) {
382      return method;
383    }
384  }
385  return NULL;
386}
387
388ArtMethod* Class::FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
389  if (GetDexCache() == dex_cache) {
390    for (size_t i = 0; i < NumDirectMethods(); ++i) {
391      ArtMethod* method = GetDirectMethod(i);
392      if (method->GetDexMethodIndex() == dex_method_idx) {
393        return method;
394      }
395    }
396  }
397  return NULL;
398}
399
400ArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature) const {
401  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
402    ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature);
403    if (method != NULL) {
404      return method;
405    }
406  }
407  return NULL;
408}
409
410ArtMethod* Class::FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
411  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
412    ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx);
413    if (method != NULL) {
414      return method;
415    }
416  }
417  return NULL;
418}
419
420ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name,
421                                         const StringPiece& signature) const {
422  MethodHelper mh;
423  for (size_t i = 0; i < NumVirtualMethods(); ++i) {
424    ArtMethod* method = GetVirtualMethod(i);
425    mh.ChangeMethod(method);
426    if (name == mh.GetName() && signature == mh.GetSignature()) {
427      return method;
428    }
429  }
430  return NULL;
431}
432
433ArtMethod* Class::FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
434  if (GetDexCache() == dex_cache) {
435    for (size_t i = 0; i < NumVirtualMethods(); ++i) {
436      ArtMethod* method = GetVirtualMethod(i);
437      if (method->GetDexMethodIndex() == dex_method_idx) {
438        return method;
439      }
440    }
441  }
442  return NULL;
443}
444
445ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const {
446  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
447    ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature);
448    if (method != NULL) {
449      return method;
450    }
451  }
452  return NULL;
453}
454
455ArtMethod* Class::FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
456  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
457    ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
458    if (method != NULL) {
459      return method;
460    }
461  }
462  return NULL;
463}
464
465ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) {
466  // Is the field in this class?
467  // Interfaces are not relevant because they can't contain instance fields.
468  FieldHelper fh;
469  for (size_t i = 0; i < NumInstanceFields(); ++i) {
470    ArtField* f = GetInstanceField(i);
471    fh.ChangeField(f);
472    if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
473      return f;
474    }
475  }
476  return NULL;
477}
478
479ArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
480  if (GetDexCache() == dex_cache) {
481    for (size_t i = 0; i < NumInstanceFields(); ++i) {
482      ArtField* f = GetInstanceField(i);
483      if (f->GetDexFieldIndex() == dex_field_idx) {
484        return f;
485      }
486    }
487  }
488  return NULL;
489}
490
491ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) {
492  // Is the field in this class, or any of its superclasses?
493  // Interfaces are not relevant because they can't contain instance fields.
494  for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
495    ArtField* f = c->FindDeclaredInstanceField(name, type);
496    if (f != NULL) {
497      return f;
498    }
499  }
500  return NULL;
501}
502
503ArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
504  // Is the field in this class, or any of its superclasses?
505  // Interfaces are not relevant because they can't contain instance fields.
506  for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
507    ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx);
508    if (f != NULL) {
509      return f;
510    }
511  }
512  return NULL;
513}
514
515ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) {
516  DCHECK(type != NULL);
517  FieldHelper fh;
518  for (size_t i = 0; i < NumStaticFields(); ++i) {
519    ArtField* f = GetStaticField(i);
520    fh.ChangeField(f);
521    if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
522      return f;
523    }
524  }
525  return NULL;
526}
527
528ArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
529  if (dex_cache == GetDexCache()) {
530    for (size_t i = 0; i < NumStaticFields(); ++i) {
531      ArtField* f = GetStaticField(i);
532      if (f->GetDexFieldIndex() == dex_field_idx) {
533        return f;
534      }
535    }
536  }
537  return NULL;
538}
539
540ArtField* Class::FindStaticField(const StringPiece& name, const StringPiece& type) {
541  // Is the field in this class (or its interfaces), or any of its
542  // superclasses (or their interfaces)?
543  ClassHelper kh;
544  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
545    // Is the field in this class?
546    ArtField* f = k->FindDeclaredStaticField(name, type);
547    if (f != NULL) {
548      return f;
549    }
550    // Is this field in any of this class' interfaces?
551    kh.ChangeClass(k);
552    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
553      Class* interface = kh.GetDirectInterface(i);
554      f = interface->FindStaticField(name, type);
555      if (f != NULL) {
556        return f;
557      }
558    }
559  }
560  return NULL;
561}
562
563ArtField* Class::FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
564  ClassHelper kh;
565  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
566    // Is the field in this class?
567    ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx);
568    if (f != NULL) {
569      return f;
570    }
571    // Is this field in any of this class' interfaces?
572    kh.ChangeClass(k);
573    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
574      Class* interface = kh.GetDirectInterface(i);
575      f = interface->FindStaticField(dex_cache, dex_field_idx);
576      if (f != NULL) {
577        return f;
578      }
579    }
580  }
581  return NULL;
582}
583
584ArtField* Class::FindField(const StringPiece& name, const StringPiece& type) {
585  // Find a field using the JLS field resolution order
586  ClassHelper kh;
587  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
588    // Is the field in this class?
589    ArtField* f = k->FindDeclaredInstanceField(name, type);
590    if (f != NULL) {
591      return f;
592    }
593    f = k->FindDeclaredStaticField(name, type);
594    if (f != NULL) {
595      return f;
596    }
597    // Is this field in any of this class' interfaces?
598    kh.ChangeClass(k);
599    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
600      Class* interface = kh.GetDirectInterface(i);
601      f = interface->FindStaticField(name, type);
602      if (f != NULL) {
603        return f;
604      }
605    }
606  }
607  return NULL;
608}
609
610static void SetPreverifiedFlagOnMethods(mirror::ObjectArray<mirror::ArtMethod>* methods)
611    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
612  if (methods != NULL) {
613    for (int32_t index = 0, end = methods->GetLength(); index < end; ++index) {
614      mirror::ArtMethod* method = methods->GetWithoutChecks(index);
615      DCHECK(method != NULL);
616      method->SetPreverified();
617    }
618  }
619}
620
621void Class::SetPreverifiedFlagOnAllMethods() {
622  DCHECK(IsVerified());
623  SetPreverifiedFlagOnMethods(GetDirectMethods());
624  SetPreverifiedFlagOnMethods(GetVirtualMethods());
625}
626
627}  // namespace mirror
628}  // namespace art
629