blob: 73de683a1243dd985a650d4a0a25a843105fe773 [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() {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070044 DCHECK(!java_lang_reflect_ArtMethod_.IsNull());
45 return java_lang_reflect_ArtMethod_.Read<kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070046}
47
Ian Rogersef7d42f2014-01-06 12:55:46 -080048inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070049 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 DCHECK(result != NULL) << this;
51 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
52 return result;
53}
54
Brian Carlstromea46f952013-07-30 01:26:50 -070055inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010056 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070057 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058}
59
Ian Rogersef7d42f2014-01-06 12:55:46 -080060inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070062 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063}
64
Ian Rogersef7d42f2014-01-06 12:55:46 -080065inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080066 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070067 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068}
69
Ian Rogersef7d42f2014-01-06 12:55:46 -080070inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070071#ifdef ART_SEA_IR_MODE
72 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
73 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
74#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070076#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070077 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078}
79
Ian Rogersef7d42f2014-01-06 12:55:46 -080080inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
Ian Rogers700a4022014-05-19 16:49:03 -070081 return GetFieldObject<ObjectArray<String>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070082 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070083}
84
Ian Rogersef7d42f2014-01-06 12:55:46 -080085inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070086 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070087 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070088}
89
Ian Rogersef7d42f2014-01-06 12:55:46 -080090inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -070091 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070092 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070093}
94
Ian Rogersef7d42f2014-01-06 12:55:46 -080095inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +010097 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
98 if (code == nullptr) {
99 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100101 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800102}
103
Brian Carlstromea46f952013-07-30 01:26:50 -0700104inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 switch (type) {
106 case kStatic:
107 return !IsStatic();
108 case kDirect:
109 return !IsDirect() || IsStatic();
110 case kVirtual: {
111 Class* methods_class = GetDeclaringClass();
112 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
113 }
114 case kSuper:
115 return false; // TODO: appropriate checks for call to super class.
116 case kInterface: {
117 Class* methods_class = GetDeclaringClass();
118 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
119 }
120 default:
121 LOG(FATAL) << "Unreachable - invocation type: " << type;
122 return true;
123 }
124}
125
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 if (!kIsDebugBuild) {
128 return;
129 }
130 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
131 return;
132 }
Ian Rogers848871b2013-08-05 10:56:33 -0700133 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700134 return;
135 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 const void* code = GetEntryPointFromQuickCompiledCode();
137 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800138 return;
139 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700140 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700141 if (code == class_linker->GetQuickResolutionTrampoline() ||
142 code == class_linker->GetQuickToInterpreterBridgeTrampoline()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700143 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 DCHECK(IsWithinQuickCode(pc))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 << PrettyMethod(this)
147 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700148 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800149 << " size=" << GetCodeSize();
150}
151
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800154 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155}
156
Ian Rogersef7d42f2014-01-06 12:55:46 -0800157inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800159 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160}
161
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800164 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
165}
166
167inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
168 DCHECK(!Runtime::Current()->IsStarted());
169 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
170}
171
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100172inline const void* ArtMethod::GetQuickOatEntryPoint() {
173 if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) {
174 return nullptr;
175 }
176 Runtime* runtime = Runtime::Current();
177 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
178 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
179 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
180 // for non-native methods.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700181 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100182 if (UNLIKELY(entry_point == GetQuickToInterpreterBridge()) ||
183 UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
184 return nullptr;
185 }
186 return entry_point;
187}
188
189inline const void* ArtMethod::GetQuickOatCodePointer() {
190 return EntryPointToCodePointer(GetQuickOatEntryPoint());
191}
192
193inline const uint8_t* ArtMethod::GetMappingTable() {
194 const void* code_pointer = GetQuickOatCodePointer();
195 if (code_pointer == nullptr) {
196 return nullptr;
197 }
198 return GetMappingTable(code_pointer);
199}
200
201inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) {
202 DCHECK(code_pointer != nullptr);
203 DCHECK(code_pointer == GetQuickOatCodePointer());
204 uint32_t offset =
205 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
206 if (UNLIKELY(offset == 0u)) {
207 return nullptr;
208 }
209 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
210}
211
212inline const uint8_t* ArtMethod::GetVmapTable() {
213 const void* code_pointer = GetQuickOatCodePointer();
214 if (code_pointer == nullptr) {
215 return nullptr;
216 }
217 return GetVmapTable(code_pointer);
218}
219
220inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) {
221 DCHECK(code_pointer != nullptr);
222 DCHECK(code_pointer == GetQuickOatCodePointer());
223 uint32_t offset =
224 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
225 if (UNLIKELY(offset == 0u)) {
226 return nullptr;
227 }
228 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
229}
230
Brian Carlstromea46f952013-07-30 01:26:50 -0700231inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 DCHECK(!Runtime::Current()->IsStarted());
233 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
234}
235
Ian Rogersef7d42f2014-01-06 12:55:46 -0800236inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800238 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800239}
240
Ian Rogersef7d42f2014-01-06 12:55:46 -0800241inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700242 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243}
244
Ian Rogersef7d42f2014-01-06 12:55:46 -0800245inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246 if (!IsRuntimeMethod()) {
247 return false;
248 }
249 Runtime* runtime = Runtime::Current();
250 bool result = false;
251 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
252 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
253 result = true;
254 break;
255 }
256 }
257 return result;
258}
259
Ian Rogersef7d42f2014-01-06 12:55:46 -0800260inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261 bool result = this == Runtime::Current()->GetResolutionMethod();
262 // Check that if we do think it is phony it looks like the resolution method.
263 DCHECK(!result || IsRuntimeMethod());
264 return result;
265}
Jeff Hao88474b42013-10-23 16:24:40 -0700266
Ian Rogersef7d42f2014-01-06 12:55:46 -0800267inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700268 bool result = this == Runtime::Current()->GetImtConflictMethod();
269 // Check that if we do think it is phony it looks like the imt conflict method.
270 DCHECK(!result || IsRuntimeMethod());
271 return result;
272}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800273
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100274inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) {
275 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
276 return pc - reinterpret_cast<uintptr_t>(code);
277}
278
279inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc, const void* quick_entry_point) {
280 DCHECK(quick_entry_point != GetQuickToInterpreterBridge());
281 DCHECK(quick_entry_point == Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this));
282 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
283}
284
Mathieu Chartier4e305412014-02-19 10:54:44 -0800285template<VerifyObjectFlags kVerifyFlags>
286inline void ArtMethod::SetNativeMethod(const void* native_method) {
287 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700288 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800289}
290
Vladimir Marko7624d252014-05-02 14:40:15 +0100291inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() {
292 if (UNLIKELY(IsPortableCompiled())) {
293 // Portable compiled dex bytecode or jni stub.
294 return QuickMethodFrameInfo(kStackAlignment, 0u, 0u);
295 }
296 Runtime* runtime = Runtime::Current();
297 if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod())) {
298 return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
299 }
300 if (UNLIKELY(IsRuntimeMethod())) {
301 return runtime->GetRuntimeMethodFrameInfo(this);
302 }
303
304 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
305 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
306 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
307 // for non-native methods. And we really shouldn't see a failure for non-native methods here.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700308 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko7624d252014-05-02 14:40:15 +0100309 CHECK(entry_point != GetQuickToInterpreterBridge());
310
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700311 if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100312 // Generic JNI frame.
313 DCHECK(IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700314 StackHandleScope<1> hs(Thread::Current());
315 uint32_t handle_refs =
316 MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700317 size_t scope_size = HandleScope::SizeOf(handle_refs);
Vladimir Marko7624d252014-05-02 14:40:15 +0100318 QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700319
320 // Callee saves + handle scope + method ref + alignment
321 size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size
322 - kPointerSize // callee-save frame stores a whole method pointer
323 + sizeof(StackReference<mirror::ArtMethod>),
324 kStackAlignment);
325
326 return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask());
Vladimir Marko7624d252014-05-02 14:40:15 +0100327 }
328
329 const void* code_pointer = EntryPointToCodePointer(entry_point);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100330 return GetQuickFrameInfo(code_pointer);
331}
332
333inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
334 DCHECK(code_pointer != nullptr);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700335 DCHECK_EQ(code_pointer, GetQuickOatCodePointer());
Vladimir Marko7624d252014-05-02 14:40:15 +0100336 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
337}
338
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700339inline const DexFile* ArtMethod::GetDexFile() {
340 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile();
341}
342
343inline const char* ArtMethod::GetDeclaringClassDescriptor() {
344 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
345 uint32_t dex_method_idx = method->GetDexMethodIndex();
346 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
347 return "<runtime method>";
348 }
349 const DexFile* dex_file = method->GetDexFile();
350 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
351}
352
353inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
354 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
355 const DexFile* dex_file = method->GetDexFile();
356 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
357}
358
359inline const Signature ArtMethod::GetSignature() {
360 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
361 uint32_t dex_method_idx = method->GetDexMethodIndex();
362 if (dex_method_idx != DexFile::kDexNoIndex) {
363 const DexFile* dex_file = method->GetDexFile();
364 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
365 }
366 return Signature::NoSignature();
367}
368
369inline const char* ArtMethod::GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
370 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
371 uint32_t dex_method_idx = method->GetDexMethodIndex();
372 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
373 const DexFile* dex_file = method->GetDexFile();
374 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
375 }
376 Runtime* runtime = Runtime::Current();
377 if (method == runtime->GetResolutionMethod()) {
378 return "<runtime internal resolution method>";
379 } else if (method == runtime->GetImtConflictMethod()) {
380 return "<runtime internal imt conflict method>";
381 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
382 return "<runtime internal callee-save all registers method>";
383 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
384 return "<runtime internal callee-save reference registers method>";
385 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
386 return "<runtime internal callee-save reference and argument registers method>";
387 } else {
388 return "<unknown runtime internal method>";
389 }
390}
391
392inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
393 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
394 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
395}
396
397inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
398 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
399 return method->GetDexCacheResolvedTypes()->Get(type_idx) != nullptr;
400}
401
402inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
403 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
404 if (dex_pc == DexFile::kDexNoIndex) {
405 return method->IsNative() ? -2 : -1;
406 }
407 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
408}
409
410inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
411 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
412 const DexFile* dex_file = method->GetDexFile();
413 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
414}
415
416inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
417 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
418 const DexFile* dex_file = method->GetDexFile();
419 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
420 dex_file->GetMethodId(method->GetDexMethodIndex()));
421 return dex_file->GetProtoParameters(proto);
422}
423
424inline const char* ArtMethod::GetDeclaringClassSourceFile() {
425 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
426}
427
428inline uint16_t ArtMethod::GetClassDefIndex() {
429 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
430}
431
432inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
433 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
434 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
435}
436
437inline const char* ArtMethod::GetReturnTypeDescriptor() {
438 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
439 const DexFile* dex_file = method->GetDexFile();
440 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
441 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
442 uint16_t return_type_idx = proto_id.return_type_idx_;
443 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
444}
445
446inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
447 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
448 const DexFile* dex_file = method->GetDexFile();
449 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
450}
451
452inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
453 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
454}
455
456inline mirror::DexCache* ArtMethod::GetDexCache() {
457 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
458}
459
460inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
461 mirror::Class* klass = GetDeclaringClass();
462 if (LIKELY(!klass->IsProxyClass())) {
463 return this;
464 }
465 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
466 DCHECK(interface_method != nullptr);
467 DCHECK_EQ(interface_method,
468 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
469 return interface_method;
470}
471
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800472} // namespace mirror
473} // namespace art
474
Brian Carlstromea46f952013-07-30 01:26:50 -0700475#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_