blob: 3dbcd58f0545b904d76e9a7303e5f6d79326c50e [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
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010020#include "base/bit_utils.h"
Vladimir Marko05792b92015-08-03 11:56:49 +010021#include "base/casts.h"
Jeff Hao790ad902013-05-22 15:02:08 -070022#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070023#include "gc_root.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "invoke_type.h"
Mathieu Chartier36b58f52014-12-10 12:06:45 -080025#include "method_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "modifiers.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "mirror/object.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"
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;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010035class OatQuickMethodHeader;
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
Nicolas Geoffray796d6302016-03-13 22:22:31 +000047// Table to resolve IMT conflicts at runtime. The table is attached to
48// the jni entrypoint of IMT conflict ArtMethods.
49// The table contains a list of pairs of { interface_method, implementation_method }
50// with the last entry being null to make an assembly implementation of a lookup
51// faster.
52class ImtConflictTable {
53 public:
54 // Build a new table copying `other` and adding the new entry formed of
55 // the pair { `interface_method`, `implementation_method` }
56 ImtConflictTable(ImtConflictTable* other,
57 ArtMethod* interface_method,
58 ArtMethod* implementation_method) {
59 size_t index = 0;
60 while (other->entries_[index].interface_method != nullptr) {
61 entries_[index] = other->entries_[index];
62 index++;
63 }
64 entries_[index].interface_method = interface_method;
65 entries_[index].implementation_method = implementation_method;
66 // Add the null marker.
67 entries_[index + 1].interface_method = nullptr;
68 entries_[index + 1].implementation_method = nullptr;
69 }
70
71 // Lookup the implementation ArtMethod associated to `interface_method`. Return null
72 // if not found.
73 ArtMethod* Lookup(ArtMethod* interface_method) const {
74 uint32_t table_index = 0;
75 ArtMethod* current_interface_method;
76 while ((current_interface_method = entries_[table_index].interface_method) != nullptr) {
77 if (current_interface_method == interface_method) {
78 return entries_[table_index].implementation_method;
79 }
80 table_index++;
81 }
82 return nullptr;
83 }
84
85 // Compute the size in bytes taken by this table.
86 size_t ComputeSize() const {
87 uint32_t table_index = 0;
88 size_t total_size = 0;
89 while ((entries_[table_index].interface_method) != nullptr) {
90 total_size += sizeof(Entry);
91 table_index++;
92 }
93 // Add the end marker.
94 return total_size + sizeof(Entry);
95 }
96
97 // Compute the size in bytes needed for copying the given `table` and add
98 // one more entry.
99 static size_t ComputeSizeWithOneMoreEntry(ImtConflictTable* table) {
100 return table->ComputeSize() + sizeof(Entry);
101 }
102
103 struct Entry {
104 ArtMethod* interface_method;
105 ArtMethod* implementation_method;
106 };
107
108 private:
109 // Array of entries that the assembly stubs will iterate over. Note that this is
110 // not fixed size, and we allocate data prior to calling the constructor
111 // of ImtConflictTable.
112 Entry entries_[0];
113
114 DISALLOW_COPY_AND_ASSIGN(ImtConflictTable);
115};
116
Mathieu Chartiere401d142015-04-22 13:56:20 -0700117class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800118 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700119 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
120 method_index_(0) { }
121
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000122 ArtMethod(ArtMethod* src, size_t image_pointer_size) {
123 CopyFrom(src, image_pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700124 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700125
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700126 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
127 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700128 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -0700129
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800130 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700131 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800133 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700134 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -0700135 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700136
137 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700138 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139
Mathieu Chartier10e5ea92015-08-13 12:56:31 -0700140 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
141 SHARED_REQUIRES(Locks::mutator_lock_);
142
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700144 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145 }
146
Andreas Gampecbc96b82015-09-30 20:05:24 +0000147 // Note: GetAccessFlags acquires the mutator lock in debug mode to check that it is not called for
148 // a proxy method.
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800149 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampecbc96b82015-09-30 20:05:24 +0000150 ALWAYS_INLINE uint32_t GetAccessFlags();
Jeff Hao5d917302013-02-27 17:57:33 -0800151
Mathieu Chartiere401d142015-04-22 13:56:20 -0700152 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100153 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700154 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 }
156
157 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159
160 // Returns true if the method is declared public.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000161 bool IsPublic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162 return (GetAccessFlags() & kAccPublic) != 0;
163 }
164
165 // Returns true if the method is declared private.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000166 bool IsPrivate() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800167 return (GetAccessFlags() & kAccPrivate) != 0;
168 }
169
170 // Returns true if the method is declared static.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000171 bool IsStatic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 return (GetAccessFlags() & kAccStatic) != 0;
173 }
174
175 // Returns true if the method is a constructor.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000176 bool IsConstructor() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177 return (GetAccessFlags() & kAccConstructor) != 0;
178 }
179
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700180 // Returns true if the method is a class initializer.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000181 bool IsClassInitializer() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700182 return IsConstructor() && IsStatic();
183 }
184
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185 // Returns true if the method is static, private, or a constructor.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000186 bool IsDirect() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 return IsDirect(GetAccessFlags());
188 }
189
190 static bool IsDirect(uint32_t access_flags) {
Andreas Gampecbc96b82015-09-30 20:05:24 +0000191 constexpr uint32_t direct = kAccStatic | kAccPrivate | kAccConstructor;
192 return (access_flags & direct) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 }
194
195 // Returns true if the method is declared synchronized.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000196 bool IsSynchronized() {
197 constexpr uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198 return (GetAccessFlags() & synchonized) != 0;
199 }
200
Andreas Gampecbc96b82015-09-30 20:05:24 +0000201 bool IsFinal() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 return (GetAccessFlags() & kAccFinal) != 0;
203 }
204
Alex Light36121492016-02-22 13:43:29 -0800205 bool IsCopied() {
206 const bool copied = (GetAccessFlags() & kAccCopied) != 0;
207 // (IsMiranda() || IsDefaultConflicting()) implies copied
208 DCHECK(!(IsMiranda() || IsDefaultConflicting()) || copied)
209 << "Miranda or default-conflict methods must always be copied.";
210 return copied;
Alex Lightfcea56f2016-02-17 11:59:05 -0800211 }
212
Andreas Gampecbc96b82015-09-30 20:05:24 +0000213 bool IsMiranda() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 return (GetAccessFlags() & kAccMiranda) != 0;
215 }
216
Alex Light9139e002015-10-09 15:59:48 -0700217 // Returns true if invoking this method will not throw an AbstractMethodError or
218 // IncompatibleClassChangeError.
219 bool IsInvokable() {
220 return !IsAbstract() && !IsDefaultConflicting();
221 }
222
223 // A default conflict method is a special sentinel method that stands for a conflict between
224 // multiple default methods. It cannot be invoked, throwing an IncompatibleClassChangeError if one
225 // attempts to do so.
226 bool IsDefaultConflicting() {
227 return (GetAccessFlags() & kAccDefaultConflict) != 0u;
228 }
229
Alex Lighteb7c1442015-08-31 13:17:42 -0700230 // This is set by the class linker.
231 bool IsDefault() {
232 return (GetAccessFlags() & kAccDefault) != 0;
233 }
234
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800235 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampecbc96b82015-09-30 20:05:24 +0000236 bool IsNative() {
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800237 return (GetAccessFlags<kReadBarrierOption>() & kAccNative) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800238 }
239
Andreas Gampecbc96b82015-09-30 20:05:24 +0000240 bool IsFastNative() {
241 constexpr uint32_t mask = kAccFastNative | kAccNative;
Ian Rogers16ce0922014-01-10 14:59:36 -0800242 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700243 }
244
Andreas Gampecbc96b82015-09-30 20:05:24 +0000245 bool IsAbstract() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246 return (GetAccessFlags() & kAccAbstract) != 0;
247 }
248
Andreas Gampecbc96b82015-09-30 20:05:24 +0000249 bool IsSynthetic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250 return (GetAccessFlags() & kAccSynthetic) != 0;
251 }
252
Mathieu Chartier90443472015-07-16 20:32:27 -0700253 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800254
Igor Murashkindf707e42016-02-02 16:56:50 -0800255 bool SkipAccessChecks() {
256 return (GetAccessFlags() & kAccSkipAccessChecks) != 0;
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200257 }
258
Igor Murashkindf707e42016-02-02 16:56:50 -0800259 void SetSkipAccessChecks() {
260 DCHECK(!SkipAccessChecks());
261 SetAccessFlags(GetAccessFlags() | kAccSkipAccessChecks);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200262 }
263
Alex Lighteb7c1442015-08-31 13:17:42 -0700264 // Returns true if this method could be overridden by a default method.
Alex Light9139e002015-10-09 15:59:48 -0700265 bool IsOverridableByDefaultMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Alex Lighteb7c1442015-08-31 13:17:42 -0700266
Mathieu Chartier90443472015-07-16 20:32:27 -0700267 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800268
Alex Light9139e002015-10-09 15:59:48 -0700269 // Throws the error that would result from trying to invoke this method (i.e.
270 // IncompatibleClassChangeError or AbstractMethodError). Only call if !IsInvokable();
271 void ThrowInvocationTimeError() SHARED_REQUIRES(Locks::mutator_lock_);
272
Mathieu Chartier90443472015-07-16 20:32:27 -0700273 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800274
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700275 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700276 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700277
Mathieu Chartier90443472015-07-16 20:32:27 -0700278 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800279 return GetMethodIndex();
280 }
281
Mathieu Chartier90443472015-07-16 20:32:27 -0700282 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100283 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700284 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285 }
286
Vladimir Markoc1363122015-04-09 14:13:13 +0100287 static MemberOffset DexMethodIndexOffset() {
288 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
289 }
290
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800291 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700292 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800293 }
294
Mathieu Chartiere401d142015-04-22 13:56:20 -0700295 uint32_t GetCodeItemOffset() {
296 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 }
298
Mathieu Chartiere401d142015-04-22 13:56:20 -0700299 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100300 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700301 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800302 }
303
304 // Number of 32bit registers that would be required to hold all the arguments
305 static size_t NumArgRegisters(const StringPiece& shorty);
306
Mathieu Chartier90443472015-07-16 20:32:27 -0700307 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800308
Mathieu Chartiere401d142015-04-22 13:56:20 -0700309 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100310 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700311 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312 }
313
Vladimir Marko05792b92015-08-03 11:56:49 +0100314 ALWAYS_INLINE ArtMethod** GetDexCacheResolvedMethods(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700315 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100316 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700317 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100318 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_index,
319 ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700320 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700321 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100322 ALWAYS_INLINE void SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700323 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100324 bool HasDexCacheResolvedMethods(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
325 bool HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700326 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100327 bool HasSameDexCacheResolvedMethods(ArtMethod** other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700328 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329
Andreas Gampe58a5af82014-07-31 16:23:49 -0700330 template <bool kWithCheck = true>
Vladimir Marko05792b92015-08-03 11:56:49 +0100331 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700332 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100333 void SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700334 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100335 bool HasDexCacheResolvedTypes(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
336 bool HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size)
337 SHARED_REQUIRES(Locks::mutator_lock_);
338 bool HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700339 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800340
Ian Rogersa0485602014-12-02 15:48:04 -0800341 // Get the Class* from the type index into this method's dex cache.
Vladimir Marko05792b92015-08-03 11:56:49 +0100342 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700343 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800344
Alex Light6c8467f2015-11-20 15:03:26 -0800345 // Returns true if this method has the same name and signature of the other method.
346 bool HasSameNameAndSignature(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
347
Ian Rogerse0a02da2014-12-02 14:10:53 -0800348 // Find the method that this method overrides.
Alex Light705ad492015-09-21 11:36:30 -0700349 ArtMethod* FindOverriddenMethod(size_t pointer_size)
350 REQUIRES(Roles::uninterruptible_)
351 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352
Ian Rogerse0a02da2014-12-02 14:10:53 -0800353 // Find the method index for this method within other_dexfile. If this method isn't present then
354 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
355 // name and signature in the other_dexfile, such as the method index used to resolve this method
356 // in the other_dexfile.
357 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
358 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700359 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800360
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700361 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700362 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363
Mathieu Chartiere401d142015-04-22 13:56:20 -0700364 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800365 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
366 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700367 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100368 return GetNativePointer<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800369 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800370 }
371
Mathieu Chartiere401d142015-04-22 13:56:20 -0700372 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800373 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
374 sizeof(void*));
375 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800376 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700377 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100378 SetNativePointer(EntryPointFromQuickCompiledCodeOffset(pointer_size),
379 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800380 }
381
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700382 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700383 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800384
Mathieu Chartier90443472015-07-16 20:32:27 -0700385 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386
Vladimir Marko05792b92015-08-03 11:56:49 +0100387 static MemberOffset DexCacheResolvedMethodsOffset(size_t pointer_size) {
388 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
389 PtrSizedFields, dex_cache_resolved_methods_) / sizeof(void*) * pointer_size);
390 }
391
392 static MemberOffset DexCacheResolvedTypesOffset(size_t pointer_size) {
393 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
394 PtrSizedFields, dex_cache_resolved_types_) / sizeof(void*) * pointer_size);
395 }
396
Mathieu Chartier2d721012014-11-10 11:08:06 -0800397 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800398 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800399 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800400 }
401
Mathieu Chartier2d721012014-11-10 11:08:06 -0800402 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800403 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800404 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
405 }
406
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700407 ProfilingInfo* GetProfilingInfo(size_t pointer_size) {
408 return reinterpret_cast<ProfilingInfo*>(GetEntryPointFromJniPtrSize(pointer_size));
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100409 }
410
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000411 ImtConflictTable* GetImtConflictTable(size_t pointer_size) {
412 DCHECK(IsRuntimeMethod());
413 return reinterpret_cast<ImtConflictTable*>(GetEntryPointFromJniPtrSize(pointer_size));
414 }
415
416 ALWAYS_INLINE void SetImtConflictTable(ImtConflictTable* table) {
417 SetEntryPointFromJniPtrSize(table, sizeof(void*));
418 }
419
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000420 ALWAYS_INLINE void SetProfilingInfo(ProfilingInfo* info) {
421 SetEntryPointFromJniPtrSize(info, sizeof(void*));
422 }
423
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000424 ALWAYS_INLINE void SetProfilingInfoPtrSize(ProfilingInfo* info, size_t pointer_size) {
425 SetEntryPointFromJniPtrSize(info, pointer_size);
426 }
427
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000428 static MemberOffset ProfilingInfoOffset() {
429 return EntryPointFromJniOffset(sizeof(void*));
430 }
431
Mathieu Chartiere401d142015-04-22 13:56:20 -0700432 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800433 return GetEntryPointFromJniPtrSize(sizeof(void*));
434 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100435
Mathieu Chartiere401d142015-04-22 13:56:20 -0700436 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100437 return GetNativePointer<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800438 }
439
Andreas Gampecbc96b82015-09-30 20:05:24 +0000440 void SetEntryPointFromJni(const void* entrypoint) {
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100441 DCHECK(IsNative());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700442 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800443 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100444
Mathieu Chartiere401d142015-04-22 13:56:20 -0700445 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100446 SetNativePointer(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800447 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800448
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
450 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700451 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800452
453 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700454 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800455
Mathieu Chartier90443472015-07-16 20:32:27 -0700456 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700459
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800461 return MethodReference(GetDexFile(), GetDexMethodIndex());
462 }
463
Ian Rogersc449aa82013-07-29 14:35:46 -0700464 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
465 // indicates whether the found catch block is responsible for clearing the exception or whether
466 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700467 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
468 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800470
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700471 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700472 template<typename RootVisitorType>
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700473 void VisitRoots(RootVisitorType& visitor, size_t pointer_size) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800474
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700476
Mathieu Chartier90443472015-07-16 20:32:27 -0700477 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700478
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700480 uint32_t unused_length;
481 return GetShorty(&unused_length);
482 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700483
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700485
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700487
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700489
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700491
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700493
Vladimir Marko05792b92015-08-03 11:56:49 +0100494 bool IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700495
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700501
Mathieu Chartier90443472015-07-16 20:32:27 -0700502 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700503
Mathieu Chartier90443472015-07-16 20:32:27 -0700504 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700505
Mathieu Chartier90443472015-07-16 20:32:27 -0700506 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700507
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700509
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700510 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700511 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700512
Ian Rogersded66a02014-10-28 18:12:55 -0700513 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
514 // number of bugs at call sites.
Vladimir Marko05792b92015-08-03 11:56:49 +0100515 mirror::Class* GetReturnType(bool resolve, size_t ptr_size)
516 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700517
Mathieu Chartier90443472015-07-16 20:32:27 -0700518 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700519
Mathieu Chartier90443472015-07-16 20:32:27 -0700520 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700521
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700523 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700524
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700525 // May cause thread suspension due to class resolution.
526 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700527 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700528
Vladimir Marko14632852015-08-17 12:07:23 +0100529 // Size of an instance of this native class.
530 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700531 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800532 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800533 }
534
Vladimir Marko14632852015-08-17 12:07:23 +0100535 // Alignment of an instance of this native class.
536 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100537 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100538 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100539 return pointer_size;
540 }
541
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000542 void CopyFrom(ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700543 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700544
Vladimir Marko05792b92015-08-03 11:56:49 +0100545 ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700546 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700547
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100548 uint16_t IncrementCounter() {
549 return ++hotness_count_;
550 }
551
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100552 void ClearCounter() {
553 hotness_count_ = 0;
554 }
555
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100556 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
557
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100558 // Returns the method header for the compiled code containing 'pc'. Note that runtime
559 // methods will return null for this method, as they are not oat based.
560 const OatQuickMethodHeader* GetOatQuickMethodHeader(uintptr_t pc)
561 SHARED_REQUIRES(Locks::mutator_lock_);
562
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000563 // Returns whether the method has any compiled code, JIT or AOT.
564 bool HasAnyCompiledCode() SHARED_REQUIRES(Locks::mutator_lock_);
565
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800566
567 // Update heap objects and non-entrypoint pointers by the passed in visitor for image relocation.
568 // Does not use read barrier.
569 template <typename Visitor>
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800570 ALWAYS_INLINE void UpdateObjectsForImageRelocation(const Visitor& visitor, size_t pointer_size)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800571 SHARED_REQUIRES(Locks::mutator_lock_);
572
573 // Update entry points by passing them through the visitor.
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800574 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor>
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800575 ALWAYS_INLINE void UpdateEntrypoints(const Visitor& visitor, size_t pointer_size);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800576
Mathieu Chartier2d721012014-11-10 11:08:06 -0800577 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800578 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800579 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700580 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800581
Ian Rogersef7d42f2014-01-06 12:55:46 -0800582 // Access flags; low 16 bits are defined by spec.
583 uint32_t access_flags_;
584
585 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
586
587 // Offset to the CodeItem.
588 uint32_t dex_code_item_offset_;
589
590 // Index into method_ids of the dex file associated with this method.
591 uint32_t dex_method_index_;
592
593 /* End of dex file fields. */
594
595 // Entry within a dispatch table for this method. For static/direct methods the index is into
596 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
597 // ifTable.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100598 uint16_t method_index_;
599
600 // The hotness we measure for this method. Incremented by the interpreter. Not atomic, as we allow
601 // missing increments: if the method is hot, we will see it eventually.
602 uint16_t hotness_count_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800603
Mathieu Chartiereace4582014-11-24 18:29:54 -0800604 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800605
606 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700607 // PACKED(4) is necessary for the correctness of
608 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800609 struct PACKED(4) PtrSizedFields {
Vladimir Marko05792b92015-08-03 11:56:49 +0100610 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
611 ArtMethod** dex_cache_resolved_methods_;
612
613 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
614 GcRoot<mirror::Class>* dex_cache_resolved_types_;
615
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100616 // Pointer to JNI function registered to this method, or a function to resolve the JNI function,
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000617 // or the profiling data for non-native methods, or an ImtConflictTable.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800618 void* entry_point_from_jni_;
619
620 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800621 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800622 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800623 } ptr_sized_fields_;
624
Mathieu Chartier02e25112013-08-14 16:14:24 -0700625 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800626 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700627 // Round up to pointer size for padding field.
628 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
629 }
630
631 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100632 ALWAYS_INLINE T GetNativePointer(MemberOffset offset, size_t pointer_size) const {
633 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700634 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
635 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
636 if (pointer_size == sizeof(uint32_t)) {
637 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
638 } else {
639 auto v = *reinterpret_cast<const uint64_t*>(addr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100640 return reinterpret_cast<T>(dchecked_integral_cast<uintptr_t>(v));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700641 }
642 }
643
644 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100645 ALWAYS_INLINE void SetNativePointer(MemberOffset offset, T new_value, size_t pointer_size) {
646 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700647 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
648 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
649 if (pointer_size == sizeof(uint32_t)) {
650 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
Vladimir Marko05792b92015-08-03 11:56:49 +0100651 *reinterpret_cast<uint32_t*>(addr) = dchecked_integral_cast<uint32_t>(ptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700652 } else {
653 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
654 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800655 }
656
Mathieu Chartiere401d142015-04-22 13:56:20 -0700657 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800658};
659
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800660} // namespace art
661
Mathieu Chartiere401d142015-04-22 13:56:20 -0700662#endif // ART_RUNTIME_ART_METHOD_H_