blob: 8fcacc2a156f00be8c4735e99a1e75aa35495f14 [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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "dex_file.h"
Ian Rogers7655f292013-07-29 11:07:13 -070023#include "entrypoints/entrypoint_utils.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070024#include "object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010025#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010026#include "quick/quick_method_frame_info.h"
27#include "runtime-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028
29namespace art {
30namespace mirror {
31
Ian Rogersef7d42f2014-01-06 12:55:46 -080032inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070033 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034 DCHECK(result != NULL) << this;
35 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
36 return result;
37}
38
Brian Carlstromea46f952013-07-30 01:26:50 -070039inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010040 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070041 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042}
43
Ian Rogersef7d42f2014-01-06 12:55:46 -080044inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070046 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047}
48
Ian Rogersef7d42f2014-01-06 12:55:46 -080049inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070051 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052}
53
Ian Rogersef7d42f2014-01-06 12:55:46 -080054inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070055#ifdef ART_SEA_IR_MODE
56 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
57 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
58#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070060#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070061 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062}
63
Ian Rogersef7d42f2014-01-06 12:55:46 -080064inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
Ian Rogers700a4022014-05-19 16:49:03 -070065 return GetFieldObject<ObjectArray<String>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070066 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070067}
68
Ian Rogersef7d42f2014-01-06 12:55:46 -080069inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070070 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070071 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070072}
73
Ian Rogersef7d42f2014-01-06 12:55:46 -080074inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -070075 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070076 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070077}
78
Ian Rogersef7d42f2014-01-06 12:55:46 -080079inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +010081 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
82 if (code == nullptr) {
83 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080084 }
Vladimir Marko7624d252014-05-02 14:40:15 +010085 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086}
87
Brian Carlstromea46f952013-07-30 01:26:50 -070088inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 switch (type) {
90 case kStatic:
91 return !IsStatic();
92 case kDirect:
93 return !IsDirect() || IsStatic();
94 case kVirtual: {
95 Class* methods_class = GetDeclaringClass();
96 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
97 }
98 case kSuper:
99 return false; // TODO: appropriate checks for call to super class.
100 case kInterface: {
101 Class* methods_class = GetDeclaringClass();
102 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
103 }
104 default:
105 LOG(FATAL) << "Unreachable - invocation type: " << type;
106 return true;
107 }
108}
109
Ian Rogersef7d42f2014-01-06 12:55:46 -0800110inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 if (!kIsDebugBuild) {
112 return;
113 }
114 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
115 return;
116 }
Ian Rogers848871b2013-08-05 10:56:33 -0700117 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700118 return;
119 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800120 const void* code = GetEntryPointFromQuickCompiledCode();
121 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800122 return;
123 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700124 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Vladimir Marko8a630572014-04-09 18:45:35 +0100125 if (code == GetQuickResolutionTrampoline(class_linker) ||
126 code == GetQuickToInterpreterBridgeTrampoline(class_linker)) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700127 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800129 DCHECK(IsWithinQuickCode(pc))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800130 << PrettyMethod(this)
131 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700132 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800133 << " size=" << GetCodeSize();
134}
135
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800138 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139}
140
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800143 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144}
145
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800148 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
149}
150
151inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
152 DCHECK(!Runtime::Current()->IsStarted());
153 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
154}
155
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100156inline const void* ArtMethod::GetQuickOatEntryPoint() {
157 if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) {
158 return nullptr;
159 }
160 Runtime* runtime = Runtime::Current();
161 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
162 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
163 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
164 // for non-native methods.
165 DCHECK(entry_point != GetQuickToInterpreterBridgeTrampoline(runtime->GetClassLinker()));
166 if (UNLIKELY(entry_point == GetQuickToInterpreterBridge()) ||
167 UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
168 return nullptr;
169 }
170 return entry_point;
171}
172
173inline const void* ArtMethod::GetQuickOatCodePointer() {
174 return EntryPointToCodePointer(GetQuickOatEntryPoint());
175}
176
177inline const uint8_t* ArtMethod::GetMappingTable() {
178 const void* code_pointer = GetQuickOatCodePointer();
179 if (code_pointer == nullptr) {
180 return nullptr;
181 }
182 return GetMappingTable(code_pointer);
183}
184
185inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) {
186 DCHECK(code_pointer != nullptr);
187 DCHECK(code_pointer == GetQuickOatCodePointer());
188 uint32_t offset =
189 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
190 if (UNLIKELY(offset == 0u)) {
191 return nullptr;
192 }
193 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
194}
195
196inline const uint8_t* ArtMethod::GetVmapTable() {
197 const void* code_pointer = GetQuickOatCodePointer();
198 if (code_pointer == nullptr) {
199 return nullptr;
200 }
201 return GetVmapTable(code_pointer);
202}
203
204inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) {
205 DCHECK(code_pointer != nullptr);
206 DCHECK(code_pointer == GetQuickOatCodePointer());
207 uint32_t offset =
208 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
209 if (UNLIKELY(offset == 0u)) {
210 return nullptr;
211 }
212 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
213}
214
Brian Carlstromea46f952013-07-30 01:26:50 -0700215inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216 DCHECK(!Runtime::Current()->IsStarted());
217 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
218}
219
Ian Rogersef7d42f2014-01-06 12:55:46 -0800220inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800222 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223}
224
Ian Rogersef7d42f2014-01-06 12:55:46 -0800225inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700226 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227}
228
Ian Rogersef7d42f2014-01-06 12:55:46 -0800229inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 if (!IsRuntimeMethod()) {
231 return false;
232 }
233 Runtime* runtime = Runtime::Current();
234 bool result = false;
235 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
236 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
237 result = true;
238 break;
239 }
240 }
241 return result;
242}
243
Ian Rogersef7d42f2014-01-06 12:55:46 -0800244inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 bool result = this == Runtime::Current()->GetResolutionMethod();
246 // Check that if we do think it is phony it looks like the resolution method.
247 DCHECK(!result || IsRuntimeMethod());
248 return result;
249}
Jeff Hao88474b42013-10-23 16:24:40 -0700250
Ian Rogersef7d42f2014-01-06 12:55:46 -0800251inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700252 bool result = this == Runtime::Current()->GetImtConflictMethod();
253 // Check that if we do think it is phony it looks like the imt conflict method.
254 DCHECK(!result || IsRuntimeMethod());
255 return result;
256}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800257
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100258inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) {
259 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
260 return pc - reinterpret_cast<uintptr_t>(code);
261}
262
263inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc, const void* quick_entry_point) {
264 DCHECK(quick_entry_point != GetQuickToInterpreterBridge());
265 DCHECK(quick_entry_point == Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this));
266 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
267}
268
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269template<VerifyObjectFlags kVerifyFlags>
270inline void ArtMethod::SetNativeMethod(const void* native_method) {
271 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700272 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800273}
274
Vladimir Marko7624d252014-05-02 14:40:15 +0100275inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() {
276 if (UNLIKELY(IsPortableCompiled())) {
277 // Portable compiled dex bytecode or jni stub.
278 return QuickMethodFrameInfo(kStackAlignment, 0u, 0u);
279 }
280 Runtime* runtime = Runtime::Current();
281 if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod())) {
282 return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
283 }
284 if (UNLIKELY(IsRuntimeMethod())) {
285 return runtime->GetRuntimeMethodFrameInfo(this);
286 }
287
288 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
289 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
290 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
291 // for non-native methods. And we really shouldn't see a failure for non-native methods here.
292 DCHECK(entry_point != GetQuickToInterpreterBridgeTrampoline(runtime->GetClassLinker()));
293 CHECK(entry_point != GetQuickToInterpreterBridge());
294
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700295 if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100296 // Generic JNI frame.
297 DCHECK(IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700298 StackHandleScope<1> hs(Thread::Current());
299 uint32_t handle_refs =
300 MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700301 size_t scope_size = HandleScope::SizeOf(handle_refs);
Vladimir Marko7624d252014-05-02 14:40:15 +0100302 QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700303
304 // Callee saves + handle scope + method ref + alignment
305 size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size
306 - kPointerSize // callee-save frame stores a whole method pointer
307 + sizeof(StackReference<mirror::ArtMethod>),
308 kStackAlignment);
309
310 return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask());
Vladimir Marko7624d252014-05-02 14:40:15 +0100311 }
312
313 const void* code_pointer = EntryPointToCodePointer(entry_point);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100314 return GetQuickFrameInfo(code_pointer);
315}
316
317inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
318 DCHECK(code_pointer != nullptr);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700319 DCHECK_EQ(code_pointer, GetQuickOatCodePointer());
Vladimir Marko7624d252014-05-02 14:40:15 +0100320 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
321}
322
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700323inline const DexFile* ArtMethod::GetDexFile() {
324 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile();
325}
326
327inline const char* ArtMethod::GetDeclaringClassDescriptor() {
328 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
329 uint32_t dex_method_idx = method->GetDexMethodIndex();
330 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
331 return "<runtime method>";
332 }
333 const DexFile* dex_file = method->GetDexFile();
334 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
335}
336
337inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
338 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
339 const DexFile* dex_file = method->GetDexFile();
340 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
341}
342
343inline const Signature ArtMethod::GetSignature() {
344 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
345 uint32_t dex_method_idx = method->GetDexMethodIndex();
346 if (dex_method_idx != DexFile::kDexNoIndex) {
347 const DexFile* dex_file = method->GetDexFile();
348 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
349 }
350 return Signature::NoSignature();
351}
352
353inline const char* ArtMethod::GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
354 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
355 uint32_t dex_method_idx = method->GetDexMethodIndex();
356 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
357 const DexFile* dex_file = method->GetDexFile();
358 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
359 }
360 Runtime* runtime = Runtime::Current();
361 if (method == runtime->GetResolutionMethod()) {
362 return "<runtime internal resolution method>";
363 } else if (method == runtime->GetImtConflictMethod()) {
364 return "<runtime internal imt conflict method>";
365 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
366 return "<runtime internal callee-save all registers method>";
367 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
368 return "<runtime internal callee-save reference registers method>";
369 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
370 return "<runtime internal callee-save reference and argument registers method>";
371 } else {
372 return "<unknown runtime internal method>";
373 }
374}
375
376inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
377 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
378 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
379}
380
381inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
382 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
383 return method->GetDexCacheResolvedTypes()->Get(type_idx) != nullptr;
384}
385
386inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
387 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
388 if (dex_pc == DexFile::kDexNoIndex) {
389 return method->IsNative() ? -2 : -1;
390 }
391 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
392}
393
394inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
395 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
396 const DexFile* dex_file = method->GetDexFile();
397 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
398}
399
400inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
401 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
402 const DexFile* dex_file = method->GetDexFile();
403 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
404 dex_file->GetMethodId(method->GetDexMethodIndex()));
405 return dex_file->GetProtoParameters(proto);
406}
407
408inline const char* ArtMethod::GetDeclaringClassSourceFile() {
409 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
410}
411
412inline uint16_t ArtMethod::GetClassDefIndex() {
413 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
414}
415
416inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
417 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
418 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
419}
420
421inline const char* ArtMethod::GetReturnTypeDescriptor() {
422 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
423 const DexFile* dex_file = method->GetDexFile();
424 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
425 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
426 uint16_t return_type_idx = proto_id.return_type_idx_;
427 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
428}
429
430inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
431 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
432 const DexFile* dex_file = method->GetDexFile();
433 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
434}
435
436inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
437 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
438}
439
440inline mirror::DexCache* ArtMethod::GetDexCache() {
441 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
442}
443
444inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
445 mirror::Class* klass = GetDeclaringClass();
446 if (LIKELY(!klass->IsProxyClass())) {
447 return this;
448 }
449 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
450 DCHECK(interface_method != nullptr);
451 DCHECK_EQ(interface_method,
452 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
453 return interface_method;
454}
455
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456} // namespace mirror
457} // namespace art
458
Brian Carlstromea46f952013-07-30 01:26:50 -0700459#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_