blob: d38cc560673f2e2654dde805b450ee15b2a9fa06 [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#ifndef ART_RUNTIME_ART_METHOD_INL_H_
18#define ART_RUNTIME_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"
Mathieu Chartier7c0fe5e2015-07-17 19:53:47 -070023#include "base/logging.h"
Hiroshi Yamauchi00370822015-08-18 14:47:25 -070024#include "class_linker-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "dex_file.h"
Elliott Hughes956af0f2014-12-11 14:34:28 -080026#include "dex_file-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "gc_root-inl.h"
28#include "mirror/class-inl.h"
29#include "mirror/dex_cache.h"
30#include "mirror/object-inl.h"
31#include "mirror/object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010032#include "oat.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010033#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070034#include "read_barrier-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010035#include "runtime-inl.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010036#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037
38namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039
Mathieu Chartiere401d142015-04-22 13:56:20 -070040inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070041 GcRootSource gc_root_source(this);
42 return declaring_class_.Read(&gc_root_source);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070043}
44
Mathieu Chartiere401d142015-04-22 13:56:20 -070045inline mirror::Class* ArtMethod::GetDeclaringClassNoBarrier() {
46 return declaring_class_.Read<kWithoutReadBarrier>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070047}
48
Mathieu Chartiere401d142015-04-22 13:56:20 -070049inline mirror::Class* ArtMethod::GetDeclaringClass() {
50 mirror::Class* result = GetDeclaringClassUnchecked();
51 if (kIsDebugBuild) {
52 if (!IsRuntimeMethod()) {
53 CHECK(result != nullptr) << this;
54 CHECK(result->IsIdxLoaded() || result->IsErroneous())
55 << result->GetStatus() << " " << PrettyClass(result);
56 } else {
57 CHECK(result == nullptr) << this;
58 }
59 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060 return result;
61}
62
Mathieu Chartiere401d142015-04-22 13:56:20 -070063inline void ArtMethod::SetDeclaringClass(mirror::Class* new_declaring_class) {
64 declaring_class_ = GcRoot<mirror::Class>(new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065}
66
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070067inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class,
68 mirror::Class* desired_class) {
69 GcRoot<mirror::Class> expected_root(expected_class);
70 GcRoot<mirror::Class> desired_root(desired_class);
71 return reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_)->
72 CompareExchangeStrongSequentiallyConsistent(
73 expected_root, desired_root);
74}
75
Ian Rogersef7d42f2014-01-06 12:55:46 -080076inline uint32_t ArtMethod::GetAccessFlags() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070077 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
78 GetDeclaringClass()->IsErroneous());
79 return access_flags_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080}
81
Ian Rogersef7d42f2014-01-06 12:55:46 -080082inline uint16_t ArtMethod::GetMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070083 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() ||
84 GetDeclaringClass()->IsErroneous());
85 return method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086}
87
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070088inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070089 return method_index_;
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070090}
91
Ian Rogersef7d42f2014-01-06 12:55:46 -080092inline uint32_t ArtMethod::GetDexMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070093 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
94 GetDeclaringClass()->IsErroneous());
95 return dex_method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096}
97
Mathieu Chartiere401d142015-04-22 13:56:20 -070098inline mirror::PointerArray* ArtMethod::GetDexCacheResolvedMethods() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070099 GcRootSource gc_root_source(this);
100 return dex_cache_resolved_methods_.Read(&gc_root_source);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700101}
102
Mathieu Chartiere401d142015-04-22 13:56:20 -0700103inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) {
104 auto* method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
105 method_index, ptr_size);
106 if (LIKELY(method != nullptr)) {
107 auto* declaring_class = method->GetDeclaringClass();
108 if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) {
109 return method;
110 }
Andreas Gampe58a5af82014-07-31 16:23:49 -0700111 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700112 return nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700113}
114
Mathieu Chartiere401d142015-04-22 13:56:20 -0700115inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
116 size_t ptr_size) {
117 DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr);
118 GetDexCacheResolvedMethods()->SetElementPtrSize(method_idx, new_method, ptr_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700119}
120
121inline bool ArtMethod::HasDexCacheResolvedMethods() {
122 return GetDexCacheResolvedMethods() != nullptr;
123}
124
Mathieu Chartiere401d142015-04-22 13:56:20 -0700125inline bool ArtMethod::HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache) {
Andreas Gampe58a5af82014-07-31 16:23:49 -0700126 return GetDexCacheResolvedMethods() == other_cache;
127}
128
129inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
130 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
131}
132
Mathieu Chartiere401d142015-04-22 13:56:20 -0700133inline mirror::ObjectArray<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700134 GcRootSource gc_root_source(this);
135 return dex_cache_resolved_types_.Read(&gc_root_source);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700136}
137
Andreas Gampe58a5af82014-07-31 16:23:49 -0700138template <bool kWithCheck>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700139inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
140 mirror::Class* klass = kWithCheck ?
141 GetDexCacheResolvedTypes()->Get(type_index) :
142 GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700143 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
144}
145
146inline bool ArtMethod::HasDexCacheResolvedTypes() {
147 return GetDexCacheResolvedTypes() != nullptr;
148}
149
Mathieu Chartiere401d142015-04-22 13:56:20 -0700150inline bool ArtMethod::HasSameDexCacheResolvedTypes(
151 mirror::ObjectArray<mirror::Class>* other_cache) {
Andreas Gampe58a5af82014-07-31 16:23:49 -0700152 return GetDexCacheResolvedTypes() == other_cache;
153}
154
155inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
156 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
157}
158
Ian Rogersa0485602014-12-02 15:48:04 -0800159inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
160 mirror::Class* type = GetDexCacheResolvedType(type_idx);
161 if (type == nullptr && resolve) {
162 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
163 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
164 }
165 return type;
166}
167
Ian Rogersef7d42f2014-01-06 12:55:46 -0800168inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800169 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800170 return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
171}
172
173inline uint32_t ArtMethod::GetCodeSize(const void* code) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100174 if (code == nullptr) {
175 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100177 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178}
179
Brian Carlstromea46f952013-07-30 01:26:50 -0700180inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 switch (type) {
182 case kStatic:
183 return !IsStatic();
184 case kDirect:
185 return !IsDirect() || IsStatic();
186 case kVirtual: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700187 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
189 }
190 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700191 // Constructors and static methods are called with invoke-direct.
192 // Interface methods cannot be invoked with invoke-super.
193 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 case kInterface: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700195 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
197 }
198 default:
199 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700200 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 }
202}
203
Ian Rogersef7d42f2014-01-06 12:55:46 -0800204inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800206 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207}
208
Ian Rogersef7d42f2014-01-06 12:55:46 -0800209inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800210 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
212}
213
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800214inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
215 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100216 if (code_pointer == nullptr) {
217 return nullptr;
218 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800219 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100220}
221
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800222inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100223 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800224 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100225 uint32_t offset =
226 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
227 if (UNLIKELY(offset == 0u)) {
228 return nullptr;
229 }
230 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
231}
232
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800233inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
234 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100235 if (code_pointer == nullptr) {
236 return nullptr;
237 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800238 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100239}
240
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800241inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
242 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100243 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800244 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100245 uint32_t offset =
246 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
247 if (UNLIKELY(offset == 0u)) {
248 return nullptr;
249 }
250 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
251}
252
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100253inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800254 DCHECK(IsOptimized(sizeof(void*)));
255 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100256 DCHECK(code_pointer != nullptr);
257 uint32_t offset =
258 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700259 const void* data =
260 reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100261 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100262}
263
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800264inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
265 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
266 if (code_pointer == nullptr) {
267 return nullptr;
268 }
269 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800270}
271
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800272inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
273 DCHECK(code_pointer != nullptr);
274 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
275 uint32_t offset =
276 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
277 if (UNLIKELY(offset == 0u)) {
278 return nullptr;
279 }
280 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800281}
282
Ian Rogersef7d42f2014-01-06 12:55:46 -0800283inline bool ArtMethod::IsRuntimeMethod() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700284 return dex_method_index_ == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285}
286
Ian Rogersef7d42f2014-01-06 12:55:46 -0800287inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800288 if (!IsRuntimeMethod()) {
289 return false;
290 }
291 Runtime* runtime = Runtime::Current();
292 bool result = false;
293 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
294 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
295 result = true;
296 break;
297 }
298 }
299 return result;
300}
301
Ian Rogersef7d42f2014-01-06 12:55:46 -0800302inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303 bool result = this == Runtime::Current()->GetResolutionMethod();
304 // Check that if we do think it is phony it looks like the resolution method.
305 DCHECK(!result || IsRuntimeMethod());
306 return result;
307}
Jeff Hao88474b42013-10-23 16:24:40 -0700308
Ian Rogersef7d42f2014-01-06 12:55:46 -0800309inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700310 bool result = this == Runtime::Current()->GetImtConflictMethod();
311 // Check that if we do think it is phony it looks like the imt conflict method.
312 DCHECK(!result || IsRuntimeMethod());
313 return result;
314}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800315
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700316inline bool ArtMethod::IsImtUnimplementedMethod() {
317 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
318 // Check that if we do think it is phony it looks like the imt unimplemented method.
319 DCHECK(!result || IsRuntimeMethod());
320 return result;
321}
322
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700323inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800324 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
325 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100326 return pc - reinterpret_cast<uintptr_t>(code);
327}
328
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100329inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
330 DCHECK(code_pointer != nullptr);
Mathieu Chartier7c0fe5e2015-07-17 19:53:47 -0700331 if (kIsDebugBuild && !IsProxyMethod()) {
332 CHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
333 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100334 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
335}
336
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700337inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700338 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700339}
340
341inline const char* ArtMethod::GetDeclaringClassDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700342 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700343 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
344 return "<runtime method>";
345 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700346 DCHECK(!IsProxyMethod());
347 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700348 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
349}
350
351inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700352 DCHECK(!IsProxyMethod());
353 const DexFile* dex_file = GetDexFile();
354 return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700355}
356
357inline const Signature ArtMethod::GetSignature() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700358 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700359 if (dex_method_idx != DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700360 DCHECK(!IsProxyMethod());
361 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700362 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
363 }
364 return Signature::NoSignature();
365}
366
Ian Rogers1ff3c982014-08-12 02:30:58 -0700367inline const char* ArtMethod::GetName() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700368 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700369 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700370 DCHECK(!IsProxyMethod());
371 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700372 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
373 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700374 Runtime* const runtime = Runtime::Current();
375 if (this == runtime->GetResolutionMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700376 return "<runtime internal resolution method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700377 } else if (this == runtime->GetImtConflictMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700378 return "<runtime internal imt conflict method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700379 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700380 return "<runtime internal callee-save all registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700381 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700382 return "<runtime internal callee-save reference registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700383 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700384 return "<runtime internal callee-save reference and argument registers method>";
385 } else {
386 return "<unknown runtime internal method>";
387 }
388}
389
390inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800391 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700392}
393
394inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 DCHECK(!IsProxyMethod());
396 return GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700397}
398
399inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700400 DCHECK(!IsProxyMethod());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700401 if (dex_pc == DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700402 return IsNative() ? -2 : -1;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700403 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700404 return GetDexFile()->GetLineNumFromPC(this, dex_pc);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700405}
406
407inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700408 DCHECK(!IsProxyMethod());
409 const DexFile* dex_file = GetDexFile();
410 return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700411}
412
413inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700414 DCHECK(!IsProxyMethod());
415 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700416 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700417 dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700418 return dex_file->GetProtoParameters(proto);
419}
420
421inline const char* ArtMethod::GetDeclaringClassSourceFile() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700422 DCHECK(!IsProxyMethod());
423 return GetDeclaringClass()->GetSourceFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700424}
425
426inline uint16_t ArtMethod::GetClassDefIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700427 DCHECK(!IsProxyMethod());
428 return GetDeclaringClass()->GetDexClassDefIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700429}
430
431inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700432 DCHECK(!IsProxyMethod());
433 return GetDexFile()->GetClassDef(GetClassDefIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700434}
435
436inline const char* ArtMethod::GetReturnTypeDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700437 DCHECK(!IsProxyMethod());
438 const DexFile* dex_file = GetDexFile();
439 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700440 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) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700446 DCHECK(!IsProxyMethod());
447 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700448 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
449}
450
451inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700452 DCHECK(!IsProxyMethod());
453 return GetDeclaringClass()->GetClassLoader();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700454}
455
456inline mirror::DexCache* ArtMethod::GetDexCache() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700457 DCHECK(!IsProxyMethod());
458 return GetDeclaringClass()->GetDexCache();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700459}
460
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700461inline bool ArtMethod::IsProxyMethod() {
462 return GetDeclaringClass()->IsProxyClass();
463}
464
Mathieu Chartiere401d142015-04-22 13:56:20 -0700465inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(size_t pointer_size) {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700466 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700467 return this;
468 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700469 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700470 auto interface_method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
471 GetDexMethodIndex(), pointer_size);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700472 DCHECK(interface_method != nullptr);
473 DCHECK_EQ(interface_method,
474 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
475 return interface_method;
476}
477
Mathieu Chartiere401d142015-04-22 13:56:20 -0700478inline void ArtMethod::SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods) {
479 dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(new_dex_cache_methods);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700480}
481
Mathieu Chartiere401d142015-04-22 13:56:20 -0700482inline void ArtMethod::SetDexCacheResolvedTypes(
483 mirror::ObjectArray<mirror::Class>* new_dex_cache_types) {
484 dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(new_dex_cache_types);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700485}
486
Ian Rogersded66a02014-10-28 18:12:55 -0700487inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
488 DCHECK(!IsProxyMethod());
489 const DexFile* dex_file = GetDexFile();
490 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
491 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
492 uint16_t return_type_idx = proto_id.return_type_idx_;
493 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
494 if (type == nullptr && resolve) {
495 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
496 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
497 }
498 return type;
499}
500
Mathieu Chartiere401d142015-04-22 13:56:20 -0700501template<typename RootVisitorType>
502void ArtMethod::VisitRoots(RootVisitorType& visitor) {
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700503 visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
504 visitor.VisitRootIfNonNull(dex_cache_resolved_methods_.AddressWithoutBarrier());
505 visitor.VisitRootIfNonNull(dex_cache_resolved_types_.AddressWithoutBarrier());
Mathieu Chartier2d721012014-11-10 11:08:06 -0800506}
507
Mathieu Chartiere401d142015-04-22 13:56:20 -0700508inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) {
509 memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src),
Vladimir Marko14632852015-08-17 12:07:23 +0100510 Size(image_pointer_size));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700511 declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
512 dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(
513 const_cast<ArtMethod*>(src)->GetDexCacheResolvedMethods());
514 dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(
515 const_cast<ArtMethod*>(src)->GetDexCacheResolvedTypes());
516}
517
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800518} // namespace art
519
Mathieu Chartiere401d142015-04-22 13:56:20 -0700520#endif // ART_RUNTIME_ART_METHOD_INL_H_