blob: cec183789e9ab4bf84bd960b6bfae3dc09b6665a [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_H_
18#define ART_RUNTIME_ART_METHOD_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Jeff Hao790ad902013-05-22 15:02:08 -070020#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070021#include "gc_root.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "invoke_type.h"
Mathieu Chartier36b58f52014-12-10 12:06:45 -080023#include "method_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "modifiers.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070025#include "mirror/object.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010026#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "read_barrier_option.h"
Sebastien Hertze4b7c892014-12-17 20:02:50 +010028#include "stack.h"
Nicolas Geoffray39468442014-09-02 15:17:15 +010029#include "stack_map.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070030#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
32namespace art {
33
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070035class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070037class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
39namespace mirror {
Mathieu Chartiere401d142015-04-22 13:56:20 -070040class Array;
41class Class;
42class PointerArray;
43} // namespace mirror
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044
Mathieu Chartiere401d142015-04-22 13:56:20 -070045class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -070047 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
48 method_index_(0) { }
49
50 ArtMethod(const ArtMethod& src, size_t image_pointer_size) {
51 CopyFrom(&src, image_pointer_size);
52 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -070053
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070054 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
55 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -070056 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -070057
Mathieu Chartier90443472015-07-16 20:32:27 -070058 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059
Mathieu Chartiere401d142015-04-22 13:56:20 -070060 ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier()
Mathieu Chartier90443472015-07-16 20:32:27 -070061 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070062
63 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -070064 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070065
66 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -070067 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070069 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
70 SHARED_REQUIRES(Locks::mutator_lock_);
71
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070073 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 }
75
Mathieu Chartier90443472015-07-16 20:32:27 -070076 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080077
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010079 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -070080 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081 }
82
83 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -070084 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085
86 // Returns true if the method is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -070087 bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088 return (GetAccessFlags() & kAccPublic) != 0;
89 }
90
91 // Returns true if the method is declared private.
Mathieu Chartier90443472015-07-16 20:32:27 -070092 bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 return (GetAccessFlags() & kAccPrivate) != 0;
94 }
95
96 // Returns true if the method is declared static.
Mathieu Chartier90443472015-07-16 20:32:27 -070097 bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 return (GetAccessFlags() & kAccStatic) != 0;
99 }
100
101 // Returns true if the method is a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700102 bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103 return (GetAccessFlags() & kAccConstructor) != 0;
104 }
105
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700106 // Returns true if the method is a class initializer.
Mathieu Chartier90443472015-07-16 20:32:27 -0700107 bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700108 return IsConstructor() && IsStatic();
109 }
110
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 // Returns true if the method is static, private, or a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700112 bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800113 return IsDirect(GetAccessFlags());
114 }
115
116 static bool IsDirect(uint32_t access_flags) {
117 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
118 }
119
120 // Returns true if the method is declared synchronized.
Mathieu Chartier90443472015-07-16 20:32:27 -0700121 bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
123 return (GetAccessFlags() & synchonized) != 0;
124 }
125
Mathieu Chartier90443472015-07-16 20:32:27 -0700126 bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 return (GetAccessFlags() & kAccFinal) != 0;
128 }
129
Mathieu Chartier90443472015-07-16 20:32:27 -0700130 bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131 return (GetAccessFlags() & kAccMiranda) != 0;
132 }
133
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135 return (GetAccessFlags() & kAccNative) != 0;
136 }
137
Mathieu Chartier90443472015-07-16 20:32:27 -0700138 bool ShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000139 return (GetAccessFlags() & kAccDontInline) != 0;
140 }
141
Mathieu Chartier90443472015-07-16 20:32:27 -0700142 void SetShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000143 SetAccessFlags(GetAccessFlags() | kAccDontInline);
144 }
145
Mathieu Chartier90443472015-07-16 20:32:27 -0700146 bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800147 uint32_t mask = kAccFastNative | kAccNative;
148 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700149 }
150
Mathieu Chartier90443472015-07-16 20:32:27 -0700151 bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152 return (GetAccessFlags() & kAccAbstract) != 0;
153 }
154
Mathieu Chartier90443472015-07-16 20:32:27 -0700155 bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 return (GetAccessFlags() & kAccSynthetic) != 0;
157 }
158
Mathieu Chartier90443472015-07-16 20:32:27 -0700159 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160
Mathieu Chartier90443472015-07-16 20:32:27 -0700161 bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200162 return (GetAccessFlags() & kAccPreverified) != 0;
163 }
164
Mathieu Chartier90443472015-07-16 20:32:27 -0700165 void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800166 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200167 SetAccessFlags(GetAccessFlags() | kAccPreverified);
168 }
169
Mathieu Chartier90443472015-07-16 20:32:27 -0700170 bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100171 // Temporary solution for detecting if a method has been optimized: the compiler
172 // does not create a GC map. Instead, the vmap table contains the stack map
173 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000174 return !IsNative()
175 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800176 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800177 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100178 }
179
Mathieu Chartier90443472015-07-16 20:32:27 -0700180 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181
Mathieu Chartier90443472015-07-16 20:32:27 -0700182 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700184 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700186
Mathieu Chartier90443472015-07-16 20:32:27 -0700187 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 return GetMethodIndex();
189 }
190
Mathieu Chartier90443472015-07-16 20:32:27 -0700191 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100192 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700193 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 }
195
Vladimir Markoc1363122015-04-09 14:13:13 +0100196 static MemberOffset DexMethodIndexOffset() {
197 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
198 }
199
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700201 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 }
203
Mathieu Chartiere401d142015-04-22 13:56:20 -0700204 uint32_t GetCodeItemOffset() {
205 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800206 }
207
Mathieu Chartiere401d142015-04-22 13:56:20 -0700208 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100209 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700210 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 }
212
213 // Number of 32bit registers that would be required to hold all the arguments
214 static size_t NumArgRegisters(const StringPiece& shorty);
215
Mathieu Chartier90443472015-07-16 20:32:27 -0700216 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217
Mathieu Chartiere401d142015-04-22 13:56:20 -0700218 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100219 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700220 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221 }
222
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700224 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 }
226
227 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700228 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800229 }
230
Mathieu Chartiere401d142015-04-22 13:56:20 -0700231 ALWAYS_INLINE mirror::PointerArray* GetDexCacheResolvedMethods()
Mathieu Chartier90443472015-07-16 20:32:27 -0700232 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700233 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700235 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
236 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700237 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700238 ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods)
Mathieu Chartier90443472015-07-16 20:32:27 -0700239 SHARED_REQUIRES(Locks::mutator_lock_);
240 bool HasDexCacheResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700241 bool HasSameDexCacheResolvedMethods(ArtMethod* other)
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700243 bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700244 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245
Andreas Gampe58a5af82014-07-31 16:23:49 -0700246 template <bool kWithCheck = true>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700247 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700248 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700249 void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types)
Mathieu Chartier90443472015-07-16 20:32:27 -0700250 SHARED_REQUIRES(Locks::mutator_lock_);
251 bool HasDexCacheResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_);
252 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700253 bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700254 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255
Ian Rogersa0485602014-12-02 15:48:04 -0800256 // Get the Class* from the type index into this method's dex cache.
257 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
Mathieu Chartier90443472015-07-16 20:32:27 -0700258 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800259
Ian Rogerse0a02da2014-12-02 14:10:53 -0800260 // Find the method that this method overrides.
Mathieu Chartier90443472015-07-16 20:32:27 -0700261 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800262
Ian Rogerse0a02da2014-12-02 14:10:53 -0800263 // Find the method index for this method within other_dexfile. If this method isn't present then
264 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
265 // name and signature in the other_dexfile, such as the method index used to resolve this method
266 // in the other_dexfile.
267 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
268 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700269 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800270
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700271 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700272 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800273
Mathieu Chartiere401d142015-04-22 13:56:20 -0700274 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800275 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
276 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700277 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
278 return GetEntryPoint<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800279 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800280 }
281
Mathieu Chartiere401d142015-04-22 13:56:20 -0700282 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800283 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
284 sizeof(void*));
285 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800286 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700287 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
288 SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size),
289 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800290 }
291
Mathieu Chartier90443472015-07-16 20:32:27 -0700292 uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800293
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700294 // Check whether the given PC is within the quick compiled code associated with this method's
295 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
296 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700297 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800298 return PcIsWithinQuickCode(
299 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800300 }
301
Mathieu Chartier90443472015-07-16 20:32:27 -0700302 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700304 // Returns true if the entrypoint points to the interpreter, as
305 // opposed to the compiled code, that is, this method will be
306 // interpretered on invocation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700307 bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700308
Mathieu Chartiere401d142015-04-22 13:56:20 -0700309 uint32_t GetQuickOatCodeOffset();
310 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700312 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100313 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700314 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
315 // least 2 byte aligned.
316 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100317 return reinterpret_cast<const void*>(code);
318 }
319
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700320 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800321 const void* GetQuickOatEntryPoint(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700322 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700323 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800324 const void* GetQuickOatCodePointer(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700325 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800326 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700327 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100328
Ian Rogers1809a722013-08-09 22:05:32 -0700329 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800330 const uint8_t* GetMappingTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700331 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800332 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700333 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800334
Ian Rogers1809a722013-08-09 22:05:32 -0700335 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800336 const uint8_t* GetVmapTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700337 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800338 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700339 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800340
Mathieu Chartier90443472015-07-16 20:32:27 -0700341 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000342
Mathieu Chartier90443472015-07-16 20:32:27 -0700343 CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100344
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800345 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
346 const uint8_t* GetNativeGcMap(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700347 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800348 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700349 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350
Andreas Gampe90546832014-03-12 18:07:19 -0700351 template <bool kCheckFrameSize = true>
Mathieu Chartier90443472015-07-16 20:32:27 -0700352 uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100353 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700354 if (kCheckFrameSize) {
355 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
356 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800357 return result;
358 }
359
Mathieu Chartier90443472015-07-16 20:32:27 -0700360 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100361 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700362 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363
Mathieu Chartier90443472015-07-16 20:32:27 -0700364 FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700365 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100366 }
367
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700368 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700369 SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100370 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700371 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372 }
373
Mathieu Chartier90443472015-07-16 20:32:27 -0700374 FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700375 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100376 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
377 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800378 }
379
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700380 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700381 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382
Mathieu Chartier90443472015-07-16 20:32:27 -0700383 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800384
Mathieu Chartier2d721012014-11-10 11:08:06 -0800385 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800386 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800387 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 }
389
Mathieu Chartier2d721012014-11-10 11:08:06 -0800390 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800391 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800392 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
393 }
394
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800396 return GetEntryPointFromJniPtrSize(sizeof(void*));
397 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700398 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
399 return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800400 }
401
Mathieu Chartier90443472015-07-16 20:32:27 -0700402 void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700403 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800404 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700405 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
406 SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800407 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800408
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
410 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700411 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412
413 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700414 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415
Mathieu Chartier90443472015-07-16 20:32:27 -0700416 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417
Mathieu Chartier90443472015-07-16 20:32:27 -0700418 bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700419
Mathieu Chartier90443472015-07-16 20:32:27 -0700420 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700421
Mathieu Chartier90443472015-07-16 20:32:27 -0700422 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700423#ifdef NDEBUG
424 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700425 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700426 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
427 }
428#else
429 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700430 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700431#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432
433 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800434 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700435 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436
437 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000438 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700439 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440
Mathieu Chartier90443472015-07-16 20:32:27 -0700441 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800442 return MethodReference(GetDexFile(), GetDexMethodIndex());
443 }
444
Ian Rogersc449aa82013-07-29 14:35:46 -0700445 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
446 // indicates whether the found catch block is responsible for clearing the exception or whether
447 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700448 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
449 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700450 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700452 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700453 template<typename RootVisitorType>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700454 void VisitRoots(RootVisitorType& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800455
Mathieu Chartier90443472015-07-16 20:32:27 -0700456 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700457
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700459
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700461 uint32_t unused_length;
462 return GetShorty(&unused_length);
463 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700464
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700466
Mathieu Chartier90443472015-07-16 20:32:27 -0700467 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700468
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700470
Mathieu Chartier90443472015-07-16 20:32:27 -0700471 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700472
Mathieu Chartier90443472015-07-16 20:32:27 -0700473 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700474
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700476
Mathieu Chartier90443472015-07-16 20:32:27 -0700477 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700478
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700480
Mathieu Chartier90443472015-07-16 20:32:27 -0700481 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700482
Mathieu Chartier90443472015-07-16 20:32:27 -0700483 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700484
Mathieu Chartier90443472015-07-16 20:32:27 -0700485 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700486
Mathieu Chartier90443472015-07-16 20:32:27 -0700487 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700488
Mathieu Chartier90443472015-07-16 20:32:27 -0700489 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700490
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700491 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700493
Ian Rogersded66a02014-10-28 18:12:55 -0700494 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
495 // number of bugs at call sites.
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 mirror::Class* GetReturnType(bool resolve = true) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700497
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700501
Mathieu Chartiere401d142015-04-22 13:56:20 -0700502 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700503 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700504
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700505 // May cause thread suspension due to class resolution.
506 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700507 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700508
Vladimir Marko14632852015-08-17 12:07:23 +0100509 // Size of an instance of this native class.
510 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700511 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800512 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800513 }
514
Vladimir Marko14632852015-08-17 12:07:23 +0100515 // Alignment of an instance of this native class.
516 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100517 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100518 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100519 return pointer_size;
520 }
521
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700523 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700524
525 ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes()
Mathieu Chartier90443472015-07-16 20:32:27 -0700526 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700527
Mathieu Chartier2d721012014-11-10 11:08:06 -0800528 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800530 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700531 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800532
Ian Rogersef7d42f2014-01-06 12:55:46 -0800533 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700534 GcRoot<mirror::PointerArray> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800535
Ian Rogersef7d42f2014-01-06 12:55:46 -0800536 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700537 GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800538
Ian Rogersef7d42f2014-01-06 12:55:46 -0800539 // Access flags; low 16 bits are defined by spec.
540 uint32_t access_flags_;
541
542 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
543
544 // Offset to the CodeItem.
545 uint32_t dex_code_item_offset_;
546
547 // Index into method_ids of the dex file associated with this method.
548 uint32_t dex_method_index_;
549
550 /* End of dex file fields. */
551
552 // Entry within a dispatch table for this method. For static/direct methods the index is into
553 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
554 // ifTable.
555 uint32_t method_index_;
556
Mathieu Chartiereace4582014-11-24 18:29:54 -0800557 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800558
559 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700560 // PACKED(4) is necessary for the correctness of
561 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800562 struct PACKED(4) PtrSizedFields {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800563 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
564 void* entry_point_from_jni_;
565
566 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800567 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800568 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800569 } ptr_sized_fields_;
570
Mathieu Chartier02e25112013-08-14 16:14:24 -0700571 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800572 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700573 // Round up to pointer size for padding field.
574 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
575 }
576
577 template<typename T>
578 ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const {
579 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
580 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
581 if (pointer_size == sizeof(uint32_t)) {
582 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
583 } else {
584 auto v = *reinterpret_cast<const uint64_t*>(addr);
585 DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits";
586 return reinterpret_cast<T>(v);
587 }
588 }
589
590 template<typename T>
591 ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) {
592 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
593 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
594 if (pointer_size == sizeof(uint32_t)) {
595 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
596 DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits";
597 *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr);
598 } else {
599 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
600 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800601 }
602
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800603 // Code points to the start of the quick code.
604 static uint32_t GetCodeSize(const void* code);
605
606 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
607 if (code == 0) {
608 return pc == 0;
609 }
610 /*
611 * During a stack walk, a return PC may point past-the-end of the code
612 * in the case that the last instruction is a call that isn't expected to
613 * return. Thus, we check <= code + GetCodeSize().
614 *
615 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
616 */
617 return code <= pc && pc <= code + GetCodeSize(
618 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
619 }
620
Mathieu Chartiere401d142015-04-22 13:56:20 -0700621 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800622};
623
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800624} // namespace art
625
Mathieu Chartiere401d142015-04-22 13:56:20 -0700626#endif // ART_RUNTIME_ART_METHOD_H_