blob: 6cdc4a6bb03234f48eabf9aa834b31e4b1241356 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#ifndef ART_RUNTIME_ART_METHOD_H_
18#define ART_RUNTIME_ART_METHOD_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Jeff Hao790ad902013-05-22 15:02:08 -070020#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070021#include "gc_root.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "invoke_type.h"
Mathieu Chartier36b58f52014-12-10 12:06:45 -080023#include "method_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "modifiers.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070025#include "mirror/object.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010026#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "read_barrier_option.h"
Sebastien Hertze4b7c892014-12-17 20:02:50 +010028#include "stack.h"
Nicolas Geoffray39468442014-09-02 15:17:15 +010029#include "stack_map.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070030#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
32namespace art {
33
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070035class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070037class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
39namespace mirror {
Mathieu Chartiere401d142015-04-22 13:56:20 -070040class Array;
41class Class;
42class PointerArray;
43} // namespace mirror
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044
Mathieu Chartiere401d142015-04-22 13:56:20 -070045class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -070047 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
48 method_index_(0) { }
49
50 ArtMethod(const ArtMethod& src, size_t image_pointer_size) {
51 CopyFrom(&src, image_pointer_size);
52 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -070053
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070054 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
55 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -070056 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -070057
Mathieu Chartier90443472015-07-16 20:32:27 -070058 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059
Mathieu Chartiere401d142015-04-22 13:56:20 -070060 ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier()
Mathieu Chartier90443472015-07-16 20:32:27 -070061 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070062
63 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -070064 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070065
66 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -070067 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070069 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
70 SHARED_REQUIRES(Locks::mutator_lock_);
71
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070073 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 }
75
Mathieu Chartier90443472015-07-16 20:32:27 -070076 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080077
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010079 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -070080 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081 }
82
83 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -070084 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085
86 // Returns true if the method is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -070087 bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088 return (GetAccessFlags() & kAccPublic) != 0;
89 }
90
91 // Returns true if the method is declared private.
Mathieu Chartier90443472015-07-16 20:32:27 -070092 bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 return (GetAccessFlags() & kAccPrivate) != 0;
94 }
95
96 // Returns true if the method is declared static.
Mathieu Chartier90443472015-07-16 20:32:27 -070097 bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 return (GetAccessFlags() & kAccStatic) != 0;
99 }
100
101 // Returns true if the method is a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700102 bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103 return (GetAccessFlags() & kAccConstructor) != 0;
104 }
105
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700106 // Returns true if the method is a class initializer.
Mathieu Chartier90443472015-07-16 20:32:27 -0700107 bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700108 return IsConstructor() && IsStatic();
109 }
110
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 // Returns true if the method is static, private, or a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700112 bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800113 return IsDirect(GetAccessFlags());
114 }
115
116 static bool IsDirect(uint32_t access_flags) {
117 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
118 }
119
120 // Returns true if the method is declared synchronized.
Mathieu Chartier90443472015-07-16 20:32:27 -0700121 bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
123 return (GetAccessFlags() & synchonized) != 0;
124 }
125
Mathieu Chartier90443472015-07-16 20:32:27 -0700126 bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 return (GetAccessFlags() & kAccFinal) != 0;
128 }
129
Mathieu Chartier90443472015-07-16 20:32:27 -0700130 bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131 return (GetAccessFlags() & kAccMiranda) != 0;
132 }
133
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135 return (GetAccessFlags() & kAccNative) != 0;
136 }
137
Mathieu Chartier90443472015-07-16 20:32:27 -0700138 bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800139 uint32_t mask = kAccFastNative | kAccNative;
140 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700141 }
142
Mathieu Chartier90443472015-07-16 20:32:27 -0700143 bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144 return (GetAccessFlags() & kAccAbstract) != 0;
145 }
146
Mathieu Chartier90443472015-07-16 20:32:27 -0700147 bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800148 return (GetAccessFlags() & kAccSynthetic) != 0;
149 }
150
Mathieu Chartier90443472015-07-16 20:32:27 -0700151 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152
Mathieu Chartier90443472015-07-16 20:32:27 -0700153 bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200154 return (GetAccessFlags() & kAccPreverified) != 0;
155 }
156
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200159 SetAccessFlags(GetAccessFlags() | kAccPreverified);
160 }
161
Mathieu Chartier90443472015-07-16 20:32:27 -0700162 bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100163 // Temporary solution for detecting if a method has been optimized: the compiler
164 // does not create a GC map. Instead, the vmap table contains the stack map
165 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000166 return !IsNative()
167 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800168 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800169 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100170 }
171
Mathieu Chartier90443472015-07-16 20:32:27 -0700172 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173
Mathieu Chartier90443472015-07-16 20:32:27 -0700174 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700176 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700177 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700178
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180 return GetMethodIndex();
181 }
182
Mathieu Chartier90443472015-07-16 20:32:27 -0700183 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100184 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700185 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 }
187
Vladimir Markoc1363122015-04-09 14:13:13 +0100188 static MemberOffset DexMethodIndexOffset() {
189 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
190 }
191
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700193 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 }
195
Mathieu Chartiere401d142015-04-22 13:56:20 -0700196 uint32_t GetCodeItemOffset() {
197 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198 }
199
Mathieu Chartiere401d142015-04-22 13:56:20 -0700200 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100201 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700202 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203 }
204
205 // Number of 32bit registers that would be required to hold all the arguments
206 static size_t NumArgRegisters(const StringPiece& shorty);
207
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209
Mathieu Chartiere401d142015-04-22 13:56:20 -0700210 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100211 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700212 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800213 }
214
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700216 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217 }
218
219 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700220 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221 }
222
Mathieu Chartiere401d142015-04-22 13:56:20 -0700223 ALWAYS_INLINE mirror::PointerArray* GetDexCacheResolvedMethods()
Mathieu Chartier90443472015-07-16 20:32:27 -0700224 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700225 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700226 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700227 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method,
228 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700229 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700230 ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods)
Mathieu Chartier90443472015-07-16 20:32:27 -0700231 SHARED_REQUIRES(Locks::mutator_lock_);
232 bool HasDexCacheResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700233 bool HasSameDexCacheResolvedMethods(ArtMethod* other)
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700235 bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700236 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237
Andreas Gampe58a5af82014-07-31 16:23:49 -0700238 template <bool kWithCheck = true>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700239 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700240 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700241 void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types)
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 SHARED_REQUIRES(Locks::mutator_lock_);
243 bool HasDexCacheResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_);
244 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700245 bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800247
Ian Rogersa0485602014-12-02 15:48:04 -0800248 // Get the Class* from the type index into this method's dex cache.
249 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
Mathieu Chartier90443472015-07-16 20:32:27 -0700250 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800251
Ian Rogerse0a02da2014-12-02 14:10:53 -0800252 // Find the method that this method overrides.
Mathieu Chartier90443472015-07-16 20:32:27 -0700253 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800254
Ian Rogerse0a02da2014-12-02 14:10:53 -0800255 // Find the method index for this method within other_dexfile. If this method isn't present then
256 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
257 // name and signature in the other_dexfile, such as the method index used to resolve this method
258 // in the other_dexfile.
259 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
260 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700261 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800262
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700263 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700264 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265
Mathieu Chartiere401d142015-04-22 13:56:20 -0700266 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800267 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
268 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700269 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
270 return GetEntryPoint<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800271 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800272 }
273
Mathieu Chartiere401d142015-04-22 13:56:20 -0700274 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800275 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
276 sizeof(void*));
277 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800278 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700279 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
280 SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size),
281 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800282 }
283
Mathieu Chartier90443472015-07-16 20:32:27 -0700284 uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800285
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700286 // Check whether the given PC is within the quick compiled code associated with this method's
287 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
288 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700289 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800290 return PcIsWithinQuickCode(
291 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800292 }
293
Mathieu Chartier90443472015-07-16 20:32:27 -0700294 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800295
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700296 // Returns true if the entrypoint points to the interpreter, as
297 // opposed to the compiled code, that is, this method will be
298 // interpretered on invocation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700299 bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700300
Mathieu Chartiere401d142015-04-22 13:56:20 -0700301 uint32_t GetQuickOatCodeOffset();
302 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700304 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100305 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700306 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
307 // least 2 byte aligned.
308 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100309 return reinterpret_cast<const void*>(code);
310 }
311
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700312 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800313 const void* GetQuickOatEntryPoint(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700314 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700315 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800316 const void* GetQuickOatCodePointer(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700317 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800318 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700319 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100320
Ian Rogers1809a722013-08-09 22:05:32 -0700321 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800322 const uint8_t* GetMappingTable(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 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700325 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800326
Ian Rogers1809a722013-08-09 22:05:32 -0700327 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800328 const uint8_t* GetVmapTable(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* GetVmapTable(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
Mathieu Chartier90443472015-07-16 20:32:27 -0700333 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000334
Mathieu Chartier90443472015-07-16 20:32:27 -0700335 CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100336
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800337 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
338 const uint8_t* GetNativeGcMap(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700339 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800340 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700341 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800342
Andreas Gampe90546832014-03-12 18:07:19 -0700343 template <bool kCheckFrameSize = true>
Mathieu Chartier90443472015-07-16 20:32:27 -0700344 uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100345 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700346 if (kCheckFrameSize) {
347 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
348 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800349 return result;
350 }
351
Mathieu Chartier90443472015-07-16 20:32:27 -0700352 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100353 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700354 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800355
Mathieu Chartier90443472015-07-16 20:32:27 -0700356 FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700357 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100358 }
359
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700360 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700361 SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100362 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700363 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364 }
365
Mathieu Chartier90443472015-07-16 20:32:27 -0700366 FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700367 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100368 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
369 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800370 }
371
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700372 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700373 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800374
Mathieu Chartier90443472015-07-16 20:32:27 -0700375 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800376
Mathieu Chartier2d721012014-11-10 11:08:06 -0800377 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800378 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800379 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380 }
381
Mathieu Chartier2d721012014-11-10 11:08:06 -0800382 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800383 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800384 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
385 }
386
Mathieu Chartiere401d142015-04-22 13:56:20 -0700387 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800388 return GetEntryPointFromJniPtrSize(sizeof(void*));
389 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700390 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
391 return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800392 }
393
Mathieu Chartier90443472015-07-16 20:32:27 -0700394 void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800396 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700397 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
398 SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800399 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800400
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800401 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
402 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700403 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404
405 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700406 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407
Mathieu Chartier90443472015-07-16 20:32:27 -0700408 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409
Mathieu Chartier90443472015-07-16 20:32:27 -0700410 bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700411
Mathieu Chartier90443472015-07-16 20:32:27 -0700412 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700413
Mathieu Chartier90443472015-07-16 20:32:27 -0700414 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700415#ifdef NDEBUG
416 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700417 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700418 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
419 }
420#else
421 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700422 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700423#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424
425 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800426 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700427 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800428
429 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000430 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700431 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432
Mathieu Chartier90443472015-07-16 20:32:27 -0700433 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800434 return MethodReference(GetDexFile(), GetDexMethodIndex());
435 }
436
Ian Rogersc449aa82013-07-29 14:35:46 -0700437 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
438 // indicates whether the found catch block is responsible for clearing the exception or whether
439 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700440 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
441 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800443
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700444 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700445 template<typename RootVisitorType>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700446 void VisitRoots(RootVisitorType& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800447
Mathieu Chartier90443472015-07-16 20:32:27 -0700448 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700449
Mathieu Chartier90443472015-07-16 20:32:27 -0700450 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700451
Mathieu Chartier90443472015-07-16 20:32:27 -0700452 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700453 uint32_t unused_length;
454 return GetShorty(&unused_length);
455 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700456
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700458
Mathieu Chartier90443472015-07-16 20:32:27 -0700459 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700460
Mathieu Chartier90443472015-07-16 20:32:27 -0700461 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700462
Mathieu Chartier90443472015-07-16 20:32:27 -0700463 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700464
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700466
Mathieu Chartier90443472015-07-16 20:32:27 -0700467 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700468
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700470
Mathieu Chartier90443472015-07-16 20:32:27 -0700471 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700472
Mathieu Chartier90443472015-07-16 20:32:27 -0700473 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700474
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700476
Mathieu Chartier90443472015-07-16 20:32:27 -0700477 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700478
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700480
Mathieu Chartier90443472015-07-16 20:32:27 -0700481 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700482
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700483 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700485
Ian Rogersded66a02014-10-28 18:12:55 -0700486 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
487 // number of bugs at call sites.
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 mirror::Class* GetReturnType(bool resolve = true) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700489
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700491
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700493
Mathieu Chartiere401d142015-04-22 13:56:20 -0700494 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700495 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700496
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700497 // May cause thread suspension due to class resolution.
498 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700500
Vladimir Marko14632852015-08-17 12:07:23 +0100501 // Size of an instance of this native class.
502 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700503 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800504 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800505 }
506
Vladimir Marko14632852015-08-17 12:07:23 +0100507 // Alignment of an instance of this native class.
508 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100509 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100510 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100511 return pointer_size;
512 }
513
Mathieu Chartiere401d142015-04-22 13:56:20 -0700514 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700515 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700516
517 ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes()
Mathieu Chartier90443472015-07-16 20:32:27 -0700518 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700519
Mathieu Chartier2d721012014-11-10 11:08:06 -0800520 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800521 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800522 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700523 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524
Ian Rogersef7d42f2014-01-06 12:55:46 -0800525 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700526 GcRoot<mirror::PointerArray> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800527
Ian Rogersef7d42f2014-01-06 12:55:46 -0800528 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700529 GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530
Ian Rogersef7d42f2014-01-06 12:55:46 -0800531 // Access flags; low 16 bits are defined by spec.
532 uint32_t access_flags_;
533
534 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
535
536 // Offset to the CodeItem.
537 uint32_t dex_code_item_offset_;
538
539 // Index into method_ids of the dex file associated with this method.
540 uint32_t dex_method_index_;
541
542 /* End of dex file fields. */
543
544 // Entry within a dispatch table for this method. For static/direct methods the index is into
545 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
546 // ifTable.
547 uint32_t method_index_;
548
Mathieu Chartiereace4582014-11-24 18:29:54 -0800549 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800550
551 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700552 // PACKED(4) is necessary for the correctness of
553 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800554 struct PACKED(4) PtrSizedFields {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800555 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
556 void* entry_point_from_jni_;
557
558 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800559 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800560 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800561 } ptr_sized_fields_;
562
Mathieu Chartier02e25112013-08-14 16:14:24 -0700563 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800564 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700565 // Round up to pointer size for padding field.
566 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
567 }
568
569 template<typename T>
570 ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const {
571 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
572 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
573 if (pointer_size == sizeof(uint32_t)) {
574 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
575 } else {
576 auto v = *reinterpret_cast<const uint64_t*>(addr);
577 DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits";
578 return reinterpret_cast<T>(v);
579 }
580 }
581
582 template<typename T>
583 ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) {
584 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
585 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
586 if (pointer_size == sizeof(uint32_t)) {
587 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
588 DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits";
589 *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr);
590 } else {
591 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
592 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800593 }
594
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800595 // Code points to the start of the quick code.
596 static uint32_t GetCodeSize(const void* code);
597
598 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
599 if (code == 0) {
600 return pc == 0;
601 }
602 /*
603 * During a stack walk, a return PC may point past-the-end of the code
604 * in the case that the last instruction is a call that isn't expected to
605 * return. Thus, we check <= code + GetCodeSize().
606 *
607 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
608 */
609 return code <= pc && pc <= code + GetCodeSize(
610 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
611 }
612
Mathieu Chartiere401d142015-04-22 13:56:20 -0700613 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614};
615
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800616} // namespace art
617
Mathieu Chartiere401d142015-04-22 13:56:20 -0700618#endif // ART_RUNTIME_ART_METHOD_H_