blob: 40bb9e1d9b5795e070c68eb2aaa1acf8b067dfa6 [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
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070066inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class,
67 mirror::Class* desired_class) {
68 GcRoot<mirror::Class> expected_root(expected_class);
69 GcRoot<mirror::Class> desired_root(desired_class);
70 return reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_)->
71 CompareExchangeStrongSequentiallyConsistent(
72 expected_root, desired_root);
73}
74
Ian Rogersef7d42f2014-01-06 12:55:46 -080075inline uint32_t ArtMethod::GetAccessFlags() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070076 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
77 GetDeclaringClass()->IsErroneous());
78 return access_flags_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079}
80
Ian Rogersef7d42f2014-01-06 12:55:46 -080081inline uint16_t ArtMethod::GetMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070082 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() ||
83 GetDeclaringClass()->IsErroneous());
84 return method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085}
86
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070087inline uint16_t ArtMethod::GetMethodIndexDuringLinking() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070088 return method_index_;
Mathieu Chartier9f3629d2014-10-28 18:23:02 -070089}
90
Ian Rogersef7d42f2014-01-06 12:55:46 -080091inline uint32_t ArtMethod::GetDexMethodIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070092 DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
93 GetDeclaringClass()->IsErroneous());
94 return dex_method_index_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095}
96
Mathieu Chartiere401d142015-04-22 13:56:20 -070097inline mirror::PointerArray* ArtMethod::GetDexCacheResolvedMethods() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070098 GcRootSource gc_root_source(this);
99 return dex_cache_resolved_methods_.Read(&gc_root_source);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700100}
101
Mathieu Chartiere401d142015-04-22 13:56:20 -0700102inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) {
103 auto* method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
104 method_index, ptr_size);
105 if (LIKELY(method != nullptr)) {
106 auto* declaring_class = method->GetDeclaringClass();
107 if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) {
108 return method;
109 }
Andreas Gampe58a5af82014-07-31 16:23:49 -0700110 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700111 return nullptr;
Andreas Gampe58a5af82014-07-31 16:23:49 -0700112}
113
Mathieu Chartiere401d142015-04-22 13:56:20 -0700114inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
115 size_t ptr_size) {
116 DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr);
117 GetDexCacheResolvedMethods()->SetElementPtrSize(method_idx, new_method, ptr_size);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700118}
119
120inline bool ArtMethod::HasDexCacheResolvedMethods() {
121 return GetDexCacheResolvedMethods() != nullptr;
122}
123
Mathieu Chartiere401d142015-04-22 13:56:20 -0700124inline bool ArtMethod::HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache) {
Andreas Gampe58a5af82014-07-31 16:23:49 -0700125 return GetDexCacheResolvedMethods() == other_cache;
126}
127
128inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) {
129 return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods();
130}
131
Mathieu Chartiere401d142015-04-22 13:56:20 -0700132inline mirror::ObjectArray<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes() {
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -0700133 GcRootSource gc_root_source(this);
134 return dex_cache_resolved_types_.Read(&gc_root_source);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700135}
136
Andreas Gampe58a5af82014-07-31 16:23:49 -0700137template <bool kWithCheck>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700138inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) {
139 mirror::Class* klass = kWithCheck ?
140 GetDexCacheResolvedTypes()->Get(type_index) :
141 GetDexCacheResolvedTypes()->GetWithoutChecks(type_index);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700142 return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr;
143}
144
145inline bool ArtMethod::HasDexCacheResolvedTypes() {
146 return GetDexCacheResolvedTypes() != nullptr;
147}
148
Mathieu Chartiere401d142015-04-22 13:56:20 -0700149inline bool ArtMethod::HasSameDexCacheResolvedTypes(
150 mirror::ObjectArray<mirror::Class>* other_cache) {
Andreas Gampe58a5af82014-07-31 16:23:49 -0700151 return GetDexCacheResolvedTypes() == other_cache;
152}
153
154inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
155 return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
156}
157
Ian Rogersa0485602014-12-02 15:48:04 -0800158inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
159 mirror::Class* type = GetDexCacheResolvedType(type_idx);
160 if (type == nullptr && resolve) {
161 type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
162 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
163 }
164 return type;
165}
166
Ian Rogersef7d42f2014-01-06 12:55:46 -0800167inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800169 return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
170}
171
172inline uint32_t ArtMethod::GetCodeSize(const void* code) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100173 if (code == nullptr) {
174 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100176 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177}
178
Brian Carlstromea46f952013-07-30 01:26:50 -0700179inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180 switch (type) {
181 case kStatic:
182 return !IsStatic();
183 case kDirect:
184 return !IsDirect() || IsStatic();
185 case kVirtual: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700186 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
188 }
189 case kSuper:
Andreas Gampe8f252e62014-08-25 20:46:31 -0700190 // Constructors and static methods are called with invoke-direct.
191 // Interface methods cannot be invoked with invoke-super.
192 return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 case kInterface: {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700194 mirror::Class* methods_class = GetDeclaringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
196 }
197 default:
198 LOG(FATAL) << "Unreachable - invocation type: " << type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700199 UNREACHABLE();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201}
202
Ian Rogersef7d42f2014-01-06 12:55:46 -0800203inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800205 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800206}
207
Ian Rogersef7d42f2014-01-06 12:55:46 -0800208inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800210 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
211}
212
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800213inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) {
214 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100215 if (code_pointer == nullptr) {
216 return nullptr;
217 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800218 return GetMappingTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100219}
220
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800221inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100222 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800223 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100224 uint32_t offset =
225 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_;
226 if (UNLIKELY(offset == 0u)) {
227 return nullptr;
228 }
229 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
230}
231
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800232inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) {
233 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100234 if (code_pointer == nullptr) {
235 return nullptr;
236 }
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800237 return GetVmapTable(code_pointer, pointer_size);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100238}
239
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800240inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) {
241 CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler";
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100242 DCHECK(code_pointer != nullptr);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800243 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100244 uint32_t offset =
245 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
246 if (UNLIKELY(offset == 0u)) {
247 return nullptr;
248 }
249 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
250}
251
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100252inline CodeInfo ArtMethod::GetOptimizedCodeInfo() {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800253 DCHECK(IsOptimized(sizeof(void*)));
254 const void* code_pointer = GetQuickOatCodePointer(sizeof(void*));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100255 DCHECK(code_pointer != nullptr);
256 uint32_t offset =
257 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700258 const void* data =
259 reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100260 return CodeInfo(data);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100261}
262
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800263inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) {
264 const void* code_pointer = GetQuickOatCodePointer(pointer_size);
265 if (code_pointer == nullptr) {
266 return nullptr;
267 }
268 return GetNativeGcMap(code_pointer, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800269}
270
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800271inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) {
272 DCHECK(code_pointer != nullptr);
273 DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size));
274 uint32_t offset =
275 reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_;
276 if (UNLIKELY(offset == 0u)) {
277 return nullptr;
278 }
279 return reinterpret_cast<const uint8_t*>(code_pointer) - offset;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800280}
281
Ian Rogersef7d42f2014-01-06 12:55:46 -0800282inline bool ArtMethod::IsRuntimeMethod() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700283 return dex_method_index_ == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800284}
285
Ian Rogersef7d42f2014-01-06 12:55:46 -0800286inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 if (!IsRuntimeMethod()) {
288 return false;
289 }
290 Runtime* runtime = Runtime::Current();
291 bool result = false;
292 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
293 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
294 result = true;
295 break;
296 }
297 }
298 return result;
299}
300
Ian Rogersef7d42f2014-01-06 12:55:46 -0800301inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800302 bool result = this == Runtime::Current()->GetResolutionMethod();
303 // Check that if we do think it is phony it looks like the resolution method.
304 DCHECK(!result || IsRuntimeMethod());
305 return result;
306}
Jeff Hao88474b42013-10-23 16:24:40 -0700307
Ian Rogersef7d42f2014-01-06 12:55:46 -0800308inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700309 bool result = this == Runtime::Current()->GetImtConflictMethod();
310 // Check that if we do think it is phony it looks like the imt conflict method.
311 DCHECK(!result || IsRuntimeMethod());
312 return result;
313}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800314
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700315inline bool ArtMethod::IsImtUnimplementedMethod() {
316 bool result = this == Runtime::Current()->GetImtUnimplementedMethod();
317 // Check that if we do think it is phony it looks like the imt unimplemented method.
318 DCHECK(!result || IsRuntimeMethod());
319 return result;
320}
321
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700322inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800323 const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(
324 this, sizeof(void*));
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100325 return pc - reinterpret_cast<uintptr_t>(code);
326}
327
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100328inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) {
329 DCHECK(code_pointer != nullptr);
Mathieu Chartier7c0fe5e2015-07-17 19:53:47 -0700330 if (kIsDebugBuild && !IsProxyMethod()) {
331 CHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*)));
332 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100333 return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_;
334}
335
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700336inline const DexFile* ArtMethod::GetDexFile() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700337 return GetDexCache()->GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700338}
339
340inline const char* ArtMethod::GetDeclaringClassDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700341 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700342 if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) {
343 return "<runtime method>";
344 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700345 DCHECK(!IsProxyMethod());
346 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700347 return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx));
348}
349
350inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700351 DCHECK(!IsProxyMethod());
352 const DexFile* dex_file = GetDexFile();
353 return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700354}
355
356inline const Signature ArtMethod::GetSignature() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700357 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700358 if (dex_method_idx != DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700359 DCHECK(!IsProxyMethod());
360 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700361 return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx));
362 }
363 return Signature::NoSignature();
364}
365
Ian Rogers1ff3c982014-08-12 02:30:58 -0700366inline const char* ArtMethod::GetName() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700367 uint32_t dex_method_idx = GetDexMethodIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700368 if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700369 DCHECK(!IsProxyMethod());
370 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700371 return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx));
372 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700373 Runtime* const runtime = Runtime::Current();
374 if (this == runtime->GetResolutionMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700375 return "<runtime internal resolution method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700376 } else if (this == runtime->GetImtConflictMethod()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700377 return "<runtime internal imt conflict method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700378 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700379 return "<runtime internal callee-save all registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700380 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700381 return "<runtime internal callee-save reference registers method>";
Mathieu Chartiere401d142015-04-22 13:56:20 -0700382 } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700383 return "<runtime internal callee-save reference and argument registers method>";
384 } else {
385 return "<unknown runtime internal method>";
386 }
387}
388
389inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
Mathieu Chartier12b3dd72014-12-11 13:25:33 -0800390 return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700391}
392
393inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700394 DCHECK(!IsProxyMethod());
395 return GetDexCacheResolvedType(type_idx) != nullptr;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700396}
397
398inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700399 DCHECK(!IsProxyMethod());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700400 if (dex_pc == DexFile::kDexNoIndex) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700401 return IsNative() ? -2 : -1;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700402 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700403 return GetDexFile()->GetLineNumFromPC(this, dex_pc);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700404}
405
406inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700407 DCHECK(!IsProxyMethod());
408 const DexFile* dex_file = GetDexFile();
409 return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700410}
411
412inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700413 DCHECK(!IsProxyMethod());
414 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700415 const DexFile::ProtoId& proto = dex_file->GetMethodPrototype(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700416 dex_file->GetMethodId(GetDexMethodIndex()));
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700417 return dex_file->GetProtoParameters(proto);
418}
419
420inline const char* ArtMethod::GetDeclaringClassSourceFile() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700421 DCHECK(!IsProxyMethod());
422 return GetDeclaringClass()->GetSourceFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700423}
424
425inline uint16_t ArtMethod::GetClassDefIndex() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700426 DCHECK(!IsProxyMethod());
427 return GetDeclaringClass()->GetDexClassDefIndex();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700428}
429
430inline const DexFile::ClassDef& ArtMethod::GetClassDef() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700431 DCHECK(!IsProxyMethod());
432 return GetDexFile()->GetClassDef(GetClassDefIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700433}
434
435inline const char* ArtMethod::GetReturnTypeDescriptor() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700436 DCHECK(!IsProxyMethod());
437 const DexFile* dex_file = GetDexFile();
438 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700439 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
440 uint16_t return_type_idx = proto_id.return_type_idx_;
441 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx));
442}
443
444inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700445 DCHECK(!IsProxyMethod());
446 const DexFile* dex_file = GetDexFile();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700447 return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx));
448}
449
450inline mirror::ClassLoader* ArtMethod::GetClassLoader() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700451 DCHECK(!IsProxyMethod());
452 return GetDeclaringClass()->GetClassLoader();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700453}
454
455inline mirror::DexCache* ArtMethod::GetDexCache() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700456 DCHECK(!IsProxyMethod());
457 return GetDeclaringClass()->GetDexCache();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700458}
459
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700460inline bool ArtMethod::IsProxyMethod() {
461 return GetDeclaringClass()->IsProxyClass();
462}
463
Mathieu Chartiere401d142015-04-22 13:56:20 -0700464inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(size_t pointer_size) {
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700465 if (LIKELY(!IsProxyMethod())) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700466 return this;
467 }
Ian Rogers03b6eaf2014-10-28 09:34:57 -0700468 mirror::Class* klass = GetDeclaringClass();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700469 auto interface_method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>(
470 GetDexMethodIndex(), pointer_size);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700471 DCHECK(interface_method != nullptr);
472 DCHECK_EQ(interface_method,
473 Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this));
474 return interface_method;
475}
476
Mathieu Chartiere401d142015-04-22 13:56:20 -0700477inline void ArtMethod::SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods) {
478 dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(new_dex_cache_methods);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700479}
480
Mathieu Chartiere401d142015-04-22 13:56:20 -0700481inline void ArtMethod::SetDexCacheResolvedTypes(
482 mirror::ObjectArray<mirror::Class>* new_dex_cache_types) {
483 dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(new_dex_cache_types);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700484}
485
Ian Rogersded66a02014-10-28 18:12:55 -0700486inline mirror::Class* ArtMethod::GetReturnType(bool resolve) {
487 DCHECK(!IsProxyMethod());
488 const DexFile* dex_file = GetDexFile();
489 const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex());
490 const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id);
491 uint16_t return_type_idx = proto_id.return_type_idx_;
492 mirror::Class* type = GetDexCacheResolvedType(return_type_idx);
493 if (type == nullptr && resolve) {
494 type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this);
495 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
496 }
497 return type;
498}
499
Mathieu Chartiere401d142015-04-22 13:56:20 -0700500template<typename RootVisitorType>
501void ArtMethod::VisitRoots(RootVisitorType& visitor) {
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700502 visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
503 visitor.VisitRootIfNonNull(dex_cache_resolved_methods_.AddressWithoutBarrier());
504 visitor.VisitRootIfNonNull(dex_cache_resolved_types_.AddressWithoutBarrier());
Mathieu Chartier2d721012014-11-10 11:08:06 -0800505}
506
Mathieu Chartiere401d142015-04-22 13:56:20 -0700507inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) {
508 memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src),
Vladimir Marko14632852015-08-17 12:07:23 +0100509 Size(image_pointer_size));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700510 declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
511 dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(
512 const_cast<ArtMethod*>(src)->GetDexCacheResolvedMethods());
513 dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(
514 const_cast<ArtMethod*>(src)->GetDexCacheResolvedTypes());
515}
516
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517} // namespace art
518
Mathieu Chartiere401d142015-04-22 13:56:20 -0700519#endif // ART_RUNTIME_ART_METHOD_INL_H_