blob: 08f02852ee6505d9314ce22271a76ecd4579312d [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
Nicolas Geoffray250a3782016-04-20 16:27:53 +0100223 bool IsCompilable() {
224 return (GetAccessFlags() & kAccCompileDontBother) == 0;
225 }
226
Alex Light9139e002015-10-09 15:59:48 -0700227 // A default conflict method is a special sentinel method that stands for a conflict between
228 // multiple default methods. It cannot be invoked, throwing an IncompatibleClassChangeError if one
229 // attempts to do so.
230 bool IsDefaultConflicting() {
231 return (GetAccessFlags() & kAccDefaultConflict) != 0u;
232 }
233
Alex Lighteb7c1442015-08-31 13:17:42 -0700234 // This is set by the class linker.
235 bool IsDefault() {
236 return (GetAccessFlags() & kAccDefault) != 0;
237 }
238
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800239 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampecbc96b82015-09-30 20:05:24 +0000240 bool IsNative() {
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800241 return (GetAccessFlags<kReadBarrierOption>() & kAccNative) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242 }
243
Andreas Gampecbc96b82015-09-30 20:05:24 +0000244 bool IsFastNative() {
245 constexpr uint32_t mask = kAccFastNative | kAccNative;
Ian Rogers16ce0922014-01-10 14:59:36 -0800246 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700247 }
248
Andreas Gampecbc96b82015-09-30 20:05:24 +0000249 bool IsAbstract() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250 return (GetAccessFlags() & kAccAbstract) != 0;
251 }
252
Andreas Gampecbc96b82015-09-30 20:05:24 +0000253 bool IsSynthetic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800254 return (GetAccessFlags() & kAccSynthetic) != 0;
255 }
256
Mathieu Chartier90443472015-07-16 20:32:27 -0700257 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800258
Igor Murashkindf707e42016-02-02 16:56:50 -0800259 bool SkipAccessChecks() {
260 return (GetAccessFlags() & kAccSkipAccessChecks) != 0;
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200261 }
262
Igor Murashkindf707e42016-02-02 16:56:50 -0800263 void SetSkipAccessChecks() {
264 DCHECK(!SkipAccessChecks());
265 SetAccessFlags(GetAccessFlags() | kAccSkipAccessChecks);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200266 }
267
Alex Lighteb7c1442015-08-31 13:17:42 -0700268 // Returns true if this method could be overridden by a default method.
Alex Light9139e002015-10-09 15:59:48 -0700269 bool IsOverridableByDefaultMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Alex Lighteb7c1442015-08-31 13:17:42 -0700270
Mathieu Chartier90443472015-07-16 20:32:27 -0700271 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800272
Alex Light9139e002015-10-09 15:59:48 -0700273 // Throws the error that would result from trying to invoke this method (i.e.
274 // IncompatibleClassChangeError or AbstractMethodError). Only call if !IsInvokable();
275 void ThrowInvocationTimeError() SHARED_REQUIRES(Locks::mutator_lock_);
276
Mathieu Chartier90443472015-07-16 20:32:27 -0700277 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800278
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700279 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700280 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700281
Mathieu Chartier90443472015-07-16 20:32:27 -0700282 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800283 return GetMethodIndex();
284 }
285
Mathieu Chartier90443472015-07-16 20:32:27 -0700286 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100287 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700288 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800289 }
290
Vladimir Markoc1363122015-04-09 14:13:13 +0100291 static MemberOffset DexMethodIndexOffset() {
292 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
293 }
294
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800295 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700296 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 }
298
Mathieu Chartiere401d142015-04-22 13:56:20 -0700299 uint32_t GetCodeItemOffset() {
300 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800301 }
302
Mathieu Chartiere401d142015-04-22 13:56:20 -0700303 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100304 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700305 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 }
307
308 // Number of 32bit registers that would be required to hold all the arguments
309 static size_t NumArgRegisters(const StringPiece& shorty);
310
Mathieu Chartier90443472015-07-16 20:32:27 -0700311 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312
Mathieu Chartiere401d142015-04-22 13:56:20 -0700313 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100314 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700315 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800316 }
317
Vladimir Marko05792b92015-08-03 11:56:49 +0100318 ALWAYS_INLINE ArtMethod** GetDexCacheResolvedMethods(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700319 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100320 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_index, 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 SetDexCacheResolvedMethod(uint16_t method_index,
323 ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700324 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700325 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100326 ALWAYS_INLINE void SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700327 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100328 bool HasDexCacheResolvedMethods(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
329 bool HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700330 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100331 bool HasSameDexCacheResolvedMethods(ArtMethod** other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700332 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333
Andreas Gampe58a5af82014-07-31 16:23:49 -0700334 template <bool kWithCheck = true>
Vladimir Marko05792b92015-08-03 11:56:49 +0100335 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700336 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100337 void SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700338 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100339 bool HasDexCacheResolvedTypes(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
340 bool HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size)
341 SHARED_REQUIRES(Locks::mutator_lock_);
342 bool HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700343 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344
Ian Rogersa0485602014-12-02 15:48:04 -0800345 // Get the Class* from the type index into this method's dex cache.
Vladimir Marko05792b92015-08-03 11:56:49 +0100346 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700347 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800348
Alex Light6c8467f2015-11-20 15:03:26 -0800349 // Returns true if this method has the same name and signature of the other method.
350 bool HasSameNameAndSignature(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
351
Ian Rogerse0a02da2014-12-02 14:10:53 -0800352 // Find the method that this method overrides.
Alex Light705ad492015-09-21 11:36:30 -0700353 ArtMethod* FindOverriddenMethod(size_t pointer_size)
354 REQUIRES(Roles::uninterruptible_)
355 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356
Ian Rogerse0a02da2014-12-02 14:10:53 -0800357 // Find the method index for this method within other_dexfile. If this method isn't present then
358 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
359 // name and signature in the other_dexfile, such as the method index used to resolve this method
360 // in the other_dexfile.
361 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
362 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700363 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800364
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700365 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700366 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367
Mathieu Chartiere401d142015-04-22 13:56:20 -0700368 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800369 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
370 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700371 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100372 return GetNativePointer<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800373 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800374 }
375
Mathieu Chartiere401d142015-04-22 13:56:20 -0700376 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800377 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
378 sizeof(void*));
379 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800380 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700381 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100382 SetNativePointer(EntryPointFromQuickCompiledCodeOffset(pointer_size),
383 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800384 }
385
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700386 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700387 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388
Mathieu Chartier90443472015-07-16 20:32:27 -0700389 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800390
Vladimir Marko05792b92015-08-03 11:56:49 +0100391 static MemberOffset DexCacheResolvedMethodsOffset(size_t pointer_size) {
392 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
393 PtrSizedFields, dex_cache_resolved_methods_) / sizeof(void*) * pointer_size);
394 }
395
396 static MemberOffset DexCacheResolvedTypesOffset(size_t pointer_size) {
397 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
398 PtrSizedFields, dex_cache_resolved_types_) / sizeof(void*) * pointer_size);
399 }
400
Mathieu Chartier2d721012014-11-10 11:08:06 -0800401 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800402 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800403 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404 }
405
Mathieu Chartier2d721012014-11-10 11:08:06 -0800406 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800407 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800408 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
409 }
410
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700411 ProfilingInfo* GetProfilingInfo(size_t pointer_size) {
412 return reinterpret_cast<ProfilingInfo*>(GetEntryPointFromJniPtrSize(pointer_size));
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100413 }
414
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000415 ImtConflictTable* GetImtConflictTable(size_t pointer_size) {
416 DCHECK(IsRuntimeMethod());
417 return reinterpret_cast<ImtConflictTable*>(GetEntryPointFromJniPtrSize(pointer_size));
418 }
419
420 ALWAYS_INLINE void SetImtConflictTable(ImtConflictTable* table) {
421 SetEntryPointFromJniPtrSize(table, sizeof(void*));
422 }
423
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000424 ALWAYS_INLINE void SetProfilingInfo(ProfilingInfo* info) {
425 SetEntryPointFromJniPtrSize(info, sizeof(void*));
426 }
427
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000428 ALWAYS_INLINE void SetProfilingInfoPtrSize(ProfilingInfo* info, size_t pointer_size) {
429 SetEntryPointFromJniPtrSize(info, pointer_size);
430 }
431
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000432 static MemberOffset ProfilingInfoOffset() {
433 return EntryPointFromJniOffset(sizeof(void*));
434 }
435
Mathieu Chartiere401d142015-04-22 13:56:20 -0700436 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800437 return GetEntryPointFromJniPtrSize(sizeof(void*));
438 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100439
Mathieu Chartiere401d142015-04-22 13:56:20 -0700440 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100441 return GetNativePointer<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800442 }
443
Andreas Gampecbc96b82015-09-30 20:05:24 +0000444 void SetEntryPointFromJni(const void* entrypoint) {
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100445 DCHECK(IsNative());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700446 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800447 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100448
Mathieu Chartiere401d142015-04-22 13:56:20 -0700449 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100450 SetNativePointer(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800451 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800452
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
454 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700455 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456
457 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800459
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461
Mathieu Chartier90443472015-07-16 20:32:27 -0700462 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700463
Mathieu Chartier90443472015-07-16 20:32:27 -0700464 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800465 return MethodReference(GetDexFile(), GetDexMethodIndex());
466 }
467
Ian Rogersc449aa82013-07-29 14:35:46 -0700468 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
469 // indicates whether the found catch block is responsible for clearing the exception or whether
470 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700471 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
472 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700473 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700475 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700476 template<typename RootVisitorType>
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700477 void VisitRoots(RootVisitorType& visitor, size_t pointer_size) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800478
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700480
Mathieu Chartier90443472015-07-16 20:32:27 -0700481 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700482
Mathieu Chartier90443472015-07-16 20:32:27 -0700483 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700484 uint32_t unused_length;
485 return GetShorty(&unused_length);
486 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700487
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700489
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700491
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700493
Mathieu Chartier90443472015-07-16 20:32:27 -0700494 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700495
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Vladimir Marko05792b92015-08-03 11:56:49 +0100498 bool IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700501
Mathieu Chartier90443472015-07-16 20:32:27 -0700502 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700503
Mathieu Chartier90443472015-07-16 20:32:27 -0700504 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700505
Mathieu Chartier90443472015-07-16 20:32:27 -0700506 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700507
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700509
Mathieu Chartier90443472015-07-16 20:32:27 -0700510 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700511
Mathieu Chartier90443472015-07-16 20:32:27 -0700512 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700513
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700514 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700515 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700516
Ian Rogersded66a02014-10-28 18:12:55 -0700517 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
518 // number of bugs at call sites.
Vladimir Marko05792b92015-08-03 11:56:49 +0100519 mirror::Class* GetReturnType(bool resolve, size_t ptr_size)
520 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700521
Mathieu Chartier90443472015-07-16 20:32:27 -0700522 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700523
Mathieu Chartier90443472015-07-16 20:32:27 -0700524 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700525
Mathieu Chartiere401d142015-04-22 13:56:20 -0700526 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700527 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700528
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700529 // May cause thread suspension due to class resolution.
530 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700531 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700532
Vladimir Marko14632852015-08-17 12:07:23 +0100533 // Size of an instance of this native class.
534 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700535 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800536 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800537 }
538
Vladimir Marko14632852015-08-17 12:07:23 +0100539 // Alignment of an instance of this native class.
540 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100541 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100542 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100543 return pointer_size;
544 }
545
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000546 void CopyFrom(ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700547 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700548
Vladimir Marko05792b92015-08-03 11:56:49 +0100549 ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700550 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700551
Bill Buzbee1d011d92016-04-04 16:59:29 +0000552 // Note, hotness_counter_ updates are non-atomic but it doesn't need to be precise. Also,
553 // given that the counter is only 16 bits wide we can expect wrap-around in some
554 // situations. Consumers of hotness_count_ must be able to deal with that.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100555 uint16_t IncrementCounter() {
556 return ++hotness_count_;
557 }
558
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100559 void ClearCounter() {
560 hotness_count_ = 0;
561 }
562
Bill Buzbee1d011d92016-04-04 16:59:29 +0000563 void SetCounter(int16_t hotness_count) {
564 hotness_count_ = hotness_count;
565 }
566
567 uint16_t GetCounter() const {
568 return hotness_count_;
569 }
570
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100571 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
572
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100573 // Returns the method header for the compiled code containing 'pc'. Note that runtime
574 // methods will return null for this method, as they are not oat based.
575 const OatQuickMethodHeader* GetOatQuickMethodHeader(uintptr_t pc)
576 SHARED_REQUIRES(Locks::mutator_lock_);
577
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000578 // Returns whether the method has any compiled code, JIT or AOT.
579 bool HasAnyCompiledCode() SHARED_REQUIRES(Locks::mutator_lock_);
580
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800581
582 // Update heap objects and non-entrypoint pointers by the passed in visitor for image relocation.
583 // Does not use read barrier.
584 template <typename Visitor>
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800585 ALWAYS_INLINE void UpdateObjectsForImageRelocation(const Visitor& visitor, size_t pointer_size)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800586 SHARED_REQUIRES(Locks::mutator_lock_);
587
588 // Update entry points by passing them through the visitor.
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800589 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor>
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800590 ALWAYS_INLINE void UpdateEntrypoints(const Visitor& visitor, size_t pointer_size);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800591
Mathieu Chartier2d721012014-11-10 11:08:06 -0800592 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800593 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800594 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700595 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800596
Ian Rogersef7d42f2014-01-06 12:55:46 -0800597 // Access flags; low 16 bits are defined by spec.
598 uint32_t access_flags_;
599
600 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
601
602 // Offset to the CodeItem.
603 uint32_t dex_code_item_offset_;
604
605 // Index into method_ids of the dex file associated with this method.
606 uint32_t dex_method_index_;
607
608 /* End of dex file fields. */
609
610 // Entry within a dispatch table for this method. For static/direct methods the index is into
611 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
612 // ifTable.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100613 uint16_t method_index_;
614
Bill Buzbee1d011d92016-04-04 16:59:29 +0000615 // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100616 // missing increments: if the method is hot, we will see it eventually.
617 uint16_t hotness_count_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800618
Mathieu Chartiereace4582014-11-24 18:29:54 -0800619 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800620
621 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700622 // PACKED(4) is necessary for the correctness of
623 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800624 struct PACKED(4) PtrSizedFields {
Vladimir Marko05792b92015-08-03 11:56:49 +0100625 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
626 ArtMethod** dex_cache_resolved_methods_;
627
628 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
629 GcRoot<mirror::Class>* dex_cache_resolved_types_;
630
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100631 // Pointer to JNI function registered to this method, or a function to resolve the JNI function,
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000632 // or the profiling data for non-native methods, or an ImtConflictTable.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800633 void* entry_point_from_jni_;
634
635 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800636 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800637 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800638 } ptr_sized_fields_;
639
Mathieu Chartier02e25112013-08-14 16:14:24 -0700640 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800641 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700642 // Round up to pointer size for padding field.
643 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
644 }
645
646 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100647 ALWAYS_INLINE T GetNativePointer(MemberOffset offset, size_t pointer_size) const {
648 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700649 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
650 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
651 if (pointer_size == sizeof(uint32_t)) {
652 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
653 } else {
654 auto v = *reinterpret_cast<const uint64_t*>(addr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100655 return reinterpret_cast<T>(dchecked_integral_cast<uintptr_t>(v));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700656 }
657 }
658
659 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100660 ALWAYS_INLINE void SetNativePointer(MemberOffset offset, T new_value, size_t pointer_size) {
661 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700662 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
663 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
664 if (pointer_size == sizeof(uint32_t)) {
665 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
Vladimir Marko05792b92015-08-03 11:56:49 +0100666 *reinterpret_cast<uint32_t*>(addr) = dchecked_integral_cast<uint32_t>(ptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700667 } else {
668 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
669 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800670 }
671
Mathieu Chartiere401d142015-04-22 13:56:20 -0700672 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800673};
674
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800675} // namespace art
676
Mathieu Chartiere401d142015-04-22 13:56:20 -0700677#endif // ART_RUNTIME_ART_METHOD_H_