blob: ae170702b5934799eecdf8569f211f95b32a5767 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstromea46f952013-07-30 01:26:50 -070017#ifndef ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
18#define ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "art_method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021
Andreas Gampe58a5af82014-07-31 16:23:49 -070022#include "art_field.h"
23#include "class.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070024#include "class_linker.h"
25#include "dex_cache.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "dex_file.h"
Ian Rogers7655f292013-07-29 11:07:13 -070027#include "entrypoints/entrypoint_utils.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070028#include "method_helper.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070029#include "object-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070030#include "object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010031#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010032#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070033#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010034#include "runtime-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035
36namespace art {
37namespace mirror {
38
Mingyao Yang98d1cc82014-05-15 17:02:16 -070039inline uint32_t ArtMethod::ClassSize() {
40 uint32_t vtable_entries = Object::kVTableLength + 8;
Fred Shih37f05ef2014-07-16 18:38:08 -070041 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070042}
43
44template<ReadBarrierOption kReadBarrierOption>
45inline Class* ArtMethod::GetJavaLangReflectArtMethod() {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070046 DCHECK(!java_lang_reflect_ArtMethod_.IsNull());
47 return java_lang_reflect_ArtMethod_.Read<kReadBarrierOption>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070048}
49
Ian Rogersef7d42f2014-01-06 12:55:46 -080050inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070051 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052 DCHECK(result != NULL) << this;
53 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
54 return result;
55}
56
Brian Carlstromea46f952013-07-30 01:26:50 -070057inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010058 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070059 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060}
61
Ian Rogersef7d42f2014-01-06 12:55:46 -080062inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070064 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065}
66
Ian Rogersef7d42f2014-01-06 12:55:46 -080067inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070069 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070}
71
Ian Rogersef7d42f2014-01-06 12:55:46 -080072inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070073#ifdef ART_SEA_IR_MODE
74 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
75 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
76#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070078#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070079 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080}
81
Ian Rogersef7d42f2014-01-06 12:55:46 -080082inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
Ian Rogers700a4022014-05-19 16:49:03 -070083 return GetFieldObject<ObjectArray<String>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070084 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070085}
86
Ian Rogersef7d42f2014-01-06 12:55:46 -080087inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
Ian Rogers700a4022014-05-19 16:49:03 -070088 return GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070089 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070090}
91
Andreas Gampe58a5af82014-07-31 16:23:49 -070092inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) {
93 ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index);
94 if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) {
95 return method;
96 } else {
97 return nullptr;
98 }
99}
100
101inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) {
102 GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method);
103}
104
105inline bool ArtMethod::HasDexCacheResolvedMethods() {
106 return GetDexCacheResolvedMethods() != nullptr;
107}
108
109inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) {
110 return GetDexCacheResolvedMethods() == other_cache;
111}
112
113inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
114 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
115}
116
117
Ian Rogersef7d42f2014-01-06 12:55:46 -0800118inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
Ian Rogers700a4022014-05-19 16:49:03 -0700119 return GetFieldObject<ObjectArray<Class>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700120 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700121}
122
Andreas Gampe58a5af82014-07-31 16:23:49 -0700123template <bool kWithCheck>
124inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
125 Class* klass;
126 if (kWithCheck) {
127 klass = GetDexCacheResolvedTypes()->Get(type_index);
128 } else {
129 klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
130 }
131 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
132}
133
134inline bool ArtMethod::HasDexCacheResolvedTypes() {
135 return GetDexCacheResolvedTypes() != nullptr;
136}
137
138inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) {
139 return GetDexCacheResolvedTypes() == other_cache;
140}
141
142inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
143 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
144}
145
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +0100148 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
149 if (code == nullptr) {
150 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800151 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100152 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153}
154
Brian Carlstromea46f952013-07-30 01:26:50 -0700155inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 switch (type) {
157 case kStatic:
158 return !IsStatic();
159 case kDirect:
160 return !IsDirect() || IsStatic();
161 case kVirtual: {
162 Class* methods_class = GetDeclaringClass();
163 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
164 }
165 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700166 // Constructors and static methods are called with invoke-direct.
167 // Interface methods cannot be invoked with invoke-super.
168 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800169 case kInterface: {
170 Class* methods_class = GetDeclaringClass();
171 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
172 }
173 default:
174 LOG(FATAL) << "Unreachable - invocation type: " << type;
175 return true;
176 }
177}
178
Ian Rogersef7d42f2014-01-06 12:55:46 -0800179inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180 if (!kIsDebugBuild) {
181 return;
182 }
183 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
184 return;
185 }
Ian Rogers848871b2013-08-05 10:56:33 -0700186 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700187 return;
188 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189 const void* code = GetEntryPointFromQuickCompiledCode();
190 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800191 return;
192 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700193 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700194 if (code == class_linker->GetQuickResolutionTrampoline() ||
195 code == class_linker->GetQuickToInterpreterBridgeTrampoline()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700196 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800198 DCHECK(IsWithinQuickCode(pc))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800199 << PrettyMethod(this)
200 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700201 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 << " size=" << GetCodeSize();
203}
204
Ian Rogersef7d42f2014-01-06 12:55:46 -0800205inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800206 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800207 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800208}
209
Ian Rogersef7d42f2014-01-06 12:55:46 -0800210inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800212 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800213}
214
Ian Rogersef7d42f2014-01-06 12:55:46 -0800215inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800217 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
218}
219
220inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
221 DCHECK(!Runtime::Current()->IsStarted());
222 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
223}
224
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100225inline const void* ArtMethod::GetQuickOatEntryPoint() {
226 if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) {
227 return nullptr;
228 }
229 Runtime* runtime = Runtime::Current();
230 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
231 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
232 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
233 // for non-native methods.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700234 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100235 if (UNLIKELY(entry_point == GetQuickToInterpreterBridge()) ||
236 UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
237 return nullptr;
238 }
239 return entry_point;
240}
241
242inline const void* ArtMethod::GetQuickOatCodePointer() {
243 return EntryPointToCodePointer(GetQuickOatEntryPoint());
244}
245
246inline const uint8_t* ArtMethod::GetMappingTable() {
247 const void* code_pointer = GetQuickOatCodePointer();
248 if (code_pointer == nullptr) {
249 return nullptr;
250 }
251 return GetMappingTable(code_pointer);
252}
253
254inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) {
255 DCHECK(code_pointer != nullptr);
256 DCHECK(code_pointer == GetQuickOatCodePointer());
257 uint32_t offset =
258 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
259 if (UNLIKELY(offset == 0u)) {
260 return nullptr;
261 }
262 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
263}
264
265inline const uint8_t* ArtMethod::GetVmapTable() {
266 const void* code_pointer = GetQuickOatCodePointer();
267 if (code_pointer == nullptr) {
268 return nullptr;
269 }
270 return GetVmapTable(code_pointer);
271}
272
273inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100274 if (IsOptimized()) {
275 LOG(FATAL) << "Unimplemented vmap table for optimized compiler";
276 }
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100277 DCHECK(code_pointer != nullptr);
278 DCHECK(code_pointer == GetQuickOatCodePointer());
279 uint32_t offset =
280 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
281 if (UNLIKELY(offset == 0u)) {
282 return nullptr;
283 }
284 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
285}
286
Nicolas Geoffray39468442014-09-02 15:17:15 +0100287inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) {
288 DCHECK(IsOptimized());
289 const void* code_pointer = GetQuickOatCodePointer();
290 DCHECK(code_pointer != nullptr);
291 uint32_t offset =
292 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
293 const void* data = reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
294 CodeInfo code_info(data);
295 return code_info.GetStackMapForNativePcOffset(native_pc_offset);
296}
297
Brian Carlstromea46f952013-07-30 01:26:50 -0700298inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800299 DCHECK(!Runtime::Current()->IsStarted());
300 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
301}
302
Ian Rogersef7d42f2014-01-06 12:55:46 -0800303inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800304 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800305 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306}
307
Ian Rogersef7d42f2014-01-06 12:55:46 -0800308inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700309 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800310}
311
Ian Rogersef7d42f2014-01-06 12:55:46 -0800312inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 if (!IsRuntimeMethod()) {
314 return false;
315 }
316 Runtime* runtime = Runtime::Current();
317 bool result = false;
318 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
319 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
320 result = true;
321 break;
322 }
323 }
324 return result;
325}
326
Ian Rogersef7d42f2014-01-06 12:55:46 -0800327inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800328 bool result = this == Runtime::Current()->GetResolutionMethod();
329 // Check that if we do think it is phony it looks like the resolution method.
330 DCHECK(!result || IsRuntimeMethod());
331 return result;
332}
Jeff Hao88474b42013-10-23 16:24:40 -0700333
Ian Rogersef7d42f2014-01-06 12:55:46 -0800334inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700335 bool result = this == Runtime::Current()->GetImtConflictMethod();
336 // Check that if we do think it is phony it looks like the imt conflict method.
337 DCHECK(!result || IsRuntimeMethod());
338 return result;
339}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800340
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100341inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) {
342 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this);
343 return pc - reinterpret_cast<uintptr_t>(code);
344}
345
346inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc, const void* quick_entry_point) {
347 DCHECK(quick_entry_point != GetQuickToInterpreterBridge());
348 DCHECK(quick_entry_point == Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this));
349 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
350}
351
Mathieu Chartier4e305412014-02-19 10:54:44 -0800352template<VerifyObjectFlags kVerifyFlags>
353inline void ArtMethod::SetNativeMethod(const void* native_method) {
354 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700355 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800356}
357
Vladimir Marko7624d252014-05-02 14:40:15 +0100358inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() {
359 if (UNLIKELY(IsPortableCompiled())) {
360 // Portable compiled dex bytecode or jni stub.
361 return QuickMethodFrameInfo(kStackAlignment, 0u, 0u);
362 }
363 Runtime* runtime = Runtime::Current();
Serguei Katkov805bab12014-08-29 18:20:15 +0700364 // For Proxy method we exclude direct method (there is only one direct method - constructor).
365 // Direct method is cloned from original java.lang.reflect.Proxy class together with code
366 // and as a result it is executed as usual quick compiled method without any stubs.
367 // So the frame info should be returned as it is a quick method not a stub.
368 if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod() && !IsDirect())) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100369 return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
370 }
371 if (UNLIKELY(IsRuntimeMethod())) {
372 return runtime->GetRuntimeMethodFrameInfo(this);
373 }
374
375 const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this);
376 // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method
377 // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline)
378 // for non-native methods. And we really shouldn't see a failure for non-native methods here.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700379 DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline());
Vladimir Marko7624d252014-05-02 14:40:15 +0100380 CHECK(entry_point != GetQuickToInterpreterBridge());
381
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700382 if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100383 // Generic JNI frame.
384 DCHECK(IsNative());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700385 StackHandleScope<1> hs(Thread::Current());
386 uint32_t handle_refs =
387 MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700388 size_t scope_size = HandleScope::SizeOf(handle_refs);
Vladimir Marko7624d252014-05-02 14:40:15 +0100389 QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700390
391 // Callee saves + handle scope + method ref + alignment
392 size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size
393 - kPointerSize // callee-save frame stores a whole method pointer
394 + sizeof(StackReference<mirror::ArtMethod>),
395 kStackAlignment);
396
397 return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask());
Vladimir Marko7624d252014-05-02 14:40:15 +0100398 }
399
400 const void* code_pointer = EntryPointToCodePointer(entry_point);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100401 return GetQuickFrameInfo(code_pointer);
402}
403
404inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
405 DCHECK(code_pointer != nullptr);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700406 DCHECK_EQ(code_pointer, GetQuickOatCodePointer());
Vladimir Marko7624d252014-05-02 14:40:15 +0100407 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
408}
409
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700410inline const DexFile* ArtMethod::GetDexFile() {
411 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile();
412}
413
414inline const char* ArtMethod::GetDeclaringClassDescriptor() {
415 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
416 uint32_t dex_method_idx = method->GetDexMethodIndex();
417 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
418 return "<runtime method>";
419 }
420 const DexFile* dex_file = method->GetDexFile();
421 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
422}
423
424inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
425 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
426 const DexFile* dex_file = method->GetDexFile();
427 return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length);
428}
429
430inline const Signature ArtMethod::GetSignature() {
431 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
432 uint32_t dex_method_idx = method->GetDexMethodIndex();
433 if (dex_method_idx != DexFile::kDexNoIndex) {
434 const DexFile* dex_file = method->GetDexFile();
435 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
436 }
437 return Signature::NoSignature();
438}
439
Ian Rogers1ff3c982014-08-12 02:30:58 -0700440inline const char* ArtMethod::GetName() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700441 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
442 uint32_t dex_method_idx = method->GetDexMethodIndex();
443 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
444 const DexFile* dex_file = method->GetDexFile();
445 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
446 }
447 Runtime* runtime = Runtime::Current();
448 if (method == runtime->GetResolutionMethod()) {
449 return "<runtime internal resolution method>";
450 } else if (method == runtime->GetImtConflictMethod()) {
451 return "<runtime internal imt conflict method>";
452 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
453 return "<runtime internal callee-save all registers method>";
454 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
455 return "<runtime internal callee-save reference registers method>";
456 } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
457 return "<runtime internal callee-save reference and argument registers method>";
458 } else {
459 return "<unknown runtime internal method>";
460 }
461}
462
463inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
464 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
465 return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
466}
467
468inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
469 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
Andreas Gampe58a5af82014-07-31 16:23:49 -0700470 return method->GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700471}
472
473inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
474 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
475 if (dex_pc == DexFile::kDexNoIndex) {
476 return method->IsNative() ? -2 : -1;
477 }
478 return method->GetDexFile()->GetLineNumFromPC(method, dex_pc);
479}
480
481inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
482 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
483 const DexFile* dex_file = method->GetDexFile();
484 return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex()));
485}
486
487inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
488 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
489 const DexFile* dex_file = method->GetDexFile();
490 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
491 dex_file->GetMethodId(method->GetDexMethodIndex()));
492 return dex_file->GetProtoParameters(proto);
493}
494
495inline const char* ArtMethod::GetDeclaringClassSourceFile() {
496 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile();
497}
498
499inline uint16_t ArtMethod::GetClassDefIndex() {
500 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex();
501}
502
503inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
504 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
505 return method->GetDexFile()->GetClassDef(GetClassDefIndex());
506}
507
508inline const char* ArtMethod::GetReturnTypeDescriptor() {
509 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
510 const DexFile* dex_file = method->GetDexFile();
511 const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex());
512 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
513 uint16_t return_type_idx = proto_id.return_type_idx_;
514 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
515}
516
517inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
518 mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
519 const DexFile* dex_file = method->GetDexFile();
520 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
521}
522
523inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
524 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader();
525}
526
527inline mirror::DexCache* ArtMethod::GetDexCache() {
528 return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache();
529}
530
531inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() {
532 mirror::Class* klass = GetDeclaringClass();
533 if (LIKELY(!klass->IsProxyClass())) {
534 return this;
535 }
536 mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex());
537 DCHECK(interface_method != nullptr);
538 DCHECK_EQ(interface_method,
539 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
540 return interface_method;
541}
542
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800543} // namespace mirror
544} // namespace art
545
Brian Carlstromea46f952013-07-30 01:26:50 -0700546#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_