blob: bb3c72c4334cd64c264370692a17e674d3f672af [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "dex_file.h"
Elliott Hughes956af0f2014-12-11 14:34:28 -080025#include "dex_file-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070026#include "gc_root-inl.h"
27#include "mirror/class-inl.h"
28#include "mirror/dex_cache.h"
29#include "mirror/object-inl.h"
30#include "mirror/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"
Vladimir Marko80afd022015-05-19 18:08:00 +010035#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036
37namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
Mathieu Chartiere401d142015-04-22 13:56:20 -070039inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070040 GcRootSource gc_root_source(this);
41 return declaring_class_.Read(&gc_root_source);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070042}
43
Mathieu Chartiere401d142015-04-22 13:56:20 -070044inline mirror::Class* ArtMethod::GetDeclaringClassNoBarrier() {
45 return declaring_class_.Read<kWithoutReadBarrier>();
Mingyao Yang98d1cc82014-05-15 17:02:16 -070046}
47
Mathieu Chartiere401d142015-04-22 13:56:20 -070048inline mirror::Class* ArtMethod::GetDeclaringClass() {
49 mirror::Class* result = GetDeclaringClassUnchecked();
50 if (kIsDebugBuild) {
51 if (!IsRuntimeMethod()) {
52 CHECK(result != nullptr) << this;
53 CHECK(result->IsIdxLoaded() || result->IsErroneous())
54 << result->GetStatus() << " " << PrettyClass(result);
55 } else {
56 CHECK(result == nullptr) << this;
57 }
58 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059 return result;
60}
61
Mathieu Chartiere401d142015-04-22 13:56:20 -070062inline void ArtMethod::SetDeclaringClass(mirror::Class* new_declaring_class) {
63 declaring_class_ = GcRoot<mirror::Class>(new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064}
65
Ian Rogersef7d42f2014-01-06 12:55:46 -080066inline uint32_t ArtMethod::GetAccessFlags() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070067 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
68 GetDeclaringClass()->IsErroneous());
69 return access_flags_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070}
71
Ian Rogersef7d42f2014-01-06 12:55:46 -080072inline uint16_t ArtMethod::GetMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070073 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() ||
74 GetDeclaringClass()->IsErroneous());
75 return method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076}
77
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070078inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070079 return method_index_;
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070080}
81
Ian Rogersef7d42f2014-01-06 12:55:46 -080082inline uint32_t ArtMethod::GetDexMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070083 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
84 GetDeclaringClass()->IsErroneous());
85 return dex_method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086}
87
Mathieu Chartiere401d142015-04-22 13:56:20 -070088inline mirror::PointerArray* ArtMethod::GetDexCacheResolvedMethods() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070089 GcRootSource gc_root_source(this);
90 return dex_cache_resolved_methods_.Read(&gc_root_source);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070091}
92
Mathieu Chartiere401d142015-04-22 13:56:20 -070093inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) {
94 auto* method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
95 method_index, ptr_size);
96 if (LIKELY(method != nullptr)) {
97 auto* declaring_class = method->GetDeclaringClass();
98 if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) {
99 return method;
100 }
Andreas Gampe58a5af82014-07-31 16:23:49 -0700101 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700102 return nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700103}
104
Mathieu Chartiere401d142015-04-22 13:56:20 -0700105inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
106 size_t ptr_size) {
107 DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr);
108 GetDexCacheResolvedMethods()->SetElementPtrSize(method_idx, new_method, ptr_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700109}
110
111inline bool ArtMethod::HasDexCacheResolvedMethods() {
112 return GetDexCacheResolvedMethods() != nullptr;
113}
114
Mathieu Chartiere401d142015-04-22 13:56:20 -0700115inline bool ArtMethod::HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache) {
Andreas Gampe58a5af82014-07-31 16:23:49 -0700116 return GetDexCacheResolvedMethods() == other_cache;
117}
118
119inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
120 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
121}
122
Mathieu Chartiere401d142015-04-22 13:56:20 -0700123inline mirror::ObjectArray<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700124 GcRootSource gc_root_source(this);
125 return dex_cache_resolved_types_.Read(&gc_root_source);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700126}
127
Andreas Gampe58a5af82014-07-31 16:23:49 -0700128template <bool kWithCheck>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700129inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
130 mirror::Class* klass = kWithCheck ?
131 GetDexCacheResolvedTypes()->Get(type_index) :
132 GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700133 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
134}
135
136inline bool ArtMethod::HasDexCacheResolvedTypes() {
137 return GetDexCacheResolvedTypes() != nullptr;
138}
139
Mathieu Chartiere401d142015-04-22 13:56:20 -0700140inline bool ArtMethod::HasSameDexCacheResolvedTypes(
141 mirror::ObjectArray<mirror::Class>* other_cache) {
Andreas Gampe58a5af82014-07-31 16:23:49 -0700142 return GetDexCacheResolvedTypes() == other_cache;
143}
144
145inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
146 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
147}
148
Ian Rogersa0485602014-12-02 15:48:04 -0800149inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
150 mirror::Class* type = GetDexCacheResolvedType(type_idx);
151 if (type == nullptr && resolve) {
152 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
153 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
154 }
155 return type;
156}
157
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800160 return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
161}
162
163inline uint32_t ArtMethod::GetCodeSize(const void* code) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100164 if (code == nullptr) {
165 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100167 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168}
169
Brian Carlstromea46f952013-07-30 01:26:50 -0700170inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 switch (type) {
172 case kStatic:
173 return !IsStatic();
174 case kDirect:
175 return !IsDirect() || IsStatic();
176 case kVirtual: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700177 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
179 }
180 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700181 // Constructors and static methods are called with invoke-direct.
182 // Interface methods cannot be invoked with invoke-super.
183 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 case kInterface: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700185 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
187 }
188 default:
189 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700190 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 }
192}
193
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800196 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197}
198
Ian Rogersef7d42f2014-01-06 12:55:46 -0800199inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800201 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
202}
203
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800204inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
205 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100206 if (code_pointer == nullptr) {
207 return nullptr;
208 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800209 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100210}
211
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800212inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100213 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800214 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100215 uint32_t offset =
216 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
217 if (UNLIKELY(offset == 0u)) {
218 return nullptr;
219 }
220 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
221}
222
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800223inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
224 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100225 if (code_pointer == nullptr) {
226 return nullptr;
227 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800228 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100229}
230
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800231inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
232 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100233 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800234 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100235 uint32_t offset =
236 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
237 if (UNLIKELY(offset == 0u)) {
238 return nullptr;
239 }
240 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
241}
242
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100243inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800244 DCHECK(IsOptimized(sizeof(void*)));
245 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100246 DCHECK(code_pointer != nullptr);
247 uint32_t offset =
248 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700249 const void* data =
250 reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100251 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100252}
253
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800254inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
255 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
256 if (code_pointer == nullptr) {
257 return nullptr;
258 }
259 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260}
261
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800262inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
263 DCHECK(code_pointer != nullptr);
264 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
265 uint32_t offset =
266 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
267 if (UNLIKELY(offset == 0u)) {
268 return nullptr;
269 }
270 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800271}
272
Ian Rogersef7d42f2014-01-06 12:55:46 -0800273inline bool ArtMethod::IsRuntimeMethod() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700274 return dex_method_index_ == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800275}
276
Ian Rogersef7d42f2014-01-06 12:55:46 -0800277inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800278 if (!IsRuntimeMethod()) {
279 return false;
280 }
281 Runtime* runtime = Runtime::Current();
282 bool result = false;
283 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
284 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
285 result = true;
286 break;
287 }
288 }
289 return result;
290}
291
Ian Rogersef7d42f2014-01-06 12:55:46 -0800292inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800293 bool result = this == Runtime::Current()->GetResolutionMethod();
294 // Check that if we do think it is phony it looks like the resolution method.
295 DCHECK(!result || IsRuntimeMethod());
296 return result;
297}
Jeff Hao88474b42013-10-23 16:24:40 -0700298
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700300 bool result = this == Runtime::Current()->GetImtConflictMethod();
301 // Check that if we do think it is phony it looks like the imt conflict method.
302 DCHECK(!result || IsRuntimeMethod());
303 return result;
304}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800305
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700306inline bool ArtMethod::IsImtUnimplementedMethod() {
307 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
308 // Check that if we do think it is phony it looks like the imt unimplemented method.
309 DCHECK(!result || IsRuntimeMethod());
310 return result;
311}
312
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700313inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800314 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
315 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100316 return pc - reinterpret_cast<uintptr_t>(code);
317}
318
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100319inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
320 DCHECK(code_pointer != nullptr);
Mathieu Chartier7c0fe5e2015-07-17 19:53:47 -0700321 if (kIsDebugBuild && !IsProxyMethod()) {
322 CHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
323 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100324 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
325}
326
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700327inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700328 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700329}
330
331inline const char* ArtMethod::GetDeclaringClassDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700332 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700333 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
334 return "<runtime method>";
335 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700336 DCHECK(!IsProxyMethod());
337 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700338 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
339}
340
341inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700342 DCHECK(!IsProxyMethod());
343 const DexFile* dex_file = GetDexFile();
344 return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700345}
346
347inline const Signature ArtMethod::GetSignature() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700348 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700349 if (dex_method_idx != DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700350 DCHECK(!IsProxyMethod());
351 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700352 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
353 }
354 return Signature::NoSignature();
355}
356
Ian Rogers1ff3c982014-08-12 02:30:58 -0700357inline const char* ArtMethod::GetName() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700358 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700359 if (LIKELY(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->GetMethodName(dex_file->GetMethodId(dex_method_idx));
363 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700364 Runtime* const runtime = Runtime::Current();
365 if (this == runtime->GetResolutionMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700366 return "<runtime internal resolution method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700367 } else if (this == runtime->GetImtConflictMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700368 return "<runtime internal imt conflict method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700369 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700370 return "<runtime internal callee-save all registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700371 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700372 return "<runtime internal callee-save reference registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700373 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700374 return "<runtime internal callee-save reference and argument registers method>";
375 } else {
376 return "<unknown runtime internal method>";
377 }
378}
379
380inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800381 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700382}
383
384inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700385 DCHECK(!IsProxyMethod());
386 return GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700387}
388
389inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700390 DCHECK(!IsProxyMethod());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700391 if (dex_pc == DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700392 return IsNative() ? -2 : -1;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700393 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700394 return GetDexFile()->GetLineNumFromPC(this, dex_pc);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700395}
396
397inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700398 DCHECK(!IsProxyMethod());
399 const DexFile* dex_file = GetDexFile();
400 return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700401}
402
403inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700404 DCHECK(!IsProxyMethod());
405 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700406 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700407 dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700408 return dex_file->GetProtoParameters(proto);
409}
410
411inline const char* ArtMethod::GetDeclaringClassSourceFile() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700412 DCHECK(!IsProxyMethod());
413 return GetDeclaringClass()->GetSourceFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700414}
415
416inline uint16_t ArtMethod::GetClassDefIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700417 DCHECK(!IsProxyMethod());
418 return GetDeclaringClass()->GetDexClassDefIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700419}
420
421inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700422 DCHECK(!IsProxyMethod());
423 return GetDexFile()->GetClassDef(GetClassDefIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700424}
425
426inline const char* ArtMethod::GetReturnTypeDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700427 DCHECK(!IsProxyMethod());
428 const DexFile* dex_file = GetDexFile();
429 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700430 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
431 uint16_t return_type_idx = proto_id.return_type_idx_;
432 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
433}
434
435inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700436 DCHECK(!IsProxyMethod());
437 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700438 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
439}
440
441inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700442 DCHECK(!IsProxyMethod());
443 return GetDeclaringClass()->GetClassLoader();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700444}
445
446inline mirror::DexCache* ArtMethod::GetDexCache() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700447 DCHECK(!IsProxyMethod());
448 return GetDeclaringClass()->GetDexCache();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700449}
450
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700451inline bool ArtMethod::IsProxyMethod() {
452 return GetDeclaringClass()->IsProxyClass();
453}
454
Mathieu Chartiere401d142015-04-22 13:56:20 -0700455inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(size_t pointer_size) {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700456 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700457 return this;
458 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700459 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700460 auto interface_method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
461 GetDexMethodIndex(), pointer_size);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700462 DCHECK(interface_method != nullptr);
463 DCHECK_EQ(interface_method,
464 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
465 return interface_method;
466}
467
Mathieu Chartiere401d142015-04-22 13:56:20 -0700468inline void ArtMethod::SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods) {
469 dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(new_dex_cache_methods);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700470}
471
Mathieu Chartiere401d142015-04-22 13:56:20 -0700472inline void ArtMethod::SetDexCacheResolvedTypes(
473 mirror::ObjectArray<mirror::Class>* new_dex_cache_types) {
474 dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(new_dex_cache_types);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700475}
476
Ian Rogersded66a02014-10-28 18:12:55 -0700477inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
478 DCHECK(!IsProxyMethod());
479 const DexFile* dex_file = GetDexFile();
480 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
481 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
482 uint16_t return_type_idx = proto_id.return_type_idx_;
483 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
484 if (type == nullptr && resolve) {
485 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
486 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
487 }
488 return type;
489}
490
Mathieu Chartiere401d142015-04-22 13:56:20 -0700491template<typename RootVisitorType>
492void ArtMethod::VisitRoots(RootVisitorType& visitor) {
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700493 visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
494 visitor.VisitRootIfNonNull(dex_cache_resolved_methods_.AddressWithoutBarrier());
495 visitor.VisitRootIfNonNull(dex_cache_resolved_types_.AddressWithoutBarrier());
Mathieu Chartier2d721012014-11-10 11:08:06 -0800496}
497
Mathieu Chartiere401d142015-04-22 13:56:20 -0700498inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) {
499 memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src),
500 ObjectSize(image_pointer_size));
501 declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
502 dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(
503 const_cast<ArtMethod*>(src)->GetDexCacheResolvedMethods());
504 dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(
505 const_cast<ArtMethod*>(src)->GetDexCacheResolvedTypes());
506}
507
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800508} // namespace art
509
Mathieu Chartiere401d142015-04-22 13:56:20 -0700510#endif // ART_RUNTIME_ART_METHOD_INL_H_