blob: d262fd521112b1395549d08acdc50fb6992fabd9 [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
Ian Rogersef7d42f2014-01-06 12:55:46 -080071inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070072#ifdef ART_SEA_IR_MODE
73 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
74 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
75#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070077#endif
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<String>* ArtMethod::GetDexCacheStrings() {
Ian Rogers700a4022014-05-19 16:49:03 -070082 return GetFieldObject<ObjectArray<String>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070083 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070084}
85
Ian Rogersef7d42f2014-01-06 12:55:46 -080086inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070087 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070088 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070089}
90
Andreas Gampe58a5af82014-07-31 16:23:49 -070091inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) {
92 ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index);
93 if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) {
94 return method;
95 } else {
96 return nullptr;
97 }
98}
99
100inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) {
101 GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method);
102}
103
104inline bool ArtMethod::HasDexCacheResolvedMethods() {
105 return GetDexCacheResolvedMethods() != nullptr;
106}
107
108inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) {
109 return GetDexCacheResolvedMethods() == other_cache;
110}
111
112inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
113 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
114}
115
116
Ian Rogersef7d42f2014-01-06 12:55:46 -0800117inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -0700118 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700119 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700120}
121
Andreas Gampe58a5af82014-07-31 16:23:49 -0700122template <bool kWithCheck>
123inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
124 Class* klass;
125 if (kWithCheck) {
126 klass = GetDexCacheResolvedTypes()->Get(type_index);
127 } else {
128 klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
129 }
130 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
131}
132
133inline bool ArtMethod::HasDexCacheResolvedTypes() {
134 return GetDexCacheResolvedTypes() != nullptr;
135}
136
137inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) {
138 return GetDexCacheResolvedTypes() == other_cache;
139}
140
141inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
142 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
143}
144
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +0100147 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
148 if (code == nullptr) {
149 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100151 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152}
153
Brian Carlstromea46f952013-07-30 01:26:50 -0700154inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 switch (type) {
156 case kStatic:
157 return !IsStatic();
158 case kDirect:
159 return !IsDirect() || IsStatic();
160 case kVirtual: {
161 Class* methods_class = GetDeclaringClass();
162 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
163 }
164 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700165 // Constructors and static methods are called with invoke-direct.
166 // Interface methods cannot be invoked with invoke-super.
167 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168 case kInterface: {
169 Class* methods_class = GetDeclaringClass();
170 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
171 }
172 default:
173 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700174 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175 }
176}
177
Ian Rogersef7d42f2014-01-06 12:55:46 -0800178inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800180 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181}
182
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800185 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186}
187
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800190 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
191}
192
193inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
194 DCHECK(!Runtime::Current()->IsStarted());
195 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
196}
197
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100198inline const uint8_t* ArtMethod::GetMappingTable() {
199 const void* code_pointer = GetQuickOatCodePointer();
200 if (code_pointer == nullptr) {
201 return nullptr;
202 }
203 return GetMappingTable(code_pointer);
204}
205
206inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) {
207 DCHECK(code_pointer != nullptr);
208 DCHECK(code_pointer == GetQuickOatCodePointer());
209 uint32_t offset =
210 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
211 if (UNLIKELY(offset == 0u)) {
212 return nullptr;
213 }
214 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
215}
216
217inline const uint8_t* ArtMethod::GetVmapTable() {
218 const void* code_pointer = GetQuickOatCodePointer();
219 if (code_pointer == nullptr) {
220 return nullptr;
221 }
222 return GetVmapTable(code_pointer);
223}
224
225inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) {
Ian Rogers2c4257b2014-10-24 14:20:06 -0700226 CHECK(!IsOptimized()) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100227 DCHECK(code_pointer != nullptr);
228 DCHECK(code_pointer == GetQuickOatCodePointer());
229 uint32_t offset =
230 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
231 if (UNLIKELY(offset == 0u)) {
232 return nullptr;
233 }
234 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
235}
236
Nicolas Geoffray39468442014-09-02 15:17:15 +0100237inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100238 return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset);
239}
240
241inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100242 DCHECK(IsOptimized());
243 const void* code_pointer = GetQuickOatCodePointer();
244 DCHECK(code_pointer != nullptr);
245 uint32_t offset =
246 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
247 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100248 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100249}
250
Brian Carlstromea46f952013-07-30 01:26:50 -0700251inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800252 DCHECK(!Runtime::Current()->IsStarted());
253 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
254}
255
Ian Rogersef7d42f2014-01-06 12:55:46 -0800256inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800257 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800258 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800259}
260
Ian Rogersef7d42f2014-01-06 12:55:46 -0800261inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700262 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800263}
264
Ian Rogersef7d42f2014-01-06 12:55:46 -0800265inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800266 if (!IsRuntimeMethod()) {
267 return false;
268 }
269 Runtime* runtime = Runtime::Current();
270 bool result = false;
271 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
272 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
273 result = true;
274 break;
275 }
276 }
277 return result;
278}
279
Ian Rogersef7d42f2014-01-06 12:55:46 -0800280inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800281 bool result = this == Runtime::Current()->GetResolutionMethod();
282 // Check that if we do think it is phony it looks like the resolution method.
283 DCHECK(!result || IsRuntimeMethod());
284 return result;
285}
Jeff Hao88474b42013-10-23 16:24:40 -0700286
Ian Rogersef7d42f2014-01-06 12:55:46 -0800287inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700288 bool result = this == Runtime::Current()->GetImtConflictMethod();
289 // Check that if we do think it is phony it looks like the imt conflict method.
290 DCHECK(!result || IsRuntimeMethod());
291 return result;
292}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800293
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700294inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100295 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
296 return pc - reinterpret_cast<uintptr_t>(code);
297}
298
Mathieu Chartier4e305412014-02-19 10:54:44 -0800299template<VerifyObjectFlags kVerifyFlags>
300inline void ArtMethod::SetNativeMethod(const void* native_method) {
301 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700302 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800303}
304
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100305inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
306 DCHECK(code_pointer != nullptr);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700307 DCHECK_EQ(code_pointer, GetQuickOatCodePointer());
Vladimir Marko7624d252014-05-02 14:40:15 +0100308 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
309}
310
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700311inline const DexFile* ArtMethod::GetDexFile() {
312 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile();
313}
314
315inline const char* ArtMethod::GetDeclaringClassDescriptor() {
316 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
317 uint32_t dex_method_idx = method->GetDexMethodIndex();
318 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
319 return "<runtime method>";
320 }
321 const DexFile* dex_file = method->GetDexFile();
322 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
323}
324
325inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
326 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
327 const DexFile* dex_file = method->GetDexFile();
328 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
329}
330
331inline const Signature ArtMethod::GetSignature() {
332 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
333 uint32_t dex_method_idx = method->GetDexMethodIndex();
334 if (dex_method_idx != DexFile::kDexNoIndex) {
335 const DexFile* dex_file = method->GetDexFile();
336 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
337 }
338 return Signature::NoSignature();
339}
340
Ian Rogers1ff3c982014-08-12 02:30:58 -0700341inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700342 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
343 uint32_t dex_method_idx = method->GetDexMethodIndex();
344 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
345 const DexFile* dex_file = method->GetDexFile();
346 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
347 }
348 Runtime* runtime = Runtime::Current();
349 if (method == runtime->GetResolutionMethod()) {
350 return "<runtime internal resolution method>";
351 } else if (method == runtime->GetImtConflictMethod()) {
352 return "<runtime internal imt conflict method>";
353 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
354 return "<runtime internal callee-save all registers method>";
355 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
356 return "<runtime internal callee-save reference registers method>";
357 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
358 return "<runtime internal callee-save reference and argument registers method>";
359 } else {
360 return "<unknown runtime internal method>";
361 }
362}
363
364inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
365 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
366 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
367}
368
369inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
370 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700371 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700372}
373
374inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
375 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
376 if (dex_pc == DexFile::kDexNoIndex) {
377 return method->IsNative() ? -2 : -1;
378 }
379 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
380}
381
382inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
383 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
384 const DexFile* dex_file = method->GetDexFile();
385 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
386}
387
388inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
389 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
390 const DexFile* dex_file = method->GetDexFile();
391 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
392 dex_file->GetMethodId(method->GetDexMethodIndex()));
393 return dex_file->GetProtoParameters(proto);
394}
395
396inline const char* ArtMethod::GetDeclaringClassSourceFile() {
397 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
398}
399
400inline uint16_t ArtMethod::GetClassDefIndex() {
401 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
402}
403
404inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
405 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
406 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
407}
408
409inline const char* ArtMethod::GetReturnTypeDescriptor() {
410 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
411 const DexFile* dex_file = method->GetDexFile();
412 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
413 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
414 uint16_t return_type_idx = proto_id.return_type_idx_;
415 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
416}
417
418inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
419 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
420 const DexFile* dex_file = method->GetDexFile();
421 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
422}
423
424inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
425 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
426}
427
428inline mirror::DexCache* ArtMethod::GetDexCache() {
429 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
430}
431
432inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
433 mirror::Class* klass = GetDeclaringClass();
434 if (LIKELY(!klass->IsProxyClass())) {
435 return this;
436 }
437 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
438 DCHECK(interface_method != nullptr);
439 DCHECK_EQ(interface_method,
440 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
441 return interface_method;
442}
443
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444} // namespace mirror
445} // namespace art
446
Brian Carlstromea46f952013-07-30 01:26:50 -0700447#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_