blob: c27c6e94414148d8b4d8a21ed166c489ef4ad233 [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"
Elliott Hughes956af0f2014-12-11 14:34:28 -080027#include "dex_file-inl.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070028#include "object-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070029#include "object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010030#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010031#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070032#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010033#include "runtime-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034
35namespace art {
36namespace mirror {
37
Mingyao Yang98d1cc82014-05-15 17:02:16 -070038inline uint32_t ArtMethod::ClassSize() {
39 uint32_t vtable_entries = Object::kVTableLength + 8;
Fred Shih37f05ef2014-07-16 18:38:08 -070040 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070041}
42
43template<ReadBarrierOption kReadBarrierOption>
44inline Class* ArtMethod::GetJavaLangReflectArtMethod() {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070045 DCHECK(!java_lang_reflect_ArtMethod_.IsNull());
46 return java_lang_reflect_ArtMethod_.Read<kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070047}
48
Ian Rogersef7d42f2014-01-06 12:55:46 -080049inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070050 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051 DCHECK(result != NULL) << this;
52 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
53 return result;
54}
55
Brian Carlstromea46f952013-07-30 01:26:50 -070056inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010057 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070058 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059}
60
Ian Rogersef7d42f2014-01-06 12:55:46 -080061inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070063 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064}
65
Ian Rogersef7d42f2014-01-06 12:55:46 -080066inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070068 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069}
70
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070071inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
72 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
73}
74
Ian Rogersef7d42f2014-01-06 12:55:46 -080075inline uint32_t ArtMethod::GetDexMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070077 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078}
79
Ian Rogersef7d42f2014-01-06 12:55:46 -080080inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070081 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070082 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070083}
84
Andreas Gampe58a5af82014-07-31 16:23:49 -070085inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) {
86 ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index);
87 if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) {
88 return method;
89 } else {
90 return nullptr;
91 }
92}
93
94inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) {
95 GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method);
96}
97
98inline bool ArtMethod::HasDexCacheResolvedMethods() {
99 return GetDexCacheResolvedMethods() != nullptr;
100}
101
102inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) {
103 return GetDexCacheResolvedMethods() == other_cache;
104}
105
106inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
107 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
108}
109
110
Ian Rogersef7d42f2014-01-06 12:55:46 -0800111inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -0700112 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700113 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700114}
115
Andreas Gampe58a5af82014-07-31 16:23:49 -0700116template <bool kWithCheck>
117inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
118 Class* klass;
119 if (kWithCheck) {
120 klass = GetDexCacheResolvedTypes()->Get(type_index);
121 } else {
122 klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
123 }
124 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
125}
126
127inline bool ArtMethod::HasDexCacheResolvedTypes() {
128 return GetDexCacheResolvedTypes() != nullptr;
129}
130
131inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) {
132 return GetDexCacheResolvedTypes() == other_cache;
133}
134
135inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
136 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
137}
138
Ian Rogersa0485602014-12-02 15:48:04 -0800139inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
140 mirror::Class* type = GetDexCacheResolvedType(type_idx);
141 if (type == nullptr && resolve) {
142 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
143 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
144 }
145 return type;
146}
147
Ian Rogersef7d42f2014-01-06 12:55:46 -0800148inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800149 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800150 return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
151}
152
153inline uint32_t ArtMethod::GetCodeSize(const void* code) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100154 if (code == nullptr) {
155 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100157 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158}
159
Brian Carlstromea46f952013-07-30 01:26:50 -0700160inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 switch (type) {
162 case kStatic:
163 return !IsStatic();
164 case kDirect:
165 return !IsDirect() || IsStatic();
166 case kVirtual: {
167 Class* methods_class = GetDeclaringClass();
168 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
169 }
170 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700171 // Constructors and static methods are called with invoke-direct.
172 // Interface methods cannot be invoked with invoke-super.
173 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174 case kInterface: {
175 Class* methods_class = GetDeclaringClass();
176 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
177 }
178 default:
179 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700180 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 }
182}
183
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187}
188
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800191 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
192}
193
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800194inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
195 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100196 if (code_pointer == nullptr) {
197 return nullptr;
198 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800199 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100200}
201
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800202inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100203 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800204 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100205 uint32_t offset =
206 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
207 if (UNLIKELY(offset == 0u)) {
208 return nullptr;
209 }
210 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
211}
212
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800213inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
214 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100215 if (code_pointer == nullptr) {
216 return nullptr;
217 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800218 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100219}
220
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800221inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
222 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100223 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800224 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100225 uint32_t offset =
226 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
227 if (UNLIKELY(offset == 0u)) {
228 return nullptr;
229 }
230 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
231}
232
Nicolas Geoffray39468442014-09-02 15:17:15 +0100233inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100234 return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset);
235}
236
237inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800238 DCHECK(IsOptimized(sizeof(void*)));
239 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100240 DCHECK(code_pointer != nullptr);
241 uint32_t offset =
242 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
243 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100244 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100245}
246
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800247inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
248 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
249 if (code_pointer == nullptr) {
250 return nullptr;
251 }
252 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800253}
254
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800255inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
256 DCHECK(code_pointer != nullptr);
257 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
258 uint32_t offset =
259 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
260 if (UNLIKELY(offset == 0u)) {
261 return nullptr;
262 }
263 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800264}
265
Ian Rogersef7d42f2014-01-06 12:55:46 -0800266inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700267 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800268}
269
Ian Rogersef7d42f2014-01-06 12:55:46 -0800270inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800271 if (!IsRuntimeMethod()) {
272 return false;
273 }
274 Runtime* runtime = Runtime::Current();
275 bool result = false;
276 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
277 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
278 result = true;
279 break;
280 }
281 }
282 return result;
283}
284
Ian Rogersef7d42f2014-01-06 12:55:46 -0800285inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 bool result = this == Runtime::Current()->GetResolutionMethod();
287 // Check that if we do think it is phony it looks like the resolution method.
288 DCHECK(!result || IsRuntimeMethod());
289 return result;
290}
Jeff Hao88474b42013-10-23 16:24:40 -0700291
Ian Rogersef7d42f2014-01-06 12:55:46 -0800292inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700293 bool result = this == Runtime::Current()->GetImtConflictMethod();
294 // Check that if we do think it is phony it looks like the imt conflict method.
295 DCHECK(!result || IsRuntimeMethod());
296 return result;
297}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800298
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700299inline bool ArtMethod::IsImtUnimplementedMethod() {
300 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
301 // Check that if we do think it is phony it looks like the imt unimplemented method.
302 DCHECK(!result || IsRuntimeMethod());
303 return result;
304}
305
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700306inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800307 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
308 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100309 return pc - reinterpret_cast<uintptr_t>(code);
310}
311
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100312inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
313 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800314 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
Vladimir Marko7624d252014-05-02 14:40:15 +0100315 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
316}
317
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700318inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700319 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700320}
321
322inline const char* ArtMethod::GetDeclaringClassDescriptor() {
323 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
324 uint32_t dex_method_idx = method->GetDexMethodIndex();
325 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
326 return "<runtime method>";
327 }
328 const DexFile* dex_file = method->GetDexFile();
329 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
330}
331
332inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
333 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
334 const DexFile* dex_file = method->GetDexFile();
335 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
336}
337
338inline const Signature ArtMethod::GetSignature() {
339 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
340 uint32_t dex_method_idx = method->GetDexMethodIndex();
341 if (dex_method_idx != DexFile::kDexNoIndex) {
342 const DexFile* dex_file = method->GetDexFile();
343 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
344 }
345 return Signature::NoSignature();
346}
347
Ian Rogers1ff3c982014-08-12 02:30:58 -0700348inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700349 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
350 uint32_t dex_method_idx = method->GetDexMethodIndex();
351 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
352 const DexFile* dex_file = method->GetDexFile();
353 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
354 }
355 Runtime* runtime = Runtime::Current();
356 if (method == runtime->GetResolutionMethod()) {
357 return "<runtime internal resolution method>";
358 } else if (method == runtime->GetImtConflictMethod()) {
359 return "<runtime internal imt conflict method>";
360 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
361 return "<runtime internal callee-save all registers method>";
362 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
363 return "<runtime internal callee-save reference registers method>";
364 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
365 return "<runtime internal callee-save reference and argument registers method>";
366 } else {
367 return "<unknown runtime internal method>";
368 }
369}
370
371inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800372 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700373}
374
375inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
376 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700377 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700378}
379
380inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
381 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
382 if (dex_pc == DexFile::kDexNoIndex) {
383 return method->IsNative() ? -2 : -1;
384 }
385 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
386}
387
388inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
389 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
390 const DexFile* dex_file = method->GetDexFile();
391 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
392}
393
394inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
395 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
396 const DexFile* dex_file = method->GetDexFile();
397 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
398 dex_file->GetMethodId(method->GetDexMethodIndex()));
399 return dex_file->GetProtoParameters(proto);
400}
401
402inline const char* ArtMethod::GetDeclaringClassSourceFile() {
403 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
404}
405
406inline uint16_t ArtMethod::GetClassDefIndex() {
407 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
408}
409
410inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
411 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
412 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
413}
414
415inline const char* ArtMethod::GetReturnTypeDescriptor() {
416 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
417 const DexFile* dex_file = method->GetDexFile();
418 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
419 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
420 uint16_t return_type_idx = proto_id.return_type_idx_;
421 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
422}
423
424inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
425 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
426 const DexFile* dex_file = method->GetDexFile();
427 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
428}
429
430inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
431 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
432}
433
434inline mirror::DexCache* ArtMethod::GetDexCache() {
435 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
436}
437
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700438inline bool ArtMethod::IsProxyMethod() {
439 return GetDeclaringClass()->IsProxyClass();
440}
441
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700442inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700443 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700444 return this;
445 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700446 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700447 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
448 DCHECK(interface_method != nullptr);
449 DCHECK_EQ(interface_method,
450 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
451 return interface_method;
452}
453
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700454inline void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) {
455 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_),
456 new_dex_cache_methods);
457}
458
459inline void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) {
460 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_),
461 new_dex_cache_classes);
462}
463
Ian Rogersded66a02014-10-28 18:12:55 -0700464inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
465 DCHECK(!IsProxyMethod());
466 const DexFile* dex_file = GetDexFile();
467 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
468 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
469 uint16_t return_type_idx = proto_id.return_type_idx_;
470 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
471 if (type == nullptr && resolve) {
472 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
473 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
474 }
475 return type;
476}
477
Mathieu Chartier2d721012014-11-10 11:08:06 -0800478inline void ArtMethod::CheckObjectSizeEqualsMirrorSize() {
479 // Using the default, check the class object size to make sure it matches the size of the
480 // object.
Mathieu Chartiereace4582014-11-24 18:29:54 -0800481 size_t this_size = sizeof(*this);
482#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
483 this_size += sizeof(void*) - sizeof(uint32_t);
484#endif
485 DCHECK_EQ(GetClass()->GetObjectSize(), this_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800486}
487
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488} // namespace mirror
489} // namespace art
490
Brian Carlstromea46f952013-07-30 01:26:50 -0700491#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_