blob: ae60447c412f1e177abc0d75e259d5876ab7a180 [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
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -070071 // num_entries excludes the header.
72 explicit ImtConflictTable(size_t num_entries) {
73 entries_[num_entries].interface_method = nullptr;
74 entries_[num_entries].implementation_method = nullptr;
75 }
76
77 // Set an entry at an index.
78 void SetInterfaceMethod(size_t index, ArtMethod* method) {
79 entries_[index].interface_method = method;
80 }
81
82 void SetImplementationMethod(size_t index, ArtMethod* method) {
83 entries_[index].implementation_method = method;
84 }
85
86 ArtMethod* GetInterfaceMethod(size_t index) const {
87 return entries_[index].interface_method;
88 }
89
90 ArtMethod* GetImplementationMethod(size_t index) const {
91 return entries_[index].implementation_method;
92 }
93
Nicolas Geoffray796d6302016-03-13 22:22:31 +000094 // Lookup the implementation ArtMethod associated to `interface_method`. Return null
95 // if not found.
96 ArtMethod* Lookup(ArtMethod* interface_method) const {
97 uint32_t table_index = 0;
98 ArtMethod* current_interface_method;
99 while ((current_interface_method = entries_[table_index].interface_method) != nullptr) {
100 if (current_interface_method == interface_method) {
101 return entries_[table_index].implementation_method;
102 }
103 table_index++;
104 }
105 return nullptr;
106 }
107
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700108 // Compute the number of entries in this table.
109 size_t NumEntries() const {
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000110 uint32_t table_index = 0;
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700111 while (entries_[table_index].interface_method != nullptr) {
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000112 table_index++;
113 }
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700114 return table_index;
115 }
116
117 // Compute the size in bytes taken by this table.
118 size_t ComputeSize() const {
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000119 // Add the end marker.
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700120 return ComputeSize(NumEntries());
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000121 }
122
123 // Compute the size in bytes needed for copying the given `table` and add
124 // one more entry.
125 static size_t ComputeSizeWithOneMoreEntry(ImtConflictTable* table) {
126 return table->ComputeSize() + sizeof(Entry);
127 }
128
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700129 // Compute size with a fixed number of entries.
130 static size_t ComputeSize(size_t num_entries) {
131 return (num_entries + 1) * sizeof(Entry); // Add one for null terminator.
132 }
133
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000134 struct Entry {
135 ArtMethod* interface_method;
136 ArtMethod* implementation_method;
137 };
138
139 private:
140 // Array of entries that the assembly stubs will iterate over. Note that this is
141 // not fixed size, and we allocate data prior to calling the constructor
142 // of ImtConflictTable.
143 Entry entries_[0];
144
145 DISALLOW_COPY_AND_ASSIGN(ImtConflictTable);
146};
147
Mathieu Chartiere401d142015-04-22 13:56:20 -0700148class ArtMethod FINAL {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800149 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700150 ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0),
151 method_index_(0) { }
152
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000153 ArtMethod(ArtMethod* src, size_t image_pointer_size) {
154 CopyFrom(src, image_pointer_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700155 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700156
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700157 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
158 jobject jlr_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700159 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62f05122014-03-21 11:21:29 -0700160
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800161 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700162 ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800164 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700165 ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked()
Mathieu Chartier90443472015-07-16 20:32:27 -0700166 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700167
168 void SetDeclaringClass(mirror::Class *new_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700169 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170
Mathieu Chartier10e5ea92015-08-13 12:56:31 -0700171 bool CASDeclaringClass(mirror::Class* expected_class, mirror::Class* desired_class)
172 SHARED_REQUIRES(Locks::mutator_lock_);
173
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700175 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176 }
177
Andreas Gampecbc96b82015-09-30 20:05:24 +0000178 // Note: GetAccessFlags acquires the mutator lock in debug mode to check that it is not called for
179 // a proxy method.
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800180 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampecbc96b82015-09-30 20:05:24 +0000181 ALWAYS_INLINE uint32_t GetAccessFlags();
Jeff Hao5d917302013-02-27 17:57:33 -0800182
Mathieu Chartiere401d142015-04-22 13:56:20 -0700183 void SetAccessFlags(uint32_t new_access_flags) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100184 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700185 access_flags_ = new_access_flags;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 }
187
188 // Approximate what kind of method call would be used for this method.
Mathieu Chartier90443472015-07-16 20:32:27 -0700189 InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190
191 // Returns true if the method is declared public.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000192 bool IsPublic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 return (GetAccessFlags() & kAccPublic) != 0;
194 }
195
196 // Returns true if the method is declared private.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000197 bool IsPrivate() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198 return (GetAccessFlags() & kAccPrivate) != 0;
199 }
200
201 // Returns true if the method is declared static.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000202 bool IsStatic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203 return (GetAccessFlags() & kAccStatic) != 0;
204 }
205
206 // Returns true if the method is a constructor.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000207 bool IsConstructor() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800208 return (GetAccessFlags() & kAccConstructor) != 0;
209 }
210
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700211 // Returns true if the method is a class initializer.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000212 bool IsClassInitializer() {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700213 return IsConstructor() && IsStatic();
214 }
215
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216 // Returns true if the method is static, private, or a constructor.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000217 bool IsDirect() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800218 return IsDirect(GetAccessFlags());
219 }
220
221 static bool IsDirect(uint32_t access_flags) {
Andreas Gampecbc96b82015-09-30 20:05:24 +0000222 constexpr uint32_t direct = kAccStatic | kAccPrivate | kAccConstructor;
223 return (access_flags & direct) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224 }
225
226 // Returns true if the method is declared synchronized.
Andreas Gampecbc96b82015-09-30 20:05:24 +0000227 bool IsSynchronized() {
228 constexpr uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800229 return (GetAccessFlags() & synchonized) != 0;
230 }
231
Andreas Gampecbc96b82015-09-30 20:05:24 +0000232 bool IsFinal() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233 return (GetAccessFlags() & kAccFinal) != 0;
234 }
235
Alex Light36121492016-02-22 13:43:29 -0800236 bool IsCopied() {
237 const bool copied = (GetAccessFlags() & kAccCopied) != 0;
238 // (IsMiranda() || IsDefaultConflicting()) implies copied
239 DCHECK(!(IsMiranda() || IsDefaultConflicting()) || copied)
240 << "Miranda or default-conflict methods must always be copied.";
241 return copied;
Alex Lightfcea56f2016-02-17 11:59:05 -0800242 }
243
Andreas Gampecbc96b82015-09-30 20:05:24 +0000244 bool IsMiranda() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800245 return (GetAccessFlags() & kAccMiranda) != 0;
246 }
247
Alex Light9139e002015-10-09 15:59:48 -0700248 // Returns true if invoking this method will not throw an AbstractMethodError or
249 // IncompatibleClassChangeError.
250 bool IsInvokable() {
251 return !IsAbstract() && !IsDefaultConflicting();
252 }
253
Nicolas Geoffray250a3782016-04-20 16:27:53 +0100254 bool IsCompilable() {
255 return (GetAccessFlags() & kAccCompileDontBother) == 0;
256 }
257
Alex Light9139e002015-10-09 15:59:48 -0700258 // A default conflict method is a special sentinel method that stands for a conflict between
259 // multiple default methods. It cannot be invoked, throwing an IncompatibleClassChangeError if one
260 // attempts to do so.
261 bool IsDefaultConflicting() {
262 return (GetAccessFlags() & kAccDefaultConflict) != 0u;
263 }
264
Alex Lighteb7c1442015-08-31 13:17:42 -0700265 // This is set by the class linker.
266 bool IsDefault() {
267 return (GetAccessFlags() & kAccDefault) != 0;
268 }
269
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800270 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampecbc96b82015-09-30 20:05:24 +0000271 bool IsNative() {
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800272 return (GetAccessFlags<kReadBarrierOption>() & kAccNative) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800273 }
274
Andreas Gampecbc96b82015-09-30 20:05:24 +0000275 bool IsFastNative() {
276 constexpr uint32_t mask = kAccFastNative | kAccNative;
Ian Rogers16ce0922014-01-10 14:59:36 -0800277 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700278 }
279
Andreas Gampecbc96b82015-09-30 20:05:24 +0000280 bool IsAbstract() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800281 return (GetAccessFlags() & kAccAbstract) != 0;
282 }
283
Andreas Gampecbc96b82015-09-30 20:05:24 +0000284 bool IsSynthetic() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285 return (GetAccessFlags() & kAccSynthetic) != 0;
286 }
287
Mathieu Chartier90443472015-07-16 20:32:27 -0700288 bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800289
Igor Murashkindf707e42016-02-02 16:56:50 -0800290 bool SkipAccessChecks() {
291 return (GetAccessFlags() & kAccSkipAccessChecks) != 0;
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200292 }
293
Igor Murashkindf707e42016-02-02 16:56:50 -0800294 void SetSkipAccessChecks() {
295 DCHECK(!SkipAccessChecks());
296 SetAccessFlags(GetAccessFlags() | kAccSkipAccessChecks);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200297 }
298
Alex Lighteb7c1442015-08-31 13:17:42 -0700299 // Returns true if this method could be overridden by a default method.
Alex Light9139e002015-10-09 15:59:48 -0700300 bool IsOverridableByDefaultMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Alex Lighteb7c1442015-08-31 13:17:42 -0700301
Mathieu Chartier90443472015-07-16 20:32:27 -0700302 bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303
Alex Light9139e002015-10-09 15:59:48 -0700304 // Throws the error that would result from trying to invoke this method (i.e.
305 // IncompatibleClassChangeError or AbstractMethodError). Only call if !IsInvokable();
306 void ThrowInvocationTimeError() SHARED_REQUIRES(Locks::mutator_lock_);
307
Mathieu Chartier90443472015-07-16 20:32:27 -0700308 uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700310 // Doesn't do erroneous / unresolved class checks.
Mathieu Chartier90443472015-07-16 20:32:27 -0700311 uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700312
Mathieu Chartier90443472015-07-16 20:32:27 -0700313 size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314 return GetMethodIndex();
315 }
316
Mathieu Chartier90443472015-07-16 20:32:27 -0700317 void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100318 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700319 method_index_ = new_method_index;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 }
321
Vladimir Markoc1363122015-04-09 14:13:13 +0100322 static MemberOffset DexMethodIndexOffset() {
323 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
324 }
325
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800326 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700327 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800328 }
329
Mathieu Chartiere401d142015-04-22 13:56:20 -0700330 uint32_t GetCodeItemOffset() {
331 return dex_code_item_offset_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800332 }
333
Mathieu Chartiere401d142015-04-22 13:56:20 -0700334 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100335 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700336 dex_code_item_offset_ = new_code_off;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800337 }
338
339 // Number of 32bit registers that would be required to hold all the arguments
340 static size_t NumArgRegisters(const StringPiece& shorty);
341
Mathieu Chartier90443472015-07-16 20:32:27 -0700342 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800343
Mathieu Chartiere401d142015-04-22 13:56:20 -0700344 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100345 // Not called within a transaction.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700346 dex_method_index_ = new_idx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 }
348
Vladimir Marko05792b92015-08-03 11:56:49 +0100349 ALWAYS_INLINE ArtMethod** GetDexCacheResolvedMethods(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100351 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700352 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100353 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_index,
354 ArtMethod* new_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700355 size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700356 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100357 ALWAYS_INLINE void SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700358 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100359 bool HasDexCacheResolvedMethods(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
360 bool HasSameDexCacheResolvedMethods(ArtMethod* other, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700361 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100362 bool HasSameDexCacheResolvedMethods(ArtMethod** other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700363 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364
Andreas Gampe58a5af82014-07-31 16:23:49 -0700365 template <bool kWithCheck = true>
Vladimir Marko05792b92015-08-03 11:56:49 +0100366 mirror::Class* GetDexCacheResolvedType(uint32_t type_idx, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700367 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100368 void SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700369 SHARED_REQUIRES(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100370 bool HasDexCacheResolvedTypes(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_);
371 bool HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size)
372 SHARED_REQUIRES(Locks::mutator_lock_);
373 bool HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700374 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375
Ian Rogersa0485602014-12-02 15:48:04 -0800376 // Get the Class* from the type index into this method's dex cache.
Vladimir Marko05792b92015-08-03 11:56:49 +0100377 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve, size_t ptr_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700378 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersa0485602014-12-02 15:48:04 -0800379
Alex Light6c8467f2015-11-20 15:03:26 -0800380 // Returns true if this method has the same name and signature of the other method.
381 bool HasSameNameAndSignature(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_);
382
Ian Rogerse0a02da2014-12-02 14:10:53 -0800383 // Find the method that this method overrides.
Alex Light705ad492015-09-21 11:36:30 -0700384 ArtMethod* FindOverriddenMethod(size_t pointer_size)
385 REQUIRES(Roles::uninterruptible_)
386 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800387
Ian Rogerse0a02da2014-12-02 14:10:53 -0800388 // Find the method index for this method within other_dexfile. If this method isn't present then
389 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
390 // name and signature in the other_dexfile, such as the method index used to resolve this method
391 // in the other_dexfile.
392 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
393 uint32_t name_and_signature_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700394 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800395
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700396 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
Mathieu Chartier90443472015-07-16 20:32:27 -0700397 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800398
Mathieu Chartiere401d142015-04-22 13:56:20 -0700399 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800400 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
401 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700402 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100403 return GetNativePointer<const void*>(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800404 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800405 }
406
Mathieu Chartiere401d142015-04-22 13:56:20 -0700407 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800408 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
409 sizeof(void*));
410 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800411 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
Mathieu Chartiere401d142015-04-22 13:56:20 -0700412 const void* entry_point_from_quick_compiled_code, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100413 SetNativePointer(EntryPointFromQuickCompiledCodeOffset(pointer_size),
414 entry_point_from_quick_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800415 }
416
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700417 void RegisterNative(const void* native_method, bool is_fast)
Mathieu Chartier90443472015-07-16 20:32:27 -0700418 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800419
Mathieu Chartier90443472015-07-16 20:32:27 -0700420 void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421
Vladimir Marko05792b92015-08-03 11:56:49 +0100422 static MemberOffset DexCacheResolvedMethodsOffset(size_t pointer_size) {
423 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
424 PtrSizedFields, dex_cache_resolved_methods_) / sizeof(void*) * pointer_size);
425 }
426
427 static MemberOffset DexCacheResolvedTypesOffset(size_t pointer_size) {
428 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
429 PtrSizedFields, dex_cache_resolved_types_) / sizeof(void*) * pointer_size);
430 }
431
Mathieu Chartier2d721012014-11-10 11:08:06 -0800432 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800433 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800434 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800435 }
436
Mathieu Chartier2d721012014-11-10 11:08:06 -0800437 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800438 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800439 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
440 }
441
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700442 ProfilingInfo* GetProfilingInfo(size_t pointer_size) {
443 return reinterpret_cast<ProfilingInfo*>(GetEntryPointFromJniPtrSize(pointer_size));
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100444 }
445
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000446 ImtConflictTable* GetImtConflictTable(size_t pointer_size) {
447 DCHECK(IsRuntimeMethod());
448 return reinterpret_cast<ImtConflictTable*>(GetEntryPointFromJniPtrSize(pointer_size));
449 }
450
451 ALWAYS_INLINE void SetImtConflictTable(ImtConflictTable* table) {
452 SetEntryPointFromJniPtrSize(table, sizeof(void*));
453 }
454
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000455 ALWAYS_INLINE void SetProfilingInfo(ProfilingInfo* info) {
456 SetEntryPointFromJniPtrSize(info, sizeof(void*));
457 }
458
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000459 ALWAYS_INLINE void SetProfilingInfoPtrSize(ProfilingInfo* info, size_t pointer_size) {
460 SetEntryPointFromJniPtrSize(info, pointer_size);
461 }
462
Nicolas Geoffray26705e22015-10-28 12:50:11 +0000463 static MemberOffset ProfilingInfoOffset() {
464 return EntryPointFromJniOffset(sizeof(void*));
465 }
466
Mathieu Chartiere401d142015-04-22 13:56:20 -0700467 void* GetEntryPointFromJni() {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800468 return GetEntryPointFromJniPtrSize(sizeof(void*));
469 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100470
Mathieu Chartiere401d142015-04-22 13:56:20 -0700471 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100472 return GetNativePointer<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800473 }
474
Andreas Gampecbc96b82015-09-30 20:05:24 +0000475 void SetEntryPointFromJni(const void* entrypoint) {
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100476 DCHECK(IsNative());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700477 SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800478 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100479
Mathieu Chartiere401d142015-04-22 13:56:20 -0700480 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100481 SetNativePointer(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800482 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800483
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
485 // conventions for a method of managed code. Returns false for Proxy methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700486 ALWAYS_INLINE bool IsRuntimeMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800487
488 // Is this a hand crafted method used for something like describing callee saves?
Mathieu Chartier90443472015-07-16 20:32:27 -0700489 bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490
Mathieu Chartier90443472015-07-16 20:32:27 -0700491 bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492
Mathieu Chartier90443472015-07-16 20:32:27 -0700493 bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700494
Mathieu Chartier90443472015-07-16 20:32:27 -0700495 MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800496 return MethodReference(GetDexFile(), GetDexMethodIndex());
497 }
498
Ian Rogersc449aa82013-07-29 14:35:46 -0700499 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
500 // indicates whether the found catch block is responsible for clearing the exception or whether
501 // a move-exception instruction is present.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700502 uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc,
503 bool* has_no_move_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700504 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800505
Mathieu Chartierda7c6502015-07-23 16:01:26 -0700506 // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700507 template<typename RootVisitorType>
Mathieu Chartier1147b9b2015-09-14 18:50:08 -0700508 void VisitRoots(RootVisitorType& visitor, size_t pointer_size) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800509
Mathieu Chartier90443472015-07-16 20:32:27 -0700510 const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700511
Mathieu Chartier90443472015-07-16 20:32:27 -0700512 const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700513
Mathieu Chartier90443472015-07-16 20:32:27 -0700514 const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700515 uint32_t unused_length;
516 return GetShorty(&unused_length);
517 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700518
Mathieu Chartier90443472015-07-16 20:32:27 -0700519 const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700520
Mathieu Chartier90443472015-07-16 20:32:27 -0700521 const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700522
Mathieu Chartier90443472015-07-16 20:32:27 -0700523 ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700524
Mathieu Chartier90443472015-07-16 20:32:27 -0700525 mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6b14d552014-10-28 21:50:58 -0700526
Mathieu Chartier90443472015-07-16 20:32:27 -0700527 const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700528
Vladimir Marko05792b92015-08-03 11:56:49 +0100529 bool IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700530
Mathieu Chartier90443472015-07-16 20:32:27 -0700531 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700532
Mathieu Chartier90443472015-07-16 20:32:27 -0700533 const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700534
Mathieu Chartier90443472015-07-16 20:32:27 -0700535 const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700536
Mathieu Chartier90443472015-07-16 20:32:27 -0700537 const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700538
Mathieu Chartier90443472015-07-16 20:32:27 -0700539 uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700540
Mathieu Chartier90443472015-07-16 20:32:27 -0700541 const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700542
Mathieu Chartier90443472015-07-16 20:32:27 -0700543 const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700544
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700545 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700546 SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700547
Ian Rogersded66a02014-10-28 18:12:55 -0700548 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
549 // number of bugs at call sites.
Vladimir Marko05792b92015-08-03 11:56:49 +0100550 mirror::Class* GetReturnType(bool resolve, size_t ptr_size)
551 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersded66a02014-10-28 18:12:55 -0700552
Mathieu Chartier90443472015-07-16 20:32:27 -0700553 mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700554
Mathieu Chartier90443472015-07-16 20:32:27 -0700555 mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700556
Mathieu Chartiere401d142015-04-22 13:56:20 -0700557 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700558 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700559
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700560 // May cause thread suspension due to class resolution.
561 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
Mathieu Chartier90443472015-07-16 20:32:27 -0700562 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700563
Vladimir Marko14632852015-08-17 12:07:23 +0100564 // Size of an instance of this native class.
565 static size_t Size(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700566 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) +
Mathieu Chartiereace4582014-11-24 18:29:54 -0800567 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800568 }
569
Vladimir Marko14632852015-08-17 12:07:23 +0100570 // Alignment of an instance of this native class.
571 static size_t Alignment(size_t pointer_size) {
Vladimir Markocf36d492015-08-12 19:27:26 +0100572 // The ArtMethod alignment is the same as image pointer size. This differs from
Vladimir Marko14632852015-08-17 12:07:23 +0100573 // alignof(ArtMethod) if cross-compiling with pointer_size != sizeof(void*).
Vladimir Markocf36d492015-08-12 19:27:26 +0100574 return pointer_size;
575 }
576
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000577 void CopyFrom(ArtMethod* src, size_t image_pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700578 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700579
Vladimir Marko05792b92015-08-03 11:56:49 +0100580 ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700581 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700582
Bill Buzbee1d011d92016-04-04 16:59:29 +0000583 // Note, hotness_counter_ updates are non-atomic but it doesn't need to be precise. Also,
584 // given that the counter is only 16 bits wide we can expect wrap-around in some
585 // situations. Consumers of hotness_count_ must be able to deal with that.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100586 uint16_t IncrementCounter() {
587 return ++hotness_count_;
588 }
589
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100590 void ClearCounter() {
591 hotness_count_ = 0;
592 }
593
Bill Buzbee1d011d92016-04-04 16:59:29 +0000594 void SetCounter(int16_t hotness_count) {
595 hotness_count_ = hotness_count;
596 }
597
598 uint16_t GetCounter() const {
599 return hotness_count_;
600 }
601
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100602 const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
603
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100604 // Returns the method header for the compiled code containing 'pc'. Note that runtime
605 // methods will return null for this method, as they are not oat based.
606 const OatQuickMethodHeader* GetOatQuickMethodHeader(uintptr_t pc)
607 SHARED_REQUIRES(Locks::mutator_lock_);
608
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000609 // Returns whether the method has any compiled code, JIT or AOT.
610 bool HasAnyCompiledCode() SHARED_REQUIRES(Locks::mutator_lock_);
611
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800612
613 // Update heap objects and non-entrypoint pointers by the passed in visitor for image relocation.
614 // Does not use read barrier.
615 template <typename Visitor>
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800616 ALWAYS_INLINE void UpdateObjectsForImageRelocation(const Visitor& visitor, size_t pointer_size)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800617 SHARED_REQUIRES(Locks::mutator_lock_);
618
619 // Update entry points by passing them through the visitor.
Mathieu Chartiere7f75f32016-02-01 16:08:15 -0800620 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor>
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800621 ALWAYS_INLINE void UpdateEntrypoints(const Visitor& visitor, size_t pointer_size);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800622
Mathieu Chartier2d721012014-11-10 11:08:06 -0800623 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800624 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800625 // The class we are a part of.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700626 GcRoot<mirror::Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800627
Ian Rogersef7d42f2014-01-06 12:55:46 -0800628 // Access flags; low 16 bits are defined by spec.
629 uint32_t access_flags_;
630
631 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
632
633 // Offset to the CodeItem.
634 uint32_t dex_code_item_offset_;
635
636 // Index into method_ids of the dex file associated with this method.
637 uint32_t dex_method_index_;
638
639 /* End of dex file fields. */
640
641 // Entry within a dispatch table for this method. For static/direct methods the index is into
642 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
643 // ifTable.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100644 uint16_t method_index_;
645
Bill Buzbee1d011d92016-04-04 16:59:29 +0000646 // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100647 // missing increments: if the method is hot, we will see it eventually.
648 uint16_t hotness_count_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800649
Mathieu Chartiereace4582014-11-24 18:29:54 -0800650 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800651
652 // Must be the last fields in the method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700653 // PACKED(4) is necessary for the correctness of
654 // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size).
Mathieu Chartier2d721012014-11-10 11:08:06 -0800655 struct PACKED(4) PtrSizedFields {
Vladimir Marko05792b92015-08-03 11:56:49 +0100656 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
657 ArtMethod** dex_cache_resolved_methods_;
658
659 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
660 GcRoot<mirror::Class>* dex_cache_resolved_types_;
661
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100662 // Pointer to JNI function registered to this method, or a function to resolve the JNI function,
Nicolas Geoffray796d6302016-03-13 22:22:31 +0000663 // or the profiling data for non-native methods, or an ImtConflictTable.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800664 void* entry_point_from_jni_;
665
666 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800667 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800668 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800669 } ptr_sized_fields_;
670
Mathieu Chartier02e25112013-08-14 16:14:24 -0700671 private:
Mathieu Chartiereace4582014-11-24 18:29:54 -0800672 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700673 // Round up to pointer size for padding field.
674 return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size);
675 }
676
677 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100678 ALWAYS_INLINE T GetNativePointer(MemberOffset offset, size_t pointer_size) const {
679 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700680 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
681 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
682 if (pointer_size == sizeof(uint32_t)) {
683 return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr));
684 } else {
685 auto v = *reinterpret_cast<const uint64_t*>(addr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100686 return reinterpret_cast<T>(dchecked_integral_cast<uintptr_t>(v));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700687 }
688 }
689
690 template<typename T>
Vladimir Marko05792b92015-08-03 11:56:49 +0100691 ALWAYS_INLINE void SetNativePointer(MemberOffset offset, T new_value, size_t pointer_size) {
692 static_assert(std::is_pointer<T>::value, "T must be a pointer type");
Mathieu Chartiere401d142015-04-22 13:56:20 -0700693 DCHECK(ValidPointerSize(pointer_size)) << pointer_size;
694 const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value();
695 if (pointer_size == sizeof(uint32_t)) {
696 uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value);
Vladimir Marko05792b92015-08-03 11:56:49 +0100697 *reinterpret_cast<uint32_t*>(addr) = dchecked_integral_cast<uint32_t>(ptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700698 } else {
699 *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value);
700 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800701 }
702
Mathieu Chartiere401d142015-04-22 13:56:20 -0700703 DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800704};
705
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800706} // namespace art
707
Mathieu Chartiere401d142015-04-22 13:56:20 -0700708#endif // ART_RUNTIME_ART_METHOD_H_