blob: 9415372f1147f6317d78bd0f28c23aa8da146f8e [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
Vladimir Marko05792b92015-08-03 11:56:49 +010020#include "base/casts.h"
Jeff Hao790ad902013-05-22 15:02:08 -070021#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070022#include "gc_root.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "invoke_type.h"
Mathieu Chartier36b58f52014-12-10 12:06:45 -080024#include "method_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "modifiers.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070026#include "mirror/object.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;
Nicolas Geoffray5550ca82015-08-21 18:38:30 +010036class ProfilingInfo;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070037class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070039class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040
41namespace mirror {
Mathieu Chartiere401d142015-04-22 13:56:20 -070042class Array;
43class Class;
44class PointerArray;
45} // namespace mirror
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046
Mathieu Chartiere401d142015-04-22 13:56:20 -070047class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -070049 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
50 method_index_(0) { }
51
52 ArtMethod(const ArtMethod& src, size_t image_pointer_size) {
53 CopyFrom(&src, image_pointer_size);
54 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -070055
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070056 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
57 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -070058 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -070059
Mathieu Chartier90443472015-07-16 20:32:27 -070060 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061
Mathieu Chartiere401d142015-04-22 13:56:20 -070062 ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier()
Mathieu Chartier90443472015-07-16 20:32:27 -070063 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070064
65 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -070066 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070067
68 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -070069 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070071 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
72 SHARED_REQUIRES(Locks::mutator_lock_);
73
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070075 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 }
77
Mathieu Chartier90443472015-07-16 20:32:27 -070078 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080079
Mathieu Chartiere401d142015-04-22 13:56:20 -070080 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010081 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -070082 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083 }
84
85 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -070086 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087
88 // Returns true if the method is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -070089 bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080090 return (GetAccessFlags() & kAccPublic) != 0;
91 }
92
93 // Returns true if the method is declared private.
Mathieu Chartier90443472015-07-16 20:32:27 -070094 bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095 return (GetAccessFlags() & kAccPrivate) != 0;
96 }
97
98 // Returns true if the method is declared static.
Mathieu Chartier90443472015-07-16 20:32:27 -070099 bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100 return (GetAccessFlags() & kAccStatic) != 0;
101 }
102
103 // Returns true if the method is a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700104 bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 return (GetAccessFlags() & kAccConstructor) != 0;
106 }
107
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700108 // Returns true if the method is a class initializer.
Mathieu Chartier90443472015-07-16 20:32:27 -0700109 bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700110 return IsConstructor() && IsStatic();
111 }
112
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800113 // Returns true if the method is static, private, or a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700114 bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115 return IsDirect(GetAccessFlags());
116 }
117
118 static bool IsDirect(uint32_t access_flags) {
119 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
120 }
121
122 // Returns true if the method is declared synchronized.
Mathieu Chartier90443472015-07-16 20:32:27 -0700123 bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
125 return (GetAccessFlags() & synchonized) != 0;
126 }
127
Mathieu Chartier90443472015-07-16 20:32:27 -0700128 bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129 return (GetAccessFlags() & kAccFinal) != 0;
130 }
131
Mathieu Chartier90443472015-07-16 20:32:27 -0700132 bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800133 return (GetAccessFlags() & kAccMiranda) != 0;
134 }
135
Mathieu Chartier90443472015-07-16 20:32:27 -0700136 bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 return (GetAccessFlags() & kAccNative) != 0;
138 }
139
Mathieu Chartier90443472015-07-16 20:32:27 -0700140 bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800141 uint32_t mask = kAccFastNative | kAccNative;
142 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700143 }
144
Mathieu Chartier90443472015-07-16 20:32:27 -0700145 bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 return (GetAccessFlags() & kAccAbstract) != 0;
147 }
148
Mathieu Chartier90443472015-07-16 20:32:27 -0700149 bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 return (GetAccessFlags() & kAccSynthetic) != 0;
151 }
152
Mathieu Chartier90443472015-07-16 20:32:27 -0700153 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154
Mathieu Chartier90443472015-07-16 20:32:27 -0700155 bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200156 return (GetAccessFlags() & kAccPreverified) != 0;
157 }
158
Mathieu Chartier90443472015-07-16 20:32:27 -0700159 void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800160 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200161 SetAccessFlags(GetAccessFlags() | kAccPreverified);
162 }
163
Mathieu Chartier90443472015-07-16 20:32:27 -0700164 bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100165 // Temporary solution for detecting if a method has been optimized: the compiler
166 // does not create a GC map. Instead, the vmap table contains the stack map
167 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000168 return !IsNative()
169 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800170 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800171 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100172 }
173
Mathieu Chartier90443472015-07-16 20:32:27 -0700174 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175
Mathieu Chartier90443472015-07-16 20:32:27 -0700176 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700178 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700180
Mathieu Chartier90443472015-07-16 20:32:27 -0700181 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800182 return GetMethodIndex();
183 }
184
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100186 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700187 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 }
189
Vladimir Markoc1363122015-04-09 14:13:13 +0100190 static MemberOffset DexMethodIndexOffset() {
191 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
192 }
193
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700195 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
Mathieu Chartiere401d142015-04-22 13:56:20 -0700198 uint32_t GetCodeItemOffset() {
199 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201
Mathieu Chartiere401d142015-04-22 13:56:20 -0700202 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100203 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700204 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 }
206
207 // Number of 32bit registers that would be required to hold all the arguments
208 static size_t NumArgRegisters(const StringPiece& shorty);
209
Mathieu Chartier90443472015-07-16 20:32:27 -0700210 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211
Mathieu Chartiere401d142015-04-22 13:56:20 -0700212 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100213 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700214 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 }
216
Vladimir Marko05792b92015-08-03 11:56:49 +0100217 ALWAYS_INLINE ArtMethod** GetDexCacheResolvedMethods(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700218 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100219 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700220 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100221 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_index,
222 ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700223 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700224 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100225 ALWAYS_INLINE void SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700226 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100227 bool HasDexCacheResolvedMethods(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
228 bool HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700229 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100230 bool HasSameDexCacheResolvedMethods(ArtMethod** other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700231 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232
Andreas Gampe58a5af82014-07-31 16:23:49 -0700233 template <bool kWithCheck = true>
Vladimir Marko05792b92015-08-03 11:56:49 +0100234 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700235 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100236 void SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700237 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100238 bool HasDexCacheResolvedTypes(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
239 bool HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size)
240 SHARED_REQUIRES(Locks::mutator_lock_);
241 bool HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243
Ian Rogersa0485602014-12-02 15:48:04 -0800244 // Get the Class* from the type index into this method's dex cache.
Vladimir Marko05792b92015-08-03 11:56:49 +0100245 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800247
Ian Rogerse0a02da2014-12-02 14:10:53 -0800248 // Find the method that this method overrides.
Mathieu Chartier90443472015-07-16 20:32:27 -0700249 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250
Ian Rogerse0a02da2014-12-02 14:10:53 -0800251 // Find the method index for this method within other_dexfile. If this method isn't present then
252 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
253 // name and signature in the other_dexfile, such as the method index used to resolve this method
254 // in the other_dexfile.
255 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
256 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700257 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800258
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700259 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700260 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261
Mathieu Chartiere401d142015-04-22 13:56:20 -0700262 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800263 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
264 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700265 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100266 return GetNativePointer<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800267 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268 }
269
Mathieu Chartiere401d142015-04-22 13:56:20 -0700270 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800271 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
272 sizeof(void*));
273 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800274 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700275 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100276 SetNativePointer(EntryPointFromQuickCompiledCodeOffset(pointer_size),
277 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278 }
279
Mathieu Chartier90443472015-07-16 20:32:27 -0700280 uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800281
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700282 // Check whether the given PC is within the quick compiled code associated with this method's
283 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
284 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700285 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800286 return PcIsWithinQuickCode(
287 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800288 }
289
Mathieu Chartier90443472015-07-16 20:32:27 -0700290 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800291
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700292 // Returns true if the entrypoint points to the interpreter, as
293 // opposed to the compiled code, that is, this method will be
294 // interpretered on invocation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700295 bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700296
Mathieu Chartiere401d142015-04-22 13:56:20 -0700297 uint32_t GetQuickOatCodeOffset();
298 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800299
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700300 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100301 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700302 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
303 // least 2 byte aligned.
304 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100305 return reinterpret_cast<const void*>(code);
306 }
307
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700308 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800309 const void* GetQuickOatEntryPoint(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700310 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700311 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800312 const void* GetQuickOatCodePointer(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700313 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800314 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700315 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100316
Ian Rogers1809a722013-08-09 22:05:32 -0700317 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800318 const uint8_t* GetMappingTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700319 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800320 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700321 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800322
Ian Rogers1809a722013-08-09 22:05:32 -0700323 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800324 const uint8_t* GetVmapTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700325 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800326 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700327 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800328
Mathieu Chartier90443472015-07-16 20:32:27 -0700329 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000330
Mathieu Chartier90443472015-07-16 20:32:27 -0700331 CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100332
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800333 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
334 const uint8_t* GetNativeGcMap(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700335 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800336 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700337 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338
Andreas Gampe90546832014-03-12 18:07:19 -0700339 template <bool kCheckFrameSize = true>
Mathieu Chartier90443472015-07-16 20:32:27 -0700340 uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100341 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700342 if (kCheckFrameSize) {
343 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
344 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800345 return result;
346 }
347
Mathieu Chartier90443472015-07-16 20:32:27 -0700348 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100349 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351
Mathieu Chartier90443472015-07-16 20:32:27 -0700352 FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700353 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100354 }
355
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700356 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700357 SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100358 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700359 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800360 }
361
Mathieu Chartier90443472015-07-16 20:32:27 -0700362 FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700363 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100364 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
365 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800366 }
367
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700368 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700369 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800370
Mathieu Chartier90443472015-07-16 20:32:27 -0700371 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372
Vladimir Marko05792b92015-08-03 11:56:49 +0100373 static MemberOffset DexCacheResolvedMethodsOffset(size_t pointer_size) {
374 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
375 PtrSizedFields, dex_cache_resolved_methods_) / sizeof(void*) * pointer_size);
376 }
377
378 static MemberOffset DexCacheResolvedTypesOffset(size_t pointer_size) {
379 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
380 PtrSizedFields, dex_cache_resolved_types_) / sizeof(void*) * pointer_size);
381 }
382
Mathieu Chartier2d721012014-11-10 11:08:06 -0800383 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800384 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800385 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386 }
387
Mathieu Chartier2d721012014-11-10 11:08:06 -0800388 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800389 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800390 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
391 }
392
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100393 ProfilingInfo* CreateProfilingInfo() SHARED_REQUIRES(Locks::mutator_lock_);
394
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700395 ProfilingInfo* GetProfilingInfo(size_t pointer_size) {
396 return reinterpret_cast<ProfilingInfo*>(GetEntryPointFromJniPtrSize(pointer_size));
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100397 }
398
Mathieu Chartiere401d142015-04-22 13:56:20 -0700399 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800400 return GetEntryPointFromJniPtrSize(sizeof(void*));
401 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100402
Mathieu Chartiere401d142015-04-22 13:56:20 -0700403 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100404 return GetNativePointer<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800405 }
406
Mathieu Chartier90443472015-07-16 20:32:27 -0700407 void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100408 DCHECK(IsNative());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700409 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800410 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100411
Mathieu Chartiere401d142015-04-22 13:56:20 -0700412 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100413 SetNativePointer(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800414 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800416 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
417 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700418 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800419
420 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700421 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800422
Mathieu Chartier90443472015-07-16 20:32:27 -0700423 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424
Mathieu Chartier90443472015-07-16 20:32:27 -0700425 bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700426
Mathieu Chartier90443472015-07-16 20:32:27 -0700427 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700428
Mathieu Chartier90443472015-07-16 20:32:27 -0700429 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700430#ifdef NDEBUG
431 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700432 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700433 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
434 }
435#else
436 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700437 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700438#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800439
440 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800441 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800443
444 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000445 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700446 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447
Mathieu Chartier90443472015-07-16 20:32:27 -0700448 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800449 return MethodReference(GetDexFile(), GetDexMethodIndex());
450 }
451
Ian Rogersc449aa82013-07-29 14:35:46 -0700452 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
453 // indicates whether the found catch block is responsible for clearing the exception or whether
454 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700455 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
456 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800458
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700459 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700460 template<typename RootVisitorType>
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700461 void VisitRoots(RootVisitorType& visitor, size_t pointer_size) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800462
Mathieu Chartier90443472015-07-16 20:32:27 -0700463 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700464
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700466
Mathieu Chartier90443472015-07-16 20:32:27 -0700467 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700468 uint32_t unused_length;
469 return GetShorty(&unused_length);
470 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700471
Mathieu Chartier90443472015-07-16 20:32:27 -0700472 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700473
Mathieu Chartier90443472015-07-16 20:32:27 -0700474 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700475
Mathieu Chartier90443472015-07-16 20:32:27 -0700476 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700477
Mathieu Chartier90443472015-07-16 20:32:27 -0700478 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700479
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700481
Vladimir Marko05792b92015-08-03 11:56:49 +0100482 bool IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700483
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700485
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700487
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700489
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700491
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700493
Mathieu Chartier90443472015-07-16 20:32:27 -0700494 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700495
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700498 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700500
Ian Rogersded66a02014-10-28 18:12:55 -0700501 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
502 // number of bugs at call sites.
Vladimir Marko05792b92015-08-03 11:56:49 +0100503 mirror::Class* GetReturnType(bool resolve, size_t ptr_size)
504 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700505
Mathieu Chartier90443472015-07-16 20:32:27 -0700506 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700507
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700509
Mathieu Chartiere401d142015-04-22 13:56:20 -0700510 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700511 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700512
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700513 // May cause thread suspension due to class resolution.
514 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700515 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700516
Vladimir Marko14632852015-08-17 12:07:23 +0100517 // Size of an instance of this native class.
518 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700519 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800520 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800521 }
522
Vladimir Marko14632852015-08-17 12:07:23 +0100523 // Alignment of an instance of this native class.
524 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100525 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100526 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100527 return pointer_size;
528 }
529
Mathieu Chartiere401d142015-04-22 13:56:20 -0700530 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700531 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700532
Vladimir Marko05792b92015-08-03 11:56:49 +0100533 ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700534 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700535
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100536 uint16_t IncrementCounter() {
537 return ++hotness_count_;
538 }
539
Mathieu Chartier2d721012014-11-10 11:08:06 -0800540 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800541 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800542 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700543 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800544
Ian Rogersef7d42f2014-01-06 12:55:46 -0800545 // Access flags; low 16 bits are defined by spec.
546 uint32_t access_flags_;
547
548 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
549
550 // Offset to the CodeItem.
551 uint32_t dex_code_item_offset_;
552
553 // Index into method_ids of the dex file associated with this method.
554 uint32_t dex_method_index_;
555
556 /* End of dex file fields. */
557
558 // Entry within a dispatch table for this method. For static/direct methods the index is into
559 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
560 // ifTable.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100561 uint16_t method_index_;
562
563 // The hotness we measure for this method. Incremented by the interpreter. Not atomic, as we allow
564 // missing increments: if the method is hot, we will see it eventually.
565 uint16_t hotness_count_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800566
Mathieu Chartiereace4582014-11-24 18:29:54 -0800567 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800568
569 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700570 // PACKED(4) is necessary for the correctness of
571 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800572 struct PACKED(4) PtrSizedFields {
Vladimir Marko05792b92015-08-03 11:56:49 +0100573 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
574 ArtMethod** dex_cache_resolved_methods_;
575
576 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
577 GcRoot<mirror::Class>* dex_cache_resolved_types_;
578
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100579 // Pointer to JNI function registered to this method, or a function to resolve the JNI function,
580 // or the profiling data for non-native methods.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800581 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>
Vladimir Marko05792b92015-08-03 11:56:49 +0100595 ALWAYS_INLINE T GetNativePointer(MemberOffset offset, size_t pointer_size) const {
596 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700597 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
598 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
599 if (pointer_size == sizeof(uint32_t)) {
600 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
601 } else {
602 auto v = *reinterpret_cast<const uint64_t*>(addr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100603 return reinterpret_cast<T>(dchecked_integral_cast<uintptr_t>(v));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700604 }
605 }
606
607 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100608 ALWAYS_INLINE void SetNativePointer(MemberOffset offset, T new_value, size_t pointer_size) {
609 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700610 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
611 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
612 if (pointer_size == sizeof(uint32_t)) {
613 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
Vladimir Marko05792b92015-08-03 11:56:49 +0100614 *reinterpret_cast<uint32_t*>(addr) = dchecked_integral_cast<uint32_t>(ptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700615 } 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_