blob: cf548ada33d9d222c0a56d2e813a7b36f5906d9f [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#ifndef ART_RUNTIME_ART_METHOD_INL_H_
18#define ART_RUNTIME_ART_METHOD_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "art_method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021
Andreas Gampe58a5af82014-07-31 16:23:49 -070022#include "art_field.h"
Mathieu Chartier7c0fe5e2015-07-17 19:53:47 -070023#include "base/logging.h"
Hiroshi Yamauchi00370822015-08-18 14:47:25 -070024#include "class_linker-inl.h"
Vladimir Marko05792b92015-08-03 11:56:49 +010025#include "common_throws.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "dex_file.h"
Elliott Hughes956af0f2014-12-11 14:34:28 -080027#include "dex_file-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "gc_root-inl.h"
Nicolas Geoffray5550ca82015-08-21 18:38:30 +010029#include "jit/profiling_info.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070030#include "mirror/class-inl.h"
Vladimir Marko05792b92015-08-03 11:56:49 +010031#include "mirror/dex_cache-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070032#include "mirror/object-inl.h"
33#include "mirror/object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010034#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010035#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070036#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010037#include "runtime-inl.h"
Andreas Gampecbc96b82015-09-30 20:05:24 +000038#include "scoped_thread_state_change.h"
39#include "thread-inl.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010040#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041
42namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043
Mathieu Chartiere401d142015-04-22 13:56:20 -070044inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070045 GcRootSource gc_root_source(this);
46 return declaring_class_.Read(&gc_root_source);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070047}
48
Mathieu Chartiere401d142015-04-22 13:56:20 -070049inline mirror::Class* ArtMethod::GetDeclaringClassNoBarrier() {
50 return declaring_class_.Read<kWithoutReadBarrier>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070051}
52
Mathieu Chartiere401d142015-04-22 13:56:20 -070053inline mirror::Class* ArtMethod::GetDeclaringClass() {
54 mirror::Class* result = GetDeclaringClassUnchecked();
55 if (kIsDebugBuild) {
56 if (!IsRuntimeMethod()) {
57 CHECK(result != nullptr) << this;
58 CHECK(result->IsIdxLoaded() || result->IsErroneous())
59 << result->GetStatus() << " " << PrettyClass(result);
60 } else {
61 CHECK(result == nullptr) << this;
62 }
63 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064 return result;
65}
66
Mathieu Chartiere401d142015-04-22 13:56:20 -070067inline void ArtMethod::SetDeclaringClass(mirror::Class* new_declaring_class) {
68 declaring_class_ = GcRoot<mirror::Class>(new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069}
70
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070071inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class,
72 mirror::Class* desired_class) {
73 GcRoot<mirror::Class> expected_root(expected_class);
74 GcRoot<mirror::Class> desired_root(desired_class);
75 return reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_)->
76 CompareExchangeStrongSequentiallyConsistent(
77 expected_root, desired_root);
78}
79
Andreas Gampecbc96b82015-09-30 20:05:24 +000080// AssertSharedHeld doesn't work in GetAccessFlags, so use a NO_THREAD_SAFETY_ANALYSIS helper.
81// TODO: Figure out why ASSERT_SHARED_CAPABILITY doesn't work.
82ALWAYS_INLINE
83static inline void DoGetAccessFlagsHelper(ArtMethod* method) NO_THREAD_SAFETY_ANALYSIS {
84 CHECK(method->IsRuntimeMethod() || method->GetDeclaringClass()->IsIdxLoaded() ||
85 method->GetDeclaringClass()->IsErroneous());
86}
87
Ian Rogersef7d42f2014-01-06 12:55:46 -080088inline uint32_t ArtMethod::GetAccessFlags() {
Andreas Gampecbc96b82015-09-30 20:05:24 +000089 if (kIsDebugBuild) {
90 Thread* self = Thread::Current();
91 if (!Locks::mutator_lock_->IsSharedHeld(self)) {
92 ScopedObjectAccess soa(self);
93 CHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
94 GetDeclaringClass()->IsErroneous());
95 } else {
96 // We cannot use SOA in this case. We might be holding the lock, but may not be in the
97 // runnable state (e.g., during GC).
98 Locks::mutator_lock_->AssertSharedHeld(self);
99 DoGetAccessFlagsHelper(this);
100 }
101 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700102 return access_flags_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103}
104
Ian Rogersef7d42f2014-01-06 12:55:46 -0800105inline uint16_t ArtMethod::GetMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700106 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() ||
107 GetDeclaringClass()->IsErroneous());
108 return method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800109}
110
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700111inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700112 return method_index_;
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700113}
114
Ian Rogersef7d42f2014-01-06 12:55:46 -0800115inline uint32_t ArtMethod::GetDexMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700116 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
117 GetDeclaringClass()->IsErroneous());
118 return dex_method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119}
120
Vladimir Marko05792b92015-08-03 11:56:49 +0100121inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(size_t pointer_size) {
122 return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size),
123 pointer_size);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700124}
125
Mathieu Chartiere401d142015-04-22 13:56:20 -0700126inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100127 // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here
128 // without accessing the DexCache and we don't want to do that in release build.
129 DCHECK_LT(method_index,
130 GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()
131 ->GetDexCache()->NumResolvedMethods());
132 ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(ptr_size),
133 method_index,
134 ptr_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700135 if (LIKELY(method != nullptr)) {
136 auto* declaring_class = method->GetDeclaringClass();
137 if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) {
138 return method;
139 }
Andreas Gampe58a5af82014-07-31 16:23:49 -0700140 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700141 return nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700142}
143
Vladimir Marko05792b92015-08-03 11:56:49 +0100144inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700145 size_t ptr_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100146 // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here
147 // without accessing the DexCache and we don't want to do that in release build.
148 DCHECK_LT(method_index,
149 GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()
150 ->GetDexCache()->NumResolvedMethods());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700151 DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100152 mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(ptr_size),
153 method_index,
154 new_method,
155 ptr_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700156}
157
Vladimir Marko05792b92015-08-03 11:56:49 +0100158inline bool ArtMethod::HasDexCacheResolvedMethods(size_t pointer_size) {
159 return GetDexCacheResolvedMethods(pointer_size) != nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700160}
161
Vladimir Marko05792b92015-08-03 11:56:49 +0100162inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache,
163 size_t pointer_size) {
164 return GetDexCacheResolvedMethods(pointer_size) == other_cache;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700165}
166
Vladimir Marko05792b92015-08-03 11:56:49 +0100167inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size) {
168 return GetDexCacheResolvedMethods(pointer_size) ==
169 other->GetDexCacheResolvedMethods(pointer_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700170}
171
Vladimir Marko05792b92015-08-03 11:56:49 +0100172inline GcRoot<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes(size_t pointer_size) {
173 return GetNativePointer<GcRoot<mirror::Class>*>(DexCacheResolvedTypesOffset(pointer_size),
174 pointer_size);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700175}
176
Andreas Gampe58a5af82014-07-31 16:23:49 -0700177template <bool kWithCheck>
Vladimir Marko05792b92015-08-03 11:56:49 +0100178inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index, size_t ptr_size) {
179 if (kWithCheck) {
180 mirror::DexCache* dex_cache =
181 GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()->GetDexCache();
182 if (UNLIKELY(type_index >= dex_cache->NumResolvedTypes())) {
183 ThrowArrayIndexOutOfBoundsException(type_index, dex_cache->NumResolvedTypes());
184 return nullptr;
185 }
186 }
187 mirror::Class* klass = GetDexCacheResolvedTypes(ptr_size)[type_index].Read();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700188 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
189}
190
Vladimir Marko05792b92015-08-03 11:56:49 +0100191inline bool ArtMethod::HasDexCacheResolvedTypes(size_t pointer_size) {
192 return GetDexCacheResolvedTypes(pointer_size) != nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700193}
194
Vladimir Marko05792b92015-08-03 11:56:49 +0100195inline bool ArtMethod::HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache,
196 size_t pointer_size) {
197 return GetDexCacheResolvedTypes(pointer_size) == other_cache;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700198}
199
Vladimir Marko05792b92015-08-03 11:56:49 +0100200inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size) {
201 return GetDexCacheResolvedTypes(pointer_size) == other->GetDexCacheResolvedTypes(pointer_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700202}
203
Vladimir Marko05792b92015-08-03 11:56:49 +0100204inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx,
205 bool resolve,
206 size_t ptr_size) {
207 mirror::Class* type = GetDexCacheResolvedType(type_idx, ptr_size);
Ian Rogersa0485602014-12-02 15:48:04 -0800208 if (type == nullptr && resolve) {
209 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
210 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
211 }
212 return type;
213}
214
Brian Carlstromea46f952013-07-30 01:26:50 -0700215inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216 switch (type) {
217 case kStatic:
218 return !IsStatic();
219 case kDirect:
220 return !IsDirect() || IsStatic();
221 case kVirtual: {
Alex Lighteb7c1442015-08-31 13:17:42 -0700222 // We have an error if we are direct or a non-default, non-miranda interface method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700223 mirror::Class* methods_class = GetDeclaringClass();
Alex Lighteb7c1442015-08-31 13:17:42 -0700224 return IsDirect() || (methods_class->IsInterface() && !IsDefault() && !IsMiranda());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 }
226 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700227 // Constructors and static methods are called with invoke-direct.
228 // Interface methods cannot be invoked with invoke-super.
229 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 case kInterface: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700231 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
233 }
234 default:
235 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700236 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 }
238}
239
Ian Rogersef7d42f2014-01-06 12:55:46 -0800240inline bool ArtMethod::IsRuntimeMethod() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700241 return dex_method_index_ == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242}
243
Ian Rogersef7d42f2014-01-06 12:55:46 -0800244inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 if (!IsRuntimeMethod()) {
246 return false;
247 }
248 Runtime* runtime = Runtime::Current();
249 bool result = false;
250 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
251 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
252 result = true;
253 break;
254 }
255 }
256 return result;
257}
258
Ian Rogersef7d42f2014-01-06 12:55:46 -0800259inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 bool result = this == Runtime::Current()->GetResolutionMethod();
261 // Check that if we do think it is phony it looks like the resolution method.
262 DCHECK(!result || IsRuntimeMethod());
263 return result;
264}
Jeff Hao88474b42013-10-23 16:24:40 -0700265
Ian Rogersef7d42f2014-01-06 12:55:46 -0800266inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700267 bool result = this == Runtime::Current()->GetImtConflictMethod();
268 // Check that if we do think it is phony it looks like the imt conflict method.
269 DCHECK(!result || IsRuntimeMethod());
270 return result;
271}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800272
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700273inline bool ArtMethod::IsImtUnimplementedMethod() {
274 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
275 // Check that if we do think it is phony it looks like the imt unimplemented method.
276 DCHECK(!result || IsRuntimeMethod());
277 return result;
278}
279
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700280inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700281 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700282}
283
284inline const char* ArtMethod::GetDeclaringClassDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700285 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700286 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
287 return "<runtime method>";
288 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700289 DCHECK(!IsProxyMethod());
290 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700291 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
292}
293
294inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000295 DCHECK(!IsProxyMethod());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700296 const DexFile* dex_file = GetDexFile();
297 return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700298}
299
300inline const Signature ArtMethod::GetSignature() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700301 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700302 if (dex_method_idx != DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700303 DCHECK(!IsProxyMethod());
304 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700305 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
306 }
307 return Signature::NoSignature();
308}
309
Ian Rogers1ff3c982014-08-12 02:30:58 -0700310inline const char* ArtMethod::GetName() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700311 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700312 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700313 DCHECK(!IsProxyMethod());
314 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700315 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
316 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700317 Runtime* const runtime = Runtime::Current();
318 if (this == runtime->GetResolutionMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700319 return "<runtime internal resolution method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700320 } else if (this == runtime->GetImtConflictMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700321 return "<runtime internal imt conflict method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700322 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700323 return "<runtime internal callee-save all registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700324 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700325 return "<runtime internal callee-save reference registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700326 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700327 return "<runtime internal callee-save reference and argument registers method>";
328 } else {
329 return "<unknown runtime internal method>";
330 }
331}
332
333inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800334 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700335}
336
Vladimir Marko05792b92015-08-03 11:56:49 +0100337inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700338 DCHECK(!IsProxyMethod());
Vladimir Marko05792b92015-08-03 11:56:49 +0100339 return GetDexCacheResolvedType(type_idx, ptr_size) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700340}
341
342inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700343 DCHECK(!IsProxyMethod());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700344 if (dex_pc == DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700345 return IsNative() ? -2 : -1;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700346 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700347 return GetDexFile()->GetLineNumFromPC(this, dex_pc);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700348}
349
350inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700351 DCHECK(!IsProxyMethod());
352 const DexFile* dex_file = GetDexFile();
353 return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700354}
355
356inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000357 DCHECK(!IsProxyMethod());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700358 const DexFile* dex_file = GetDexFile();
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000359 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
360 dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700361 return dex_file->GetProtoParameters(proto);
362}
363
364inline const char* ArtMethod::GetDeclaringClassSourceFile() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700365 DCHECK(!IsProxyMethod());
366 return GetDeclaringClass()->GetSourceFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700367}
368
369inline uint16_t ArtMethod::GetClassDefIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700370 DCHECK(!IsProxyMethod());
371 return GetDeclaringClass()->GetDexClassDefIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700372}
373
374inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700375 DCHECK(!IsProxyMethod());
376 return GetDexFile()->GetClassDef(GetClassDefIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700377}
378
379inline const char* ArtMethod::GetReturnTypeDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700380 DCHECK(!IsProxyMethod());
381 const DexFile* dex_file = GetDexFile();
382 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700383 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
384 uint16_t return_type_idx = proto_id.return_type_idx_;
385 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
386}
387
388inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700389 DCHECK(!IsProxyMethod());
390 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700391 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
392}
393
394inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 DCHECK(!IsProxyMethod());
396 return GetDeclaringClass()->GetClassLoader();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700397}
398
399inline mirror::DexCache* ArtMethod::GetDexCache() {
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000400 DCHECK(!IsProxyMethod());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700401 return GetDeclaringClass()->GetDexCache();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700402}
403
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700404inline bool ArtMethod::IsProxyMethod() {
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000405 return GetDeclaringClass()->IsProxyClass();
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700406}
407
Mathieu Chartiere401d142015-04-22 13:56:20 -0700408inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(size_t pointer_size) {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700409 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700410 return this;
411 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700412 mirror::Class* klass = GetDeclaringClass();
Vladimir Marko05792b92015-08-03 11:56:49 +0100413 ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize(
414 GetDexCacheResolvedMethods(pointer_size),
415 GetDexMethodIndex(),
416 pointer_size);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700417 DCHECK(interface_method != nullptr);
418 DCHECK_EQ(interface_method,
419 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
420 return interface_method;
421}
422
Vladimir Marko05792b92015-08-03 11:56:49 +0100423inline void ArtMethod::SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods,
424 size_t ptr_size) {
425 SetNativePointer(DexCacheResolvedMethodsOffset(ptr_size), new_dex_cache_methods, ptr_size);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700426}
427
Vladimir Marko05792b92015-08-03 11:56:49 +0100428inline void ArtMethod::SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types,
429 size_t ptr_size) {
430 SetNativePointer(DexCacheResolvedTypesOffset(ptr_size), new_dex_cache_types, ptr_size);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700431}
432
Vladimir Marko05792b92015-08-03 11:56:49 +0100433inline mirror::Class* ArtMethod::GetReturnType(bool resolve, size_t ptr_size) {
Ian Rogersded66a02014-10-28 18:12:55 -0700434 DCHECK(!IsProxyMethod());
435 const DexFile* dex_file = GetDexFile();
436 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
437 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
438 uint16_t return_type_idx = proto_id.return_type_idx_;
Vladimir Marko05792b92015-08-03 11:56:49 +0100439 mirror::Class* type = GetDexCacheResolvedType(return_type_idx, ptr_size);
Ian Rogersded66a02014-10-28 18:12:55 -0700440 if (type == nullptr && resolve) {
441 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
442 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
443 }
444 return type;
445}
446
Mathieu Chartiere401d142015-04-22 13:56:20 -0700447template<typename RootVisitorType>
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700448void ArtMethod::VisitRoots(RootVisitorType& visitor, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100449 ArtMethod* interface_method = nullptr;
450 mirror::Class* klass = declaring_class_.Read();
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000451 if (UNLIKELY(klass != nullptr && klass->IsProxyClass())) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100452 // For normal methods, dex cache shortcuts will be visited through the declaring class.
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000453 // However, for proxies we need to keep the interface method alive, so we visit its roots.
Vladimir Marko05792b92015-08-03 11:56:49 +0100454 interface_method = mirror::DexCache::GetElementPtrSize(
455 GetDexCacheResolvedMethods(pointer_size),
456 GetDexMethodIndex(),
457 pointer_size);
458 DCHECK(interface_method != nullptr);
459 DCHECK_EQ(interface_method,
460 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700461 interface_method->VisitRoots(visitor, pointer_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100462 }
463
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700464 visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700465 ProfilingInfo* profiling_info = GetProfilingInfo(pointer_size);
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100466 if (hotness_count_ != 0 && !IsNative() && profiling_info != nullptr) {
467 profiling_info->VisitRoots(visitor);
468 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800469}
470
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800471} // namespace art
472
Mathieu Chartiere401d142015-04-22 13:56:20 -0700473#endif // ART_RUNTIME_ART_METHOD_INL_H_