blob: 85ef4e6575304226fb3bdaee0869c3496856c8bb [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
Brian Carlstromea46f952013-07-30 01:26:50 -070017#ifndef ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
18#define ART_RUNTIME_MIRROR_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"
23#include "class.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070024#include "class_linker.h"
25#include "dex_cache.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "dex_file.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "object-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070028#include "object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010029#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010030#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070031#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010032#include "runtime-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033
34namespace art {
35namespace mirror {
36
Mingyao Yang98d1cc82014-05-15 17:02:16 -070037inline uint32_t ArtMethod::ClassSize() {
38 uint32_t vtable_entries = Object::kVTableLength + 8;
Fred Shih37f05ef2014-07-16 18:38:08 -070039 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070040}
41
42template<ReadBarrierOption kReadBarrierOption>
43inline Class* ArtMethod::GetJavaLangReflectArtMethod() {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070044 DCHECK(!java_lang_reflect_ArtMethod_.IsNull());
45 return java_lang_reflect_ArtMethod_.Read<kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070046}
47
Ian Rogersef7d42f2014-01-06 12:55:46 -080048inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070049 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 DCHECK(result != NULL) << this;
51 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
52 return result;
53}
54
Brian Carlstromea46f952013-07-30 01:26:50 -070055inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010056 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070057 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058}
59
Ian Rogersef7d42f2014-01-06 12:55:46 -080060inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070062 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063}
64
Ian Rogersef7d42f2014-01-06 12:55:46 -080065inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080066 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070067 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068}
69
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070070inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
71 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
72}
73
Ian Rogersef7d42f2014-01-06 12:55:46 -080074inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070075#ifdef ART_SEA_IR_MODE
76 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
77 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
78#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070080#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070081 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082}
83
Ian Rogersef7d42f2014-01-06 12:55:46 -080084inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070085 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070086 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070087}
88
Andreas Gampe58a5af82014-07-31 16:23:49 -070089inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) {
90 ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index);
91 if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) {
92 return method;
93 } else {
94 return nullptr;
95 }
96}
97
98inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) {
99 GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method);
100}
101
102inline bool ArtMethod::HasDexCacheResolvedMethods() {
103 return GetDexCacheResolvedMethods() != nullptr;
104}
105
106inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) {
107 return GetDexCacheResolvedMethods() == other_cache;
108}
109
110inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
111 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
112}
113
114
Ian Rogersef7d42f2014-01-06 12:55:46 -0800115inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -0700116 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700117 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700118}
119
Andreas Gampe58a5af82014-07-31 16:23:49 -0700120template <bool kWithCheck>
121inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
122 Class* klass;
123 if (kWithCheck) {
124 klass = GetDexCacheResolvedTypes()->Get(type_index);
125 } else {
126 klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
127 }
128 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
129}
130
131inline bool ArtMethod::HasDexCacheResolvedTypes() {
132 return GetDexCacheResolvedTypes() != nullptr;
133}
134
135inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) {
136 return GetDexCacheResolvedTypes() == other_cache;
137}
138
139inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
140 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
141}
142
Ian Rogersef7d42f2014-01-06 12:55:46 -0800143inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +0100145 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
146 if (code == nullptr) {
147 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800148 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100149 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150}
151
Brian Carlstromea46f952013-07-30 01:26:50 -0700152inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 switch (type) {
154 case kStatic:
155 return !IsStatic();
156 case kDirect:
157 return !IsDirect() || IsStatic();
158 case kVirtual: {
159 Class* methods_class = GetDeclaringClass();
160 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
161 }
162 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700163 // Constructors and static methods are called with invoke-direct.
164 // Interface methods cannot be invoked with invoke-super.
165 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 case kInterface: {
167 Class* methods_class = GetDeclaringClass();
168 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
169 }
170 default:
171 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700172 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 }
174}
175
Ian Rogersef7d42f2014-01-06 12:55:46 -0800176inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800178 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179}
180
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800182 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184}
185
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
189}
190
191inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
192 DCHECK(!Runtime::Current()->IsStarted());
193 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
194}
195
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800196inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
197 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100198 if (code_pointer == nullptr) {
199 return nullptr;
200 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800201 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100202}
203
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800204inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100205 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800206 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100207 uint32_t offset =
208 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
209 if (UNLIKELY(offset == 0u)) {
210 return nullptr;
211 }
212 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
213}
214
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800215inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
216 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100217 if (code_pointer == nullptr) {
218 return nullptr;
219 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800220 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100221}
222
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800223inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
224 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100225 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800226 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100227 uint32_t offset =
228 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
229 if (UNLIKELY(offset == 0u)) {
230 return nullptr;
231 }
232 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
233}
234
Nicolas Geoffray39468442014-09-02 15:17:15 +0100235inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100236 return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset);
237}
238
239inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800240 DCHECK(IsOptimized(sizeof(void*)));
241 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100242 DCHECK(code_pointer != nullptr);
243 uint32_t offset =
244 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
245 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100246 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100247}
248
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800249inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
250 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
251 if (code_pointer == nullptr) {
252 return nullptr;
253 }
254 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255}
256
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800257inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
258 DCHECK(code_pointer != nullptr);
259 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
260 uint32_t offset =
261 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
262 if (UNLIKELY(offset == 0u)) {
263 return nullptr;
264 }
265 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800266}
267
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700269 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800270}
271
Ian Rogersef7d42f2014-01-06 12:55:46 -0800272inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800273 if (!IsRuntimeMethod()) {
274 return false;
275 }
276 Runtime* runtime = Runtime::Current();
277 bool result = false;
278 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
279 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
280 result = true;
281 break;
282 }
283 }
284 return result;
285}
286
Ian Rogersef7d42f2014-01-06 12:55:46 -0800287inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800288 bool result = this == Runtime::Current()->GetResolutionMethod();
289 // Check that if we do think it is phony it looks like the resolution method.
290 DCHECK(!result || IsRuntimeMethod());
291 return result;
292}
Jeff Hao88474b42013-10-23 16:24:40 -0700293
Ian Rogersef7d42f2014-01-06 12:55:46 -0800294inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700295 bool result = this == Runtime::Current()->GetImtConflictMethod();
296 // Check that if we do think it is phony it looks like the imt conflict method.
297 DCHECK(!result || IsRuntimeMethod());
298 return result;
299}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800300
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700301inline bool ArtMethod::IsImtUnimplementedMethod() {
302 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
303 // Check that if we do think it is phony it looks like the imt unimplemented method.
304 DCHECK(!result || IsRuntimeMethod());
305 return result;
306}
307
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700308inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800309 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
310 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100311 return pc - reinterpret_cast<uintptr_t>(code);
312}
313
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100314inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
315 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800316 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
Vladimir Marko7624d252014-05-02 14:40:15 +0100317 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
318}
319
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700320inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700321 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700322}
323
324inline const char* ArtMethod::GetDeclaringClassDescriptor() {
325 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
326 uint32_t dex_method_idx = method->GetDexMethodIndex();
327 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
328 return "<runtime method>";
329 }
330 const DexFile* dex_file = method->GetDexFile();
331 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
332}
333
334inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
335 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
336 const DexFile* dex_file = method->GetDexFile();
337 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
338}
339
340inline const Signature ArtMethod::GetSignature() {
341 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
342 uint32_t dex_method_idx = method->GetDexMethodIndex();
343 if (dex_method_idx != DexFile::kDexNoIndex) {
344 const DexFile* dex_file = method->GetDexFile();
345 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
346 }
347 return Signature::NoSignature();
348}
349
Ian Rogers1ff3c982014-08-12 02:30:58 -0700350inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700351 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
352 uint32_t dex_method_idx = method->GetDexMethodIndex();
353 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
354 const DexFile* dex_file = method->GetDexFile();
355 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
356 }
357 Runtime* runtime = Runtime::Current();
358 if (method == runtime->GetResolutionMethod()) {
359 return "<runtime internal resolution method>";
360 } else if (method == runtime->GetImtConflictMethod()) {
361 return "<runtime internal imt conflict method>";
362 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
363 return "<runtime internal callee-save all registers method>";
364 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
365 return "<runtime internal callee-save reference registers method>";
366 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
367 return "<runtime internal callee-save reference and argument registers method>";
368 } else {
369 return "<unknown runtime internal method>";
370 }
371}
372
373inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
374 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
375 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
376}
377
378inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
379 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700380 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700381}
382
383inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
384 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
385 if (dex_pc == DexFile::kDexNoIndex) {
386 return method->IsNative() ? -2 : -1;
387 }
388 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
389}
390
391inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
392 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
393 const DexFile* dex_file = method->GetDexFile();
394 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
395}
396
397inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
398 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
399 const DexFile* dex_file = method->GetDexFile();
400 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
401 dex_file->GetMethodId(method->GetDexMethodIndex()));
402 return dex_file->GetProtoParameters(proto);
403}
404
405inline const char* ArtMethod::GetDeclaringClassSourceFile() {
406 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
407}
408
409inline uint16_t ArtMethod::GetClassDefIndex() {
410 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
411}
412
413inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
414 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
415 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
416}
417
418inline const char* ArtMethod::GetReturnTypeDescriptor() {
419 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
420 const DexFile* dex_file = method->GetDexFile();
421 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
422 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
423 uint16_t return_type_idx = proto_id.return_type_idx_;
424 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
425}
426
427inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
428 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
429 const DexFile* dex_file = method->GetDexFile();
430 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
431}
432
433inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
434 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
435}
436
437inline mirror::DexCache* ArtMethod::GetDexCache() {
438 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
439}
440
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700441inline bool ArtMethod::IsProxyMethod() {
442 return GetDeclaringClass()->IsProxyClass();
443}
444
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700445inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700446 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700447 return this;
448 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700449 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700450 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
451 DCHECK(interface_method != nullptr);
452 DCHECK_EQ(interface_method,
453 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
454 return interface_method;
455}
456
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700457inline void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) {
458 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_),
459 new_dex_cache_methods);
460}
461
462inline void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) {
463 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_),
464 new_dex_cache_classes);
465}
466
Ian Rogersded66a02014-10-28 18:12:55 -0700467inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
468 DCHECK(!IsProxyMethod());
469 const DexFile* dex_file = GetDexFile();
470 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
471 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
472 uint16_t return_type_idx = proto_id.return_type_idx_;
473 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
474 if (type == nullptr && resolve) {
475 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
476 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
477 }
478 return type;
479}
480
Mathieu Chartier2d721012014-11-10 11:08:06 -0800481inline void ArtMethod::CheckObjectSizeEqualsMirrorSize() {
482 // Using the default, check the class object size to make sure it matches the size of the
483 // object.
Mathieu Chartiereace4582014-11-24 18:29:54 -0800484 size_t this_size = sizeof(*this);
485#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
486 this_size += sizeof(void*) - sizeof(uint32_t);
487#endif
488 DCHECK_EQ(GetClass()->GetObjectSize(), this_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800489}
490
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491} // namespace mirror
492} // namespace art
493
Brian Carlstromea46f952013-07-30 01:26:50 -0700494#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_