reg_type_cache.cc revision cd21f85f65197b7d52be1bd793d09cdfb05238ad
1/*
2 * Copyright (C) 2012 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 "reg_type_cache-inl.h"
18
19#include "base/casts.h"
20#include "class_linker-inl.h"
21#include "dex_file-inl.h"
22#include "mirror/class-inl.h"
23#include "mirror/object-inl.h"
24#include "object_utils.h"
25
26namespace art {
27namespace verifier {
28
29bool RegTypeCache::primitive_initialized_ = false;
30uint16_t RegTypeCache::primitive_count_ = 0;
31PreciseConstType* RegTypeCache::small_precise_constants_[kMaxSmallConstant - kMinSmallConstant + 1];
32
33static bool MatchingPrecisionForClass(RegType* entry, bool precise)
34    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
35  if (entry->IsPreciseReference() == precise) {
36    // We were or weren't looking for a precise reference and we found what we need.
37    return true;
38  } else {
39    if (!precise && entry->GetClass()->CannotBeAssignedFromOtherTypes()) {
40      // We weren't looking for a precise reference, as we're looking up based on a descriptor, but
41      // we found a matching entry based on the descriptor. Return the precise entry in that case.
42      return true;
43    }
44    return false;
45  }
46}
47
48void RegTypeCache::FillPrimitiveAndSmallConstantTypes() {
49  entries_.push_back(UndefinedType::GetInstance());
50  entries_.push_back(ConflictType::GetInstance());
51  entries_.push_back(BooleanType::GetInstance());
52  entries_.push_back(ByteType::GetInstance());
53  entries_.push_back(ShortType::GetInstance());
54  entries_.push_back(CharType::GetInstance());
55  entries_.push_back(IntegerType::GetInstance());
56  entries_.push_back(LongLoType::GetInstance());
57  entries_.push_back(LongHiType::GetInstance());
58  entries_.push_back(FloatType::GetInstance());
59  entries_.push_back(DoubleLoType::GetInstance());
60  entries_.push_back(DoubleHiType::GetInstance());
61  for (int32_t value = kMinSmallConstant; value <= kMaxSmallConstant; ++value) {
62    int32_t i = value - kMinSmallConstant;
63    DCHECK_EQ(entries_.size(), small_precise_constants_[i]->GetId());
64    entries_.push_back(small_precise_constants_[i]);
65  }
66  DCHECK_EQ(entries_.size(), primitive_count_);
67}
68
69const RegType& RegTypeCache::FromDescriptor(mirror::ClassLoader* loader, const char* descriptor,
70                                            bool precise) {
71  DCHECK(RegTypeCache::primitive_initialized_);
72  if (descriptor[1] == '\0') {
73    switch (descriptor[0]) {
74      case 'Z':
75        return Boolean();
76      case 'B':
77        return Byte();
78      case 'S':
79        return Short();
80      case 'C':
81        return Char();
82      case 'I':
83        return Integer();
84      case 'J':
85        return LongLo();
86      case 'F':
87        return Float();
88      case 'D':
89        return DoubleLo();
90      case 'V':  // For void types, conflict types.
91      default:
92        return Conflict();
93    }
94  } else if (descriptor[0] == 'L' || descriptor[0] == '[') {
95    return From(loader, descriptor, precise);
96  } else {
97    return Conflict();
98  }
99};
100
101const RegType& RegTypeCache::RegTypeFromPrimitiveType(Primitive::Type prim_type) const {
102  CHECK(RegTypeCache::primitive_initialized_);
103  switch (prim_type) {
104    case Primitive::kPrimBoolean:
105      return *BooleanType::GetInstance();
106    case Primitive::kPrimByte:
107      return *ByteType::GetInstance();
108    case Primitive::kPrimShort:
109      return *ShortType::GetInstance();
110    case Primitive::kPrimChar:
111      return *CharType::GetInstance();
112    case Primitive::kPrimInt:
113      return *IntegerType::GetInstance();
114    case Primitive::kPrimLong:
115      return *LongLoType::GetInstance();
116    case Primitive::kPrimFloat:
117      return *FloatType::GetInstance();
118    case Primitive::kPrimDouble:
119      return *DoubleLoType::GetInstance();
120    case Primitive::kPrimVoid:
121    default:
122      return *ConflictType::GetInstance();
123  }
124}
125
126bool RegTypeCache::MatchDescriptor(size_t idx, const char* descriptor, bool precise) {
127  RegType* entry = entries_[idx];
128  if (entry->descriptor_ != descriptor) {
129    return false;
130  }
131  if (entry->HasClass()) {
132    return MatchingPrecisionForClass(entry, precise);
133  }
134  // There is no notion of precise unresolved references, the precise information is just dropped
135  // on the floor.
136  DCHECK(entry->IsUnresolvedReference());
137  return true;
138}
139
140mirror::Class* RegTypeCache::ResolveClass(const char* descriptor, mirror::ClassLoader* loader) {
141  // Class was not found, must create new type.
142  // Try resolving class
143  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
144  Thread* self = Thread::Current();
145  StackHandleScope<1> hs(self);
146  Handle<mirror::ClassLoader> class_loader(hs.NewHandle(loader));
147  mirror::Class* klass = NULL;
148  if (can_load_classes_) {
149    klass = class_linker->FindClass(self, descriptor, class_loader);
150  } else {
151    klass = class_linker->LookupClass(descriptor, loader);
152    if (klass != nullptr && !klass->IsLoaded()) {
153      // We found the class but without it being loaded its not safe for use.
154      klass = nullptr;
155    }
156  }
157  return klass;
158}
159
160const RegType& RegTypeCache::From(mirror::ClassLoader* loader, const char* descriptor,
161                                  bool precise) {
162  // Try looking up the class in the cache first.
163  for (size_t i = primitive_count_; i < entries_.size(); i++) {
164    if (MatchDescriptor(i, descriptor, precise)) {
165      return *(entries_[i]);
166    }
167  }
168  // Class not found in the cache, will create a new type for that.
169  // Try resolving class.
170  mirror::Class* klass = ResolveClass(descriptor, loader);
171  if (klass != NULL) {
172    // Class resolved, first look for the class in the list of entries
173    // Class was not found, must create new type.
174    // To pass the verification, the type should be imprecise,
175    // instantiable or an interface with the precise type set to false.
176    DCHECK(!precise || klass->IsInstantiable());
177    // Create a precise type if:
178    // 1- Class is final and NOT an interface. a precise interface is meaningless !!
179    // 2- Precise Flag passed as true.
180    RegType* entry;
181    // Create an imprecise type if we can't tell for a fact that it is precise.
182    if (klass->CannotBeAssignedFromOtherTypes() || precise) {
183      DCHECK(!(klass->IsAbstract()) || klass->IsArrayClass());
184      DCHECK(!klass->IsInterface());
185      entry = new PreciseReferenceType(klass, descriptor, entries_.size());
186    } else {
187      entry = new ReferenceType(klass, descriptor, entries_.size());
188    }
189    AddEntry(entry);
190    return *entry;
191  } else {  // Class not resolved.
192    // We tried loading the class and failed, this might get an exception raised
193    // so we want to clear it before we go on.
194    if (can_load_classes_) {
195      DCHECK(Thread::Current()->IsExceptionPending());
196      Thread::Current()->ClearException();
197    } else {
198      DCHECK(!Thread::Current()->IsExceptionPending());
199    }
200    if (IsValidDescriptor(descriptor)) {
201      RegType* entry = new UnresolvedReferenceType(descriptor, entries_.size());
202      AddEntry(entry);
203      return *entry;
204    } else {
205      // The descriptor is broken return the unknown type as there's nothing sensible that
206      // could be done at runtime
207      return Conflict();
208    }
209  }
210}
211
212const RegType& RegTypeCache::FromClass(const char* descriptor, mirror::Class* klass, bool precise) {
213  DCHECK(klass != nullptr && !klass->IsErroneous());
214  if (klass->IsPrimitive()) {
215    // Note: precise isn't used for primitive classes. A char is assignable to an int. All
216    // primitive classes are final.
217    return RegTypeFromPrimitiveType(klass->GetPrimitiveType());
218  } else {
219    // Look for the reference in the list of entries to have.
220    for (size_t i = primitive_count_; i < entries_.size(); i++) {
221      RegType* cur_entry = entries_[i];
222      if (cur_entry->klass_ == klass && MatchingPrecisionForClass(cur_entry, precise)) {
223        return *cur_entry;
224      }
225    }
226    // No reference to the class was found, create new reference.
227    RegType* entry;
228    if (precise) {
229      entry = new PreciseReferenceType(klass, descriptor, entries_.size());
230    } else {
231      entry = new ReferenceType(klass, descriptor, entries_.size());
232    }
233    AddEntry(entry);
234    return *entry;
235  }
236}
237
238RegTypeCache::RegTypeCache(bool can_load_classes) : can_load_classes_(can_load_classes) {
239  if (kIsDebugBuild && can_load_classes) {
240    Thread::Current()->AssertThreadSuspensionIsAllowable();
241  }
242  entries_.reserve(64);
243  FillPrimitiveAndSmallConstantTypes();
244}
245
246RegTypeCache::~RegTypeCache() {
247  CHECK_LE(primitive_count_, entries_.size());
248  // Delete only the non primitive types.
249  if (entries_.size() == kNumPrimitivesAndSmallConstants) {
250    // All entries are from the global pool, nothing to delete.
251    return;
252  }
253  std::vector<RegType*>::iterator non_primitive_begin = entries_.begin();
254  std::advance(non_primitive_begin, kNumPrimitivesAndSmallConstants);
255  STLDeleteContainerPointers(non_primitive_begin, entries_.end());
256}
257
258void RegTypeCache::ShutDown() {
259  if (RegTypeCache::primitive_initialized_) {
260    UndefinedType::Destroy();
261    ConflictType::Destroy();
262    BooleanType::Destroy();
263    ByteType::Destroy();
264    ShortType::Destroy();
265    CharType::Destroy();
266    IntegerType::Destroy();
267    LongLoType::Destroy();
268    LongHiType::Destroy();
269    FloatType::Destroy();
270    DoubleLoType::Destroy();
271    DoubleHiType::Destroy();
272    for (int32_t value = kMinSmallConstant; value <= kMaxSmallConstant; ++value) {
273      PreciseConstType* type = small_precise_constants_[value - kMinSmallConstant];
274      delete type;
275      small_precise_constants_[value - kMinSmallConstant] = nullptr;
276    }
277    RegTypeCache::primitive_initialized_ = false;
278    RegTypeCache::primitive_count_ = 0;
279  }
280}
281
282template <class Type>
283Type* RegTypeCache::CreatePrimitiveTypeInstance(const std::string& descriptor) {
284  mirror::Class* klass = NULL;
285  // Try loading the class from linker.
286  if (!descriptor.empty()) {
287    klass = art::Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(),
288                                                                       descriptor.c_str());
289  }
290  Type* entry = Type::CreateInstance(klass, descriptor, RegTypeCache::primitive_count_);
291  RegTypeCache::primitive_count_++;
292  return entry;
293}
294
295void RegTypeCache::CreatePrimitiveAndSmallConstantTypes() {
296  CreatePrimitiveTypeInstance<UndefinedType>("");
297  CreatePrimitiveTypeInstance<ConflictType>("");
298  CreatePrimitiveTypeInstance<BooleanType>("Z");
299  CreatePrimitiveTypeInstance<ByteType>("B");
300  CreatePrimitiveTypeInstance<ShortType>("S");
301  CreatePrimitiveTypeInstance<CharType>("C");
302  CreatePrimitiveTypeInstance<IntegerType>("I");
303  CreatePrimitiveTypeInstance<LongLoType>("J");
304  CreatePrimitiveTypeInstance<LongHiType>("J");
305  CreatePrimitiveTypeInstance<FloatType>("F");
306  CreatePrimitiveTypeInstance<DoubleLoType>("D");
307  CreatePrimitiveTypeInstance<DoubleHiType>("D");
308  for (int32_t value = kMinSmallConstant; value <= kMaxSmallConstant; ++value) {
309    PreciseConstType* type = new PreciseConstType(value, primitive_count_);
310    small_precise_constants_[value - kMinSmallConstant] = type;
311    primitive_count_++;
312  }
313}
314
315const RegType& RegTypeCache::FromUnresolvedMerge(const RegType& left, const RegType& right) {
316  std::set<uint16_t> types;
317  if (left.IsUnresolvedMergedReference()) {
318    RegType& non_const(const_cast<RegType&>(left));
319    types = (down_cast<UnresolvedMergedType*>(&non_const))->GetMergedTypes();
320  } else {
321    types.insert(left.GetId());
322  }
323  if (right.IsUnresolvedMergedReference()) {
324    RegType& non_const(const_cast<RegType&>(right));
325    std::set<uint16_t> right_types = (down_cast<UnresolvedMergedType*>(&non_const))->GetMergedTypes();
326    types.insert(right_types.begin(), right_types.end());
327  } else {
328    types.insert(right.GetId());
329  }
330  // Check if entry already exists.
331  for (size_t i = primitive_count_; i < entries_.size(); i++) {
332    RegType* cur_entry = entries_[i];
333    if (cur_entry->IsUnresolvedMergedReference()) {
334      std::set<uint16_t> cur_entry_types =
335          (down_cast<UnresolvedMergedType*>(cur_entry))->GetMergedTypes();
336      if (cur_entry_types == types) {
337        return *cur_entry;
338      }
339    }
340  }
341  // Create entry.
342  RegType* entry = new UnresolvedMergedType(left.GetId(), right.GetId(), this, entries_.size());
343  AddEntry(entry);
344  if (kIsDebugBuild) {
345    UnresolvedMergedType* tmp_entry = down_cast<UnresolvedMergedType*>(entry);
346    std::set<uint16_t> check_types = tmp_entry->GetMergedTypes();
347    CHECK(check_types == types);
348  }
349  return *entry;
350}
351
352const RegType& RegTypeCache::FromUnresolvedSuperClass(const RegType& child) {
353  // Check if entry already exists.
354  for (size_t i = primitive_count_; i < entries_.size(); i++) {
355    RegType* cur_entry = entries_[i];
356    if (cur_entry->IsUnresolvedSuperClass()) {
357      UnresolvedSuperClass* tmp_entry =
358          down_cast<UnresolvedSuperClass*>(cur_entry);
359      uint16_t unresolved_super_child_id =
360          tmp_entry->GetUnresolvedSuperClassChildId();
361      if (unresolved_super_child_id == child.GetId()) {
362        return *cur_entry;
363      }
364    }
365  }
366  RegType* entry = new UnresolvedSuperClass(child.GetId(), this, entries_.size());
367  AddEntry(entry);
368  return *entry;
369}
370
371const UninitializedType& RegTypeCache::Uninitialized(const RegType& type, uint32_t allocation_pc) {
372  UninitializedType* entry = NULL;
373  const std::string& descriptor(type.GetDescriptor());
374  if (type.IsUnresolvedTypes()) {
375    for (size_t i = primitive_count_; i < entries_.size(); i++) {
376      RegType* cur_entry = entries_[i];
377      if (cur_entry->IsUnresolvedAndUninitializedReference() &&
378          down_cast<UnresolvedUninitializedRefType*>(cur_entry)->GetAllocationPc() == allocation_pc &&
379          (cur_entry->GetDescriptor() == descriptor)) {
380        return *down_cast<UnresolvedUninitializedRefType*>(cur_entry);
381      }
382    }
383    entry = new UnresolvedUninitializedRefType(descriptor, allocation_pc, entries_.size());
384  } else {
385    mirror::Class* klass = type.GetClass();
386    for (size_t i = primitive_count_; i < entries_.size(); i++) {
387      RegType* cur_entry = entries_[i];
388      if (cur_entry->IsUninitializedReference() &&
389          down_cast<UninitializedReferenceType*>(cur_entry)
390              ->GetAllocationPc() == allocation_pc &&
391          cur_entry->GetClass() == klass) {
392        return *down_cast<UninitializedReferenceType*>(cur_entry);
393      }
394    }
395    entry = new UninitializedReferenceType(klass, descriptor, allocation_pc, entries_.size());
396  }
397  AddEntry(entry);
398  return *entry;
399}
400
401const RegType& RegTypeCache::FromUninitialized(const RegType& uninit_type) {
402  RegType* entry;
403
404  if (uninit_type.IsUnresolvedTypes()) {
405    const std::string& descriptor(uninit_type.GetDescriptor());
406    for (size_t i = primitive_count_; i < entries_.size(); i++) {
407      RegType* cur_entry = entries_[i];
408      if (cur_entry->IsUnresolvedReference() &&
409          cur_entry->GetDescriptor() == descriptor) {
410        return *cur_entry;
411      }
412    }
413    entry = new UnresolvedReferenceType(descriptor.c_str(), entries_.size());
414  } else {
415    mirror::Class* klass = uninit_type.GetClass();
416    if (uninit_type.IsUninitializedThisReference() && !klass->IsFinal()) {
417      // For uninitialized "this reference" look for reference types that are not precise.
418      for (size_t i = primitive_count_; i < entries_.size(); i++) {
419        RegType* cur_entry = entries_[i];
420        if (cur_entry->IsReference() && cur_entry->GetClass() == klass) {
421          return *cur_entry;
422        }
423      }
424      entry = new ReferenceType(klass, "", entries_.size());
425    } else if (klass->IsInstantiable()) {
426      // We're uninitialized because of allocation, look or create a precise type as allocations
427      // may only create objects of that type.
428      for (size_t i = primitive_count_; i < entries_.size(); i++) {
429        RegType* cur_entry = entries_[i];
430        if (cur_entry->IsPreciseReference() && cur_entry->GetClass() == klass) {
431          return *cur_entry;
432        }
433      }
434      entry = new PreciseReferenceType(klass, uninit_type.GetDescriptor(), entries_.size());
435    } else {
436      return Conflict();
437    }
438  }
439  AddEntry(entry);
440  return *entry;
441}
442
443const ImpreciseConstType& RegTypeCache::ByteConstant() {
444  const ConstantType& result = FromCat1Const(std::numeric_limits<jbyte>::min(), false);
445  DCHECK(result.IsImpreciseConstant());
446  return *down_cast<const ImpreciseConstType*>(&result);
447}
448
449const ImpreciseConstType& RegTypeCache::CharConstant() {
450  int32_t jchar_max = static_cast<int32_t>(std::numeric_limits<jchar>::max());
451  const ConstantType& result =  FromCat1Const(jchar_max, false);
452  DCHECK(result.IsImpreciseConstant());
453  return *down_cast<const ImpreciseConstType*>(&result);
454}
455
456const ImpreciseConstType& RegTypeCache::ShortConstant() {
457  const ConstantType& result =  FromCat1Const(std::numeric_limits<jshort>::min(), false);
458  DCHECK(result.IsImpreciseConstant());
459  return *down_cast<const ImpreciseConstType*>(&result);
460}
461
462const ImpreciseConstType& RegTypeCache::IntConstant() {
463  const ConstantType& result = FromCat1Const(std::numeric_limits<jint>::max(), false);
464  DCHECK(result.IsImpreciseConstant());
465  return *down_cast<const ImpreciseConstType*>(&result);
466}
467
468const ImpreciseConstType& RegTypeCache::PosByteConstant() {
469  const ConstantType& result = FromCat1Const(std::numeric_limits<jbyte>::max(), false);
470  DCHECK(result.IsImpreciseConstant());
471  return *down_cast<const ImpreciseConstType*>(&result);
472}
473
474const ImpreciseConstType& RegTypeCache::PosShortConstant() {
475  const ConstantType& result =  FromCat1Const(std::numeric_limits<jshort>::max(), false);
476  DCHECK(result.IsImpreciseConstant());
477  return *down_cast<const ImpreciseConstType*>(&result);
478}
479
480const UninitializedType& RegTypeCache::UninitializedThisArgument(const RegType& type) {
481  UninitializedType* entry;
482  const std::string& descriptor(type.GetDescriptor());
483  if (type.IsUnresolvedTypes()) {
484    for (size_t i = primitive_count_; i < entries_.size(); i++) {
485      RegType* cur_entry = entries_[i];
486      if (cur_entry->IsUnresolvedAndUninitializedThisReference() &&
487          cur_entry->GetDescriptor() == descriptor) {
488        return *down_cast<UninitializedType*>(cur_entry);
489      }
490    }
491    entry = new UnresolvedUninitializedThisRefType(descriptor, entries_.size());
492  } else {
493    mirror::Class* klass = type.GetClass();
494    for (size_t i = primitive_count_; i < entries_.size(); i++) {
495      RegType* cur_entry = entries_[i];
496      if (cur_entry->IsUninitializedThisReference() && cur_entry->GetClass() == klass) {
497        return *down_cast<UninitializedType*>(cur_entry);
498      }
499    }
500    entry = new UninitializedThisReferenceType(klass, descriptor, entries_.size());
501  }
502  AddEntry(entry);
503  return *entry;
504}
505
506const ConstantType& RegTypeCache::FromCat1NonSmallConstant(int32_t value, bool precise) {
507  for (size_t i = primitive_count_; i < entries_.size(); i++) {
508    RegType* cur_entry = entries_[i];
509    if (cur_entry->klass_ == NULL && cur_entry->IsConstant() &&
510        cur_entry->IsPreciseConstant() == precise &&
511        (down_cast<ConstantType*>(cur_entry))->ConstantValue() == value) {
512      return *down_cast<ConstantType*>(cur_entry);
513    }
514  }
515  ConstantType* entry;
516  if (precise) {
517    entry = new PreciseConstType(value, entries_.size());
518  } else {
519    entry = new ImpreciseConstType(value, entries_.size());
520  }
521  AddEntry(entry);
522  return *entry;
523}
524
525const ConstantType& RegTypeCache::FromCat2ConstLo(int32_t value, bool precise) {
526  for (size_t i = primitive_count_; i < entries_.size(); i++) {
527    RegType* cur_entry = entries_[i];
528    if (cur_entry->IsConstantLo() && (cur_entry->IsPrecise() == precise) &&
529        (down_cast<ConstantType*>(cur_entry))->ConstantValueLo() == value) {
530      return *down_cast<ConstantType*>(cur_entry);
531    }
532  }
533  ConstantType* entry;
534  if (precise) {
535    entry = new PreciseConstLoType(value, entries_.size());
536  } else {
537    entry = new ImpreciseConstLoType(value, entries_.size());
538  }
539  AddEntry(entry);
540  return *entry;
541}
542
543const ConstantType& RegTypeCache::FromCat2ConstHi(int32_t value, bool precise) {
544  for (size_t i = primitive_count_; i < entries_.size(); i++) {
545    RegType* cur_entry = entries_[i];
546    if (cur_entry->IsConstantHi() && (cur_entry->IsPrecise() == precise) &&
547        (down_cast<ConstantType*>(cur_entry))->ConstantValueHi() == value) {
548      return *down_cast<ConstantType*>(cur_entry);
549    }
550  }
551  ConstantType* entry;
552  if (precise) {
553    entry = new PreciseConstHiType(value, entries_.size());
554  } else {
555    entry = new ImpreciseConstHiType(value, entries_.size());
556  }
557  AddEntry(entry);
558  return *entry;
559}
560
561const RegType& RegTypeCache::GetComponentType(const RegType& array, mirror::ClassLoader* loader) {
562  if (!array.IsArrayTypes()) {
563    return Conflict();
564  } else if (array.IsUnresolvedTypes()) {
565    const std::string& descriptor(array.GetDescriptor());
566    const std::string component(descriptor.substr(1, descriptor.size() - 1));
567    return FromDescriptor(loader, component.c_str(), false);
568  } else {
569    mirror::Class* klass = array.GetClass()->GetComponentType();
570    if (klass->IsErroneous()) {
571      // Arrays may have erroneous component types, use unresolved in that case.
572      // We assume that the primitive classes are not erroneous, so we know it is a
573      // reference type.
574      return FromDescriptor(loader, klass->GetDescriptor().c_str(), false);
575    } else {
576      return FromClass(klass->GetDescriptor().c_str(), klass,
577                       klass->CannotBeAssignedFromOtherTypes());
578    }
579  }
580}
581
582void RegTypeCache::Dump(std::ostream& os) {
583  for (size_t i = 0; i < entries_.size(); i++) {
584    RegType* cur_entry = entries_[i];
585    if (cur_entry != NULL) {
586      os << i << ": " << cur_entry->Dump() << "\n";
587    }
588  }
589}
590
591void RegTypeCache::VisitRoots(RootCallback* callback, void* arg) {
592  for (RegType* entry : entries_) {
593    entry->VisitRoots(callback, arg);
594  }
595}
596
597void RegTypeCache::AddEntry(RegType* new_entry) {
598  entries_.push_back(new_entry);
599}
600
601}  // namespace verifier
602}  // namespace art
603