122d5e735f403c57525fe868304c7123f0ce66399Ian Rogers/* 222d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * Copyright (C) 2011 The Android Open Source Project 322d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * 422d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * Licensed under the Apache License, Version 2.0 (the "License"); 522d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * you may not use this file except in compliance with the License. 622d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * You may obtain a copy of the License at 722d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * 822d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * http://www.apache.org/licenses/LICENSE-2.0 922d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * 1022d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * Unless required by applicable law or agreed to in writing, software 1122d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * distributed under the License is distributed on an "AS IS" BASIS, 1222d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1322d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * See the License for the specific language governing permissions and 1422d5e735f403c57525fe868304c7123f0ce66399Ian Rogers * limitations under the License. 1522d5e735f403c57525fe868304c7123f0ce66399Ian Rogers */ 1622d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 1722d5e735f403c57525fe868304c7123f0ce66399Ian Rogers#ifndef ART_RUNTIME_METHOD_HELPER_INL_H_ 1822d5e735f403c57525fe868304c7123f0ce66399Ian Rogers#define ART_RUNTIME_METHOD_HELPER_INL_H_ 1922d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 2022d5e735f403c57525fe868304c7123f0ce66399Ian Rogers#include "method_helper.h" 2122d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 22e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers#include "class_linker.h" 23e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers#include "mirror/object_array.h" 2422d5e735f403c57525fe868304c7123f0ce66399Ian Rogers#include "runtime.h" 25e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers#include "thread-inl.h" 2622d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 2722d5e735f403c57525fe868304c7123f0ce66399Ian Rogersnamespace art { 2822d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 29cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogersinline bool MethodHelper::HasSameNameAndSignature(MethodHelper* other) { 30cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers const DexFile* dex_file = method_->GetDexFile(); 31cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers const DexFile::MethodId& mid = dex_file->GetMethodId(GetMethod()->GetDexMethodIndex()); 32cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers if (method_->GetDexCache() == other->method_->GetDexCache()) { 33cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers const DexFile::MethodId& other_mid = 34cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers dex_file->GetMethodId(other->GetMethod()->GetDexMethodIndex()); 35cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers return mid.name_idx_ == other_mid.name_idx_ && mid.proto_idx_ == other_mid.proto_idx_; 36cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers } 37cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers const DexFile* other_dex_file = other->method_->GetDexFile(); 38cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers const DexFile::MethodId& other_mid = 39cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers other_dex_file->GetMethodId(other->GetMethod()->GetDexMethodIndex()); 40cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers if (!DexFileStringEquals(dex_file, mid.name_idx_, other_dex_file, other_mid.name_idx_)) { 41cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers return false; // Name mismatch. 42cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers } 43cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers return dex_file->GetMethodSignature(mid) == other_dex_file->GetMethodSignature(other_mid); 44cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers} 45cb6b0f31ede2275e79e6199ec391147585a37a2aIan Rogers 4622d5e735f403c57525fe868304c7123f0ce66399Ian Rogersinline mirror::Class* MethodHelper::GetClassFromTypeIdx(uint16_t type_idx, bool resolve) { 4722d5e735f403c57525fe868304c7123f0ce66399Ian Rogers mirror::ArtMethod* method = GetMethod(); 484ef12f5b0e26c6016c87866f6a33da5ed8e98d74Andreas Gampe mirror::Class* type = method->GetDexCacheResolvedType(type_idx); 4922d5e735f403c57525fe868304c7123f0ce66399Ian Rogers if (type == nullptr && resolve) { 5022d5e735f403c57525fe868304c7123f0ce66399Ian Rogers type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method); 5122d5e735f403c57525fe868304c7123f0ce66399Ian Rogers CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); 5222d5e735f403c57525fe868304c7123f0ce66399Ian Rogers } 5322d5e735f403c57525fe868304c7123f0ce66399Ian Rogers return type; 5422d5e735f403c57525fe868304c7123f0ce66399Ian Rogers} 5522d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 56e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogersinline mirror::Class* MethodHelper::GetReturnType(bool resolve) { 57e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers mirror::ArtMethod* method = GetMethod(); 58e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers const DexFile* dex_file = method->GetDexFile(); 59e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex()); 60e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); 61e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers uint16_t return_type_idx = proto_id.return_type_idx_; 62e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers return GetClassFromTypeIdx(return_type_idx, resolve); 63e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers} 64e5877a12c30afe10a5c6a1afaff7a47ef44a2a5fIan Rogers 6522d5e735f403c57525fe868304c7123f0ce66399Ian Rogersinline mirror::String* MethodHelper::ResolveString(uint32_t string_idx) { 6622d5e735f403c57525fe868304c7123f0ce66399Ian Rogers mirror::ArtMethod* method = GetMethod(); 6722d5e735f403c57525fe868304c7123f0ce66399Ian Rogers mirror::String* s = method->GetDexCacheStrings()->Get(string_idx); 6822d5e735f403c57525fe868304c7123f0ce66399Ian Rogers if (UNLIKELY(s == nullptr)) { 6922d5e735f403c57525fe868304c7123f0ce66399Ian Rogers StackHandleScope<1> hs(Thread::Current()); 7022d5e735f403c57525fe868304c7123f0ce66399Ian Rogers Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache())); 7122d5e735f403c57525fe868304c7123f0ce66399Ian Rogers s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx, 7222d5e735f403c57525fe868304c7123f0ce66399Ian Rogers dex_cache); 7322d5e735f403c57525fe868304c7123f0ce66399Ian Rogers } 7422d5e735f403c57525fe868304c7123f0ce66399Ian Rogers return s; 7522d5e735f403c57525fe868304c7123f0ce66399Ian Rogers} 7622d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 7722d5e735f403c57525fe868304c7123f0ce66399Ian Rogers} // namespace art 7822d5e735f403c57525fe868304c7123f0ce66399Ian Rogers 7922d5e735f403c57525fe868304c7123f0ce66399Ian Rogers#endif // ART_RUNTIME_METHOD_HELPER_INL_H_ 80