class.cc revision ea46f950e7a51585db293cd7f047de190a482414
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) {
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::ArtMethod> 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::IsArtFieldClass() const {
320  Class* java_lang_Class = GetClass();
321  Class* java_lang_reflect_ArtField = java_lang_Class->GetInstanceField(0)->GetClass();
322  return this == java_lang_reflect_ArtField;
323}
324
325bool Class::IsArtMethodClass() const {
326  return this == ArtMethod::GetJavaLangReflectArtMethod();
327}
328
329void Class::SetClassLoader(ClassLoader* new_class_loader) {
330  SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false);
331}
332
333ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const StringPiece& signature) const {
334  // Check the current class before checking the interfaces.
335  ArtMethod* method = FindDeclaredVirtualMethod(name, signature);
336  if (method != NULL) {
337    return method;
338  }
339
340  int32_t iftable_count = GetIfTableCount();
341  IfTable* iftable = GetIfTable();
342  for (int32_t i = 0; i < iftable_count; i++) {
343    method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature);
344    if (method != NULL) {
345      return method;
346    }
347  }
348  return NULL;
349}
350
351ArtMethod* Class::FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
352  // Check the current class before checking the interfaces.
353  ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
354  if (method != NULL) {
355    return method;
356  }
357
358  int32_t iftable_count = GetIfTableCount();
359  IfTable* iftable = GetIfTable();
360  for (int32_t i = 0; i < iftable_count; i++) {
361    method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
362    if (method != NULL) {
363      return method;
364    }
365  }
366  return NULL;
367}
368
369
370ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) const {
371  MethodHelper mh;
372  for (size_t i = 0; i < NumDirectMethods(); ++i) {
373    ArtMethod* method = GetDirectMethod(i);
374    mh.ChangeMethod(method);
375    if (name == mh.GetName() && signature == mh.GetSignature()) {
376      return method;
377    }
378  }
379  return NULL;
380}
381
382ArtMethod* Class::FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
383  if (GetDexCache() == dex_cache) {
384    for (size_t i = 0; i < NumDirectMethods(); ++i) {
385      ArtMethod* method = GetDirectMethod(i);
386      if (method->GetDexMethodIndex() == dex_method_idx) {
387        return method;
388      }
389    }
390  }
391  return NULL;
392}
393
394ArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature) const {
395  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
396    ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature);
397    if (method != NULL) {
398      return method;
399    }
400  }
401  return NULL;
402}
403
404ArtMethod* Class::FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
405  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
406    ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx);
407    if (method != NULL) {
408      return method;
409    }
410  }
411  return NULL;
412}
413
414ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name,
415                                         const StringPiece& signature) const {
416  MethodHelper mh;
417  for (size_t i = 0; i < NumVirtualMethods(); ++i) {
418    ArtMethod* method = GetVirtualMethod(i);
419    mh.ChangeMethod(method);
420    if (name == mh.GetName() && signature == mh.GetSignature()) {
421      return method;
422    }
423  }
424  return NULL;
425}
426
427ArtMethod* Class::FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
428  if (GetDexCache() == dex_cache) {
429    for (size_t i = 0; i < NumVirtualMethods(); ++i) {
430      ArtMethod* method = GetVirtualMethod(i);
431      if (method->GetDexMethodIndex() == dex_method_idx) {
432        return method;
433      }
434    }
435  }
436  return NULL;
437}
438
439ArtMethod* Class::FindVirtualMethod(const StringPiece& name, const StringPiece& signature) const {
440  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
441    ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature);
442    if (method != NULL) {
443      return method;
444    }
445  }
446  return NULL;
447}
448
449ArtMethod* Class::FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) const {
450  for (const Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
451    ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
452    if (method != NULL) {
453      return method;
454    }
455  }
456  return NULL;
457}
458
459ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) {
460  // Is the field in this class?
461  // Interfaces are not relevant because they can't contain instance fields.
462  FieldHelper fh;
463  for (size_t i = 0; i < NumInstanceFields(); ++i) {
464    ArtField* f = GetInstanceField(i);
465    fh.ChangeField(f);
466    if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
467      return f;
468    }
469  }
470  return NULL;
471}
472
473ArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
474  if (GetDexCache() == dex_cache) {
475    for (size_t i = 0; i < NumInstanceFields(); ++i) {
476      ArtField* f = GetInstanceField(i);
477      if (f->GetDexFieldIndex() == dex_field_idx) {
478        return f;
479      }
480    }
481  }
482  return NULL;
483}
484
485ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) {
486  // Is the field in this class, or any of its superclasses?
487  // Interfaces are not relevant because they can't contain instance fields.
488  for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
489    ArtField* f = c->FindDeclaredInstanceField(name, type);
490    if (f != NULL) {
491      return f;
492    }
493  }
494  return NULL;
495}
496
497ArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
498  // Is the field in this class, or any of its superclasses?
499  // Interfaces are not relevant because they can't contain instance fields.
500  for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
501    ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx);
502    if (f != NULL) {
503      return f;
504    }
505  }
506  return NULL;
507}
508
509ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) {
510  DCHECK(type != NULL);
511  FieldHelper fh;
512  for (size_t i = 0; i < NumStaticFields(); ++i) {
513    ArtField* f = GetStaticField(i);
514    fh.ChangeField(f);
515    if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
516      return f;
517    }
518  }
519  return NULL;
520}
521
522ArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
523  if (dex_cache == GetDexCache()) {
524    for (size_t i = 0; i < NumStaticFields(); ++i) {
525      ArtField* f = GetStaticField(i);
526      if (f->GetDexFieldIndex() == dex_field_idx) {
527        return f;
528      }
529    }
530  }
531  return NULL;
532}
533
534ArtField* Class::FindStaticField(const StringPiece& name, const StringPiece& type) {
535  // Is the field in this class (or its interfaces), or any of its
536  // superclasses (or their interfaces)?
537  ClassHelper kh;
538  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
539    // Is the field in this class?
540    ArtField* f = k->FindDeclaredStaticField(name, type);
541    if (f != NULL) {
542      return f;
543    }
544    // Is this field in any of this class' interfaces?
545    kh.ChangeClass(k);
546    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
547      Class* interface = kh.GetDirectInterface(i);
548      f = interface->FindStaticField(name, type);
549      if (f != NULL) {
550        return f;
551      }
552    }
553  }
554  return NULL;
555}
556
557ArtField* Class::FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
558  ClassHelper kh;
559  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
560    // Is the field in this class?
561    ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx);
562    if (f != NULL) {
563      return f;
564    }
565    // Is this field in any of this class' interfaces?
566    kh.ChangeClass(k);
567    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
568      Class* interface = kh.GetDirectInterface(i);
569      f = interface->FindStaticField(dex_cache, dex_field_idx);
570      if (f != NULL) {
571        return f;
572      }
573    }
574  }
575  return NULL;
576}
577
578ArtField* Class::FindField(const StringPiece& name, const StringPiece& type) {
579  // Find a field using the JLS field resolution order
580  ClassHelper kh;
581  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
582    // Is the field in this class?
583    ArtField* f = k->FindDeclaredInstanceField(name, type);
584    if (f != NULL) {
585      return f;
586    }
587    f = k->FindDeclaredStaticField(name, type);
588    if (f != NULL) {
589      return f;
590    }
591    // Is this field in any of this class' interfaces?
592    kh.ChangeClass(k);
593    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
594      Class* interface = kh.GetDirectInterface(i);
595      f = interface->FindStaticField(name, type);
596      if (f != NULL) {
597        return f;
598      }
599    }
600  }
601  return NULL;
602}
603
604static void SetPreverifiedFlagOnMethods(mirror::ObjectArray<mirror::ArtMethod>* methods)
605    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
606  if (methods != NULL) {
607    for (int32_t index = 0, end = methods->GetLength(); index < end; ++index) {
608      mirror::ArtMethod* method = methods->GetWithoutChecks(index);
609      DCHECK(method != NULL);
610      method->SetPreverified();
611    }
612  }
613}
614
615void Class::SetPreverifiedFlagOnAllMethods() {
616  DCHECK(IsVerified());
617  SetPreverifiedFlagOnMethods(GetDirectMethods());
618  SetPreverifiedFlagOnMethods(GetVirtualMethods());
619}
620
621}  // namespace mirror
622}  // namespace art
623