blob: 91dd52542be0d329423e66faa5a16ac27589b1a9 [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);
Vladimir Marko8a630572014-04-09 18:45:35 +0100150 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
151 if (code == nullptr) {
152 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100154 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155}
156
Brian Carlstromea46f952013-07-30 01:26:50 -0700157inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158 switch (type) {
159 case kStatic:
160 return !IsStatic();
161 case kDirect:
162 return !IsDirect() || IsStatic();
163 case kVirtual: {
164 Class* methods_class = GetDeclaringClass();
165 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
166 }
167 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700168 // Constructors and static methods are called with invoke-direct.
169 // Interface methods cannot be invoked with invoke-super.
170 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 case kInterface: {
172 Class* methods_class = GetDeclaringClass();
173 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
174 }
175 default:
176 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700177 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 }
179}
180
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800182 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184}
185
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
189}
190
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800191inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
192 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100193 if (code_pointer == nullptr) {
194 return nullptr;
195 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800196 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100197}
198
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800199inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100200 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800201 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100202 uint32_t offset =
203 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
204 if (UNLIKELY(offset == 0u)) {
205 return nullptr;
206 }
207 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
208}
209
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800210inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
211 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100212 if (code_pointer == nullptr) {
213 return nullptr;
214 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800215 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100216}
217
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800218inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
219 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100220 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800221 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100222 uint32_t offset =
223 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
224 if (UNLIKELY(offset == 0u)) {
225 return nullptr;
226 }
227 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
228}
229
Nicolas Geoffray39468442014-09-02 15:17:15 +0100230inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100231 return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset);
232}
233
234inline 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() {
369 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
370 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
371}
372
373inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
374 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700375 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700376}
377
378inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
379 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
380 if (dex_pc == DexFile::kDexNoIndex) {
381 return method->IsNative() ? -2 : -1;
382 }
383 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
384}
385
386inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
387 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
388 const DexFile* dex_file = method->GetDexFile();
389 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
390}
391
392inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
393 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
394 const DexFile* dex_file = method->GetDexFile();
395 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
396 dex_file->GetMethodId(method->GetDexMethodIndex()));
397 return dex_file->GetProtoParameters(proto);
398}
399
400inline const char* ArtMethod::GetDeclaringClassSourceFile() {
401 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
402}
403
404inline uint16_t ArtMethod::GetClassDefIndex() {
405 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
406}
407
408inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
409 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
410 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
411}
412
413inline const char* ArtMethod::GetReturnTypeDescriptor() {
414 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
415 const DexFile* dex_file = method->GetDexFile();
416 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
417 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
418 uint16_t return_type_idx = proto_id.return_type_idx_;
419 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
420}
421
422inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
423 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
424 const DexFile* dex_file = method->GetDexFile();
425 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
426}
427
428inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
429 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
430}
431
432inline mirror::DexCache* ArtMethod::GetDexCache() {
433 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
434}
435
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700436inline bool ArtMethod::IsProxyMethod() {
437 return GetDeclaringClass()->IsProxyClass();
438}
439
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700440inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700441 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700442 return this;
443 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700444 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700445 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
446 DCHECK(interface_method != nullptr);
447 DCHECK_EQ(interface_method,
448 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
449 return interface_method;
450}
451
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700452inline void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) {
453 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_),
454 new_dex_cache_methods);
455}
456
457inline void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) {
458 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_),
459 new_dex_cache_classes);
460}
461
Ian Rogersded66a02014-10-28 18:12:55 -0700462inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
463 DCHECK(!IsProxyMethod());
464 const DexFile* dex_file = GetDexFile();
465 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
466 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
467 uint16_t return_type_idx = proto_id.return_type_idx_;
468 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
469 if (type == nullptr && resolve) {
470 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
471 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
472 }
473 return type;
474}
475
Mathieu Chartier2d721012014-11-10 11:08:06 -0800476inline void ArtMethod::CheckObjectSizeEqualsMirrorSize() {
477 // Using the default, check the class object size to make sure it matches the size of the
478 // object.
Mathieu Chartiereace4582014-11-24 18:29:54 -0800479 size_t this_size = sizeof(*this);
480#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
481 this_size += sizeof(void*) - sizeof(uint32_t);
482#endif
483 DCHECK_EQ(GetClass()->GetObjectSize(), this_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800484}
485
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800486} // namespace mirror
487} // namespace art
488
Brian Carlstromea46f952013-07-30 01:26:50 -0700489#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_