blob: 90352b7c08da75965cbdff36ec790430bae6a950 [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"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080026#include "object_callbacks.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010027#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070028#include "read_barrier_option.h"
Sebastien Hertze4b7c892014-12-17 20:02:50 +010029#include "stack.h"
Nicolas Geoffray39468442014-09-02 15:17:15 +010030#include "stack_map.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070031#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032
33namespace art {
34
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070036class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070038class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039
40namespace mirror {
Mathieu Chartiere401d142015-04-22 13:56:20 -070041class Array;
42class Class;
43class PointerArray;
44} // namespace mirror
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045
Mathieu Chartiere401d142015-04-22 13:56:20 -070046class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -070048 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
49 method_index_(0) { }
50
51 ArtMethod(const ArtMethod& src, size_t image_pointer_size) {
52 CopyFrom(&src, image_pointer_size);
53 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -070054
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070055 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
56 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -070057 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -070058
Mathieu Chartier90443472015-07-16 20:32:27 -070059 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060
Mathieu Chartiere401d142015-04-22 13:56:20 -070061 ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier()
Mathieu Chartier90443472015-07-16 20:32:27 -070062 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070063
64 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -070065 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070066
67 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -070068 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069
70 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070071 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 }
73
Mathieu Chartier90443472015-07-16 20:32:27 -070074 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080075
Mathieu Chartiere401d142015-04-22 13:56:20 -070076 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010077 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079 }
80
81 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -070082 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083
84 // Returns true if the method is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -070085 bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086 return (GetAccessFlags() & kAccPublic) != 0;
87 }
88
89 // Returns true if the method is declared private.
Mathieu Chartier90443472015-07-16 20:32:27 -070090 bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091 return (GetAccessFlags() & kAccPrivate) != 0;
92 }
93
94 // Returns true if the method is declared static.
Mathieu Chartier90443472015-07-16 20:32:27 -070095 bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096 return (GetAccessFlags() & kAccStatic) != 0;
97 }
98
99 // Returns true if the method is a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700100 bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 return (GetAccessFlags() & kAccConstructor) != 0;
102 }
103
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700104 // Returns true if the method is a class initializer.
Mathieu Chartier90443472015-07-16 20:32:27 -0700105 bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700106 return IsConstructor() && IsStatic();
107 }
108
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800109 // Returns true if the method is static, private, or a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700110 bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 return IsDirect(GetAccessFlags());
112 }
113
114 static bool IsDirect(uint32_t access_flags) {
115 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
116 }
117
118 // Returns true if the method is declared synchronized.
Mathieu Chartier90443472015-07-16 20:32:27 -0700119 bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
121 return (GetAccessFlags() & synchonized) != 0;
122 }
123
Mathieu Chartier90443472015-07-16 20:32:27 -0700124 bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800125 return (GetAccessFlags() & kAccFinal) != 0;
126 }
127
Mathieu Chartier90443472015-07-16 20:32:27 -0700128 bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129 return (GetAccessFlags() & kAccMiranda) != 0;
130 }
131
Mathieu Chartier90443472015-07-16 20:32:27 -0700132 bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800133 return (GetAccessFlags() & kAccNative) != 0;
134 }
135
Mathieu Chartier90443472015-07-16 20:32:27 -0700136 bool ShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000137 return (GetAccessFlags() & kAccDontInline) != 0;
138 }
139
Mathieu Chartier90443472015-07-16 20:32:27 -0700140 void SetShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000141 SetAccessFlags(GetAccessFlags() | kAccDontInline);
142 }
143
Mathieu Chartier90443472015-07-16 20:32:27 -0700144 bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800145 uint32_t mask = kAccFastNative | kAccNative;
146 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700147 }
148
Mathieu Chartier90443472015-07-16 20:32:27 -0700149 bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 return (GetAccessFlags() & kAccAbstract) != 0;
151 }
152
Mathieu Chartier90443472015-07-16 20:32:27 -0700153 bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154 return (GetAccessFlags() & kAccSynthetic) != 0;
155 }
156
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158
Mathieu Chartier90443472015-07-16 20:32:27 -0700159 bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200160 return (GetAccessFlags() & kAccPreverified) != 0;
161 }
162
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800164 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200165 SetAccessFlags(GetAccessFlags() | kAccPreverified);
166 }
167
Mathieu Chartier90443472015-07-16 20:32:27 -0700168 bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100169 // Temporary solution for detecting if a method has been optimized: the compiler
170 // does not create a GC map. Instead, the vmap table contains the stack map
171 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000172 return !IsNative()
173 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800174 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800175 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100176 }
177
Mathieu Chartier90443472015-07-16 20:32:27 -0700178 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179
Mathieu Chartier90443472015-07-16 20:32:27 -0700180 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700182 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700183 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700184
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 return GetMethodIndex();
187 }
188
Mathieu Chartier90443472015-07-16 20:32:27 -0700189 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100190 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700191 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 }
193
Vladimir Markoc1363122015-04-09 14:13:13 +0100194 static MemberOffset DexMethodIndexOffset() {
195 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
196 }
197
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700199 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201
Mathieu Chartiere401d142015-04-22 13:56:20 -0700202 uint32_t GetCodeItemOffset() {
203 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 }
205
Mathieu Chartiere401d142015-04-22 13:56:20 -0700206 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100207 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700208 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 }
210
211 // Number of 32bit registers that would be required to hold all the arguments
212 static size_t NumArgRegisters(const StringPiece& shorty);
213
Mathieu Chartier90443472015-07-16 20:32:27 -0700214 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215
Mathieu Chartiere401d142015-04-22 13:56:20 -0700216 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100217 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700218 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 }
220
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700222 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223 }
224
225 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700226 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227 }
228
Mathieu Chartiere401d142015-04-22 13:56:20 -0700229 ALWAYS_INLINE mirror::PointerArray* GetDexCacheResolvedMethods()
Mathieu Chartier90443472015-07-16 20:32:27 -0700230 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700231 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700232 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700233 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
234 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700235 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700236 ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods)
Mathieu Chartier90443472015-07-16 20:32:27 -0700237 SHARED_REQUIRES(Locks::mutator_lock_);
238 bool HasDexCacheResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700239 bool HasSameDexCacheResolvedMethods(ArtMethod* other)
Mathieu Chartier90443472015-07-16 20:32:27 -0700240 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700241 bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243
Andreas Gampe58a5af82014-07-31 16:23:49 -0700244 template <bool kWithCheck = true>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700245 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700247 void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types)
Mathieu Chartier90443472015-07-16 20:32:27 -0700248 SHARED_REQUIRES(Locks::mutator_lock_);
249 bool HasDexCacheResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_);
250 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700251 bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700252 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800253
Ian Rogersa0485602014-12-02 15:48:04 -0800254 // Get the Class* from the type index into this method's dex cache.
255 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800257
Ian Rogerse0a02da2014-12-02 14:10:53 -0800258 // Find the method that this method overrides.
Mathieu Chartier90443472015-07-16 20:32:27 -0700259 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260
Ian Rogerse0a02da2014-12-02 14:10:53 -0800261 // Find the method index for this method within other_dexfile. If this method isn't present then
262 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
263 // name and signature in the other_dexfile, such as the method index used to resolve this method
264 // in the other_dexfile.
265 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
266 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700267 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800268
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700269 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700270 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800271
Mathieu Chartiere401d142015-04-22 13:56:20 -0700272 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800273 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
274 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700275 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
276 return GetEntryPoint<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800277 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278 }
279
Mathieu Chartiere401d142015-04-22 13:56:20 -0700280 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800281 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
282 sizeof(void*));
283 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800284 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700285 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
286 SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size),
287 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800288 }
289
Mathieu Chartier90443472015-07-16 20:32:27 -0700290 uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800291
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700292 // Check whether the given PC is within the quick compiled code associated with this method's
293 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
294 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700295 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800296 return PcIsWithinQuickCode(
297 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800298 }
299
Mathieu Chartier90443472015-07-16 20:32:27 -0700300 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800301
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700302 // Returns true if the entrypoint points to the interpreter, as
303 // opposed to the compiled code, that is, this method will be
304 // interpretered on invocation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700306
Mathieu Chartiere401d142015-04-22 13:56:20 -0700307 uint32_t GetQuickOatCodeOffset();
308 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700310 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100311 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700312 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
313 // least 2 byte aligned.
314 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100315 return reinterpret_cast<const void*>(code);
316 }
317
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700318 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800319 const void* GetQuickOatEntryPoint(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700320 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700321 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800322 const void* GetQuickOatCodePointer(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700323 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800324 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700325 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100326
Ian Rogers1809a722013-08-09 22:05:32 -0700327 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800328 const uint8_t* GetMappingTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700329 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800330 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700331 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800332
Ian Rogers1809a722013-08-09 22:05:32 -0700333 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800334 const uint8_t* GetVmapTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700335 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800336 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700337 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338
Mathieu Chartier90443472015-07-16 20:32:27 -0700339 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000340
Mathieu Chartier90443472015-07-16 20:32:27 -0700341 CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100342
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800343 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
344 const uint8_t* GetNativeGcMap(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700345 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800346 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700347 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800348
Andreas Gampe90546832014-03-12 18:07:19 -0700349 template <bool kCheckFrameSize = true>
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100351 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700352 if (kCheckFrameSize) {
353 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
354 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800355 return result;
356 }
357
Mathieu Chartier90443472015-07-16 20:32:27 -0700358 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100359 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700360 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361
Mathieu Chartier90443472015-07-16 20:32:27 -0700362 FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700363 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100364 }
365
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700366 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700367 SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100368 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700369 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800370 }
371
Mathieu Chartier90443472015-07-16 20:32:27 -0700372 FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700373 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100374 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
375 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800376 }
377
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700378 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700379 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380
Mathieu Chartier90443472015-07-16 20:32:27 -0700381 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382
Mathieu Chartier2d721012014-11-10 11:08:06 -0800383 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800384 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800385 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386 }
387
Mathieu Chartier2d721012014-11-10 11:08:06 -0800388 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800389 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800390 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
391 }
392
Mathieu Chartiere401d142015-04-22 13:56:20 -0700393 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800394 return GetEntryPointFromJniPtrSize(sizeof(void*));
395 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700396 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
397 return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800398 }
399
Mathieu Chartier90443472015-07-16 20:32:27 -0700400 void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700401 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800402 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700403 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
404 SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800405 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
408 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700409 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410
411 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700412 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413
Mathieu Chartier90443472015-07-16 20:32:27 -0700414 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415
Mathieu Chartier90443472015-07-16 20:32:27 -0700416 bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700417
Mathieu Chartier90443472015-07-16 20:32:27 -0700418 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700419
Mathieu Chartier90443472015-07-16 20:32:27 -0700420 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700421#ifdef NDEBUG
422 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700423 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700424 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
425 }
426#else
427 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700428 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700429#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430
431 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800432 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700433 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434
435 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000436 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700437 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438
Mathieu Chartier90443472015-07-16 20:32:27 -0700439 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800440 return MethodReference(GetDexFile(), GetDexMethodIndex());
441 }
442
Ian Rogersc449aa82013-07-29 14:35:46 -0700443 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
444 // indicates whether the found catch block is responsible for clearing the exception or whether
445 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700446 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
447 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700448 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700450 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700451 template<typename RootVisitorType>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700452 void VisitRoots(RootVisitorType& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800453
Mathieu Chartier90443472015-07-16 20:32:27 -0700454 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700455
Mathieu Chartier90443472015-07-16 20:32:27 -0700456 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700457
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700459 uint32_t unused_length;
460 return GetShorty(&unused_length);
461 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700462
Mathieu Chartier90443472015-07-16 20:32:27 -0700463 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700464
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700466
Mathieu Chartier90443472015-07-16 20:32:27 -0700467 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700468
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700470
Mathieu Chartier90443472015-07-16 20:32:27 -0700471 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700472
Mathieu Chartier90443472015-07-16 20:32:27 -0700473 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700474
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700476
Mathieu Chartier90443472015-07-16 20:32:27 -0700477 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700478
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700480
Mathieu Chartier90443472015-07-16 20:32:27 -0700481 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700482
Mathieu Chartier90443472015-07-16 20:32:27 -0700483 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700484
Mathieu Chartier90443472015-07-16 20:32:27 -0700485 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700486
Mathieu Chartier90443472015-07-16 20:32:27 -0700487 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700488
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700489 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700491
Ian Rogersded66a02014-10-28 18:12:55 -0700492 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
493 // number of bugs at call sites.
Mathieu Chartier90443472015-07-16 20:32:27 -0700494 mirror::Class* GetReturnType(bool resolve = true) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700495
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Mathieu Chartiere401d142015-04-22 13:56:20 -0700500 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700501 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700502
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700503 // May cause thread suspension due to class resolution.
504 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700505 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700506
Mathieu Chartiere401d142015-04-22 13:56:20 -0700507 // Size of an instance of this object.
508 static size_t ObjectSize(size_t pointer_size) {
509 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800510 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800511 }
512
Mathieu Chartiere401d142015-04-22 13:56:20 -0700513 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700514 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700515
516 ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes()
Mathieu Chartier90443472015-07-16 20:32:27 -0700517 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700518
Mathieu Chartier2d721012014-11-10 11:08:06 -0800519 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800520 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800521 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800523
Ian Rogersef7d42f2014-01-06 12:55:46 -0800524 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525 GcRoot<mirror::PointerArray> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800526
Ian Rogersef7d42f2014-01-06 12:55:46 -0800527 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700528 GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529
Ian Rogersef7d42f2014-01-06 12:55:46 -0800530 // Access flags; low 16 bits are defined by spec.
531 uint32_t access_flags_;
532
533 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
534
535 // Offset to the CodeItem.
536 uint32_t dex_code_item_offset_;
537
538 // Index into method_ids of the dex file associated with this method.
539 uint32_t dex_method_index_;
540
541 /* End of dex file fields. */
542
543 // Entry within a dispatch table for this method. For static/direct methods the index is into
544 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
545 // ifTable.
546 uint32_t method_index_;
547
Mathieu Chartiereace4582014-11-24 18:29:54 -0800548 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800549
550 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700551 // PACKED(4) is necessary for the correctness of
552 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800553 struct PACKED(4) PtrSizedFields {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800554 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
555 void* entry_point_from_jni_;
556
557 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800558 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800559 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800560 } ptr_sized_fields_;
561
Mathieu Chartier02e25112013-08-14 16:14:24 -0700562 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800563 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700564 // Round up to pointer size for padding field.
565 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
566 }
567
568 template<typename T>
569 ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const {
570 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
571 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
572 if (pointer_size == sizeof(uint32_t)) {
573 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
574 } else {
575 auto v = *reinterpret_cast<const uint64_t*>(addr);
576 DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits";
577 return reinterpret_cast<T>(v);
578 }
579 }
580
581 template<typename T>
582 ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) {
583 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
584 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
585 if (pointer_size == sizeof(uint32_t)) {
586 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
587 DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits";
588 *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr);
589 } else {
590 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
591 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800592 }
593
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800594 // Code points to the start of the quick code.
595 static uint32_t GetCodeSize(const void* code);
596
597 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
598 if (code == 0) {
599 return pc == 0;
600 }
601 /*
602 * During a stack walk, a return PC may point past-the-end of the code
603 * in the case that the last instruction is a call that isn't expected to
604 * return. Thus, we check <= code + GetCodeSize().
605 *
606 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
607 */
608 return code <= pc && pc <= code + GetCodeSize(
609 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
610 }
611
Mathieu Chartiere401d142015-04-22 13:56:20 -0700612 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800613};
614
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800615} // namespace art
616
Mathieu Chartiere401d142015-04-22 13:56:20 -0700617#endif // ART_RUNTIME_ART_METHOD_H_