blob: 4a1e2c4532d894672487894189dda38301cef2bf [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
Ian Rogerse94652f2014-12-02 11:13:19 -080046typedef void (EntryPointFromInterpreter)(Thread* self, const DexFile::CodeItem* code_item,
47 ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070048
Mathieu Chartiere401d142015-04-22 13:56:20 -070049class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -070051 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
52 method_index_(0) { }
53
54 ArtMethod(const ArtMethod& src, size_t image_pointer_size) {
55 CopyFrom(&src, image_pointer_size);
56 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -070057
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070058 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
59 jobject jlr_method)
Ian Rogers62f05122014-03-21 11:21:29 -070060 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
61
Mathieu Chartiere401d142015-04-22 13:56:20 -070062 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063
Mathieu Chartiere401d142015-04-22 13:56:20 -070064 ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier()
65 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
66
67 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
68 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
69
70 void SetDeclaringClass(mirror::Class *new_declaring_class)
71 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072
73 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 Chartier2d2621a2014-10-23 16:48:06 -070077 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(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.
Ian Rogersef7d42f2014-01-06 12:55:46 -080085 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086
87 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080088 bool IsPublic() SHARED_LOCKS_REQUIRED(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.
Ian Rogersef7d42f2014-01-06 12:55:46 -080093 bool IsPrivate() SHARED_LOCKS_REQUIRED(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.
Ian Rogersef7d42f2014-01-06 12:55:46 -080098 bool IsStatic() SHARED_LOCKS_REQUIRED(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.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800103 bool IsConstructor() SHARED_LOCKS_REQUIRED(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.
108 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
109 return IsConstructor() && IsStatic();
110 }
111
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800113 bool IsDirect() SHARED_LOCKS_REQUIRED(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.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800122 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
124 return (GetAccessFlags() & synchonized) != 0;
125 }
126
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 return (GetAccessFlags() & kAccFinal) != 0;
129 }
130
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 return (GetAccessFlags() & kAccMiranda) != 0;
133 }
134
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 return (GetAccessFlags() & kAccNative) != 0;
137 }
138
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000139 bool ShouldNotInline() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
140 return (GetAccessFlags() & kAccDontInline) != 0;
141 }
142
143 void SetShouldNotInline() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
144 SetAccessFlags(GetAccessFlags() | kAccDontInline);
145 }
146
Ian Rogersef7d42f2014-01-06 12:55:46 -0800147 bool IsFastNative() SHARED_LOCKS_REQUIRED(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
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 return (GetAccessFlags() & kAccAbstract) != 0;
154 }
155
Ian Rogersef7d42f2014-01-06 12:55:46 -0800156 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157 return (GetAccessFlags() & kAccSynthetic) != 0;
158 }
159
Ian Rogersef7d42f2014-01-06 12:55:46 -0800160 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200163 return (GetAccessFlags() & kAccPreverified) != 0;
164 }
165
Ian Rogersef7d42f2014-01-06 12:55:46 -0800166 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
167 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200168 SetAccessFlags(GetAccessFlags() | kAccPreverified);
169 }
170
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800171 bool IsOptimized(size_t pointer_size) SHARED_LOCKS_REQUIRED(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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
182
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(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.
186 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
187
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 return GetMethodIndex();
190 }
191
Ian Rogersef7d42f2014-01-06 12:55:46 -0800192 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(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 Chartier2d2621a2014-10-23 16:48:06 -0700217 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(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()
Vladimir Markoc1363122015-04-09 14:13:13 +0100233 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700234 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, size_t ptr_size)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700235 SHARED_LOCKS_REQUIRED(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)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700238 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700239 ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700241 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700242 bool HasSameDexCacheResolvedMethods(ArtMethod* other)
243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
244 bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700245 SHARED_LOCKS_REQUIRED(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)
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
250 void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700252 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
253 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700254 bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700255 SHARED_LOCKS_REQUIRED(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)
259 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
260
Ian Rogerse0a02da2014-12-02 14:10:53 -0800261 // Find the method that this method overrides.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700262 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_LOCKS_REQUIRED(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)
270 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
271
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700272 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
273 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800274
Mathieu Chartiere401d142015-04-22 13:56:20 -0700275 EntryPointFromInterpreter* GetEntryPointFromInterpreter() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800276 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
277 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700278 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size) {
279 return GetEntryPoint<EntryPointFromInterpreter*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800280 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700281 }
282
Mathieu Chartiere401d142015-04-22 13:56:20 -0700283 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800284 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
285 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800286 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700287 size_t pointer_size) {
288 SetEntryPoint(EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter,
289 pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700290 }
291
Mathieu Chartiere401d142015-04-22 13:56:20 -0700292 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800293 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
294 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700295 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
296 return GetEntryPoint<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800297 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800298 }
299
Mathieu Chartiere401d142015-04-22 13:56:20 -0700300 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800301 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
302 sizeof(void*));
303 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800304 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700305 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
306 SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size),
307 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800308 }
309
Ian Rogersef7d42f2014-01-06 12:55:46 -0800310 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
311
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700312 // Check whether the given PC is within the quick compiled code associated with this method's
313 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
314 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700315 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800316 return PcIsWithinQuickCode(
317 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318 }
319
Ian Rogersef7d42f2014-01-06 12:55:46 -0800320 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700322 // Returns true if the entrypoint points to the interpreter, as
323 // opposed to the compiled code, that is, this method will be
324 // interpretered on invocation.
325 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
326
Mathieu Chartiere401d142015-04-22 13:56:20 -0700327 uint32_t GetQuickOatCodeOffset();
328 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700330 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100331 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700332 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
333 // least 2 byte aligned.
334 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100335 return reinterpret_cast<const void*>(code);
336 }
337
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700338 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800339 const void* GetQuickOatEntryPoint(size_t pointer_size)
340 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700341 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800342 const void* GetQuickOatCodePointer(size_t pointer_size)
343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
344 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700345 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100346
Ian Rogers1809a722013-08-09 22:05:32 -0700347 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800348 const uint8_t* GetMappingTable(size_t pointer_size)
349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
350 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352
Ian Rogers1809a722013-08-09 22:05:32 -0700353 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800354 const uint8_t* GetVmapTable(size_t pointer_size)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
356 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100357 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100359 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100360
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800361 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
362 const uint8_t* GetNativeGcMap(size_t pointer_size)
363 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
364 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366
Andreas Gampe90546832014-03-12 18:07:19 -0700367 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700368 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100369 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700370 if (kCheckFrameSize) {
371 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
372 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 return result;
374 }
375
Vladimir Marko7624d252014-05-02 14:40:15 +0100376 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100377 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700380 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
381 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100382 }
383
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700384 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
386 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700387 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 }
389
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700390 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700391 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100392 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
393 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800394 }
395
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700396 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
398
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700399 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800400
Mathieu Chartier2d721012014-11-10 11:08:06 -0800401 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800402 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800403 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404 }
405
Mathieu Chartier2d721012014-11-10 11:08:06 -0800406 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800407 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800408 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409 }
410
Mathieu Chartier2d721012014-11-10 11:08:06 -0800411 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800412 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800413 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
414 }
415
Mathieu Chartiere401d142015-04-22 13:56:20 -0700416 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800417 return GetEntryPointFromJniPtrSize(sizeof(void*));
418 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700419 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
420 return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800421 }
422
Mathieu Chartier2d721012014-11-10 11:08:06 -0800423 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700424 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800425 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700426 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
427 SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800428 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800429
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
431 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700432 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433
434 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800435 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436
Ian Rogersef7d42f2014-01-06 12:55:46 -0800437 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438
Ian Rogersef7d42f2014-01-06 12:55:46 -0800439 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700440
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700441 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
442
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700443 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
444#ifdef NDEBUG
445 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
446 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
447 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
448 }
449#else
450 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100451 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700452#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453
454 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800455 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
456 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457
458 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000459 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
460 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800462 MethodReference ToMethodReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
463 return MethodReference(GetDexFile(), GetDexMethodIndex());
464 }
465
Ian Rogersc449aa82013-07-29 14:35:46 -0700466 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
467 // indicates whether the found catch block is responsible for clearing the exception or whether
468 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700469 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
470 bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800471 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
472
Mathieu Chartiere401d142015-04-22 13:56:20 -0700473 template<typename RootVisitorType>
474 void VisitRoots(RootVisitorType& visitor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800475
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700476 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700477
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700478 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700479
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700480 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
481 uint32_t unused_length;
482 return GetShorty(&unused_length);
483 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700484
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700485 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700486
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700487 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700488
Ian Rogers1ff3c982014-08-12 02:30:58 -0700489 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700490
Ian Rogers6b14d552014-10-28 21:50:58 -0700491 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
492
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700493 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700494
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700495 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700496
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700497 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700498
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700499 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700500
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700501 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700502
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700503 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700504
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700505 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700506
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700507 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700508
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700509 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700510
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700511 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
512 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700513
Ian Rogersded66a02014-10-28 18:12:55 -0700514 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
515 // number of bugs at call sites.
516 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
517
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700518 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700519
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700520 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700521
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700524
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700525 // May cause thread suspension due to class resolution.
526 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528
Mathieu Chartiere401d142015-04-22 13:56:20 -0700529 // Size of an instance of this object.
530 static size_t ObjectSize(size_t pointer_size) {
531 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800532 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800533 }
534
Mathieu Chartiere401d142015-04-22 13:56:20 -0700535 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
536 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
537
538 ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes()
539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
540
Mathieu Chartier2d721012014-11-10 11:08:06 -0800541 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800542 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800543 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700544 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545
Ian Rogersef7d42f2014-01-06 12:55:46 -0800546 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700547 GcRoot<mirror::PointerArray> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800548
Ian Rogersef7d42f2014-01-06 12:55:46 -0800549 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700550 GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800551
Ian Rogersef7d42f2014-01-06 12:55:46 -0800552 // Access flags; low 16 bits are defined by spec.
553 uint32_t access_flags_;
554
555 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
556
557 // Offset to the CodeItem.
558 uint32_t dex_code_item_offset_;
559
560 // Index into method_ids of the dex file associated with this method.
561 uint32_t dex_method_index_;
562
563 /* End of dex file fields. */
564
565 // Entry within a dispatch table for this method. For static/direct methods the index is into
566 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
567 // ifTable.
568 uint32_t method_index_;
569
Mathieu Chartiereace4582014-11-24 18:29:54 -0800570 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800571
572 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700573 // PACKED(4) is necessary for the correctness of
574 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800575 struct PACKED(4) PtrSizedFields {
576 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
577 // compiled code.
578 void* entry_point_from_interpreter_;
579
580 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
581 void* entry_point_from_jni_;
582
583 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800584 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800585 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800586 } ptr_sized_fields_;
587
Mathieu Chartier02e25112013-08-14 16:14:24 -0700588 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800589 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700590 // Round up to pointer size for padding field.
591 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
592 }
593
594 template<typename T>
595 ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const {
596 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
597 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
598 if (pointer_size == sizeof(uint32_t)) {
599 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
600 } else {
601 auto v = *reinterpret_cast<const uint64_t*>(addr);
602 DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits";
603 return reinterpret_cast<T>(v);
604 }
605 }
606
607 template<typename T>
608 ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) {
609 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
610 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
611 if (pointer_size == sizeof(uint32_t)) {
612 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
613 DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits";
614 *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr);
615 } else {
616 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
617 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800618 }
619
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800620 // Code points to the start of the quick code.
621 static uint32_t GetCodeSize(const void* code);
622
623 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
624 if (code == 0) {
625 return pc == 0;
626 }
627 /*
628 * During a stack walk, a return PC may point past-the-end of the code
629 * in the case that the last instruction is a call that isn't expected to
630 * return. Thus, we check <= code + GetCodeSize().
631 *
632 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
633 */
634 return code <= pc && pc <= code + GetCodeSize(
635 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
636 }
637
Mathieu Chartiere401d142015-04-22 13:56:20 -0700638 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800639};
640
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800641} // namespace art
642
Mathieu Chartiere401d142015-04-22 13:56:20 -0700643#endif // ART_RUNTIME_ART_METHOD_H_