blob: 01b05a6e6fa28f2229fb55665c084d050c0e7a99 [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 Rogers22d5e732014-07-15 22:23:51 -070022#include "class_linker.h"
23#include "dex_cache.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "dex_file.h"
Ian Rogers7655f292013-07-29 11:07:13 -070025#include "entrypoints/entrypoint_utils.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070026#include "method_helper.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "object-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070028#include "object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010029#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010030#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070031#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010032#include "runtime-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033
34namespace art {
35namespace mirror {
36
Mingyao Yang98d1cc82014-05-15 17:02:16 -070037inline uint32_t ArtMethod::ClassSize() {
38 uint32_t vtable_entries = Object::kVTableLength + 8;
39 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0);
40}
41
42template<ReadBarrierOption kReadBarrierOption>
43inline Class* ArtMethod::GetJavaLangReflectArtMethod() {
44 DCHECK(java_lang_reflect_ArtMethod_ != nullptr);
45 return ReadBarrier::BarrierForRoot<mirror::Class, kReadBarrierOption>(
46 &java_lang_reflect_ArtMethod_);
47}
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
Ian Rogersef7d42f2014-01-06 12:55:46 -080091inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -070092 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070093 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070094}
95
Ian Rogersef7d42f2014-01-06 12:55:46 -080096inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080097 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +010098 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
99 if (code == nullptr) {
100 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100102 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103}
104
Brian Carlstromea46f952013-07-30 01:26:50 -0700105inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800106 switch (type) {
107 case kStatic:
108 return !IsStatic();
109 case kDirect:
110 return !IsDirect() || IsStatic();
111 case kVirtual: {
112 Class* methods_class = GetDeclaringClass();
113 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
114 }
115 case kSuper:
116 return false; // TODO: appropriate checks for call to super class.
117 case kInterface: {
118 Class* methods_class = GetDeclaringClass();
119 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
120 }
121 default:
122 LOG(FATAL) << "Unreachable - invocation type: " << type;
123 return true;
124 }
125}
126
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 if (!kIsDebugBuild) {
129 return;
130 }
131 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
132 return;
133 }
Ian Rogers848871b2013-08-05 10:56:33 -0700134 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700135 return;
136 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800137 const void* code = GetEntryPointFromQuickCompiledCode();
138 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800139 return;
140 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700141 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700142 if (code == class_linker->GetQuickResolutionTrampoline() ||
143 code == class_linker->GetQuickToInterpreterBridgeTrampoline()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700144 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146 DCHECK(IsWithinQuickCode(pc))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147 << PrettyMethod(this)
148 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700149 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 << " size=" << GetCodeSize();
151}
152
Ian Rogersef7d42f2014-01-06 12:55:46 -0800153inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800155 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156}
157
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800160 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161}
162
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800165 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
166}
167
168inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
169 DCHECK(!Runtime::Current()->IsStarted());
170 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
171}
172
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100173inline const void* ArtMethod::GetQuickOatEntryPoint() {
174 if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) {
175 return nullptr;
176 }
177 Runtime* runtime = Runtime::Current();
178 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
179 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
180 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
181 // for non-native methods.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700182 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100183 if (UNLIKELY(entry_point == GetQuickToInterpreterBridge()) ||
184 UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
185 return nullptr;
186 }
187 return entry_point;
188}
189
190inline const void* ArtMethod::GetQuickOatCodePointer() {
191 return EntryPointToCodePointer(GetQuickOatEntryPoint());
192}
193
194inline const uint8_t* ArtMethod::GetMappingTable() {
195 const void* code_pointer = GetQuickOatCodePointer();
196 if (code_pointer == nullptr) {
197 return nullptr;
198 }
199 return GetMappingTable(code_pointer);
200}
201
202inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) {
203 DCHECK(code_pointer != nullptr);
204 DCHECK(code_pointer == GetQuickOatCodePointer());
205 uint32_t offset =
206 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
207 if (UNLIKELY(offset == 0u)) {
208 return nullptr;
209 }
210 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
211}
212
213inline const uint8_t* ArtMethod::GetVmapTable() {
214 const void* code_pointer = GetQuickOatCodePointer();
215 if (code_pointer == nullptr) {
216 return nullptr;
217 }
218 return GetVmapTable(code_pointer);
219}
220
221inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) {
222 DCHECK(code_pointer != nullptr);
223 DCHECK(code_pointer == GetQuickOatCodePointer());
224 uint32_t offset =
225 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
226 if (UNLIKELY(offset == 0u)) {
227 return nullptr;
228 }
229 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
230}
231
Brian Carlstromea46f952013-07-30 01:26:50 -0700232inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233 DCHECK(!Runtime::Current()->IsStarted());
234 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
235}
236
Ian Rogersef7d42f2014-01-06 12:55:46 -0800237inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800238 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800239 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240}
241
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700243 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800244}
245
Ian Rogersef7d42f2014-01-06 12:55:46 -0800246inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800247 if (!IsRuntimeMethod()) {
248 return false;
249 }
250 Runtime* runtime = Runtime::Current();
251 bool result = false;
252 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
253 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
254 result = true;
255 break;
256 }
257 }
258 return result;
259}
260
Ian Rogersef7d42f2014-01-06 12:55:46 -0800261inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800262 bool result = this == Runtime::Current()->GetResolutionMethod();
263 // Check that if we do think it is phony it looks like the resolution method.
264 DCHECK(!result || IsRuntimeMethod());
265 return result;
266}
Jeff Hao88474b42013-10-23 16:24:40 -0700267
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700269 bool result = this == Runtime::Current()->GetImtConflictMethod();
270 // Check that if we do think it is phony it looks like the imt conflict method.
271 DCHECK(!result || IsRuntimeMethod());
272 return result;
273}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800274
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100275inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) {
276 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
277 return pc - reinterpret_cast<uintptr_t>(code);
278}
279
280inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc, const void* quick_entry_point) {
281 DCHECK(quick_entry_point != GetQuickToInterpreterBridge());
282 DCHECK(quick_entry_point == Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this));
283 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
284}
285
Mathieu Chartier4e305412014-02-19 10:54:44 -0800286template<VerifyObjectFlags kVerifyFlags>
287inline void ArtMethod::SetNativeMethod(const void* native_method) {
288 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700289 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800290}
291
Vladimir Marko7624d252014-05-02 14:40:15 +0100292inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() {
293 if (UNLIKELY(IsPortableCompiled())) {
294 // Portable compiled dex bytecode or jni stub.
295 return QuickMethodFrameInfo(kStackAlignment, 0u, 0u);
296 }
297 Runtime* runtime = Runtime::Current();
298 if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod())) {
299 return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
300 }
301 if (UNLIKELY(IsRuntimeMethod())) {
302 return runtime->GetRuntimeMethodFrameInfo(this);
303 }
304
305 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
306 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
307 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
308 // for non-native methods. And we really shouldn't see a failure for non-native methods here.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700309 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko7624d252014-05-02 14:40:15 +0100310 CHECK(entry_point != GetQuickToInterpreterBridge());
311
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700312 if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100313 // Generic JNI frame.
314 DCHECK(IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700315 StackHandleScope<1> hs(Thread::Current());
316 uint32_t handle_refs =
317 MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700318 size_t scope_size = HandleScope::SizeOf(handle_refs);
Vladimir Marko7624d252014-05-02 14:40:15 +0100319 QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700320
321 // Callee saves + handle scope + method ref + alignment
322 size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size
323 - kPointerSize // callee-save frame stores a whole method pointer
324 + sizeof(StackReference<mirror::ArtMethod>),
325 kStackAlignment);
326
327 return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask());
Vladimir Marko7624d252014-05-02 14:40:15 +0100328 }
329
330 const void* code_pointer = EntryPointToCodePointer(entry_point);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100331 return GetQuickFrameInfo(code_pointer);
332}
333
334inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
335 DCHECK(code_pointer != nullptr);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700336 DCHECK_EQ(code_pointer, GetQuickOatCodePointer());
Vladimir Marko7624d252014-05-02 14:40:15 +0100337 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
338}
339
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700340inline const DexFile* ArtMethod::GetDexFile() {
341 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile();
342}
343
344inline const char* ArtMethod::GetDeclaringClassDescriptor() {
345 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
346 uint32_t dex_method_idx = method->GetDexMethodIndex();
347 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
348 return "<runtime method>";
349 }
350 const DexFile* dex_file = method->GetDexFile();
351 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
352}
353
354inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
355 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
356 const DexFile* dex_file = method->GetDexFile();
357 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
358}
359
360inline const Signature ArtMethod::GetSignature() {
361 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
362 uint32_t dex_method_idx = method->GetDexMethodIndex();
363 if (dex_method_idx != DexFile::kDexNoIndex) {
364 const DexFile* dex_file = method->GetDexFile();
365 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
366 }
367 return Signature::NoSignature();
368}
369
370inline const char* ArtMethod::GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
371 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
372 uint32_t dex_method_idx = method->GetDexMethodIndex();
373 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
374 const DexFile* dex_file = method->GetDexFile();
375 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
376 }
377 Runtime* runtime = Runtime::Current();
378 if (method == runtime->GetResolutionMethod()) {
379 return "<runtime internal resolution method>";
380 } else if (method == runtime->GetImtConflictMethod()) {
381 return "<runtime internal imt conflict method>";
382 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
383 return "<runtime internal callee-save all registers method>";
384 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
385 return "<runtime internal callee-save reference registers method>";
386 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
387 return "<runtime internal callee-save reference and argument registers method>";
388 } else {
389 return "<unknown runtime internal method>";
390 }
391}
392
393inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
394 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
395 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
396}
397
398inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
399 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
400 return method->GetDexCacheResolvedTypes()->Get(type_idx) != nullptr;
401}
402
403inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
404 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
405 if (dex_pc == DexFile::kDexNoIndex) {
406 return method->IsNative() ? -2 : -1;
407 }
408 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
409}
410
411inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
412 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
413 const DexFile* dex_file = method->GetDexFile();
414 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
415}
416
417inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
418 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
419 const DexFile* dex_file = method->GetDexFile();
420 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
421 dex_file->GetMethodId(method->GetDexMethodIndex()));
422 return dex_file->GetProtoParameters(proto);
423}
424
425inline const char* ArtMethod::GetDeclaringClassSourceFile() {
426 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
427}
428
429inline uint16_t ArtMethod::GetClassDefIndex() {
430 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
431}
432
433inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
434 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
435 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
436}
437
438inline const char* ArtMethod::GetReturnTypeDescriptor() {
439 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
440 const DexFile* dex_file = method->GetDexFile();
441 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
442 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
443 uint16_t return_type_idx = proto_id.return_type_idx_;
444 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
445}
446
447inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
448 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
449 const DexFile* dex_file = method->GetDexFile();
450 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
451}
452
453inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
454 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
455}
456
457inline mirror::DexCache* ArtMethod::GetDexCache() {
458 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
459}
460
461inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
462 mirror::Class* klass = GetDeclaringClass();
463 if (LIKELY(!klass->IsProxyClass())) {
464 return this;
465 }
466 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
467 DCHECK(interface_method != nullptr);
468 DCHECK_EQ(interface_method,
469 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
470 return interface_method;
471}
472
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800473} // namespace mirror
474} // namespace art
475
Brian Carlstromea46f952013-07-30 01:26:50 -0700476#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_