Home | History | Annotate | Download | only in runtime
      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 #ifndef ART_RUNTIME_METHOD_HELPER_INL_H_
     18 #define ART_RUNTIME_METHOD_HELPER_INL_H_
     19 
     20 #include "method_helper.h"
     21 
     22 #include "class_linker.h"
     23 #include "mirror/object_array.h"
     24 #include "runtime.h"
     25 #include "thread-inl.h"
     26 
     27 namespace art {
     28 
     29 inline bool MethodHelper::HasSameNameAndSignature(MethodHelper* other) {
     30   const DexFile* dex_file = method_->GetDexFile();
     31   const DexFile::MethodId& mid = dex_file->GetMethodId(GetMethod()->GetDexMethodIndex());
     32   if (method_->GetDexCache() == other->method_->GetDexCache()) {
     33     const DexFile::MethodId& other_mid =
     34         dex_file->GetMethodId(other->GetMethod()->GetDexMethodIndex());
     35     return mid.name_idx_ == other_mid.name_idx_ && mid.proto_idx_ == other_mid.proto_idx_;
     36   }
     37   const DexFile* other_dex_file = other->method_->GetDexFile();
     38   const DexFile::MethodId& other_mid =
     39       other_dex_file->GetMethodId(other->GetMethod()->GetDexMethodIndex());
     40   if (!DexFileStringEquals(dex_file, mid.name_idx_, other_dex_file, other_mid.name_idx_)) {
     41     return false;  // Name mismatch.
     42   }
     43   return dex_file->GetMethodSignature(mid) == other_dex_file->GetMethodSignature(other_mid);
     44 }
     45 
     46 inline mirror::Class* MethodHelper::GetClassFromTypeIdx(uint16_t type_idx, bool resolve) {
     47   mirror::ArtMethod* method = GetMethod();
     48   mirror::Class* type = method->GetDexCacheResolvedType(type_idx);
     49   if (type == nullptr && resolve) {
     50     type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
     51     CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
     52   }
     53   return type;
     54 }
     55 
     56 inline mirror::Class* MethodHelper::GetReturnType(bool resolve) {
     57   mirror::ArtMethod* method = GetMethod();
     58   const DexFile* dex_file = method->GetDexFile();
     59   const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
     60   const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
     61   uint16_t return_type_idx = proto_id.return_type_idx_;
     62   return GetClassFromTypeIdx(return_type_idx, resolve);
     63 }
     64 
     65 inline mirror::String* MethodHelper::ResolveString(uint32_t string_idx) {
     66   mirror::ArtMethod* method = GetMethod();
     67   mirror::Class* declaringClass = method->GetDeclaringClass();
     68   mirror::String* s = declaringClass->GetDexCacheStrings()->Get(string_idx);
     69   if (UNLIKELY(s == nullptr)) {
     70     StackHandleScope<1> hs(Thread::Current());
     71     Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache()));
     72     s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx,
     73                                                             dex_cache);
     74   }
     75   return s;
     76 }
     77 
     78 }  // namespace art
     79 
     80 #endif  // ART_RUNTIME_METHOD_HELPER_INL_H_
     81