blob: 62ef6f861ccb48a2bcdcfb4206c9289c62695044 [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"
Ian Rogers22d5e732014-07-15 22:23:51 -070027#include "method_helper.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() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070076#ifdef ART_SEA_IR_MODE
77 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
78 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
79#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070081#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070082 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083}
84
Ian Rogersef7d42f2014-01-06 12:55:46 -080085inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
Ian Rogers700a4022014-05-19 16:49:03 -070086 return GetFieldObject<ObjectArray<String>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070087 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070088}
89
Ian Rogersef7d42f2014-01-06 12:55:46 -080090inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070091 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070092 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070093}
94
Andreas Gampe58a5af82014-07-31 16:23:49 -070095inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) {
96 ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index);
97 if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) {
98 return method;
99 } else {
100 return nullptr;
101 }
102}
103
104inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) {
105 GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method);
106}
107
108inline bool ArtMethod::HasDexCacheResolvedMethods() {
109 return GetDexCacheResolvedMethods() != nullptr;
110}
111
112inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) {
113 return GetDexCacheResolvedMethods() == other_cache;
114}
115
116inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
117 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
118}
119
120
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -0700122 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700123 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700124}
125
Andreas Gampe58a5af82014-07-31 16:23:49 -0700126template <bool kWithCheck>
127inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
128 Class* klass;
129 if (kWithCheck) {
130 klass = GetDexCacheResolvedTypes()->Get(type_index);
131 } else {
132 klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
133 }
134 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
135}
136
137inline bool ArtMethod::HasDexCacheResolvedTypes() {
138 return GetDexCacheResolvedTypes() != nullptr;
139}
140
141inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) {
142 return GetDexCacheResolvedTypes() == other_cache;
143}
144
145inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
146 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
147}
148
Ian Rogersef7d42f2014-01-06 12:55:46 -0800149inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +0100151 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
152 if (code == nullptr) {
153 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100155 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156}
157
Brian Carlstromea46f952013-07-30 01:26:50 -0700158inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 switch (type) {
160 case kStatic:
161 return !IsStatic();
162 case kDirect:
163 return !IsDirect() || IsStatic();
164 case kVirtual: {
165 Class* methods_class = GetDeclaringClass();
166 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
167 }
168 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700169 // Constructors and static methods are called with invoke-direct.
170 // Interface methods cannot be invoked with invoke-super.
171 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 case kInterface: {
173 Class* methods_class = GetDeclaringClass();
174 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
175 }
176 default:
177 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700178 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 }
180}
181
Ian Rogersef7d42f2014-01-06 12:55:46 -0800182inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185}
186
Ian Rogersef7d42f2014-01-06 12:55:46 -0800187inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190}
191
Ian Rogersef7d42f2014-01-06 12:55:46 -0800192inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
195}
196
197inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
198 DCHECK(!Runtime::Current()->IsStarted());
199 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
200}
201
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800202inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
203 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100204 if (code_pointer == nullptr) {
205 return nullptr;
206 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800207 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100208}
209
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800210inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100211 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800212 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100213 uint32_t offset =
214 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
215 if (UNLIKELY(offset == 0u)) {
216 return nullptr;
217 }
218 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
219}
220
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800221inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
222 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100223 if (code_pointer == nullptr) {
224 return nullptr;
225 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800226 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100227}
228
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800229inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
230 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100231 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800232 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100233 uint32_t offset =
234 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
235 if (UNLIKELY(offset == 0u)) {
236 return nullptr;
237 }
238 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
239}
240
Nicolas Geoffray39468442014-09-02 15:17:15 +0100241inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100242 return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset);
243}
244
245inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800246 DCHECK(IsOptimized(sizeof(void*)));
247 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100248 DCHECK(code_pointer != nullptr);
249 uint32_t offset =
250 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
251 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100252 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100253}
254
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800255inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
256 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
257 if (code_pointer == nullptr) {
258 return nullptr;
259 }
260 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261}
262
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800263inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
264 DCHECK(code_pointer != nullptr);
265 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
266 uint32_t offset =
267 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
268 if (UNLIKELY(offset == 0u)) {
269 return nullptr;
270 }
271 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800272}
273
Ian Rogersef7d42f2014-01-06 12:55:46 -0800274inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700275 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800276}
277
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800279 if (!IsRuntimeMethod()) {
280 return false;
281 }
282 Runtime* runtime = Runtime::Current();
283 bool result = false;
284 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
285 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
286 result = true;
287 break;
288 }
289 }
290 return result;
291}
292
Ian Rogersef7d42f2014-01-06 12:55:46 -0800293inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294 bool result = this == Runtime::Current()->GetResolutionMethod();
295 // Check that if we do think it is phony it looks like the resolution method.
296 DCHECK(!result || IsRuntimeMethod());
297 return result;
298}
Jeff Hao88474b42013-10-23 16:24:40 -0700299
Ian Rogersef7d42f2014-01-06 12:55:46 -0800300inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700301 bool result = this == Runtime::Current()->GetImtConflictMethod();
302 // Check that if we do think it is phony it looks like the imt conflict method.
303 DCHECK(!result || IsRuntimeMethod());
304 return result;
305}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800306
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700307inline bool ArtMethod::IsImtUnimplementedMethod() {
308 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
309 // Check that if we do think it is phony it looks like the imt unimplemented method.
310 DCHECK(!result || IsRuntimeMethod());
311 return result;
312}
313
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700314inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800315 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
316 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100317 return pc - reinterpret_cast<uintptr_t>(code);
318}
319
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100320inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
321 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800322 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
Vladimir Marko7624d252014-05-02 14:40:15 +0100323 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
324}
325
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700326inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700327 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700328}
329
330inline const char* ArtMethod::GetDeclaringClassDescriptor() {
331 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
332 uint32_t dex_method_idx = method->GetDexMethodIndex();
333 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
334 return "<runtime method>";
335 }
336 const DexFile* dex_file = method->GetDexFile();
337 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
338}
339
340inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
341 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
342 const DexFile* dex_file = method->GetDexFile();
343 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
344}
345
346inline const Signature ArtMethod::GetSignature() {
347 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
348 uint32_t dex_method_idx = method->GetDexMethodIndex();
349 if (dex_method_idx != DexFile::kDexNoIndex) {
350 const DexFile* dex_file = method->GetDexFile();
351 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
352 }
353 return Signature::NoSignature();
354}
355
Ian Rogers1ff3c982014-08-12 02:30:58 -0700356inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700357 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
358 uint32_t dex_method_idx = method->GetDexMethodIndex();
359 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
360 const DexFile* dex_file = method->GetDexFile();
361 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
362 }
363 Runtime* runtime = Runtime::Current();
364 if (method == runtime->GetResolutionMethod()) {
365 return "<runtime internal resolution method>";
366 } else if (method == runtime->GetImtConflictMethod()) {
367 return "<runtime internal imt conflict method>";
368 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
369 return "<runtime internal callee-save all registers method>";
370 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
371 return "<runtime internal callee-save reference registers method>";
372 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
373 return "<runtime internal callee-save reference and argument registers method>";
374 } else {
375 return "<unknown runtime internal method>";
376 }
377}
378
379inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
380 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
381 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
382}
383
384inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
385 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700386 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700387}
388
389inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
390 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
391 if (dex_pc == DexFile::kDexNoIndex) {
392 return method->IsNative() ? -2 : -1;
393 }
394 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
395}
396
397inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
398 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
399 const DexFile* dex_file = method->GetDexFile();
400 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
401}
402
403inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
404 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
405 const DexFile* dex_file = method->GetDexFile();
406 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
407 dex_file->GetMethodId(method->GetDexMethodIndex()));
408 return dex_file->GetProtoParameters(proto);
409}
410
411inline const char* ArtMethod::GetDeclaringClassSourceFile() {
412 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
413}
414
415inline uint16_t ArtMethod::GetClassDefIndex() {
416 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
417}
418
419inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
420 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
421 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
422}
423
424inline const char* ArtMethod::GetReturnTypeDescriptor() {
425 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
426 const DexFile* dex_file = method->GetDexFile();
427 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
428 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
429 uint16_t return_type_idx = proto_id.return_type_idx_;
430 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
431}
432
433inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
434 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
435 const DexFile* dex_file = method->GetDexFile();
436 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
437}
438
439inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
440 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
441}
442
443inline mirror::DexCache* ArtMethod::GetDexCache() {
444 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
445}
446
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700447inline bool ArtMethod::IsProxyMethod() {
448 return GetDeclaringClass()->IsProxyClass();
449}
450
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700451inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700452 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700453 return this;
454 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700455 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700456 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
457 DCHECK(interface_method != nullptr);
458 DCHECK_EQ(interface_method,
459 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
460 return interface_method;
461}
462
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700463inline void ArtMethod::SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) {
464 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_),
465 new_dex_cache_strings);
466}
467
468inline void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) {
469 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_),
470 new_dex_cache_methods);
471}
472
473inline void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) {
474 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_),
475 new_dex_cache_classes);
476}
477
Ian Rogersded66a02014-10-28 18:12:55 -0700478inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
479 DCHECK(!IsProxyMethod());
480 const DexFile* dex_file = GetDexFile();
481 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
482 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
483 uint16_t return_type_idx = proto_id.return_type_idx_;
484 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
485 if (type == nullptr && resolve) {
486 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
487 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
488 }
489 return type;
490}
491
Mathieu Chartier2d721012014-11-10 11:08:06 -0800492inline void ArtMethod::CheckObjectSizeEqualsMirrorSize() {
493 // Using the default, check the class object size to make sure it matches the size of the
494 // object.
495 DCHECK_EQ(GetClass()->GetObjectSize(), sizeof(*this));
496}
497
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498} // namespace mirror
499} // namespace art
500
Brian Carlstromea46f952013-07-30 01:26:50 -0700501#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_