blob: c29276a2384c603e71e1b80fd1b9e2f2f4d99690 [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 Rogersa0485602014-12-02 15:48:04 -0800143inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
144 mirror::Class* type = GetDexCacheResolvedType(type_idx);
145 if (type == nullptr && resolve) {
146 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
147 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
148 }
149 return type;
150}
151
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +0100154 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
155 if (code == nullptr) {
156 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100158 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159}
160
Brian Carlstromea46f952013-07-30 01:26:50 -0700161inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162 switch (type) {
163 case kStatic:
164 return !IsStatic();
165 case kDirect:
166 return !IsDirect() || IsStatic();
167 case kVirtual: {
168 Class* methods_class = GetDeclaringClass();
169 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
170 }
171 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700172 // Constructors and static methods are called with invoke-direct.
173 // Interface methods cannot be invoked with invoke-super.
174 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175 case kInterface: {
176 Class* methods_class = GetDeclaringClass();
177 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
178 }
179 default:
180 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700181 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800182 }
183}
184
Ian Rogersef7d42f2014-01-06 12:55:46 -0800185inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800187 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188}
189
Ian Rogersef7d42f2014-01-06 12:55:46 -0800190inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800192 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193}
194
Ian Rogersef7d42f2014-01-06 12:55:46 -0800195inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800197 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
198}
199
200inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
201 DCHECK(!Runtime::Current()->IsStarted());
202 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
203}
204
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800205inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
206 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100207 if (code_pointer == nullptr) {
208 return nullptr;
209 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800210 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100211}
212
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800213inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100214 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800215 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100216 uint32_t offset =
217 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
218 if (UNLIKELY(offset == 0u)) {
219 return nullptr;
220 }
221 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
222}
223
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800224inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
225 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100226 if (code_pointer == nullptr) {
227 return nullptr;
228 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800229 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100230}
231
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800232inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
233 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100234 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800235 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100236 uint32_t offset =
237 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
238 if (UNLIKELY(offset == 0u)) {
239 return nullptr;
240 }
241 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
242}
243
Nicolas Geoffray39468442014-09-02 15:17:15 +0100244inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100245 return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset);
246}
247
248inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800249 DCHECK(IsOptimized(sizeof(void*)));
250 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100251 DCHECK(code_pointer != nullptr);
252 uint32_t offset =
253 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
254 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100255 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100256}
257
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800258inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
259 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
260 if (code_pointer == nullptr) {
261 return nullptr;
262 }
263 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800264}
265
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800266inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
267 DCHECK(code_pointer != nullptr);
268 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
269 uint32_t offset =
270 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
271 if (UNLIKELY(offset == 0u)) {
272 return nullptr;
273 }
274 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800275}
276
Ian Rogersef7d42f2014-01-06 12:55:46 -0800277inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700278 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800279}
280
Ian Rogersef7d42f2014-01-06 12:55:46 -0800281inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 if (!IsRuntimeMethod()) {
283 return false;
284 }
285 Runtime* runtime = Runtime::Current();
286 bool result = false;
287 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
288 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
289 result = true;
290 break;
291 }
292 }
293 return result;
294}
295
Ian Rogersef7d42f2014-01-06 12:55:46 -0800296inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 bool result = this == Runtime::Current()->GetResolutionMethod();
298 // Check that if we do think it is phony it looks like the resolution method.
299 DCHECK(!result || IsRuntimeMethod());
300 return result;
301}
Jeff Hao88474b42013-10-23 16:24:40 -0700302
Ian Rogersef7d42f2014-01-06 12:55:46 -0800303inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700304 bool result = this == Runtime::Current()->GetImtConflictMethod();
305 // Check that if we do think it is phony it looks like the imt conflict method.
306 DCHECK(!result || IsRuntimeMethod());
307 return result;
308}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800309
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700310inline bool ArtMethod::IsImtUnimplementedMethod() {
311 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
312 // Check that if we do think it is phony it looks like the imt unimplemented method.
313 DCHECK(!result || IsRuntimeMethod());
314 return result;
315}
316
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700317inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800318 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
319 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100320 return pc - reinterpret_cast<uintptr_t>(code);
321}
322
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100323inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
324 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800325 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
Vladimir Marko7624d252014-05-02 14:40:15 +0100326 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
327}
328
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700329inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700330 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700331}
332
333inline const char* ArtMethod::GetDeclaringClassDescriptor() {
334 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
335 uint32_t dex_method_idx = method->GetDexMethodIndex();
336 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
337 return "<runtime method>";
338 }
339 const DexFile* dex_file = method->GetDexFile();
340 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
341}
342
343inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
344 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
345 const DexFile* dex_file = method->GetDexFile();
346 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
347}
348
349inline const Signature ArtMethod::GetSignature() {
350 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
351 uint32_t dex_method_idx = method->GetDexMethodIndex();
352 if (dex_method_idx != DexFile::kDexNoIndex) {
353 const DexFile* dex_file = method->GetDexFile();
354 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
355 }
356 return Signature::NoSignature();
357}
358
Ian Rogers1ff3c982014-08-12 02:30:58 -0700359inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700360 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
361 uint32_t dex_method_idx = method->GetDexMethodIndex();
362 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
363 const DexFile* dex_file = method->GetDexFile();
364 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
365 }
366 Runtime* runtime = Runtime::Current();
367 if (method == runtime->GetResolutionMethod()) {
368 return "<runtime internal resolution method>";
369 } else if (method == runtime->GetImtConflictMethod()) {
370 return "<runtime internal imt conflict method>";
371 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
372 return "<runtime internal callee-save all registers method>";
373 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
374 return "<runtime internal callee-save reference registers method>";
375 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
376 return "<runtime internal callee-save reference and argument registers method>";
377 } else {
378 return "<unknown runtime internal method>";
379 }
380}
381
382inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
383 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
384 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
385}
386
387inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
388 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700389 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700390}
391
392inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
393 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
394 if (dex_pc == DexFile::kDexNoIndex) {
395 return method->IsNative() ? -2 : -1;
396 }
397 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
398}
399
400inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
401 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
402 const DexFile* dex_file = method->GetDexFile();
403 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
404}
405
406inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
407 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
408 const DexFile* dex_file = method->GetDexFile();
409 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
410 dex_file->GetMethodId(method->GetDexMethodIndex()));
411 return dex_file->GetProtoParameters(proto);
412}
413
414inline const char* ArtMethod::GetDeclaringClassSourceFile() {
415 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
416}
417
418inline uint16_t ArtMethod::GetClassDefIndex() {
419 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
420}
421
422inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
423 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
424 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
425}
426
427inline const char* ArtMethod::GetReturnTypeDescriptor() {
428 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
429 const DexFile* dex_file = method->GetDexFile();
430 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
431 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
432 uint16_t return_type_idx = proto_id.return_type_idx_;
433 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
434}
435
436inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
437 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
438 const DexFile* dex_file = method->GetDexFile();
439 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
440}
441
442inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
443 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
444}
445
446inline mirror::DexCache* ArtMethod::GetDexCache() {
447 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
448}
449
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700450inline bool ArtMethod::IsProxyMethod() {
451 return GetDeclaringClass()->IsProxyClass();
452}
453
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700454inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700455 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700456 return this;
457 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700458 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700459 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
460 DCHECK(interface_method != nullptr);
461 DCHECK_EQ(interface_method,
462 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
463 return interface_method;
464}
465
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700466inline void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) {
467 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_),
468 new_dex_cache_methods);
469}
470
471inline void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) {
472 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_),
473 new_dex_cache_classes);
474}
475
Ian Rogersded66a02014-10-28 18:12:55 -0700476inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
477 DCHECK(!IsProxyMethod());
478 const DexFile* dex_file = GetDexFile();
479 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
480 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
481 uint16_t return_type_idx = proto_id.return_type_idx_;
482 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
483 if (type == nullptr && resolve) {
484 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
485 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
486 }
487 return type;
488}
489
Mathieu Chartier2d721012014-11-10 11:08:06 -0800490inline void ArtMethod::CheckObjectSizeEqualsMirrorSize() {
491 // Using the default, check the class object size to make sure it matches the size of the
492 // object.
Mathieu Chartiereace4582014-11-24 18:29:54 -0800493 size_t this_size = sizeof(*this);
494#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
495 this_size += sizeof(void*) - sizeof(uint32_t);
496#endif
497 DCHECK_EQ(GetClass()->GetObjectSize(), this_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800498}
499
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800500} // namespace mirror
501} // namespace art
502
Brian Carlstromea46f952013-07-30 01:26:50 -0700503#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_