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