blob: a5b5df6137a4c37d73283542fbef6f86810c5a88 [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"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070024#include "object-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070025#include "object_array.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026#include "object_utils.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010027#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010028#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070029#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010030#include "runtime-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
32namespace art {
33namespace mirror {
34
Mingyao Yang98d1cc82014-05-15 17:02:16 -070035inline uint32_t ArtMethod::ClassSize() {
36 uint32_t vtable_entries = Object::kVTableLength + 8;
37 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0);
38}
39
40template<ReadBarrierOption kReadBarrierOption>
41inline Class* ArtMethod::GetJavaLangReflectArtMethod() {
42 DCHECK(java_lang_reflect_ArtMethod_ != nullptr);
43 return ReadBarrier::BarrierForRoot<mirror::Class, kReadBarrierOption>(
44 &java_lang_reflect_ArtMethod_);
45}
46
Ian Rogersef7d42f2014-01-06 12:55:46 -080047inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070048 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049 DCHECK(result != NULL) << this;
50 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
51 return result;
52}
53
Brian Carlstromea46f952013-07-30 01:26:50 -070054inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010055 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070056 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057}
58
Ian Rogersef7d42f2014-01-06 12:55:46 -080059inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070061 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062}
63
Ian Rogersef7d42f2014-01-06 12:55:46 -080064inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070066 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067}
68
Ian Rogersef7d42f2014-01-06 12:55:46 -080069inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070070#ifdef ART_SEA_IR_MODE
71 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
72 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
73#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070075#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070076 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077}
78
Ian Rogersef7d42f2014-01-06 12:55:46 -080079inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
Ian Rogers700a4022014-05-19 16:49:03 -070080 return GetFieldObject<ObjectArray<String>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070081 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070082}
83
Ian Rogersef7d42f2014-01-06 12:55:46 -080084inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070085 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070086 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070087}
88
Ian Rogersef7d42f2014-01-06 12:55:46 -080089inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -070090 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070091 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070092}
93
Ian Rogersef7d42f2014-01-06 12:55:46 -080094inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +010096 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
97 if (code == nullptr) {
98 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100100 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101}
102
Brian Carlstromea46f952013-07-30 01:26:50 -0700103inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800104 switch (type) {
105 case kStatic:
106 return !IsStatic();
107 case kDirect:
108 return !IsDirect() || IsStatic();
109 case kVirtual: {
110 Class* methods_class = GetDeclaringClass();
111 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
112 }
113 case kSuper:
114 return false; // TODO: appropriate checks for call to super class.
115 case kInterface: {
116 Class* methods_class = GetDeclaringClass();
117 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
118 }
119 default:
120 LOG(FATAL) << "Unreachable - invocation type: " << type;
121 return true;
122 }
123}
124
Ian Rogersef7d42f2014-01-06 12:55:46 -0800125inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 if (!kIsDebugBuild) {
127 return;
128 }
129 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
130 return;
131 }
Ian Rogers848871b2013-08-05 10:56:33 -0700132 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700133 return;
134 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 const void* code = GetEntryPointFromQuickCompiledCode();
136 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800137 return;
138 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700139 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700140 if (code == class_linker->GetQuickResolutionTrampoline() ||
141 code == class_linker->GetQuickToInterpreterBridgeTrampoline()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700142 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800144 DCHECK(IsWithinQuickCode(pc))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145 << PrettyMethod(this)
146 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700147 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800148 << " size=" << GetCodeSize();
149}
150
Ian Rogersef7d42f2014-01-06 12:55:46 -0800151inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800153 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154}
155
Ian Rogersef7d42f2014-01-06 12:55:46 -0800156inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159}
160
Ian Rogersef7d42f2014-01-06 12:55:46 -0800161inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
164}
165
166inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
167 DCHECK(!Runtime::Current()->IsStarted());
168 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
169}
170
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100171inline const void* ArtMethod::GetQuickOatEntryPoint() {
172 if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) {
173 return nullptr;
174 }
175 Runtime* runtime = Runtime::Current();
176 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
177 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
178 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
179 // for non-native methods.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700180 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100181 if (UNLIKELY(entry_point == GetQuickToInterpreterBridge()) ||
182 UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
183 return nullptr;
184 }
185 return entry_point;
186}
187
188inline const void* ArtMethod::GetQuickOatCodePointer() {
189 return EntryPointToCodePointer(GetQuickOatEntryPoint());
190}
191
192inline const uint8_t* ArtMethod::GetMappingTable() {
193 const void* code_pointer = GetQuickOatCodePointer();
194 if (code_pointer == nullptr) {
195 return nullptr;
196 }
197 return GetMappingTable(code_pointer);
198}
199
200inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) {
201 DCHECK(code_pointer != nullptr);
202 DCHECK(code_pointer == GetQuickOatCodePointer());
203 uint32_t offset =
204 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
205 if (UNLIKELY(offset == 0u)) {
206 return nullptr;
207 }
208 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
209}
210
211inline const uint8_t* ArtMethod::GetVmapTable() {
212 const void* code_pointer = GetQuickOatCodePointer();
213 if (code_pointer == nullptr) {
214 return nullptr;
215 }
216 return GetVmapTable(code_pointer);
217}
218
219inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) {
220 DCHECK(code_pointer != nullptr);
221 DCHECK(code_pointer == GetQuickOatCodePointer());
222 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
Brian Carlstromea46f952013-07-30 01:26:50 -0700230inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 DCHECK(!Runtime::Current()->IsStarted());
232 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
233}
234
Ian Rogersef7d42f2014-01-06 12:55:46 -0800235inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800237 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800238}
239
Ian Rogersef7d42f2014-01-06 12:55:46 -0800240inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700241 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242}
243
Ian Rogersef7d42f2014-01-06 12:55:46 -0800244inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 if (!IsRuntimeMethod()) {
246 return false;
247 }
248 Runtime* runtime = Runtime::Current();
249 bool result = false;
250 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
251 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
252 result = true;
253 break;
254 }
255 }
256 return result;
257}
258
Ian Rogersef7d42f2014-01-06 12:55:46 -0800259inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 bool result = this == Runtime::Current()->GetResolutionMethod();
261 // Check that if we do think it is phony it looks like the resolution method.
262 DCHECK(!result || IsRuntimeMethod());
263 return result;
264}
Jeff Hao88474b42013-10-23 16:24:40 -0700265
Ian Rogersef7d42f2014-01-06 12:55:46 -0800266inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700267 bool result = this == Runtime::Current()->GetImtConflictMethod();
268 // Check that if we do think it is phony it looks like the imt conflict method.
269 DCHECK(!result || IsRuntimeMethod());
270 return result;
271}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800272
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100273inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) {
274 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
275 return pc - reinterpret_cast<uintptr_t>(code);
276}
277
278inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc, const void* quick_entry_point) {
279 DCHECK(quick_entry_point != GetQuickToInterpreterBridge());
280 DCHECK(quick_entry_point == Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this));
281 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
282}
283
Mathieu Chartier4e305412014-02-19 10:54:44 -0800284template<VerifyObjectFlags kVerifyFlags>
285inline void ArtMethod::SetNativeMethod(const void* native_method) {
286 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700287 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800288}
289
Vladimir Marko7624d252014-05-02 14:40:15 +0100290inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() {
291 if (UNLIKELY(IsPortableCompiled())) {
292 // Portable compiled dex bytecode or jni stub.
293 return QuickMethodFrameInfo(kStackAlignment, 0u, 0u);
294 }
295 Runtime* runtime = Runtime::Current();
296 if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod())) {
297 return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
298 }
299 if (UNLIKELY(IsRuntimeMethod())) {
300 return runtime->GetRuntimeMethodFrameInfo(this);
301 }
302
303 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
304 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
305 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
306 // for non-native methods. And we really shouldn't see a failure for non-native methods here.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700307 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko7624d252014-05-02 14:40:15 +0100308 CHECK(entry_point != GetQuickToInterpreterBridge());
309
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700310 if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100311 // Generic JNI frame.
312 DCHECK(IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700313 StackHandleScope<1> hs(Thread::Current());
314 uint32_t handle_refs =
315 MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700316 size_t scope_size = HandleScope::SizeOf(handle_refs);
Vladimir Marko7624d252014-05-02 14:40:15 +0100317 QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700318
319 // Callee saves + handle scope + method ref + alignment
320 size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size
321 - kPointerSize // callee-save frame stores a whole method pointer
322 + sizeof(StackReference<mirror::ArtMethod>),
323 kStackAlignment);
324
325 return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask());
Vladimir Marko7624d252014-05-02 14:40:15 +0100326 }
327
328 const void* code_pointer = EntryPointToCodePointer(entry_point);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100329 return GetQuickFrameInfo(code_pointer);
330}
331
332inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
333 DCHECK(code_pointer != nullptr);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700334 DCHECK_EQ(code_pointer, GetQuickOatCodePointer());
Vladimir Marko7624d252014-05-02 14:40:15 +0100335 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
336}
337
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700338inline const DexFile* ArtMethod::GetDexFile() {
339 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile();
340}
341
342inline const char* ArtMethod::GetDeclaringClassDescriptor() {
343 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
344 uint32_t dex_method_idx = method->GetDexMethodIndex();
345 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
346 return "<runtime method>";
347 }
348 const DexFile* dex_file = method->GetDexFile();
349 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
350}
351
352inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
353 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
354 const DexFile* dex_file = method->GetDexFile();
355 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
356}
357
358inline const Signature ArtMethod::GetSignature() {
359 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
360 uint32_t dex_method_idx = method->GetDexMethodIndex();
361 if (dex_method_idx != DexFile::kDexNoIndex) {
362 const DexFile* dex_file = method->GetDexFile();
363 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
364 }
365 return Signature::NoSignature();
366}
367
368inline const char* ArtMethod::GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
369 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
370 uint32_t dex_method_idx = method->GetDexMethodIndex();
371 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
372 const DexFile* dex_file = method->GetDexFile();
373 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
374 }
375 Runtime* runtime = Runtime::Current();
376 if (method == runtime->GetResolutionMethod()) {
377 return "<runtime internal resolution method>";
378 } else if (method == runtime->GetImtConflictMethod()) {
379 return "<runtime internal imt conflict method>";
380 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
381 return "<runtime internal callee-save all registers method>";
382 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
383 return "<runtime internal callee-save reference registers method>";
384 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
385 return "<runtime internal callee-save reference and argument registers method>";
386 } else {
387 return "<unknown runtime internal method>";
388 }
389}
390
391inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
392 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
393 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
394}
395
396inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
397 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
398 return method->GetDexCacheResolvedTypes()->Get(type_idx) != nullptr;
399}
400
401inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
402 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
403 if (dex_pc == DexFile::kDexNoIndex) {
404 return method->IsNative() ? -2 : -1;
405 }
406 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
407}
408
409inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
410 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
411 const DexFile* dex_file = method->GetDexFile();
412 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
413}
414
415inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
416 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
417 const DexFile* dex_file = method->GetDexFile();
418 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
419 dex_file->GetMethodId(method->GetDexMethodIndex()));
420 return dex_file->GetProtoParameters(proto);
421}
422
423inline const char* ArtMethod::GetDeclaringClassSourceFile() {
424 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
425}
426
427inline uint16_t ArtMethod::GetClassDefIndex() {
428 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
429}
430
431inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
432 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
433 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
434}
435
436inline const char* ArtMethod::GetReturnTypeDescriptor() {
437 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
438 const DexFile* dex_file = method->GetDexFile();
439 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
440 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
441 uint16_t return_type_idx = proto_id.return_type_idx_;
442 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
443}
444
445inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
446 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
447 const DexFile* dex_file = method->GetDexFile();
448 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
449}
450
451inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
452 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
453}
454
455inline mirror::DexCache* ArtMethod::GetDexCache() {
456 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
457}
458
459inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
460 mirror::Class* klass = GetDeclaringClass();
461 if (LIKELY(!klass->IsProxyClass())) {
462 return this;
463 }
464 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
465 DCHECK(interface_method != nullptr);
466 DCHECK_EQ(interface_method,
467 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
468 return interface_method;
469}
470
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800471} // namespace mirror
472} // namespace art
473
Brian Carlstromea46f952013-07-30 01:26:50 -0700474#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_