blob: 1afd0566558a3775906d8781bf9bc1c1d7d1fd21 [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
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070070 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
71 SHARED_REQUIRES(Locks::mutator_lock_);
72
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070074 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075 }
76
Mathieu Chartier90443472015-07-16 20:32:27 -070077 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080078
Mathieu Chartiere401d142015-04-22 13:56:20 -070079 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010080 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -070081 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 }
83
84 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -070085 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086
87 // Returns true if the method is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -070088 bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 return (GetAccessFlags() & kAccPublic) != 0;
90 }
91
92 // Returns true if the method is declared private.
Mathieu Chartier90443472015-07-16 20:32:27 -070093 bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080094 return (GetAccessFlags() & kAccPrivate) != 0;
95 }
96
97 // Returns true if the method is declared static.
Mathieu Chartier90443472015-07-16 20:32:27 -070098 bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 return (GetAccessFlags() & kAccStatic) != 0;
100 }
101
102 // Returns true if the method is a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700103 bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800104 return (GetAccessFlags() & kAccConstructor) != 0;
105 }
106
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700107 // Returns true if the method is a class initializer.
Mathieu Chartier90443472015-07-16 20:32:27 -0700108 bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700109 return IsConstructor() && IsStatic();
110 }
111
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 // Returns true if the method is static, private, or a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700113 bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 return IsDirect(GetAccessFlags());
115 }
116
117 static bool IsDirect(uint32_t access_flags) {
118 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
119 }
120
121 // Returns true if the method is declared synchronized.
Mathieu Chartier90443472015-07-16 20:32:27 -0700122 bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
124 return (GetAccessFlags() & synchonized) != 0;
125 }
126
Mathieu Chartier90443472015-07-16 20:32:27 -0700127 bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 return (GetAccessFlags() & kAccFinal) != 0;
129 }
130
Mathieu Chartier90443472015-07-16 20:32:27 -0700131 bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 return (GetAccessFlags() & kAccMiranda) != 0;
133 }
134
Mathieu Chartier90443472015-07-16 20:32:27 -0700135 bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 return (GetAccessFlags() & kAccNative) != 0;
137 }
138
Mathieu Chartier90443472015-07-16 20:32:27 -0700139 bool ShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000140 return (GetAccessFlags() & kAccDontInline) != 0;
141 }
142
Mathieu Chartier90443472015-07-16 20:32:27 -0700143 void SetShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000144 SetAccessFlags(GetAccessFlags() | kAccDontInline);
145 }
146
Mathieu Chartier90443472015-07-16 20:32:27 -0700147 bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800148 uint32_t mask = kAccFastNative | kAccNative;
149 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700150 }
151
Mathieu Chartier90443472015-07-16 20:32:27 -0700152 bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 return (GetAccessFlags() & kAccAbstract) != 0;
154 }
155
Mathieu Chartier90443472015-07-16 20:32:27 -0700156 bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157 return (GetAccessFlags() & kAccSynthetic) != 0;
158 }
159
Mathieu Chartier90443472015-07-16 20:32:27 -0700160 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161
Mathieu Chartier90443472015-07-16 20:32:27 -0700162 bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200163 return (GetAccessFlags() & kAccPreverified) != 0;
164 }
165
Mathieu Chartier90443472015-07-16 20:32:27 -0700166 void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800167 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200168 SetAccessFlags(GetAccessFlags() | kAccPreverified);
169 }
170
Mathieu Chartier90443472015-07-16 20:32:27 -0700171 bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100172 // Temporary solution for detecting if a method has been optimized: the compiler
173 // does not create a GC map. Instead, the vmap table contains the stack map
174 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000175 return !IsNative()
176 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800177 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800178 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100179 }
180
Mathieu Chartier90443472015-07-16 20:32:27 -0700181 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800182
Mathieu Chartier90443472015-07-16 20:32:27 -0700183 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700185 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700186 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700187
Mathieu Chartier90443472015-07-16 20:32:27 -0700188 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 return GetMethodIndex();
190 }
191
Mathieu Chartier90443472015-07-16 20:32:27 -0700192 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100193 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700194 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 }
196
Vladimir Markoc1363122015-04-09 14:13:13 +0100197 static MemberOffset DexMethodIndexOffset() {
198 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
199 }
200
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700202 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203 }
204
Mathieu Chartiere401d142015-04-22 13:56:20 -0700205 uint32_t GetCodeItemOffset() {
206 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 }
208
Mathieu Chartiere401d142015-04-22 13:56:20 -0700209 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100210 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700211 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212 }
213
214 // Number of 32bit registers that would be required to hold all the arguments
215 static size_t NumArgRegisters(const StringPiece& shorty);
216
Mathieu Chartier90443472015-07-16 20:32:27 -0700217 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800218
Mathieu Chartiere401d142015-04-22 13:56:20 -0700219 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100220 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700221 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 }
223
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700225 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800226 }
227
228 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700229 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 }
231
Mathieu Chartiere401d142015-04-22 13:56:20 -0700232 ALWAYS_INLINE mirror::PointerArray* GetDexCacheResolvedMethods()
Mathieu Chartier90443472015-07-16 20:32:27 -0700233 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700234 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, 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 SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
237 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700238 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700239 ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods)
Mathieu Chartier90443472015-07-16 20:32:27 -0700240 SHARED_REQUIRES(Locks::mutator_lock_);
241 bool HasDexCacheResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700242 bool HasSameDexCacheResolvedMethods(ArtMethod* other)
Mathieu Chartier90443472015-07-16 20:32:27 -0700243 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700244 bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700245 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246
Andreas Gampe58a5af82014-07-31 16:23:49 -0700247 template <bool kWithCheck = true>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700248 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700249 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700250 void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types)
Mathieu Chartier90443472015-07-16 20:32:27 -0700251 SHARED_REQUIRES(Locks::mutator_lock_);
252 bool HasDexCacheResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_);
253 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700254 bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700255 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800256
Ian Rogersa0485602014-12-02 15:48:04 -0800257 // Get the Class* from the type index into this method's dex cache.
258 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
Mathieu Chartier90443472015-07-16 20:32:27 -0700259 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800260
Ian Rogerse0a02da2014-12-02 14:10:53 -0800261 // Find the method that this method overrides.
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800263
Ian Rogerse0a02da2014-12-02 14:10:53 -0800264 // Find the method index for this method within other_dexfile. If this method isn't present then
265 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
266 // name and signature in the other_dexfile, such as the method index used to resolve this method
267 // in the other_dexfile.
268 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
269 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700270 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800271
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700272 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700273 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800274
Mathieu Chartiere401d142015-04-22 13:56:20 -0700275 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800276 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
277 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700278 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
279 return GetEntryPoint<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800280 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800281 }
282
Mathieu Chartiere401d142015-04-22 13:56:20 -0700283 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800284 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
285 sizeof(void*));
286 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800287 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700288 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
289 SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size),
290 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800291 }
292
Mathieu Chartier90443472015-07-16 20:32:27 -0700293 uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800294
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700295 // Check whether the given PC is within the quick compiled code associated with this method's
296 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
297 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700298 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800299 return PcIsWithinQuickCode(
300 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800301 }
302
Mathieu Chartier90443472015-07-16 20:32:27 -0700303 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800304
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700305 // Returns true if the entrypoint points to the interpreter, as
306 // opposed to the compiled code, that is, this method will be
307 // interpretered on invocation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700308 bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700309
Mathieu Chartiere401d142015-04-22 13:56:20 -0700310 uint32_t GetQuickOatCodeOffset();
311 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700313 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100314 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700315 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
316 // least 2 byte aligned.
317 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100318 return reinterpret_cast<const void*>(code);
319 }
320
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700321 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800322 const void* GetQuickOatEntryPoint(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700323 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700324 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800325 const void* GetQuickOatCodePointer(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700326 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800327 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700328 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100329
Ian Rogers1809a722013-08-09 22:05:32 -0700330 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800331 const uint8_t* GetMappingTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700332 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800333 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700334 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800335
Ian Rogers1809a722013-08-09 22:05:32 -0700336 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800337 const uint8_t* GetVmapTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700338 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800339 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700340 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800341
Mathieu Chartier90443472015-07-16 20:32:27 -0700342 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000343
Mathieu Chartier90443472015-07-16 20:32:27 -0700344 CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100345
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800346 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
347 const uint8_t* GetNativeGcMap(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700348 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800349 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351
Andreas Gampe90546832014-03-12 18:07:19 -0700352 template <bool kCheckFrameSize = true>
Mathieu Chartier90443472015-07-16 20:32:27 -0700353 uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100354 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700355 if (kCheckFrameSize) {
356 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
357 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 return result;
359 }
360
Mathieu Chartier90443472015-07-16 20:32:27 -0700361 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100362 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700363 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364
Mathieu Chartier90443472015-07-16 20:32:27 -0700365 FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700366 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100367 }
368
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700369 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700370 SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100371 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700372 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 }
374
Mathieu Chartier90443472015-07-16 20:32:27 -0700375 FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700376 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100377 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
378 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800379 }
380
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700381 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700382 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800383
Mathieu Chartier90443472015-07-16 20:32:27 -0700384 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800385
Mathieu Chartier2d721012014-11-10 11:08:06 -0800386 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800387 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800388 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389 }
390
Mathieu Chartier2d721012014-11-10 11:08:06 -0800391 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800392 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800393 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
394 }
395
Mathieu Chartiere401d142015-04-22 13:56:20 -0700396 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800397 return GetEntryPointFromJniPtrSize(sizeof(void*));
398 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700399 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
400 return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800401 }
402
Mathieu Chartier90443472015-07-16 20:32:27 -0700403 void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700404 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800405 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700406 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
407 SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800408 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
411 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700412 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413
414 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700415 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800416
Mathieu Chartier90443472015-07-16 20:32:27 -0700417 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418
Mathieu Chartier90443472015-07-16 20:32:27 -0700419 bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700420
Mathieu Chartier90443472015-07-16 20:32:27 -0700421 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700422
Mathieu Chartier90443472015-07-16 20:32:27 -0700423 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700424#ifdef NDEBUG
425 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700426 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700427 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
428 }
429#else
430 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700431 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700432#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433
434 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800435 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700436 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437
438 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000439 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700440 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800441
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800443 return MethodReference(GetDexFile(), GetDexMethodIndex());
444 }
445
Ian Rogersc449aa82013-07-29 14:35:46 -0700446 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
447 // indicates whether the found catch block is responsible for clearing the exception or whether
448 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700449 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
450 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700451 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800452
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700453 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700454 template<typename RootVisitorType>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700455 void VisitRoots(RootVisitorType& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800456
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700458
Mathieu Chartier90443472015-07-16 20:32:27 -0700459 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700460
Mathieu Chartier90443472015-07-16 20:32:27 -0700461 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700462 uint32_t unused_length;
463 return GetShorty(&unused_length);
464 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700465
Mathieu Chartier90443472015-07-16 20:32:27 -0700466 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700467
Mathieu Chartier90443472015-07-16 20:32:27 -0700468 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700469
Mathieu Chartier90443472015-07-16 20:32:27 -0700470 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700471
Mathieu Chartier90443472015-07-16 20:32:27 -0700472 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700473
Mathieu Chartier90443472015-07-16 20:32:27 -0700474 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700475
Mathieu Chartier90443472015-07-16 20:32:27 -0700476 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700477
Mathieu Chartier90443472015-07-16 20:32:27 -0700478 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700479
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700481
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700483
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700485
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700487
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700489
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700491
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700492 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700493 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700494
Ian Rogersded66a02014-10-28 18:12:55 -0700495 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
496 // number of bugs at call sites.
Mathieu Chartier90443472015-07-16 20:32:27 -0700497 mirror::Class* GetReturnType(bool resolve = true) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700498
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700500
Mathieu Chartier90443472015-07-16 20:32:27 -0700501 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700502
Mathieu Chartiere401d142015-04-22 13:56:20 -0700503 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700504 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700505
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700506 // May cause thread suspension due to class resolution.
507 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700509
Vladimir Marko14632852015-08-17 12:07:23 +0100510 // Size of an instance of this native class.
511 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700512 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800513 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800514 }
515
Vladimir Marko14632852015-08-17 12:07:23 +0100516 // Alignment of an instance of this native class.
517 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100518 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100519 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100520 return pointer_size;
521 }
522
Mathieu Chartiere401d142015-04-22 13:56:20 -0700523 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700524 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525
526 ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes()
Mathieu Chartier90443472015-07-16 20:32:27 -0700527 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700528
Mathieu Chartier2d721012014-11-10 11:08:06 -0800529 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800531 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700532 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533
Ian Rogersef7d42f2014-01-06 12:55:46 -0800534 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700535 GcRoot<mirror::PointerArray> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800536
Ian Rogersef7d42f2014-01-06 12:55:46 -0800537 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700538 GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539
Ian Rogersef7d42f2014-01-06 12:55:46 -0800540 // Access flags; low 16 bits are defined by spec.
541 uint32_t access_flags_;
542
543 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
544
545 // Offset to the CodeItem.
546 uint32_t dex_code_item_offset_;
547
548 // Index into method_ids of the dex file associated with this method.
549 uint32_t dex_method_index_;
550
551 /* End of dex file fields. */
552
553 // Entry within a dispatch table for this method. For static/direct methods the index is into
554 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
555 // ifTable.
556 uint32_t method_index_;
557
Mathieu Chartiereace4582014-11-24 18:29:54 -0800558 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800559
560 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700561 // PACKED(4) is necessary for the correctness of
562 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800563 struct PACKED(4) PtrSizedFields {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800564 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
565 void* entry_point_from_jni_;
566
567 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800568 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800569 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800570 } ptr_sized_fields_;
571
Mathieu Chartier02e25112013-08-14 16:14:24 -0700572 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800573 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700574 // Round up to pointer size for padding field.
575 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
576 }
577
578 template<typename T>
579 ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const {
580 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
581 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
582 if (pointer_size == sizeof(uint32_t)) {
583 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
584 } else {
585 auto v = *reinterpret_cast<const uint64_t*>(addr);
586 DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits";
587 return reinterpret_cast<T>(v);
588 }
589 }
590
591 template<typename T>
592 ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) {
593 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
594 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
595 if (pointer_size == sizeof(uint32_t)) {
596 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
597 DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits";
598 *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr);
599 } else {
600 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
601 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800602 }
603
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800604 // Code points to the start of the quick code.
605 static uint32_t GetCodeSize(const void* code);
606
607 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
608 if (code == 0) {
609 return pc == 0;
610 }
611 /*
612 * During a stack walk, a return PC may point past-the-end of the code
613 * in the case that the last instruction is a call that isn't expected to
614 * return. Thus, we check <= code + GetCodeSize().
615 *
616 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
617 */
618 return code <= pc && pc <= code + GetCodeSize(
619 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
620 }
621
Mathieu Chartiere401d142015-04-22 13:56:20 -0700622 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800623};
624
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800625} // namespace art
626
Mathieu Chartiere401d142015-04-22 13:56:20 -0700627#endif // ART_RUNTIME_ART_METHOD_H_