blob: 0da5925b6c66d20c73626bb73fa5c7ac42527b27 [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
Brian Carlstromea46f952013-07-30 01:26:50 -070017#ifndef ART_RUNTIME_MIRROR_ART_METHOD_H_
18#define ART_RUNTIME_MIRROR_ART_METHOD_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Jeff Hao790ad902013-05-22 15:02:08 -070020#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070021#include "gc_root.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "invoke_type.h"
Mathieu Chartier36b58f52014-12-10 12:06:45 -080023#include "method_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "modifiers.h"
25#include "object.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080026#include "object_callbacks.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010027#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070028#include "read_barrier_option.h"
Sebastien Hertze4b7c892014-12-17 20:02:50 +010029#include "stack.h"
Nicolas Geoffray39468442014-09-02 15:17:15 +010030#include "stack_map.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
32namespace art {
33
Brian Carlstromea46f952013-07-30 01:26:50 -070034struct ArtMethodOffsets;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035struct ConstructorMethodOffsets;
36union JValue;
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 {
42
Ian Rogerse94652f2014-12-02 11:13:19 -080043typedef void (EntryPointFromInterpreter)(Thread* self, const DexFile::CodeItem* code_item,
44 ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070045
Mathieu Chartiereace4582014-11-24 18:29:54 -080046#define ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
47
Mingyao Yang98d1cc82014-05-15 17:02:16 -070048// C++ mirror of java.lang.reflect.ArtMethod.
49class MANAGED ArtMethod FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070051 // Size of java.lang.reflect.ArtMethod.class.
52 static uint32_t ClassSize();
53
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070054 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
55 jobject jlr_method)
Ian Rogers62f05122014-03-21 11:21:29 -070056 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
57
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070058 Class* GetDeclaringClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059
60 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
61
62 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070063 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064 }
65
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070066 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080067
Ian Rogersef7d42f2014-01-06 12:55:46 -080068 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010069 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070070 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071 }
72
73 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080074 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075
76 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080077 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078 return (GetAccessFlags() & kAccPublic) != 0;
79 }
80
81 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080082 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083 return (GetAccessFlags() & kAccPrivate) != 0;
84 }
85
86 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080087 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088 return (GetAccessFlags() & kAccStatic) != 0;
89 }
90
91 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080092 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 return (GetAccessFlags() & kAccConstructor) != 0;
94 }
95
Mathieu Chartierbfd9a432014-05-21 17:43:44 -070096 // Returns true if the method is a class initializer.
97 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
98 return IsConstructor() && IsStatic();
99 }
100
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800102 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103 return IsDirect(GetAccessFlags());
104 }
105
106 static bool IsDirect(uint32_t access_flags) {
107 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
108 }
109
110 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800111 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
113 return (GetAccessFlags() & synchonized) != 0;
114 }
115
Ian Rogersef7d42f2014-01-06 12:55:46 -0800116 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800117 return (GetAccessFlags() & kAccFinal) != 0;
118 }
119
Ian Rogersef7d42f2014-01-06 12:55:46 -0800120 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800121 return (GetAccessFlags() & kAccMiranda) != 0;
122 }
123
Ian Rogersef7d42f2014-01-06 12:55:46 -0800124 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800125 return (GetAccessFlags() & kAccNative) != 0;
126 }
127
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000128 bool ShouldNotInline() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
129 return (GetAccessFlags() & kAccDontInline) != 0;
130 }
131
132 void SetShouldNotInline() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
133 SetAccessFlags(GetAccessFlags() | kAccDontInline);
134 }
135
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800137 uint32_t mask = kAccFastNative | kAccNative;
138 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700139 }
140
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142 return (GetAccessFlags() & kAccAbstract) != 0;
143 }
144
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 return (GetAccessFlags() & kAccSynthetic) != 0;
147 }
148
Ian Rogersef7d42f2014-01-06 12:55:46 -0800149 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150
Ian Rogersef7d42f2014-01-06 12:55:46 -0800151 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200152 return (GetAccessFlags() & kAccPreverified) != 0;
153 }
154
Ian Rogersef7d42f2014-01-06 12:55:46 -0800155 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
156 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200157 SetAccessFlags(GetAccessFlags() | kAccPreverified);
158 }
159
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800160 bool IsOptimized(size_t pointer_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100161 // Temporary solution for detecting if a method has been optimized: the compiler
162 // does not create a GC map. Instead, the vmap table contains the stack map
163 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000164 return !IsNative()
165 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800166 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800167 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100168 }
169
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
171
Ian Rogersef7d42f2014-01-06 12:55:46 -0800172 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700174 // Doesn't do erroneous / unresolved class checks.
175 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
176
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 return GetMethodIndex();
179 }
180
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100182 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700183 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 }
185
Vladimir Markoc1363122015-04-09 14:13:13 +0100186 static MemberOffset DexMethodIndexOffset() {
187 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_);
188 }
189
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700191 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 }
193
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700195 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700198 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100199 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700200 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 }
202
203 // Number of 32bit registers that would be required to hold all the arguments
204 static size_t NumArgRegisters(const StringPiece& shorty);
205
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700206 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700208 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100209 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700210 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 }
212
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800213 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700214 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 }
216
217 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700218 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 }
220
Vladimir Markoc1363122015-04-09 14:13:13 +0100221 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700223 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700225 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700227 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800228 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700229 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
230 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
231 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233
Andreas Gampe58a5af82014-07-31 16:23:49 -0700234 template <bool kWithCheck = true>
235 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700238 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
239 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
240 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242
Ian Rogersa0485602014-12-02 15:48:04 -0800243 // Get the Class* from the type index into this method's dex cache.
244 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
246
Ian Rogerse0a02da2014-12-02 14:10:53 -0800247 // Find the method that this method overrides.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800248 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800249
Ian Rogerse0a02da2014-12-02 14:10:53 -0800250 // Find the method index for this method within other_dexfile. If this method isn't present then
251 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
252 // name and signature in the other_dexfile, such as the method index used to resolve this method
253 // in the other_dexfile.
254 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
255 uint32_t name_and_signature_idx)
256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
257
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700258 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
259 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260
Mathieu Chartier4e305412014-02-19 10:54:44 -0800261 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700262 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800264 CheckObjectSizeEqualsMirrorSize();
265 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
266 }
267 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
268 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
270 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
271 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700272 }
273
Mathieu Chartier2d721012014-11-10 11:08:06 -0800274 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700275 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800277 CheckObjectSizeEqualsMirrorSize();
278 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
279 }
280 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
281 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
282 size_t pointer_size)
283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
284 SetFieldPtrWithSize<false, true, kVerifyFlags>(
285 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700286 }
287
Mathieu Chartier2d721012014-11-10 11:08:06 -0800288 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700289 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800290 CheckObjectSizeEqualsMirrorSize();
291 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
292 }
293 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
294 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
296 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
297 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800298 }
299
Mathieu Chartier2d721012014-11-10 11:08:06 -0800300 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700301 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
302 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800303 CheckObjectSizeEqualsMirrorSize();
304 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
305 sizeof(void*));
306 }
307 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
308 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
309 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
311 SetFieldPtrWithSize<false, true, kVerifyFlags>(
312 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
313 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 }
315
Ian Rogersef7d42f2014-01-06 12:55:46 -0800316 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700318 // Check whether the given PC is within the quick compiled code associated with this method's
319 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
320 // debug purposes.
321 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800322 return PcIsWithinQuickCode(
323 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800324 }
325
Ian Rogersef7d42f2014-01-06 12:55:46 -0800326 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700328 // Returns true if the entrypoint points to the interpreter, as
329 // opposed to the compiled code, that is, this method will be
330 // interpretered on invocation.
331 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
332
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700333 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700334 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800335
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700336 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100337 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700338 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
339 // least 2 byte aligned.
340 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100341 return reinterpret_cast<const void*>(code);
342 }
343
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700344 // Actual entry point pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800345 const void* GetQuickOatEntryPoint(size_t pointer_size)
346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700347 // Actual pointer to compiled oat code or null.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800348 const void* GetQuickOatCodePointer(size_t pointer_size)
349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
350 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700351 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100352
Ian Rogers1809a722013-08-09 22:05:32 -0700353 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800354 const uint8_t* GetMappingTable(size_t pointer_size)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
356 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100357 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358
Ian Rogers1809a722013-08-09 22:05:32 -0700359 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800360 const uint8_t* GetVmapTable(size_t pointer_size)
361 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
362 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100363 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100365 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100366
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800367 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
368 const uint8_t* GetNativeGcMap(size_t pointer_size)
369 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
370 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372
Andreas Gampe90546832014-03-12 18:07:19 -0700373 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700374 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100375 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700376 if (kCheckFrameSize) {
377 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
378 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379 return result;
380 }
381
Vladimir Marko7624d252014-05-02 14:40:15 +0100382 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100383 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
384 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800385
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700386 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
387 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100388 }
389
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700390 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
392 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700393 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800394 }
395
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700396 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100397 constexpr size_t handle_scope_offset = sizeof(StackReference<mirror::ArtMethod>);
398 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
399 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800400 }
401
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700402 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
404
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700405 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406
Mathieu Chartier2d721012014-11-10 11:08:06 -0800407 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800408 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800409 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410 }
411
Mathieu Chartier2d721012014-11-10 11:08:06 -0800412 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800413 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800414 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415 }
416
Mathieu Chartier2d721012014-11-10 11:08:06 -0800417 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800418 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800419 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
420 }
421
Mathieu Chartier2d721012014-11-10 11:08:06 -0800422 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
423 CheckObjectSizeEqualsMirrorSize();
424 return GetEntryPointFromJniPtrSize(sizeof(void*));
425 }
426 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
428 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
429 }
430
431 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
432 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
433 CheckObjectSizeEqualsMirrorSize();
434 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
435 }
436 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
437 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
438 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
439 SetFieldPtrWithSize<false, true, kVerifyFlags>(
440 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
441 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800443 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
444 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800445 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800446
447 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800448 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449
Ian Rogersef7d42f2014-01-06 12:55:46 -0800450 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451
Ian Rogersef7d42f2014-01-06 12:55:46 -0800452 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700453
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700454 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
455
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700456 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
457#ifdef NDEBUG
458 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
459 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
460 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
461 }
462#else
463 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700465#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800466
467 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800468 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
469 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800470
471 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000472 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
473 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800475 MethodReference ToMethodReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
476 return MethodReference(GetDexFile(), GetDexMethodIndex());
477 }
478
Ian Rogersc449aa82013-07-29 14:35:46 -0700479 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
480 // indicates whether the found catch block is responsible for clearing the exception or whether
481 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700482 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
483 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
485
Brian Carlstromea46f952013-07-30 01:26:50 -0700486 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800487
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700488 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700489 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490
Brian Carlstromea46f952013-07-30 01:26:50 -0700491 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700493 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800494 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
495
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700496 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700498 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700500 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
501 uint32_t unused_length;
502 return GetShorty(&unused_length);
503 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700504
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700505 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700506
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700507 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700508
Ian Rogers1ff3c982014-08-12 02:30:58 -0700509 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700510
Ian Rogers6b14d552014-10-28 21:50:58 -0700511 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
512
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700513 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700514
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700515 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700516
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700517 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700518
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700519 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700520
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700521 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700522
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700523 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700524
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700525 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700526
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700527 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700528
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700529 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700530
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700531 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
532 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700533
Ian Rogersded66a02014-10-28 18:12:55 -0700534 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
535 // number of bugs at call sites.
536 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
537
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700538 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700539
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700540 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700541
Ian Rogers1ff3c982014-08-12 02:30:58 -0700542 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700543
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700544 // May cause thread suspension due to class resolution.
545 bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params)
546 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
547
Mathieu Chartiereace4582014-11-24 18:29:54 -0800548 static size_t SizeWithoutPointerFields(size_t pointer_size) {
549 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
550#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
551 // Add 4 bytes if 64 bit, otherwise 0.
552 total += pointer_size - sizeof(uint32_t);
553#endif
554 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800555 }
556
557 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
558 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800559 return SizeWithoutPointerFields(pointer_size) +
560 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800561 }
562
563 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800564 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800565 // The class we are a part of.
566 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567
Ian Rogersef7d42f2014-01-06 12:55:46 -0800568 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700569 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800570
Ian Rogersef7d42f2014-01-06 12:55:46 -0800571 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700572 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800573
Ian Rogersef7d42f2014-01-06 12:55:46 -0800574 // Access flags; low 16 bits are defined by spec.
575 uint32_t access_flags_;
576
577 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
578
579 // Offset to the CodeItem.
580 uint32_t dex_code_item_offset_;
581
582 // Index into method_ids of the dex file associated with this method.
583 uint32_t dex_method_index_;
584
585 /* End of dex file fields. */
586
587 // Entry within a dispatch table for this method. For static/direct methods the index is into
588 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
589 // ifTable.
590 uint32_t method_index_;
591
Mathieu Chartiereace4582014-11-24 18:29:54 -0800592 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800593
594 // Must be the last fields in the method.
595 struct PACKED(4) PtrSizedFields {
596 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
597 // compiled code.
598 void* entry_point_from_interpreter_;
599
600 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
601 void* entry_point_from_jni_;
602
603 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800604 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800605 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800606 } ptr_sized_fields_;
607
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700608 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800609
Mathieu Chartier02e25112013-08-14 16:14:24 -0700610 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800611 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
612
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700613 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
614 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700615
Mathieu Chartiereace4582014-11-24 18:29:54 -0800616 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
617 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
618#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
619 // Add 4 bytes if 64 bit, otherwise 0.
620 offset += pointer_size - sizeof(uint32_t);
621#endif
622 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800623 }
624
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800625 // Code points to the start of the quick code.
626 static uint32_t GetCodeSize(const void* code);
627
628 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
629 if (code == 0) {
630 return pc == 0;
631 }
632 /*
633 * During a stack walk, a return PC may point past-the-end of the code
634 * in the case that the last instruction is a call that isn't expected to
635 * return. Thus, we check <= code + GetCodeSize().
636 *
637 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
638 */
639 return code <= pc && pc <= code + GetCodeSize(
640 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
641 }
642
Brian Carlstromea46f952013-07-30 01:26:50 -0700643 friend struct art::ArtMethodOffsets; // for verifying offset information
644 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800645};
646
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800647} // namespace mirror
648} // namespace art
649
Brian Carlstromea46f952013-07-30 01:26:50 -0700650#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_