blob: e0b11d0e56c58fc8b65ccedcdc24806d4f0f8aa0 [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;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070036class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070038class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039
40namespace mirror {
Mathieu Chartiere401d142015-04-22 13:56:20 -070041class Array;
42class Class;
43class PointerArray;
44} // namespace mirror
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045
Mathieu Chartiere401d142015-04-22 13:56:20 -070046class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -070048 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
49 method_index_(0) { }
50
51 ArtMethod(const ArtMethod& src, size_t image_pointer_size) {
52 CopyFrom(&src, image_pointer_size);
53 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -070054
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070055 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
56 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -070057 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -070058
Mathieu Chartier90443472015-07-16 20:32:27 -070059 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060
Mathieu Chartiere401d142015-04-22 13:56:20 -070061 ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier()
Mathieu Chartier90443472015-07-16 20:32:27 -070062 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070063
64 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -070065 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -070066
67 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -070068 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069
Mathieu Chartier10e5ea92015-08-13 12:56:31 -070070 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
71 SHARED_REQUIRES(Locks::mutator_lock_);
72
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070074 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075 }
76
Mathieu Chartier90443472015-07-16 20:32:27 -070077 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080078
Mathieu Chartiere401d142015-04-22 13:56:20 -070079 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010080 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -070081 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 }
83
84 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -070085 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086
87 // Returns true if the method is declared public.
Mathieu Chartier90443472015-07-16 20:32:27 -070088 bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 return (GetAccessFlags() & kAccPublic) != 0;
90 }
91
92 // Returns true if the method is declared private.
Mathieu Chartier90443472015-07-16 20:32:27 -070093 bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080094 return (GetAccessFlags() & kAccPrivate) != 0;
95 }
96
97 // Returns true if the method is declared static.
Mathieu Chartier90443472015-07-16 20:32:27 -070098 bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 return (GetAccessFlags() & kAccStatic) != 0;
100 }
101
102 // Returns true if the method is a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700103 bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800104 return (GetAccessFlags() & kAccConstructor) != 0;
105 }
106
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700107 // Returns true if the method is a class initializer.
Mathieu Chartier90443472015-07-16 20:32:27 -0700108 bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700109 return IsConstructor() && IsStatic();
110 }
111
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 // Returns true if the method is static, private, or a constructor.
Mathieu Chartier90443472015-07-16 20:32:27 -0700113 bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 return IsDirect(GetAccessFlags());
115 }
116
117 static bool IsDirect(uint32_t access_flags) {
118 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
119 }
120
121 // Returns true if the method is declared synchronized.
Mathieu Chartier90443472015-07-16 20:32:27 -0700122 bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
124 return (GetAccessFlags() & synchonized) != 0;
125 }
126
Mathieu Chartier90443472015-07-16 20:32:27 -0700127 bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 return (GetAccessFlags() & kAccFinal) != 0;
129 }
130
Mathieu Chartier90443472015-07-16 20:32:27 -0700131 bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 return (GetAccessFlags() & kAccMiranda) != 0;
133 }
134
Mathieu Chartier90443472015-07-16 20:32:27 -0700135 bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 return (GetAccessFlags() & kAccNative) != 0;
137 }
138
Mathieu Chartier90443472015-07-16 20:32:27 -0700139 bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800140 uint32_t mask = kAccFastNative | kAccNative;
141 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700142 }
143
Mathieu Chartier90443472015-07-16 20:32:27 -0700144 bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145 return (GetAccessFlags() & kAccAbstract) != 0;
146 }
147
Mathieu Chartier90443472015-07-16 20:32:27 -0700148 bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800149 return (GetAccessFlags() & kAccSynthetic) != 0;
150 }
151
Mathieu Chartier90443472015-07-16 20:32:27 -0700152 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153
Mathieu Chartier90443472015-07-16 20:32:27 -0700154 bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200155 return (GetAccessFlags() & kAccPreverified) != 0;
156 }
157
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800159 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200160 SetAccessFlags(GetAccessFlags() | kAccPreverified);
161 }
162
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100164 // Temporary solution for detecting if a method has been optimized: the compiler
165 // does not create a GC map. Instead, the vmap table contains the stack map
166 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000167 return !IsNative()
168 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800169 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800170 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100171 }
172
Mathieu Chartier90443472015-07-16 20:32:27 -0700173 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174
Mathieu Chartier90443472015-07-16 20:32:27 -0700175 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700177 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700178 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700179
Mathieu Chartier90443472015-07-16 20:32:27 -0700180 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 return GetMethodIndex();
182 }
183
Mathieu Chartier90443472015-07-16 20:32:27 -0700184 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100185 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700186 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 }
188
Vladimir Markoc1363122015-04-09 14:13:13 +0100189 static MemberOffset DexMethodIndexOffset() {
190 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
191 }
192
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700194 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 }
196
Mathieu Chartiere401d142015-04-22 13:56:20 -0700197 uint32_t GetCodeItemOffset() {
198 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800199 }
200
Mathieu Chartiere401d142015-04-22 13:56:20 -0700201 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100202 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700203 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 }
205
206 // Number of 32bit registers that would be required to hold all the arguments
207 static size_t NumArgRegisters(const StringPiece& shorty);
208
Mathieu Chartier90443472015-07-16 20:32:27 -0700209 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800210
Mathieu Chartiere401d142015-04-22 13:56:20 -0700211 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100212 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700213 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 }
215
Vladimir Marko05792b92015-08-03 11:56:49 +0100216 ALWAYS_INLINE ArtMethod** GetDexCacheResolvedMethods(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700217 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100218 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700219 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100220 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_index,
221 ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700222 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700223 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100224 ALWAYS_INLINE void SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700225 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100226 bool HasDexCacheResolvedMethods(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
227 bool HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700228 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100229 bool HasSameDexCacheResolvedMethods(ArtMethod** other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700230 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231
Andreas Gampe58a5af82014-07-31 16:23:49 -0700232 template <bool kWithCheck = true>
Vladimir Marko05792b92015-08-03 11:56:49 +0100233 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100235 void SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700236 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100237 bool HasDexCacheResolvedTypes(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
238 bool HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size)
239 SHARED_REQUIRES(Locks::mutator_lock_);
240 bool HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700241 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242
Ian Rogersa0485602014-12-02 15:48:04 -0800243 // Get the Class* from the type index into this method's dex cache.
Vladimir Marko05792b92015-08-03 11:56:49 +0100244 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700245 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800246
Ian Rogerse0a02da2014-12-02 14:10:53 -0800247 // Find the method that this method overrides.
Mathieu Chartier90443472015-07-16 20:32:27 -0700248 ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800249
Ian Rogerse0a02da2014-12-02 14:10:53 -0800250 // Find the method index for this method within other_dexfile. If this method isn't present then
251 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
252 // name and signature in the other_dexfile, such as the method index used to resolve this method
253 // in the other_dexfile.
254 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
255 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800257
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700258 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700259 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260
Mathieu Chartiere401d142015-04-22 13:56:20 -0700261 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800262 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
263 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700264 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100265 return GetNativePointer<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800266 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800267 }
268
Mathieu Chartiere401d142015-04-22 13:56:20 -0700269 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800270 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
271 sizeof(void*));
272 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800273 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700274 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100275 SetNativePointer(EntryPointFromQuickCompiledCodeOffset(pointer_size),
276 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800277 }
278
Mathieu Chartier90443472015-07-16 20:32:27 -0700279 uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800280
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700281 // Check whether the given PC is within the quick compiled code associated with this method's
282 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
283 // debug purposes.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700284 bool PcIsWithinQuickCode(uintptr_t pc) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800285 return PcIsWithinQuickCode(
286 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 }
288
Mathieu Chartier90443472015-07-16 20:32:27 -0700289 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800290
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700291 // Returns true if the entrypoint points to the interpreter, as
292 // opposed to the compiled code, that is, this method will be
293 // interpretered on invocation.
Mathieu Chartier90443472015-07-16 20:32:27 -0700294 bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700295
Mathieu Chartiere401d142015-04-22 13:56:20 -0700296 uint32_t GetQuickOatCodeOffset();
297 void SetQuickOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800298
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700299 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100300 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700301 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
302 // least 2 byte aligned.
303 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100304 return reinterpret_cast<const void*>(code);
305 }
306
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700307 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800308 const void* GetQuickOatEntryPoint(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700309 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700310 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800311 const void* GetQuickOatCodePointer(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700312 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800313 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700314 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100315
Ian Rogers1809a722013-08-09 22:05:32 -0700316 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800317 const uint8_t* GetMappingTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700318 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800319 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700320 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321
Ian Rogers1809a722013-08-09 22:05:32 -0700322 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800323 const uint8_t* GetVmapTable(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700324 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800325 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700326 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327
Mathieu Chartier90443472015-07-16 20:32:27 -0700328 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000329
Mathieu Chartier90443472015-07-16 20:32:27 -0700330 CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100331
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800332 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
333 const uint8_t* GetNativeGcMap(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700334 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800335 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700336 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800337
Andreas Gampe90546832014-03-12 18:07:19 -0700338 template <bool kCheckFrameSize = true>
Mathieu Chartier90443472015-07-16 20:32:27 -0700339 uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100340 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700341 if (kCheckFrameSize) {
342 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
343 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344 return result;
345 }
346
Mathieu Chartier90443472015-07-16 20:32:27 -0700347 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100348 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700349 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350
Mathieu Chartier90443472015-07-16 20:32:27 -0700351 FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700352 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100353 }
354
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700355 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700356 SHARED_REQUIRES(Locks::mutator_lock_) {
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100357 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700358 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800359 }
360
Mathieu Chartier90443472015-07-16 20:32:27 -0700361 FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700362 constexpr size_t handle_scope_offset = sizeof(ArtMethod*);
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100363 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
364 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800365 }
366
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700367 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700368 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800369
Mathieu Chartier90443472015-07-16 20:32:27 -0700370 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371
Vladimir Marko05792b92015-08-03 11:56:49 +0100372 static MemberOffset DexCacheResolvedMethodsOffset(size_t pointer_size) {
373 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
374 PtrSizedFields, dex_cache_resolved_methods_) / sizeof(void*) * pointer_size);
375 }
376
377 static MemberOffset DexCacheResolvedTypesOffset(size_t pointer_size) {
378 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
379 PtrSizedFields, dex_cache_resolved_types_) / sizeof(void*) * pointer_size);
380 }
381
Mathieu Chartier2d721012014-11-10 11:08:06 -0800382 static MemberOffset EntryPointFromJniOffset(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_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800385 }
386
Mathieu Chartier2d721012014-11-10 11:08:06 -0800387 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800388 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800389 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
390 }
391
Mathieu Chartiere401d142015-04-22 13:56:20 -0700392 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800393 return GetEntryPointFromJniPtrSize(sizeof(void*));
394 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100396 return GetNativePointer<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800397 }
398
Mathieu Chartier90443472015-07-16 20:32:27 -0700399 void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700400 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800401 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700402 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100403 SetNativePointer(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800404 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800405
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
407 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700408 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409
410 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700411 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412
Mathieu Chartier90443472015-07-16 20:32:27 -0700413 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414
Mathieu Chartier90443472015-07-16 20:32:27 -0700415 bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700416
Mathieu Chartier90443472015-07-16 20:32:27 -0700417 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700418
Mathieu Chartier90443472015-07-16 20:32:27 -0700419 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700420#ifdef NDEBUG
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 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
424 }
425#else
426 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Mathieu Chartier90443472015-07-16 20:32:27 -0700427 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700428#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800429
430 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800431 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700432 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433
434 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000435 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700436 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437
Mathieu Chartier90443472015-07-16 20:32:27 -0700438 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800439 return MethodReference(GetDexFile(), GetDexMethodIndex());
440 }
441
Ian Rogersc449aa82013-07-29 14:35:46 -0700442 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
443 // indicates whether the found catch block is responsible for clearing the exception or whether
444 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700445 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
446 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700447 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800448
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700449 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700450 template<typename RootVisitorType>
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700451 void VisitRoots(RootVisitorType& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800452
Mathieu Chartier90443472015-07-16 20:32:27 -0700453 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700454
Mathieu Chartier90443472015-07-16 20:32:27 -0700455 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700456
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700458 uint32_t unused_length;
459 return GetShorty(&unused_length);
460 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700461
Mathieu Chartier90443472015-07-16 20:32:27 -0700462 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700463
Mathieu Chartier90443472015-07-16 20:32:27 -0700464 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700465
Mathieu Chartier90443472015-07-16 20:32:27 -0700466 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700467
Mathieu Chartier90443472015-07-16 20:32:27 -0700468 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700469
Mathieu Chartier90443472015-07-16 20:32:27 -0700470 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700471
Vladimir Marko05792b92015-08-03 11:56:49 +0100472 bool IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700473
Mathieu Chartier90443472015-07-16 20:32:27 -0700474 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700475
Mathieu Chartier90443472015-07-16 20:32:27 -0700476 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700477
Mathieu Chartier90443472015-07-16 20:32:27 -0700478 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700479
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700481
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700483
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700485
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700487
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700488 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700489 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700490
Ian Rogersded66a02014-10-28 18:12:55 -0700491 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
492 // number of bugs at call sites.
Vladimir Marko05792b92015-08-03 11:56:49 +0100493 mirror::Class* GetReturnType(bool resolve, size_t ptr_size)
494 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700495
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Mathieu Chartiere401d142015-04-22 13:56:20 -0700500 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700501 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700502
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700503 // May cause thread suspension due to class resolution.
504 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700505 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700506
Vladimir Marko14632852015-08-17 12:07:23 +0100507 // Size of an instance of this native class.
508 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700509 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800510 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800511 }
512
Vladimir Marko14632852015-08-17 12:07:23 +0100513 // Alignment of an instance of this native class.
514 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100515 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100516 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100517 return pointer_size;
518 }
519
Mathieu Chartiere401d142015-04-22 13:56:20 -0700520 void CopyFrom(const ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700521 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522
Vladimir Marko05792b92015-08-03 11:56:49 +0100523 ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700524 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525
Mathieu Chartier2d721012014-11-10 11:08:06 -0800526 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800527 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800528 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700529 GcRoot<mirror::Class> declaring_class_;
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 {
Vladimir Marko05792b92015-08-03 11:56:49 +0100555 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
556 ArtMethod** dex_cache_resolved_methods_;
557
558 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
559 GcRoot<mirror::Class>* dex_cache_resolved_types_;
560
Mathieu Chartier2d721012014-11-10 11:08:06 -0800561 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
562 void* entry_point_from_jni_;
563
564 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800565 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800566 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800567 } ptr_sized_fields_;
568
Mathieu Chartier02e25112013-08-14 16:14:24 -0700569 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800570 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700571 // Round up to pointer size for padding field.
572 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
573 }
574
575 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100576 ALWAYS_INLINE T GetNativePointer(MemberOffset offset, size_t pointer_size) const {
577 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700578 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
579 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
580 if (pointer_size == sizeof(uint32_t)) {
581 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
582 } else {
583 auto v = *reinterpret_cast<const uint64_t*>(addr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100584 return reinterpret_cast<T>(dchecked_integral_cast<uintptr_t>(v));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700585 }
586 }
587
588 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100589 ALWAYS_INLINE void SetNativePointer(MemberOffset offset, T new_value, size_t pointer_size) {
590 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700591 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
592 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
593 if (pointer_size == sizeof(uint32_t)) {
594 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
Vladimir Marko05792b92015-08-03 11:56:49 +0100595 *reinterpret_cast<uint32_t*>(addr) = dchecked_integral_cast<uint32_t>(ptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700596 } else {
597 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
598 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800599 }
600
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800601 // Code points to the start of the quick code.
602 static uint32_t GetCodeSize(const void* code);
603
604 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
605 if (code == 0) {
606 return pc == 0;
607 }
608 /*
609 * During a stack walk, a return PC may point past-the-end of the code
610 * in the case that the last instruction is a call that isn't expected to
611 * return. Thus, we check <= code + GetCodeSize().
612 *
613 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
614 */
615 return code <= pc && pc <= code + GetCodeSize(
616 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
617 }
618
Mathieu Chartiere401d142015-04-22 13:56:20 -0700619 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800620};
621
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800622} // namespace art
623
Mathieu Chartiere401d142015-04-22 13:56:20 -0700624#endif // ART_RUNTIME_ART_METHOD_H_