blob: 3a5056adce3967e254239d6d31baec033926167c [file] [log] [blame]
Ian Rogers22d5e732014-07-15 22:23:51 -07001/*
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
Ian Rogerse5877a12014-07-16 12:06:35 -070022#include "class_linker.h"
23#include "mirror/object_array.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070024#include "runtime.h"
Ian Rogerse5877a12014-07-16 12:06:35 -070025#include "thread-inl.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070026
27namespace art {
28
29inline mirror::Class* MethodHelper::GetClassFromTypeIdx(uint16_t type_idx, bool resolve) {
30 mirror::ArtMethod* method = GetMethod();
Andreas Gampe58a5af82014-07-31 16:23:49 -070031 mirror::Class* type = method->GetDexCacheResolvedType(type_idx);
Ian Rogers22d5e732014-07-15 22:23:51 -070032 if (type == nullptr && resolve) {
33 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
34 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
35 }
36 return type;
37}
38
Ian Rogerse5877a12014-07-16 12:06:35 -070039inline mirror::Class* MethodHelper::GetReturnType(bool resolve) {
40 mirror::ArtMethod* method = GetMethod();
41 const DexFile* dex_file = method->GetDexFile();
42 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
43 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
44 uint16_t return_type_idx = proto_id.return_type_idx_;
45 return GetClassFromTypeIdx(return_type_idx, resolve);
46}
47
Ian Rogers22d5e732014-07-15 22:23:51 -070048inline mirror::String* MethodHelper::ResolveString(uint32_t string_idx) {
49 mirror::ArtMethod* method = GetMethod();
50 mirror::String* s = method->GetDexCacheStrings()->Get(string_idx);
51 if (UNLIKELY(s == nullptr)) {
52 StackHandleScope<1> hs(Thread::Current());
53 Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache()));
54 s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx,
55 dex_cache);
56 }
57 return s;
58}
59
60} // namespace art
61
62#endif // ART_RUNTIME_METHOD_HELPER_INL_H_