blob: d6b2b7e04d8d8580c5dd19b3f8081ef55466f6d3 [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"
Vladimir Marko80afd022015-05-19 18:08:00 +010038#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039
40namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041
Mathieu Chartiere401d142015-04-22 13:56:20 -070042inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070043 GcRootSource gc_root_source(this);
44 return declaring_class_.Read(&gc_root_source);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070045}
46
Mathieu Chartiere401d142015-04-22 13:56:20 -070047inline mirror::Class* ArtMethod::GetDeclaringClassNoBarrier() {
48 return declaring_class_.Read<kWithoutReadBarrier>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070049}
50
Mathieu Chartiere401d142015-04-22 13:56:20 -070051inline mirror::Class* ArtMethod::GetDeclaringClass() {
52 mirror::Class* result = GetDeclaringClassUnchecked();
53 if (kIsDebugBuild) {
54 if (!IsRuntimeMethod()) {
55 CHECK(result != nullptr) << this;
56 CHECK(result->IsIdxLoaded() || result->IsErroneous())
57 << result->GetStatus() << " " << PrettyClass(result);
58 } else {
59 CHECK(result == nullptr) << this;
60 }
61 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062 return result;
63}
64
Mathieu Chartiere401d142015-04-22 13:56:20 -070065inline void ArtMethod::SetDeclaringClass(mirror::Class* new_declaring_class) {
66 declaring_class_ = GcRoot<mirror::Class>(new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067}
68
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070069inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class,
70 mirror::Class* desired_class) {
71 GcRoot<mirror::Class> expected_root(expected_class);
72 GcRoot<mirror::Class> desired_root(desired_class);
73 return reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_)->
74 CompareExchangeStrongSequentiallyConsistent(
75 expected_root, desired_root);
76}
77
Ian Rogersef7d42f2014-01-06 12:55:46 -080078inline uint32_t ArtMethod::GetAccessFlags() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070079 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
80 GetDeclaringClass()->IsErroneous());
81 return access_flags_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082}
83
Ian Rogersef7d42f2014-01-06 12:55:46 -080084inline uint16_t ArtMethod::GetMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070085 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() ||
86 GetDeclaringClass()->IsErroneous());
87 return method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088}
89
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070090inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070091 return method_index_;
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070092}
93
Ian Rogersef7d42f2014-01-06 12:55:46 -080094inline uint32_t ArtMethod::GetDexMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070095 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
96 GetDeclaringClass()->IsErroneous());
97 return dex_method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098}
99
Vladimir Marko05792b92015-08-03 11:56:49 +0100100inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(size_t pointer_size) {
101 return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size),
102 pointer_size);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700103}
104
Mathieu Chartiere401d142015-04-22 13:56:20 -0700105inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100106 // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here
107 // without accessing the DexCache and we don't want to do that in release build.
108 DCHECK_LT(method_index,
109 GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()
110 ->GetDexCache()->NumResolvedMethods());
111 ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(ptr_size),
112 method_index,
113 ptr_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700114 if (LIKELY(method != nullptr)) {
115 auto* declaring_class = method->GetDeclaringClass();
116 if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) {
117 return method;
118 }
Andreas Gampe58a5af82014-07-31 16:23:49 -0700119 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700120 return nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700121}
122
Vladimir Marko05792b92015-08-03 11:56:49 +0100123inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700124 size_t ptr_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100125 // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here
126 // without accessing the DexCache and we don't want to do that in release build.
127 DCHECK_LT(method_index,
128 GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()
129 ->GetDexCache()->NumResolvedMethods());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700130 DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100131 mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(ptr_size),
132 method_index,
133 new_method,
134 ptr_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700135}
136
Vladimir Marko05792b92015-08-03 11:56:49 +0100137inline bool ArtMethod::HasDexCacheResolvedMethods(size_t pointer_size) {
138 return GetDexCacheResolvedMethods(pointer_size) != nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700139}
140
Vladimir Marko05792b92015-08-03 11:56:49 +0100141inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache,
142 size_t pointer_size) {
143 return GetDexCacheResolvedMethods(pointer_size) == other_cache;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700144}
145
Vladimir Marko05792b92015-08-03 11:56:49 +0100146inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size) {
147 return GetDexCacheResolvedMethods(pointer_size) ==
148 other->GetDexCacheResolvedMethods(pointer_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700149}
150
Vladimir Marko05792b92015-08-03 11:56:49 +0100151inline GcRoot<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes(size_t pointer_size) {
152 return GetNativePointer<GcRoot<mirror::Class>*>(DexCacheResolvedTypesOffset(pointer_size),
153 pointer_size);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700154}
155
Andreas Gampe58a5af82014-07-31 16:23:49 -0700156template <bool kWithCheck>
Vladimir Marko05792b92015-08-03 11:56:49 +0100157inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index, size_t ptr_size) {
158 if (kWithCheck) {
159 mirror::DexCache* dex_cache =
160 GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()->GetDexCache();
161 if (UNLIKELY(type_index >= dex_cache->NumResolvedTypes())) {
162 ThrowArrayIndexOutOfBoundsException(type_index, dex_cache->NumResolvedTypes());
163 return nullptr;
164 }
165 }
166 mirror::Class* klass = GetDexCacheResolvedTypes(ptr_size)[type_index].Read();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700167 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
168}
169
Vladimir Marko05792b92015-08-03 11:56:49 +0100170inline bool ArtMethod::HasDexCacheResolvedTypes(size_t pointer_size) {
171 return GetDexCacheResolvedTypes(pointer_size) != nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700172}
173
Vladimir Marko05792b92015-08-03 11:56:49 +0100174inline bool ArtMethod::HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache,
175 size_t pointer_size) {
176 return GetDexCacheResolvedTypes(pointer_size) == other_cache;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700177}
178
Vladimir Marko05792b92015-08-03 11:56:49 +0100179inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size) {
180 return GetDexCacheResolvedTypes(pointer_size) == other->GetDexCacheResolvedTypes(pointer_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700181}
182
Vladimir Marko05792b92015-08-03 11:56:49 +0100183inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx,
184 bool resolve,
185 size_t ptr_size) {
186 mirror::Class* type = GetDexCacheResolvedType(type_idx, ptr_size);
Ian Rogersa0485602014-12-02 15:48:04 -0800187 if (type == nullptr && resolve) {
188 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
189 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
190 }
191 return type;
192}
193
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800196 return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
197}
198
199inline uint32_t ArtMethod::GetCodeSize(const void* code) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100200 if (code == nullptr) {
201 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100203 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204}
205
Brian Carlstromea46f952013-07-30 01:26:50 -0700206inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 switch (type) {
208 case kStatic:
209 return !IsStatic();
210 case kDirect:
211 return !IsDirect() || IsStatic();
212 case kVirtual: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700213 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
215 }
216 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700217 // Constructors and static methods are called with invoke-direct.
218 // Interface methods cannot be invoked with invoke-super.
219 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220 case kInterface: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700221 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
223 }
224 default:
225 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700226 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227 }
228}
229
Ian Rogersef7d42f2014-01-06 12:55:46 -0800230inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800232 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233}
234
Ian Rogersef7d42f2014-01-06 12:55:46 -0800235inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800237 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
238}
239
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800240inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
241 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100242 if (code_pointer == nullptr) {
243 return nullptr;
244 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800245 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100246}
247
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800248inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100249 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800250 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100251 uint32_t offset =
252 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
253 if (UNLIKELY(offset == 0u)) {
254 return nullptr;
255 }
256 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
257}
258
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800259inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
260 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100261 if (code_pointer == nullptr) {
262 return nullptr;
263 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800264 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100265}
266
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800267inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
268 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100269 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800270 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100271 uint32_t offset =
272 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
273 if (UNLIKELY(offset == 0u)) {
274 return nullptr;
275 }
276 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
277}
278
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100279inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800280 DCHECK(IsOptimized(sizeof(void*)));
281 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100282 DCHECK(code_pointer != nullptr);
283 uint32_t offset =
284 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700285 const void* data =
286 reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100287 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100288}
289
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800290inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
291 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
292 if (code_pointer == nullptr) {
293 return nullptr;
294 }
295 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800296}
297
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800298inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
299 DCHECK(code_pointer != nullptr);
300 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
301 uint32_t offset =
302 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
303 if (UNLIKELY(offset == 0u)) {
304 return nullptr;
305 }
306 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800307}
308
Ian Rogersef7d42f2014-01-06 12:55:46 -0800309inline bool ArtMethod::IsRuntimeMethod() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700310 return dex_method_index_ == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311}
312
Ian Rogersef7d42f2014-01-06 12:55:46 -0800313inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314 if (!IsRuntimeMethod()) {
315 return false;
316 }
317 Runtime* runtime = Runtime::Current();
318 bool result = false;
319 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
320 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
321 result = true;
322 break;
323 }
324 }
325 return result;
326}
327
Ian Rogersef7d42f2014-01-06 12:55:46 -0800328inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329 bool result = this == Runtime::Current()->GetResolutionMethod();
330 // Check that if we do think it is phony it looks like the resolution method.
331 DCHECK(!result || IsRuntimeMethod());
332 return result;
333}
Jeff Hao88474b42013-10-23 16:24:40 -0700334
Ian Rogersef7d42f2014-01-06 12:55:46 -0800335inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700336 bool result = this == Runtime::Current()->GetImtConflictMethod();
337 // Check that if we do think it is phony it looks like the imt conflict method.
338 DCHECK(!result || IsRuntimeMethod());
339 return result;
340}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800341
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700342inline bool ArtMethod::IsImtUnimplementedMethod() {
343 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
344 // Check that if we do think it is phony it looks like the imt unimplemented method.
345 DCHECK(!result || IsRuntimeMethod());
346 return result;
347}
348
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700349inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800350 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
351 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100352 return pc - reinterpret_cast<uintptr_t>(code);
353}
354
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100355inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
356 DCHECK(code_pointer != nullptr);
Mathieu Chartier7c0fe5e2015-07-17 19:53:47 -0700357 if (kIsDebugBuild && !IsProxyMethod()) {
358 CHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
359 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100360 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
361}
362
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700363inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700364 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700365}
366
367inline const char* ArtMethod::GetDeclaringClassDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700368 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700369 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
370 return "<runtime method>";
371 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700372 DCHECK(!IsProxyMethod());
373 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700374 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
375}
376
377inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700378 DCHECK(!IsProxyMethod());
379 const DexFile* dex_file = GetDexFile();
380 return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700381}
382
383inline const Signature ArtMethod::GetSignature() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700384 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700385 if (dex_method_idx != DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700386 DCHECK(!IsProxyMethod());
387 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700388 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
389 }
390 return Signature::NoSignature();
391}
392
Ian Rogers1ff3c982014-08-12 02:30:58 -0700393inline const char* ArtMethod::GetName() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700394 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700395 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700396 DCHECK(!IsProxyMethod());
397 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700398 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
399 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700400 Runtime* const runtime = Runtime::Current();
401 if (this == runtime->GetResolutionMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700402 return "<runtime internal resolution method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700403 } else if (this == runtime->GetImtConflictMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700404 return "<runtime internal imt conflict method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700405 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700406 return "<runtime internal callee-save all registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700407 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700408 return "<runtime internal callee-save reference registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700409 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700410 return "<runtime internal callee-save reference and argument registers method>";
411 } else {
412 return "<unknown runtime internal method>";
413 }
414}
415
416inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800417 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700418}
419
Vladimir Marko05792b92015-08-03 11:56:49 +0100420inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700421 DCHECK(!IsProxyMethod());
Vladimir Marko05792b92015-08-03 11:56:49 +0100422 return GetDexCacheResolvedType(type_idx, ptr_size) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700423}
424
425inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700426 DCHECK(!IsProxyMethod());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700427 if (dex_pc == DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700428 return IsNative() ? -2 : -1;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700429 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700430 return GetDexFile()->GetLineNumFromPC(this, dex_pc);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700431}
432
433inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700434 DCHECK(!IsProxyMethod());
435 const DexFile* dex_file = GetDexFile();
436 return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700437}
438
439inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700440 DCHECK(!IsProxyMethod());
441 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700442 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700443 dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700444 return dex_file->GetProtoParameters(proto);
445}
446
447inline const char* ArtMethod::GetDeclaringClassSourceFile() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700448 DCHECK(!IsProxyMethod());
449 return GetDeclaringClass()->GetSourceFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700450}
451
452inline uint16_t ArtMethod::GetClassDefIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700453 DCHECK(!IsProxyMethod());
454 return GetDeclaringClass()->GetDexClassDefIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700455}
456
457inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700458 DCHECK(!IsProxyMethod());
459 return GetDexFile()->GetClassDef(GetClassDefIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700460}
461
462inline const char* ArtMethod::GetReturnTypeDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700463 DCHECK(!IsProxyMethod());
464 const DexFile* dex_file = GetDexFile();
465 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700466 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
467 uint16_t return_type_idx = proto_id.return_type_idx_;
468 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
469}
470
471inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700472 DCHECK(!IsProxyMethod());
473 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700474 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
475}
476
477inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700478 DCHECK(!IsProxyMethod());
479 return GetDeclaringClass()->GetClassLoader();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700480}
481
482inline mirror::DexCache* ArtMethod::GetDexCache() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700483 DCHECK(!IsProxyMethod());
484 return GetDeclaringClass()->GetDexCache();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700485}
486
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700487inline bool ArtMethod::IsProxyMethod() {
488 return GetDeclaringClass()->IsProxyClass();
489}
490
Mathieu Chartiere401d142015-04-22 13:56:20 -0700491inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(size_t pointer_size) {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700492 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700493 return this;
494 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700495 mirror::Class* klass = GetDeclaringClass();
Vladimir Marko05792b92015-08-03 11:56:49 +0100496 ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize(
497 GetDexCacheResolvedMethods(pointer_size),
498 GetDexMethodIndex(),
499 pointer_size);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700500 DCHECK(interface_method != nullptr);
501 DCHECK_EQ(interface_method,
502 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
503 return interface_method;
504}
505
Vladimir Marko05792b92015-08-03 11:56:49 +0100506inline void ArtMethod::SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods,
507 size_t ptr_size) {
508 SetNativePointer(DexCacheResolvedMethodsOffset(ptr_size), new_dex_cache_methods, ptr_size);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700509}
510
Vladimir Marko05792b92015-08-03 11:56:49 +0100511inline void ArtMethod::SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types,
512 size_t ptr_size) {
513 SetNativePointer(DexCacheResolvedTypesOffset(ptr_size), new_dex_cache_types, ptr_size);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700514}
515
Vladimir Marko05792b92015-08-03 11:56:49 +0100516inline mirror::Class* ArtMethod::GetReturnType(bool resolve, size_t ptr_size) {
Ian Rogersded66a02014-10-28 18:12:55 -0700517 DCHECK(!IsProxyMethod());
518 const DexFile* dex_file = GetDexFile();
519 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
520 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
521 uint16_t return_type_idx = proto_id.return_type_idx_;
Vladimir Marko05792b92015-08-03 11:56:49 +0100522 mirror::Class* type = GetDexCacheResolvedType(return_type_idx, ptr_size);
Ian Rogersded66a02014-10-28 18:12:55 -0700523 if (type == nullptr && resolve) {
524 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
525 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
526 }
527 return type;
528}
529
Mathieu Chartiere401d142015-04-22 13:56:20 -0700530template<typename RootVisitorType>
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700531void ArtMethod::VisitRoots(RootVisitorType& visitor, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100532 ArtMethod* interface_method = nullptr;
533 mirror::Class* klass = declaring_class_.Read();
534 if (UNLIKELY(klass != nullptr && klass->IsProxyClass())) {
535 // For normal methods, dex cache shortcuts will be visited through the declaring class.
536 // However, for proxies we need to keep the interface method alive, so we visit its roots.
Vladimir Marko05792b92015-08-03 11:56:49 +0100537 interface_method = mirror::DexCache::GetElementPtrSize(
538 GetDexCacheResolvedMethods(pointer_size),
539 GetDexMethodIndex(),
540 pointer_size);
541 DCHECK(interface_method != nullptr);
542 DCHECK_EQ(interface_method,
543 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700544 interface_method->VisitRoots(visitor, pointer_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100545 }
546
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700547 visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700548 ProfilingInfo* profiling_info = GetProfilingInfo(pointer_size);
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100549 if (hotness_count_ != 0 && !IsNative() && profiling_info != nullptr) {
550 profiling_info->VisitRoots(visitor);
551 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800552}
553
Mathieu Chartiere401d142015-04-22 13:56:20 -0700554inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) {
555 memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src),
Vladimir Marko14632852015-08-17 12:07:23 +0100556 Size(image_pointer_size));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700557 declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700558}
559
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800560} // namespace art
561
Mathieu Chartiere401d142015-04-22 13:56:20 -0700562#endif // ART_RUNTIME_ART_METHOD_INL_H_