blob: 7c8067adcd3944457b356c712d60c6f950c4b45c [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"
Mathieu Chartier00e466d2015-04-16 14:34:45 -070024#include "class_linker-inl.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070025#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"
Vladimir Marko80afd022015-05-19 18:08:00 +010034#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035
36namespace art {
37namespace mirror {
38
Mingyao Yang98d1cc82014-05-15 17:02:16 -070039inline uint32_t ArtMethod::ClassSize() {
Mathieu Chartierfc58af42015-04-16 18:00:39 -070040 uint32_t vtable_entries = Object::kVTableLength;
Fred Shih37f05ef2014-07-16 18:38:08 -070041 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070042}
43
44template<ReadBarrierOption kReadBarrierOption>
45inline Class* ArtMethod::GetJavaLangReflectArtMethod() {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070046 DCHECK(!java_lang_reflect_ArtMethod_.IsNull());
47 return java_lang_reflect_ArtMethod_.Read<kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070048}
49
Ian Rogersef7d42f2014-01-06 12:55:46 -080050inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070051 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070052 DCHECK(result != nullptr) << this;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
54 return result;
55}
56
Brian Carlstromea46f952013-07-30 01:26:50 -070057inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010058 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070059 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060}
61
Ian Rogersef7d42f2014-01-06 12:55:46 -080062inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070064 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065}
66
Ian Rogersef7d42f2014-01-06 12:55:46 -080067inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070069 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070}
71
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070072inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
73 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
74}
75
Ian Rogersef7d42f2014-01-06 12:55:46 -080076inline uint32_t ArtMethod::GetDexMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070078 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079}
80
Ian Rogersef7d42f2014-01-06 12:55:46 -080081inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070082 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070083 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070084}
85
Andreas Gampe58a5af82014-07-31 16:23:49 -070086inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) {
87 ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index);
88 if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) {
89 return method;
90 } else {
91 return nullptr;
92 }
93}
94
95inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) {
96 GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method);
97}
98
99inline bool ArtMethod::HasDexCacheResolvedMethods() {
100 return GetDexCacheResolvedMethods() != nullptr;
101}
102
103inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) {
104 return GetDexCacheResolvedMethods() == other_cache;
105}
106
107inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
108 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
109}
110
111
Ian Rogersef7d42f2014-01-06 12:55:46 -0800112inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -0700113 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700114 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700115}
116
Andreas Gampe58a5af82014-07-31 16:23:49 -0700117template <bool kWithCheck>
118inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
119 Class* klass;
120 if (kWithCheck) {
121 klass = GetDexCacheResolvedTypes()->Get(type_index);
122 } else {
123 klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
124 }
125 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
126}
127
128inline bool ArtMethod::HasDexCacheResolvedTypes() {
129 return GetDexCacheResolvedTypes() != nullptr;
130}
131
132inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) {
133 return GetDexCacheResolvedTypes() == other_cache;
134}
135
136inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
137 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
138}
139
Ian Rogersa0485602014-12-02 15:48:04 -0800140inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
141 mirror::Class* type = GetDexCacheResolvedType(type_idx);
142 if (type == nullptr && resolve) {
143 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
144 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
145 }
146 return type;
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);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800151 return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
152}
153
154inline uint32_t ArtMethod::GetCodeSize(const void* code) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100155 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 void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800192 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
193}
194
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800195inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
196 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100197 if (code_pointer == nullptr) {
198 return nullptr;
199 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800200 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100201}
202
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800203inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100204 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800205 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100206 uint32_t offset =
207 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
208 if (UNLIKELY(offset == 0u)) {
209 return nullptr;
210 }
211 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
212}
213
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800214inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
215 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100216 if (code_pointer == nullptr) {
217 return nullptr;
218 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800219 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100220}
221
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800222inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
223 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100224 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800225 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100226 uint32_t offset =
227 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
228 if (UNLIKELY(offset == 0u)) {
229 return nullptr;
230 }
231 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
232}
233
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100234inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800235 DCHECK(IsOptimized(sizeof(void*)));
236 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100237 DCHECK(code_pointer != nullptr);
238 uint32_t offset =
239 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
240 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100241 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100242}
243
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800244inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
245 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
246 if (code_pointer == nullptr) {
247 return nullptr;
248 }
249 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250}
251
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800252inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
253 DCHECK(code_pointer != nullptr);
254 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
255 uint32_t offset =
256 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
257 if (UNLIKELY(offset == 0u)) {
258 return nullptr;
259 }
260 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261}
262
Ian Rogersef7d42f2014-01-06 12:55:46 -0800263inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700264 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265}
266
Ian Rogersef7d42f2014-01-06 12:55:46 -0800267inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800268 if (!IsRuntimeMethod()) {
269 return false;
270 }
271 Runtime* runtime = Runtime::Current();
272 bool result = false;
273 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
274 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
275 result = true;
276 break;
277 }
278 }
279 return result;
280}
281
Ian Rogersef7d42f2014-01-06 12:55:46 -0800282inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800283 bool result = this == Runtime::Current()->GetResolutionMethod();
284 // Check that if we do think it is phony it looks like the resolution method.
285 DCHECK(!result || IsRuntimeMethod());
286 return result;
287}
Jeff Hao88474b42013-10-23 16:24:40 -0700288
Ian Rogersef7d42f2014-01-06 12:55:46 -0800289inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700290 bool result = this == Runtime::Current()->GetImtConflictMethod();
291 // Check that if we do think it is phony it looks like the imt conflict method.
292 DCHECK(!result || IsRuntimeMethod());
293 return result;
294}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800295
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700296inline bool ArtMethod::IsImtUnimplementedMethod() {
297 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
298 // Check that if we do think it is phony it looks like the imt unimplemented method.
299 DCHECK(!result || IsRuntimeMethod());
300 return result;
301}
302
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700303inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800304 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
305 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100306 return pc - reinterpret_cast<uintptr_t>(code);
307}
308
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100309inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
310 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800311 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
Vladimir Marko7624d252014-05-02 14:40:15 +0100312 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
313}
314
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700315inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700316 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700317}
318
319inline const char* ArtMethod::GetDeclaringClassDescriptor() {
320 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
321 uint32_t dex_method_idx = method->GetDexMethodIndex();
322 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
323 return "<runtime method>";
324 }
325 const DexFile* dex_file = method->GetDexFile();
326 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
327}
328
329inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
330 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
331 const DexFile* dex_file = method->GetDexFile();
332 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
333}
334
335inline const Signature ArtMethod::GetSignature() {
336 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
337 uint32_t dex_method_idx = method->GetDexMethodIndex();
338 if (dex_method_idx != DexFile::kDexNoIndex) {
339 const DexFile* dex_file = method->GetDexFile();
340 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
341 }
342 return Signature::NoSignature();
343}
344
Ian Rogers1ff3c982014-08-12 02:30:58 -0700345inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700346 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
347 uint32_t dex_method_idx = method->GetDexMethodIndex();
348 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
349 const DexFile* dex_file = method->GetDexFile();
350 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
351 }
352 Runtime* runtime = Runtime::Current();
353 if (method == runtime->GetResolutionMethod()) {
354 return "<runtime internal resolution method>";
355 } else if (method == runtime->GetImtConflictMethod()) {
356 return "<runtime internal imt conflict method>";
357 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
358 return "<runtime internal callee-save all registers method>";
359 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
360 return "<runtime internal callee-save reference registers method>";
361 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
362 return "<runtime internal callee-save reference and argument registers method>";
363 } else {
364 return "<unknown runtime internal method>";
365 }
366}
367
368inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800369 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700370}
371
372inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
373 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700374 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700375}
376
377inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
378 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
379 if (dex_pc == DexFile::kDexNoIndex) {
380 return method->IsNative() ? -2 : -1;
381 }
382 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
383}
384
385inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
386 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
387 const DexFile* dex_file = method->GetDexFile();
388 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
389}
390
391inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
392 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
393 const DexFile* dex_file = method->GetDexFile();
394 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
395 dex_file->GetMethodId(method->GetDexMethodIndex()));
396 return dex_file->GetProtoParameters(proto);
397}
398
399inline const char* ArtMethod::GetDeclaringClassSourceFile() {
400 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
401}
402
403inline uint16_t ArtMethod::GetClassDefIndex() {
404 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
405}
406
407inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
408 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
409 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
410}
411
412inline const char* ArtMethod::GetReturnTypeDescriptor() {
413 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
414 const DexFile* dex_file = method->GetDexFile();
415 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
416 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
417 uint16_t return_type_idx = proto_id.return_type_idx_;
418 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
419}
420
421inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
422 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
423 const DexFile* dex_file = method->GetDexFile();
424 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
425}
426
427inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
428 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
429}
430
431inline mirror::DexCache* ArtMethod::GetDexCache() {
432 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
433}
434
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700435inline bool ArtMethod::IsProxyMethod() {
436 return GetDeclaringClass()->IsProxyClass();
437}
438
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700439inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700440 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700441 return this;
442 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700443 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700444 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
445 DCHECK(interface_method != nullptr);
446 DCHECK_EQ(interface_method,
447 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
448 return interface_method;
449}
450
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700451inline void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) {
452 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_),
453 new_dex_cache_methods);
454}
455
456inline void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) {
457 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_),
458 new_dex_cache_classes);
459}
460
Ian Rogersded66a02014-10-28 18:12:55 -0700461inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
462 DCHECK(!IsProxyMethod());
463 const DexFile* dex_file = GetDexFile();
464 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
465 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
466 uint16_t return_type_idx = proto_id.return_type_idx_;
467 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
468 if (type == nullptr && resolve) {
469 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
470 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
471 }
472 return type;
473}
474
Mathieu Chartier2d721012014-11-10 11:08:06 -0800475inline void ArtMethod::CheckObjectSizeEqualsMirrorSize() {
476 // Using the default, check the class object size to make sure it matches the size of the
477 // object.
Mathieu Chartiereace4582014-11-24 18:29:54 -0800478 size_t this_size = sizeof(*this);
479#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
480 this_size += sizeof(void*) - sizeof(uint32_t);
481#endif
482 DCHECK_EQ(GetClass()->GetObjectSize(), this_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800483}
484
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800485} // namespace mirror
486} // namespace art
487
Brian Carlstromea46f952013-07-30 01:26:50 -0700488#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_