class.cc revision 815873ecc312b1d231acce71e1a16f42cdaf09f2
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
1610037c866b04550fc5461058c398c2e3e509381ajeffhao
1710037c866b04550fc5461058c398c2e3e509381ajeffhao#include "class.h"
1810037c866b04550fc5461058c398c2e3e509381ajeffhao
19e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe#include "art_field-inl.h"
2092572be7f754c213e615a62955cc5f65ca8c0c0eNarayan Kamath#include "art_method-inl.h"
21e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe#include "class-inl.h"
22700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers#include "class_linker.h"
2392572be7f754c213e615a62955cc5f65ca8c0c0eNarayan Kamath#include "class_loader.h"
24e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "dex_cache.h"
254f6ad8ab428038129b2d0d6c40b7fd625cca15e1Ian Rogers#include "dex_file-inl.h"
2610037c866b04550fc5461058c398c2e3e509381ajeffhao#include "gc/accounting/card_table-inl.h"
27a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "object-inl.h"
28a67249065e4c9b3cf4a7c081d95a78df28291ee9Ian Rogers#include "object_array-inl.h"
292dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "object_utils.h"
3010037c866b04550fc5461058c398c2e3e509381ajeffhao#include "runtime.h"
3110037c866b04550fc5461058c398c2e3e509381ajeffhao#include "sirt_ref.h"
3210037c866b04550fc5461058c398c2e3e509381ajeffhao#include "thread.h"
3310037c866b04550fc5461058c398c2e3e509381ajeffhao#include "throwable.h"
3410037c866b04550fc5461058c398c2e3e509381ajeffhao#include "utils.h"
3510037c866b04550fc5461058c398c2e3e509381ajeffhao#include "well_known_classes.h"
3610037c866b04550fc5461058c398c2e3e509381ajeffhao
3710037c866b04550fc5461058c398c2e3e509381ajeffhaonamespace art {
3810037c866b04550fc5461058c398c2e3e509381ajeffhaonamespace mirror {
3910037c866b04550fc5461058c398c2e3e509381ajeffhao
4010037c866b04550fc5461058c398c2e3e509381ajeffhaoClass* Class::java_lang_Class_ = NULL;
4110037c866b04550fc5461058c398c2e3e509381ajeffhao
4210037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::SetClassClass(Class* java_lang_Class) {
4310037c866b04550fc5461058c398c2e3e509381ajeffhao  CHECK(java_lang_Class_ == NULL) << java_lang_Class_ << " " << java_lang_Class;
4410037c866b04550fc5461058c398c2e3e509381ajeffhao  CHECK(java_lang_Class != NULL);
4510037c866b04550fc5461058c398c2e3e509381ajeffhao  java_lang_Class_ = java_lang_Class;
4610037c866b04550fc5461058c398c2e3e509381ajeffhao}
4710037c866b04550fc5461058c398c2e3e509381ajeffhao
4810037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::ResetClass() {
4910037c866b04550fc5461058c398c2e3e509381ajeffhao  CHECK(java_lang_Class_ != NULL);
5010037c866b04550fc5461058c398c2e3e509381ajeffhao  java_lang_Class_ = NULL;
5110037c866b04550fc5461058c398c2e3e509381ajeffhao}
5210037c866b04550fc5461058c398c2e3e509381ajeffhao
5310037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::VisitRoots(RootCallback* callback, void* arg) {
5410037c866b04550fc5461058c398c2e3e509381ajeffhao  if (java_lang_Class_ != nullptr) {
5510037c866b04550fc5461058c398c2e3e509381ajeffhao    callback(reinterpret_cast<mirror::Object**>(&java_lang_Class_), arg, 0, kRootStickyClass);
5610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
5710037c866b04550fc5461058c398c2e3e509381ajeffhao}
5810037c866b04550fc5461058c398c2e3e509381ajeffhao
5910037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::SetStatus(Status new_status, Thread* self) {
6010037c866b04550fc5461058c398c2e3e509381ajeffhao  Status old_status = GetStatus();
6110037c866b04550fc5461058c398c2e3e509381ajeffhao  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
6210037c866b04550fc5461058c398c2e3e509381ajeffhao  bool class_linker_initialized = class_linker != nullptr && class_linker->IsInitialized();
6310037c866b04550fc5461058c398c2e3e509381ajeffhao  if (LIKELY(class_linker_initialized)) {
6410037c866b04550fc5461058c398c2e3e509381ajeffhao    if (UNLIKELY(new_status <= old_status && new_status != kStatusError)) {
6510037c866b04550fc5461058c398c2e3e509381ajeffhao      LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(this) << " "
6610037c866b04550fc5461058c398c2e3e509381ajeffhao          << old_status << " -> " << new_status;
6710037c866b04550fc5461058c398c2e3e509381ajeffhao    }
6810037c866b04550fc5461058c398c2e3e509381ajeffhao    if (new_status >= kStatusResolved || old_status >= kStatusResolved) {
6910037c866b04550fc5461058c398c2e3e509381ajeffhao      // When classes are being resolved the resolution code should hold the lock.
7010037c866b04550fc5461058c398c2e3e509381ajeffhao      CHECK_EQ(GetLockOwnerThreadId(), self->GetThreadId())
71e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe            << "Attempt to change status of class while not holding its lock: "
72df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe            << PrettyClass(this) << " " << old_status << " -> " << new_status;
73e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    }
74e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  }
75e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  if (new_status == kStatusError) {
76e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    CHECK_NE(GetStatus(), kStatusError)
77e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe        << "Attempt to set as erroneous an already erroneous class " << PrettyClass(this);
78e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe
79df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe    // Stash current exception.
80e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    SirtRef<mirror::Object> old_throw_this_object(self, NULL);
81e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    SirtRef<mirror::ArtMethod> old_throw_method(self, NULL);
82e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    SirtRef<mirror::Throwable> old_exception(self, NULL);
83e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    uint32_t old_throw_dex_pc;
84e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    {
85e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      ThrowLocation old_throw_location;
86e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      mirror::Throwable* old_exception_obj = self->GetException(&old_throw_location);
87e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      old_throw_this_object.reset(old_throw_location.GetThis());
88df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe      old_throw_method.reset(old_throw_location.GetMethod());
89e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      old_exception.reset(old_exception_obj);
90e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      old_throw_dex_pc = old_throw_location.GetDexPc();
91e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      self->ClearException();
92e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    }
93e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    CHECK(old_exception.get() != NULL);
94e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe
95df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe    // clear exception to call FindSystemClass
96e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    self->ClearException();
97e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
98e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    Class* eiie_class = class_linker->FindSystemClass("Ljava/lang/ExceptionInInitializerError;");
99e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    CHECK(!self->IsExceptionPending());
100e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe
101e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    // Only verification errors, not initialization problems, should set a verify error.
102e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    // This is to ensure that ThrowEarlierClassFailure will throw NoClassDefFoundError in that case.
103e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    Class* exception_class = old_exception->GetClass();
104df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe    if (!eiie_class->IsAssignableFrom(exception_class)) {
105e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe      SetVerifyErrorClass(exception_class);
106e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    }
107e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe
108e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    // Restore exception.
109e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    ThrowLocation gc_safe_throw_location(old_throw_this_object.get(), old_throw_method.get(),
110e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe                                         old_throw_dex_pc);
111df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe
112e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    self->SetException(gc_safe_throw_location, old_exception.get());
113e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  }
114e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  CHECK(sizeof(Status) == sizeof(uint32_t)) << PrettyClass(this);
115e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  if (Runtime::Current()->IsActiveTransaction()) {
1165e31ddadd29325649260aa186e9ffa8ccdb370a2Andreas Gampe    SetField32<true>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false);
117e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  } else {
118df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe    SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status, false);
1195e31ddadd29325649260aa186e9ffa8ccdb370a2Andreas Gampe  }
120e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  // Classes that are being resolved or initialized need to notify waiters that the class status
121e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  // changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass.
122e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe  if ((old_status >= kStatusResolved || new_status >= kStatusResolved) &&
1235e31ddadd29325649260aa186e9ffa8ccdb370a2Andreas Gampe      class_linker_initialized) {
124e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe    NotifyAll(self);
125df10b32c4d0adfa86201169692eaa7ef038b642cAndreas Gampe  }
1265e31ddadd29325649260aa186e9ffa8ccdb370a2Andreas Gampe}
127e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampe
128e09269ca05e3014e86198e9a2cf6092026fafefdAndreas Gampevoid Class::SetDexCache(DexCache* new_dex_cache) {
12913735955f39b3b304c37d2b2840663c131262c18Ian Rogers  SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache, false);
1308d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
131700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers
1328d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogersvoid Class::SetClassSize(uint32_t new_class_size) {
1338d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  if (kIsDebugBuild && (new_class_size < GetClassSize())) {
1348d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    DumpClass(LOG(ERROR), kDumpClassFullDetail);
1358d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    CHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this);
1368d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  }
1378d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  // Not called within a transaction.
1388d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false);
1398d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
1408d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
14110037c866b04550fc5461058c398c2e3e509381ajeffhao// Return the class' name. The exact format is bizarre, but it's the specified behavior for
14210037c866b04550fc5461058c398c2e3e509381ajeffhao// Class.getName: keywords for primitive types, regular "[I" form for primitive arrays (so "int"
1438d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers// but "[I"), and arrays of reference types written between "L" and ";" but with dots rather than
1448d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers// slashes (so "java.lang.String" but "[Ljava.lang.String;"). Madness.
14510037c866b04550fc5461058c398c2e3e509381ajeffhaoString* Class::ComputeName() {
14610037c866b04550fc5461058c398c2e3e509381ajeffhao  String* name = GetName();
147fc787ecd91127b2c8458afd94e5148e2ae51a1f5Ian Rogers  if (name != nullptr) {
14810037c866b04550fc5461058c398c2e3e509381ajeffhao    return name;
14910037c866b04550fc5461058c398c2e3e509381ajeffhao  }
15010037c866b04550fc5461058c398c2e3e509381ajeffhao  Thread* self = Thread::Current();
15110037c866b04550fc5461058c398c2e3e509381ajeffhao  SirtRef<mirror::Class> sirt_c(self, this);
15210037c866b04550fc5461058c398c2e3e509381ajeffhao  std::string descriptor(ClassHelper(this).GetDescriptor());
15310037c866b04550fc5461058c398c2e3e509381ajeffhao  if ((descriptor[0] != 'L') && (descriptor[0] != '[')) {
15410037c866b04550fc5461058c398c2e3e509381ajeffhao    // The descriptor indicates that this is the class for
15510037c866b04550fc5461058c398c2e3e509381ajeffhao    // a primitive type; special-case the return value.
1568d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    const char* c_name = NULL;
1578d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    switch (descriptor[0]) {
1588d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    case 'Z': c_name = "boolean"; break;
15910037c866b04550fc5461058c398c2e3e509381ajeffhao    case 'B': c_name = "byte";    break;
16010037c866b04550fc5461058c398c2e3e509381ajeffhao    case 'C': c_name = "char";    break;
16110037c866b04550fc5461058c398c2e3e509381ajeffhao    case 'S': c_name = "short";   break;
16210037c866b04550fc5461058c398c2e3e509381ajeffhao    case 'I': c_name = "int";     break;
1638d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    case 'J': c_name = "long";    break;
1648d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    case 'F': c_name = "float";   break;
16510037c866b04550fc5461058c398c2e3e509381ajeffhao    case 'D': c_name = "double";  break;
16610037c866b04550fc5461058c398c2e3e509381ajeffhao    case 'V': c_name = "void";    break;
16710037c866b04550fc5461058c398c2e3e509381ajeffhao    default:
16810037c866b04550fc5461058c398c2e3e509381ajeffhao      LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]);
1698d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    }
17010037c866b04550fc5461058c398c2e3e509381ajeffhao    name = String::AllocFromModifiedUtf8(self, c_name);
17110037c866b04550fc5461058c398c2e3e509381ajeffhao  } else {
17210037c866b04550fc5461058c398c2e3e509381ajeffhao    // Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package
17310037c866b04550fc5461058c398c2e3e509381ajeffhao    // components.
17410037c866b04550fc5461058c398c2e3e509381ajeffhao    if (descriptor.size() > 2 && descriptor[0] == 'L' && descriptor[descriptor.size() - 1] == ';') {
17550d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe      descriptor.erase(0, 1);
176d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      descriptor.erase(descriptor.size() - 1);
17750d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    }
17850d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    std::replace(descriptor.begin(), descriptor.end(), '/', '.');
17950d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    name = String::AllocFromModifiedUtf8(self, descriptor.c_str());
18013735955f39b3b304c37d2b2840663c131262c18Ian Rogers  }
18113735955f39b3b304c37d2b2840663c131262c18Ian Rogers  sirt_c->SetName(name);
18250d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe  return name;
18350d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe}
18450d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe
18550d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampevoid Class::DumpClass(std::ostream& os, int flags) {
18650d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe  if ((flags & kDumpClassFullDetail) == 0) {
18750d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    os << PrettyClass(this);
18850d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    if ((flags & kDumpClassClassLoader) != 0) {
18950d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe      os << ' ' << GetClassLoader();
19050d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    }
19150d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    if ((flags & kDumpClassInitialized) != 0) {
19250d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe      os << ' ' << GetStatus();
19350d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe    }
19413735955f39b3b304c37d2b2840663c131262c18Ian Rogers    os << "\n";
19513735955f39b3b304c37d2b2840663c131262c18Ian Rogers    return;
19650d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe  }
19750d1bc198b2e347d60df74c3b0c452e1f929dd2fAndreas Gampe
1988a6bbfc66e3cf01d4aa07ee08b515beee481d553Ian Rogers  Class* super = GetSuperClass();
199e3d5581266301e6a672af6233220037abf52fea1Ian Rogers  ClassHelper kh(this);
200e3d5581266301e6a672af6233220037abf52fea1Ian Rogers  os << "----- " << (IsInterface() ? "interface" : "class") << " "
20110037c866b04550fc5461058c398c2e3e509381ajeffhao     << "'" << kh.GetDescriptor() << "' cl=" << GetClassLoader() << " -----\n",
20210037c866b04550fc5461058c398c2e3e509381ajeffhao  os << "  objectSize=" << SizeOf() << " "
20310037c866b04550fc5461058c398c2e3e509381ajeffhao     << "(" << (super != NULL ? super->SizeOf() : -1) << " from super)\n",
20410037c866b04550fc5461058c398c2e3e509381ajeffhao  os << StringPrintf("  access=0x%04x.%04x\n",
20510037c866b04550fc5461058c398c2e3e509381ajeffhao      GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask);
20613735955f39b3b304c37d2b2840663c131262c18Ian Rogers  if (super != NULL) {
207d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    os << "  super='" << PrettyClass(super) << "' (cl=" << super->GetClassLoader() << ")\n";
208d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  }
209d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  if (IsArrayClass()) {
210d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    os << "  componentType=" << PrettyClass(GetComponentType()) << "\n";
211d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  }
212d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  if (kh.NumDirectInterfaces() > 0) {
213d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    os << "  interfaces (" << kh.NumDirectInterfaces() << "):\n";
214d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    for (size_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
215d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      Class* interface = kh.GetDirectInterface(i);
216d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      const ClassLoader* cl = interface->GetClassLoader();
217d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      os << StringPrintf("    %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl);
218d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    }
219d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  }
220d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  os << "  vtable (" << NumVirtualMethods() << " entries, "
221d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe     << (super != NULL ? super->NumVirtualMethods() : 0) << " in super):\n";
222d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  for (size_t i = 0; i < NumVirtualMethods(); ++i) {
2238d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    os << StringPrintf("    %2zd: %s\n", i, PrettyMethod(GetVirtualMethodDuringLinking(i)).c_str());
2248d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  }
2258d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  os << "  direct methods (" << NumDirectMethods() << " entries):\n";
22610037c866b04550fc5461058c398c2e3e509381ajeffhao  for (size_t i = 0; i < NumDirectMethods(); ++i) {
22710037c866b04550fc5461058c398c2e3e509381ajeffhao    os << StringPrintf("    %2zd: %s\n", i, PrettyMethod(GetDirectMethod(i)).c_str());
22810037c866b04550fc5461058c398c2e3e509381ajeffhao  }
22910037c866b04550fc5461058c398c2e3e509381ajeffhao  if (NumStaticFields() > 0) {
23010037c866b04550fc5461058c398c2e3e509381ajeffhao    os << "  static fields (" << NumStaticFields() << " entries):\n";
231d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    if (IsResolved() || IsErroneous()) {
232d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      for (size_t i = 0; i < NumStaticFields(); ++i) {
233d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe        os << StringPrintf("    %2zd: %s\n", i, PrettyField(GetStaticField(i)).c_str());
234d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      }
235d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    } else {
236d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      os << "    <not yet available>";
237d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    }
238d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  }
239d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  if (NumInstanceFields() > 0) {
240d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    os << "  instance fields (" << NumInstanceFields() << " entries):\n";
241d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    if (IsResolved() || IsErroneous()) {
242d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      for (size_t i = 0; i < NumInstanceFields(); ++i) {
243d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe        os << StringPrintf("    %2zd: %s\n", i, PrettyField(GetInstanceField(i)).c_str());
244d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      }
2458d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    } else {
246f6174e8a1566bb357e82506f7ec97dc359c90eb2jeffhao      os << "    <not yet available>";
247f6174e8a1566bb357e82506f7ec97dc359c90eb2jeffhao    }
248f6174e8a1566bb357e82506f7ec97dc359c90eb2jeffhao  }
2498d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
25010037c866b04550fc5461058c398c2e3e509381ajeffhao
25110037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) {
25210037c866b04550fc5461058c398c2e3e509381ajeffhao  if (new_reference_offsets != CLASS_WALK_SUPER) {
25310037c866b04550fc5461058c398c2e3e509381ajeffhao    // Sanity check that the number of bits set in the reference offset bitmap
25410037c866b04550fc5461058c398c2e3e509381ajeffhao    // agrees with the number of references
25510037c866b04550fc5461058c398c2e3e509381ajeffhao    size_t count = 0;
25613735955f39b3b304c37d2b2840663c131262c18Ian Rogers    for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
257f6174e8a1566bb357e82506f7ec97dc359c90eb2jeffhao      count += c->NumReferenceInstanceFieldsDuringLinking();
25810037c866b04550fc5461058c398c2e3e509381ajeffhao    }
2598d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), count);
26010037c866b04550fc5461058c398c2e3e509381ajeffhao  }
26110037c866b04550fc5461058c398c2e3e509381ajeffhao  // Not called within a transaction.
26210037c866b04550fc5461058c398c2e3e509381ajeffhao  SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_),
26310037c866b04550fc5461058c398c2e3e509381ajeffhao                    new_reference_offsets, false);
26410037c866b04550fc5461058c398c2e3e509381ajeffhao}
2658d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
26610037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) {
26710037c866b04550fc5461058c398c2e3e509381ajeffhao  if (new_reference_offsets != CLASS_WALK_SUPER) {
26810037c866b04550fc5461058c398c2e3e509381ajeffhao    // Sanity check that the number of bits set in the reference offset bitmap
26910037c866b04550fc5461058c398c2e3e509381ajeffhao    // agrees with the number of references
2708d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets),
27110037c866b04550fc5461058c398c2e3e509381ajeffhao             NumReferenceStaticFieldsDuringLinking());
27210037c866b04550fc5461058c398c2e3e509381ajeffhao  }
27310037c866b04550fc5461058c398c2e3e509381ajeffhao  // Not called within a transaction.
274d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_),
275d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe                    new_reference_offsets, false);
276d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe}
277d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe
278d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampebool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) {
279d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  size_t i = 0;
280d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) {
281d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    ++i;
282d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  }
283d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  if (descriptor1.find('/', i) != StringPiece::npos ||
284d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe      descriptor2.find('/', i) != StringPiece::npos) {
285d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    return false;
286d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  } else {
28710037c866b04550fc5461058c398c2e3e509381ajeffhao    return true;
28810037c866b04550fc5461058c398c2e3e509381ajeffhao  }
2898d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
290d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe
291d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampebool Class::IsInSamePackage(Class* that) {
292d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  Class* klass1 = this;
293d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  Class* klass2 = that;
294d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  if (klass1 == klass2) {
295d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe    return true;
296d4ae41fd7a4ed711277c61c0d7fd2a3759458728Andreas Gampe  }
29710037c866b04550fc5461058c398c2e3e509381ajeffhao  // Class loaders must match.
29810037c866b04550fc5461058c398c2e3e509381ajeffhao  if (klass1->GetClassLoader() != klass2->GetClassLoader()) {
29910037c866b04550fc5461058c398c2e3e509381ajeffhao    return false;
30010037c866b04550fc5461058c398c2e3e509381ajeffhao  }
30110037c866b04550fc5461058c398c2e3e509381ajeffhao  // Arrays are in the same package when their element classes are.
30210037c866b04550fc5461058c398c2e3e509381ajeffhao  while (klass1->IsArrayClass()) {
30310037c866b04550fc5461058c398c2e3e509381ajeffhao    klass1 = klass1->GetComponentType();
30410037c866b04550fc5461058c398c2e3e509381ajeffhao  }
30510037c866b04550fc5461058c398c2e3e509381ajeffhao  while (klass2->IsArrayClass()) {
30610037c866b04550fc5461058c398c2e3e509381ajeffhao    klass2 = klass2->GetComponentType();
30710037c866b04550fc5461058c398c2e3e509381ajeffhao  }
30810037c866b04550fc5461058c398c2e3e509381ajeffhao  // trivial check again for array types
30910037c866b04550fc5461058c398c2e3e509381ajeffhao  if (klass1 == klass2) {
31010037c866b04550fc5461058c398c2e3e509381ajeffhao    return true;
31110037c866b04550fc5461058c398c2e3e509381ajeffhao  }
3128d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  // Compare the package part of the descriptor string.
3138d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  return IsInSamePackage(ClassHelper(klass1).GetDescriptor(),
31410037c866b04550fc5461058c398c2e3e509381ajeffhao                         ClassHelper(klass2).GetDescriptor());
31510037c866b04550fc5461058c398c2e3e509381ajeffhao}
3168d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
3178d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogersbool Class::IsClassClass() {
3188d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  Class* java_lang_Class = GetClass()->GetClass();
31910037c866b04550fc5461058c398c2e3e509381ajeffhao  return this == java_lang_Class;
32010037c866b04550fc5461058c398c2e3e509381ajeffhao}
32110037c866b04550fc5461058c398c2e3e509381ajeffhao
32210037c866b04550fc5461058c398c2e3e509381ajeffhaobool Class::IsStringClass() const {
32310037c866b04550fc5461058c398c2e3e509381ajeffhao  return this == String::GetJavaLangString();
3248d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
3258d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
32610037c866b04550fc5461058c398c2e3e509381ajeffhaobool Class::IsThrowableClass() {
32710037c866b04550fc5461058c398c2e3e509381ajeffhao  return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this);
32810037c866b04550fc5461058c398c2e3e509381ajeffhao}
32910037c866b04550fc5461058c398c2e3e509381ajeffhao
33010037c866b04550fc5461058c398c2e3e509381ajeffhaobool Class::IsArtFieldClass() {
33110037c866b04550fc5461058c398c2e3e509381ajeffhao  Class* java_lang_Class = GetClass();
33210037c866b04550fc5461058c398c2e3e509381ajeffhao  Class* java_lang_reflect_ArtField = java_lang_Class->GetInstanceField(0)->GetClass();
33310037c866b04550fc5461058c398c2e3e509381ajeffhao  return this == java_lang_reflect_ArtField;
3348d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
3358d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
33610037c866b04550fc5461058c398c2e3e509381ajeffhaobool Class::IsArtMethodClass() {
33710037c866b04550fc5461058c398c2e3e509381ajeffhao  return this == ArtMethod::GetJavaLangReflectArtMethod();
33810037c866b04550fc5461058c398c2e3e509381ajeffhao}
3398d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
3408d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogersvoid Class::SetClassLoader(ClassLoader* new_class_loader) {
34110037c866b04550fc5461058c398c2e3e509381ajeffhao  if (Runtime::Current()->IsActiveTransaction()) {
34210037c866b04550fc5461058c398c2e3e509381ajeffhao    SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false);
34310037c866b04550fc5461058c398c2e3e509381ajeffhao  } else {
34410037c866b04550fc5461058c398c2e3e509381ajeffhao    SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false);
34510037c866b04550fc5461058c398c2e3e509381ajeffhao  }
34610037c866b04550fc5461058c398c2e3e509381ajeffhao}
34710037c866b04550fc5461058c398c2e3e509381ajeffhao
34810037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const Signature& signature) {
34910037c866b04550fc5461058c398c2e3e509381ajeffhao  // Check the current class before checking the interfaces.
3508d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  ArtMethod* method = FindDeclaredVirtualMethod(name, signature);
3518d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  if (method != NULL) {
35210037c866b04550fc5461058c398c2e3e509381ajeffhao    return method;
35310037c866b04550fc5461058c398c2e3e509381ajeffhao  }
3548d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
3558d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  int32_t iftable_count = GetIfTableCount();
35610037c866b04550fc5461058c398c2e3e509381ajeffhao  IfTable* iftable = GetIfTable();
35710037c866b04550fc5461058c398c2e3e509381ajeffhao  for (int32_t i = 0; i < iftable_count; i++) {
3588d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature);
3598d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    if (method != NULL) {
3608d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return method;
36110037c866b04550fc5461058c398c2e3e509381ajeffhao    }
36210037c866b04550fc5461058c398c2e3e509381ajeffhao  }
3638d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  return NULL;
3648d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
3658d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
36610037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
36710037c866b04550fc5461058c398c2e3e509381ajeffhao  // Check the current class before checking the interfaces.
3688d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
3698d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  if (method != NULL) {
3708d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    return method;
37110037c866b04550fc5461058c398c2e3e509381ajeffhao  }
37210037c866b04550fc5461058c398c2e3e509381ajeffhao
3738d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  int32_t iftable_count = GetIfTableCount();
3748d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  IfTable* iftable = GetIfTable();
3758d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  for (int32_t i = 0; i < iftable_count; i++) {
37610037c866b04550fc5461058c398c2e3e509381ajeffhao    method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
37710037c866b04550fc5461058c398c2e3e509381ajeffhao    if (method != NULL) {
3788d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return method;
3798d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    }
3808d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  }
38110037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
38210037c866b04550fc5461058c398c2e3e509381ajeffhao}
3838d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
3848d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan RogersArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature) {
3858d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  MethodHelper mh;
38610037c866b04550fc5461058c398c2e3e509381ajeffhao  for (size_t i = 0; i < NumDirectMethods(); ++i) {
38710037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtMethod* method = GetDirectMethod(i);
38810037c866b04550fc5461058c398c2e3e509381ajeffhao    mh.ChangeMethod(method);
38910037c866b04550fc5461058c398c2e3e509381ajeffhao    if (name == mh.GetName() && mh.GetSignature() == signature) {
39010037c866b04550fc5461058c398c2e3e509381ajeffhao      return method;
39110037c866b04550fc5461058c398c2e3e509381ajeffhao    }
39210037c866b04550fc5461058c398c2e3e509381ajeffhao  }
39313735955f39b3b304c37d2b2840663c131262c18Ian Rogers  return NULL;
3948d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
3958d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
3968d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan RogersArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature) {
39710037c866b04550fc5461058c398c2e3e509381ajeffhao  MethodHelper mh;
39810037c866b04550fc5461058c398c2e3e509381ajeffhao  for (size_t i = 0; i < NumDirectMethods(); ++i) {
39910037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtMethod* method = GetDirectMethod(i);
40010037c866b04550fc5461058c398c2e3e509381ajeffhao    mh.ChangeMethod(method);
40110037c866b04550fc5461058c398c2e3e509381ajeffhao    if (name == mh.GetName() && signature == mh.GetSignature()) {
4028d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return method;
40313735955f39b3b304c37d2b2840663c131262c18Ian Rogers    }
40410037c866b04550fc5461058c398c2e3e509381ajeffhao  }
40510037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
40610037c866b04550fc5461058c398c2e3e509381ajeffhao}
4078a6bbfc66e3cf01d4aa07ee08b515beee481d553Ian Rogers
40810037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
40910037c866b04550fc5461058c398c2e3e509381ajeffhao  if (GetDexCache() == dex_cache) {
4108d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    for (size_t i = 0; i < NumDirectMethods(); ++i) {
4118d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      ArtMethod* method = GetDirectMethod(i);
41210037c866b04550fc5461058c398c2e3e509381ajeffhao      if (method->GetDexMethodIndex() == dex_method_idx) {
41310037c866b04550fc5461058c398c2e3e509381ajeffhao        return method;
41410037c866b04550fc5461058c398c2e3e509381ajeffhao      }
41510037c866b04550fc5461058c398c2e3e509381ajeffhao    }
41610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
41710037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
41810037c866b04550fc5461058c398c2e3e509381ajeffhao}
41910037c866b04550fc5461058c398c2e3e509381ajeffhao
42010037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature) {
42110037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
4228a6bbfc66e3cf01d4aa07ee08b515beee481d553Ian Rogers    ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature);
42310037c866b04550fc5461058c398c2e3e509381ajeffhao    if (method != NULL) {
42410037c866b04550fc5461058c398c2e3e509381ajeffhao      return method;
42510037c866b04550fc5461058c398c2e3e509381ajeffhao    }
42610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
42710037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
42810037c866b04550fc5461058c398c2e3e509381ajeffhao}
42910037c866b04550fc5461058c398c2e3e509381ajeffhao
43010037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindDirectMethod(const StringPiece& name, const Signature& signature) {
4318d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
4328d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature);
43310037c866b04550fc5461058c398c2e3e509381ajeffhao    if (method != NULL) {
43410037c866b04550fc5461058c398c2e3e509381ajeffhao      return method;
43510037c866b04550fc5461058c398c2e3e509381ajeffhao    }
43610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
43710037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
43810037c866b04550fc5461058c398c2e3e509381ajeffhao}
4398d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
4408d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan RogersArtMethod* Class::FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
44110037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
44210037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx);
44310037c866b04550fc5461058c398c2e3e509381ajeffhao    if (method != NULL) {
44410037c866b04550fc5461058c398c2e3e509381ajeffhao      return method;
44510037c866b04550fc5461058c398c2e3e509381ajeffhao    }
44610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
44710037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
44810037c866b04550fc5461058c398c2e3e509381ajeffhao}
449e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe
450e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas GampeArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature) {
451e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  MethodHelper mh;
4521a9735701d0826adbc9d68cd3762b78f96499cfbAndreas Gampe  for (size_t i = 0; i < NumVirtualMethods(); ++i) {
4538d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    ArtMethod* method = GetVirtualMethod(i);
454e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    mh.ChangeMethod(method);
45510037c866b04550fc5461058c398c2e3e509381ajeffhao    if (name == mh.GetName() && mh.GetSignature() == signature) {
45610037c866b04550fc5461058c398c2e3e509381ajeffhao      return method;
45710037c866b04550fc5461058c398c2e3e509381ajeffhao    }
45810037c866b04550fc5461058c398c2e3e509381ajeffhao  }
459e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  return NULL;
460e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe}
461e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe
462e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas GampeArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name,
463e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe                                            const Signature& signature) {
464e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  MethodHelper mh;
465e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  for (size_t i = 0; i < NumVirtualMethods(); ++i) {
466e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    ArtMethod* method = GetVirtualMethod(i);
467e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    mh.ChangeMethod(method);
468e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    if (name == mh.GetName() && signature == mh.GetSignature()) {
469e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      return method;
470e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    }
47110037c866b04550fc5461058c398c2e3e509381ajeffhao  }
4728d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  return NULL;
4738d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers}
47410037c866b04550fc5461058c398c2e3e509381ajeffhao
47510037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
47610037c866b04550fc5461058c398c2e3e509381ajeffhao  if (GetDexCache() == dex_cache) {
477e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    for (size_t i = 0; i < NumVirtualMethods(); ++i) {
478e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      ArtMethod* method = GetVirtualMethod(i);
479e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      if (method->GetDexMethodIndex() == dex_method_idx) {
480e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe        return method;
48110037c866b04550fc5461058c398c2e3e509381ajeffhao      }
48210037c866b04550fc5461058c398c2e3e509381ajeffhao    }
48310037c866b04550fc5461058c398c2e3e509381ajeffhao  }
48410037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
48510037c866b04550fc5461058c398c2e3e509381ajeffhao}
48610037c866b04550fc5461058c398c2e3e509381ajeffhao
487e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas GampeArtMethod* Class::FindVirtualMethod(const StringPiece& name, const StringPiece& signature) {
488e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
489e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature);
4901a9735701d0826adbc9d68cd3762b78f96499cfbAndreas Gampe    if (method != NULL) {
491a574b0e4772e57134538c3c098d7538d957edc90Jeff Hao      return method;
492e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    }
493a574b0e4772e57134538c3c098d7538d957edc90Jeff Hao  }
494e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  return NULL;
495e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe}
49610037c866b04550fc5461058c398c2e3e509381ajeffhao
49710037c866b04550fc5461058c398c2e3e509381ajeffhaoArtMethod* Class::FindVirtualMethod(const StringPiece& name, const Signature& signature) {
49810037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
49910037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature);
500e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    if (method != NULL) {
501e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      return method;
502e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    }
503e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  }
504e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  return NULL;
505e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe}
506e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe
507e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas GampeArtMethod* Class::FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx) {
50810037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) {
50910037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx);
51010037c866b04550fc5461058c398c2e3e509381ajeffhao    if (method != NULL) {
511e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      return method;
512a574b0e4772e57134538c3c098d7538d957edc90Jeff Hao    }
513e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  }
514e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe  return NULL;
515a574b0e4772e57134538c3c098d7538d957edc90Jeff Hao}
516a574b0e4772e57134538c3c098d7538d957edc90Jeff Hao
517a574b0e4772e57134538c3c098d7538d957edc90Jeff HaoArtMethod* Class::FindClassInitializer() {
518a574b0e4772e57134538c3c098d7538d957edc90Jeff Hao  for (size_t i = 0; i < NumDirectMethods(); ++i) {
519e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    ArtMethod* method = GetDirectMethod(i);
520e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    if (method->IsConstructor() && method->IsStatic()) {
521e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      if (kIsDebugBuild) {
522e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe        MethodHelper mh(method);
523e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe        CHECK(mh.IsClassInitializer());
524e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe        CHECK_STREQ(mh.GetName(), "<clinit>");
525e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe        CHECK_STREQ(mh.GetSignature().ToString().c_str(), "()V");
526e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      }
527e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe      return method;
528e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe    }
52910037c866b04550fc5461058c398c2e3e509381ajeffhao  }
53010037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
53110037c866b04550fc5461058c398c2e3e509381ajeffhao}
53210037c866b04550fc5461058c398c2e3e509381ajeffhao
53310037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) {
53410037c866b04550fc5461058c398c2e3e509381ajeffhao  // Is the field in this class?
5358a6bbfc66e3cf01d4aa07ee08b515beee481d553Ian Rogers  // Interfaces are not relevant because they can't contain instance fields.
53610037c866b04550fc5461058c398c2e3e509381ajeffhao  FieldHelper fh;
53713735955f39b3b304c37d2b2840663c131262c18Ian Rogers  for (size_t i = 0; i < NumInstanceFields(); ++i) {
53810037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtField* f = GetInstanceField(i);
53910037c866b04550fc5461058c398c2e3e509381ajeffhao    fh.ChangeField(f);
54010037c866b04550fc5461058c398c2e3e509381ajeffhao    if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
5418d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return f;
5428a6bbfc66e3cf01d4aa07ee08b515beee481d553Ian Rogers    }
54310037c866b04550fc5461058c398c2e3e509381ajeffhao  }
54410037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
54510037c866b04550fc5461058c398c2e3e509381ajeffhao}
54610037c866b04550fc5461058c398c2e3e509381ajeffhao
54710037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
54810037c866b04550fc5461058c398c2e3e509381ajeffhao  if (GetDexCache() == dex_cache) {
54910037c866b04550fc5461058c398c2e3e509381ajeffhao    for (size_t i = 0; i < NumInstanceFields(); ++i) {
55010037c866b04550fc5461058c398c2e3e509381ajeffhao      ArtField* f = GetInstanceField(i);
55110037c866b04550fc5461058c398c2e3e509381ajeffhao      if (f->GetDexFieldIndex() == dex_field_idx) {
55210037c866b04550fc5461058c398c2e3e509381ajeffhao        return f;
55313735955f39b3b304c37d2b2840663c131262c18Ian Rogers      }
55410037c866b04550fc5461058c398c2e3e509381ajeffhao    }
55510037c866b04550fc5461058c398c2e3e509381ajeffhao  }
55610037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
55710037c866b04550fc5461058c398c2e3e509381ajeffhao}
55810037c866b04550fc5461058c398c2e3e509381ajeffhao
55910037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) {
56010037c866b04550fc5461058c398c2e3e509381ajeffhao  // Is the field in this class, or any of its superclasses?
56110037c866b04550fc5461058c398c2e3e509381ajeffhao  // Interfaces are not relevant because they can't contain instance fields.
56210037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
5638d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    ArtField* f = c->FindDeclaredInstanceField(name, type);
5648d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    if (f != NULL) {
56510037c866b04550fc5461058c398c2e3e509381ajeffhao      return f;
56610037c866b04550fc5461058c398c2e3e509381ajeffhao    }
56710037c866b04550fc5461058c398c2e3e509381ajeffhao  }
56810037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
56910037c866b04550fc5461058c398c2e3e509381ajeffhao}
57010037c866b04550fc5461058c398c2e3e509381ajeffhao
5718d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan RogersArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
5728d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  // Is the field in this class, or any of its superclasses?
57310037c866b04550fc5461058c398c2e3e509381ajeffhao  // Interfaces are not relevant because they can't contain instance fields.
57410037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* c = this; c != NULL; c = c->GetSuperClass()) {
57510037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx);
57610037c866b04550fc5461058c398c2e3e509381ajeffhao    if (f != NULL) {
57710037c866b04550fc5461058c398c2e3e509381ajeffhao      return f;
57810037c866b04550fc5461058c398c2e3e509381ajeffhao    }
5798d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  }
5808d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  return NULL;
58110037c866b04550fc5461058c398c2e3e509381ajeffhao}
58210037c866b04550fc5461058c398c2e3e509381ajeffhao
58310037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) {
58410037c866b04550fc5461058c398c2e3e509381ajeffhao  DCHECK(type != NULL);
58510037c866b04550fc5461058c398c2e3e509381ajeffhao  FieldHelper fh;
58610037c866b04550fc5461058c398c2e3e509381ajeffhao  for (size_t i = 0; i < NumStaticFields(); ++i) {
58710037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtField* f = GetStaticField(i);
58810037c866b04550fc5461058c398c2e3e509381ajeffhao    fh.ChangeField(f);
58910037c866b04550fc5461058c398c2e3e509381ajeffhao    if (name == fh.GetName() && type == fh.GetTypeDescriptor()) {
5908d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return f;
5918d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    }
59210037c866b04550fc5461058c398c2e3e509381ajeffhao  }
59310037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
59410037c866b04550fc5461058c398c2e3e509381ajeffhao}
59510037c866b04550fc5461058c398c2e3e509381ajeffhao
59610037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
59710037c866b04550fc5461058c398c2e3e509381ajeffhao  if (dex_cache == GetDexCache()) {
59810037c866b04550fc5461058c398c2e3e509381ajeffhao    for (size_t i = 0; i < NumStaticFields(); ++i) {
59910037c866b04550fc5461058c398c2e3e509381ajeffhao      ArtField* f = GetStaticField(i);
60010037c866b04550fc5461058c398c2e3e509381ajeffhao      if (f->GetDexFieldIndex() == dex_field_idx) {
6018d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers        return f;
6028d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      }
60310037c866b04550fc5461058c398c2e3e509381ajeffhao    }
60410037c866b04550fc5461058c398c2e3e509381ajeffhao  }
60510037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
60610037c866b04550fc5461058c398c2e3e509381ajeffhao}
60710037c866b04550fc5461058c398c2e3e509381ajeffhao
60810037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindStaticField(const StringPiece& name, const StringPiece& type) {
60910037c866b04550fc5461058c398c2e3e509381ajeffhao  // Is the field in this class (or its interfaces), or any of its
61010037c866b04550fc5461058c398c2e3e509381ajeffhao  // superclasses (or their interfaces)?
61110037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
61210037c866b04550fc5461058c398c2e3e509381ajeffhao    // Is the field in this class?
6138d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    ArtField* f = k->FindDeclaredStaticField(name, type);
6148d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    if (f != NULL) {
61510037c866b04550fc5461058c398c2e3e509381ajeffhao      return f;
61610037c866b04550fc5461058c398c2e3e509381ajeffhao    }
61710037c866b04550fc5461058c398c2e3e509381ajeffhao    // Is this field in any of this class' interfaces?
61810037c866b04550fc5461058c398c2e3e509381ajeffhao    ClassHelper kh(k);
61910037c866b04550fc5461058c398c2e3e509381ajeffhao    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
62010037c866b04550fc5461058c398c2e3e509381ajeffhao      Class* interface = kh.GetDirectInterface(i);
62110037c866b04550fc5461058c398c2e3e509381ajeffhao      f = interface->FindStaticField(name, type);
62210037c866b04550fc5461058c398c2e3e509381ajeffhao      if (f != NULL) {
62310037c866b04550fc5461058c398c2e3e509381ajeffhao        return f;
6248d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      }
6258d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    }
62610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
62710037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
62810037c866b04550fc5461058c398c2e3e509381ajeffhao}
62910037c866b04550fc5461058c398c2e3e509381ajeffhao
63010037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
63110037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
63210037c866b04550fc5461058c398c2e3e509381ajeffhao    // Is the field in this class?
63310037c866b04550fc5461058c398c2e3e509381ajeffhao    ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx);
63410037c866b04550fc5461058c398c2e3e509381ajeffhao    if (f != NULL) {
6358d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return f;
6368d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    }
63710037c866b04550fc5461058c398c2e3e509381ajeffhao    // Is this field in any of this class' interfaces?
63810037c866b04550fc5461058c398c2e3e509381ajeffhao    ClassHelper kh(k);
63910037c866b04550fc5461058c398c2e3e509381ajeffhao    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
64010037c866b04550fc5461058c398c2e3e509381ajeffhao      Class* interface = kh.GetDirectInterface(i);
64110037c866b04550fc5461058c398c2e3e509381ajeffhao      f = interface->FindStaticField(dex_cache, dex_field_idx);
64210037c866b04550fc5461058c398c2e3e509381ajeffhao      if (f != NULL) {
64310037c866b04550fc5461058c398c2e3e509381ajeffhao        return f;
6448d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      }
6458d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    }
64610037c866b04550fc5461058c398c2e3e509381ajeffhao  }
64710037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
64810037c866b04550fc5461058c398c2e3e509381ajeffhao}
64910037c866b04550fc5461058c398c2e3e509381ajeffhao
65010037c866b04550fc5461058c398c2e3e509381ajeffhaoArtField* Class::FindField(const StringPiece& name, const StringPiece& type) {
65110037c866b04550fc5461058c398c2e3e509381ajeffhao  // Find a field using the JLS field resolution order
65210037c866b04550fc5461058c398c2e3e509381ajeffhao  for (Class* k = this; k != NULL; k = k->GetSuperClass()) {
6538d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    // Is the field in this class?
6548d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    ArtField* f = k->FindDeclaredInstanceField(name, type);
65510037c866b04550fc5461058c398c2e3e509381ajeffhao    if (f != NULL) {
65610037c866b04550fc5461058c398c2e3e509381ajeffhao      return f;
65710037c866b04550fc5461058c398c2e3e509381ajeffhao    }
65810037c866b04550fc5461058c398c2e3e509381ajeffhao    f = k->FindDeclaredStaticField(name, type);
6598d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    if (f != NULL) {
6608d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      return f;
66110037c866b04550fc5461058c398c2e3e509381ajeffhao    }
66210037c866b04550fc5461058c398c2e3e509381ajeffhao    // Is this field in any of this class' interfaces?
66310037c866b04550fc5461058c398c2e3e509381ajeffhao    ClassHelper kh(k);
66410037c866b04550fc5461058c398c2e3e509381ajeffhao    for (uint32_t i = 0; i < kh.NumDirectInterfaces(); ++i) {
6658d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers      Class* interface = kh.GetDirectInterface(i);
66610037c866b04550fc5461058c398c2e3e509381ajeffhao      f = interface->FindStaticField(name, type);
66710037c866b04550fc5461058c398c2e3e509381ajeffhao      if (f != NULL) {
66810037c866b04550fc5461058c398c2e3e509381ajeffhao        return f;
66910037c866b04550fc5461058c398c2e3e509381ajeffhao      }
67010037c866b04550fc5461058c398c2e3e509381ajeffhao    }
67110037c866b04550fc5461058c398c2e3e509381ajeffhao  }
67210037c866b04550fc5461058c398c2e3e509381ajeffhao  return NULL;
67310037c866b04550fc5461058c398c2e3e509381ajeffhao}
67410037c866b04550fc5461058c398c2e3e509381ajeffhao
67510037c866b04550fc5461058c398c2e3e509381ajeffhaostatic void SetPreverifiedFlagOnMethods(mirror::ObjectArray<mirror::ArtMethod>* methods)
67610037c866b04550fc5461058c398c2e3e509381ajeffhao    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
6778d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  if (methods != NULL) {
67810037c866b04550fc5461058c398c2e3e509381ajeffhao    for (int32_t index = 0, end = methods->GetLength(); index < end; ++index) {
67910037c866b04550fc5461058c398c2e3e509381ajeffhao      mirror::ArtMethod* method = methods->GetWithoutChecks(index);
68010037c866b04550fc5461058c398c2e3e509381ajeffhao      DCHECK(method != NULL);
68110037c866b04550fc5461058c398c2e3e509381ajeffhao      if (!method->IsNative() && !method->IsAbstract()) {
68210037c866b04550fc5461058c398c2e3e509381ajeffhao        method->SetPreverified();
68310037c866b04550fc5461058c398c2e3e509381ajeffhao      }
68410037c866b04550fc5461058c398c2e3e509381ajeffhao    }
68510037c866b04550fc5461058c398c2e3e509381ajeffhao  }
68610037c866b04550fc5461058c398c2e3e509381ajeffhao}
68710037c866b04550fc5461058c398c2e3e509381ajeffhao
68810037c866b04550fc5461058c398c2e3e509381ajeffhaovoid Class::SetPreverifiedFlagOnAllMethods() {
68910037c866b04550fc5461058c398c2e3e509381ajeffhao  DCHECK(IsVerified());
69010037c866b04550fc5461058c398c2e3e509381ajeffhao  SetPreverifiedFlagOnMethods(GetDirectMethods());
69110037c866b04550fc5461058c398c2e3e509381ajeffhao  SetPreverifiedFlagOnMethods(GetVirtualMethods());
69210037c866b04550fc5461058c398c2e3e509381ajeffhao}
69310037c866b04550fc5461058c398c2e3e509381ajeffhao
69410037c866b04550fc5461058c398c2e3e509381ajeffhao}  // namespace mirror
69510037c866b04550fc5461058c398c2e3e509381ajeffhao}  // namespace art
69610037c866b04550fc5461058c398c2e3e509381ajeffhao