blob: 82e5d0037760a0513e6321ca039eb83554ef1406 [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
186 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700187 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 }
189
Ian Rogersef7d42f2014-01-06 12:55:46 -0800190 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700191 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 }
193
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700194 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100195 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700196 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197 }
198
199 // Number of 32bit registers that would be required to hold all the arguments
200 static size_t NumArgRegisters(const StringPiece& shorty);
201
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700202 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700204 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100205 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700206 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 }
208
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700210 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 }
212
213 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700214 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 }
216
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700217 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700219 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700220 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700221 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700223 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
224 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
225 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227
Andreas Gampe58a5af82014-07-31 16:23:49 -0700228 template <bool kWithCheck = true>
229 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700232 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
233 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
234 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
235 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236
Ian Rogersa0485602014-12-02 15:48:04 -0800237 // Get the Class* from the type index into this method's dex cache.
238 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
240
Ian Rogerse0a02da2014-12-02 14:10:53 -0800241 // Find the method that this method overrides.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243
Ian Rogerse0a02da2014-12-02 14:10:53 -0800244 // Find the method index for this method within other_dexfile. If this method isn't present then
245 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
246 // name and signature in the other_dexfile, such as the method index used to resolve this method
247 // in the other_dexfile.
248 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
249 uint32_t name_and_signature_idx)
250 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
251
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700252 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
253 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800254
Mathieu Chartier4e305412014-02-19 10:54:44 -0800255 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700256 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800258 CheckObjectSizeEqualsMirrorSize();
259 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
260 }
261 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
262 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
264 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
265 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700266 }
267
Mathieu Chartier2d721012014-11-10 11:08:06 -0800268 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700269 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
270 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800271 CheckObjectSizeEqualsMirrorSize();
272 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
273 }
274 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
275 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
276 size_t pointer_size)
277 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
278 SetFieldPtrWithSize<false, true, kVerifyFlags>(
279 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700280 }
281
Mathieu Chartier2d721012014-11-10 11:08:06 -0800282 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700283 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800284 CheckObjectSizeEqualsMirrorSize();
285 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
286 }
287 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
288 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
289 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
290 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
291 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800292 }
293
Mathieu Chartier2d721012014-11-10 11:08:06 -0800294 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700295 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800297 CheckObjectSizeEqualsMirrorSize();
298 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
299 sizeof(void*));
300 }
301 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
302 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
303 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
305 SetFieldPtrWithSize<false, true, kVerifyFlags>(
306 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
307 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800308 }
309
Ian Rogersef7d42f2014-01-06 12:55:46 -0800310 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
311
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700312 // Check whether the given PC is within the quick compiled code associated with this method's
313 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
314 // debug purposes.
315 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800316 return PcIsWithinQuickCode(
317 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318 }
319
Ian Rogersef7d42f2014-01-06 12:55:46 -0800320 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700322 // Returns true if the entrypoint points to the interpreter, as
323 // opposed to the compiled code, that is, this method will be
324 // interpretered on invocation.
325 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
326
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700327 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700328 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700330 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100331 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700332 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
333 // least 2 byte aligned.
334 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100335 return reinterpret_cast<const void*>(code);
336 }
337
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800338 // Actual entry point pointer to compiled oat code or nullptr.
339 const void* GetQuickOatEntryPoint(size_t pointer_size)
340 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko8a630572014-04-09 18:45:35 +0100341 // Actual pointer to compiled oat code or nullptr.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800342 const void* GetQuickOatCodePointer(size_t pointer_size)
343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
344 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700345 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100346
Ian Rogers1809a722013-08-09 22:05:32 -0700347 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800348 const uint8_t* GetMappingTable(size_t pointer_size)
349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
350 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352
Ian Rogers1809a722013-08-09 22:05:32 -0700353 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800354 const uint8_t* GetVmapTable(size_t pointer_size)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
356 const uint8_t* GetVmapTable(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
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100359 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100360
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800361 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
362 const uint8_t* GetNativeGcMap(size_t pointer_size)
363 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
364 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366
Andreas Gampe90546832014-03-12 18:07:19 -0700367 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700368 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100369 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700370 if (kCheckFrameSize) {
371 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
372 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 return result;
374 }
375
Vladimir Marko7624d252014-05-02 14:40:15 +0100376 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100377 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700380 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
381 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100382 }
383
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700384 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
386 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700387 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 }
389
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700390 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100391 constexpr size_t handle_scope_offset = sizeof(StackReference<mirror::ArtMethod>);
392 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
393 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800394 }
395
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700396 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
398
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700399 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800400
Mathieu Chartier2d721012014-11-10 11:08:06 -0800401 static MemberOffset EntryPointFromInterpreterOffset(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_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404 }
405
Mathieu Chartier2d721012014-11-10 11:08:06 -0800406 static MemberOffset EntryPointFromJniOffset(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_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409 }
410
Mathieu Chartier2d721012014-11-10 11:08:06 -0800411 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800412 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800413 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
414 }
415
Mathieu Chartier2d721012014-11-10 11:08:06 -0800416 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
417 CheckObjectSizeEqualsMirrorSize();
418 return GetEntryPointFromJniPtrSize(sizeof(void*));
419 }
420 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
422 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
423 }
424
425 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
426 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
427 CheckObjectSizeEqualsMirrorSize();
428 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
429 }
430 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
431 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
433 SetFieldPtrWithSize<false, true, kVerifyFlags>(
434 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
435 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700438 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800439 }
440
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800441 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
442 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800443 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444
445 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800446 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447
Ian Rogersef7d42f2014-01-06 12:55:46 -0800448 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449
Ian Rogersef7d42f2014-01-06 12:55:46 -0800450 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700451
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700452 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
453
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700454 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
455#ifdef NDEBUG
456 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
458 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
459 }
460#else
461 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100462 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700463#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800464
465 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800466 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
467 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800468
469 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000470 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
471 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800472
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800473 MethodReference ToMethodReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
474 return MethodReference(GetDexFile(), GetDexMethodIndex());
475 }
476
Ian Rogersc449aa82013-07-29 14:35:46 -0700477 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
478 // indicates whether the found catch block is responsible for clearing the exception or whether
479 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700480 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
481 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800482 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
483
Brian Carlstromea46f952013-07-30 01:26:50 -0700484 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800485
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700486 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700487 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488
Brian Carlstromea46f952013-07-30 01:26:50 -0700489 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800491 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800492 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
493
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700494 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700495
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700496 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700498 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
499 uint32_t unused_length;
500 return GetShorty(&unused_length);
501 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700502
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700503 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700504
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700505 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700506
Ian Rogers1ff3c982014-08-12 02:30:58 -0700507 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700508
Ian Rogers6b14d552014-10-28 21:50:58 -0700509 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
510
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700511 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700512
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700513 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700514
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700515 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700516
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700517 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700518
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700519 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700520
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700521 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700522
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700523 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700524
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700525 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700526
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700527 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700528
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700529 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
530 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700531
Ian Rogersded66a02014-10-28 18:12:55 -0700532 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
533 // number of bugs at call sites.
534 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
535
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700536 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700537
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700538 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700539
Ian Rogers1ff3c982014-08-12 02:30:58 -0700540 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700541
Mathieu Chartiereace4582014-11-24 18:29:54 -0800542 static size_t SizeWithoutPointerFields(size_t pointer_size) {
543 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
544#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
545 // Add 4 bytes if 64 bit, otherwise 0.
546 total += pointer_size - sizeof(uint32_t);
547#endif
548 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800549 }
550
551 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
552 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800553 return SizeWithoutPointerFields(pointer_size) +
554 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800555 }
556
557 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800558 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800559 // The class we are a part of.
560 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800561
Ian Rogersef7d42f2014-01-06 12:55:46 -0800562 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700563 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800564
Ian Rogersef7d42f2014-01-06 12:55:46 -0800565 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700566 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567
Ian Rogersef7d42f2014-01-06 12:55:46 -0800568 // Access flags; low 16 bits are defined by spec.
569 uint32_t access_flags_;
570
571 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
572
573 // Offset to the CodeItem.
574 uint32_t dex_code_item_offset_;
575
576 // Index into method_ids of the dex file associated with this method.
577 uint32_t dex_method_index_;
578
579 /* End of dex file fields. */
580
581 // Entry within a dispatch table for this method. For static/direct methods the index is into
582 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
583 // ifTable.
584 uint32_t method_index_;
585
Mathieu Chartiereace4582014-11-24 18:29:54 -0800586 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800587
588 // Must be the last fields in the method.
589 struct PACKED(4) PtrSizedFields {
590 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
591 // compiled code.
592 void* entry_point_from_interpreter_;
593
594 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
595 void* entry_point_from_jni_;
596
597 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800598 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800599 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800600 } ptr_sized_fields_;
601
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700602 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800603
Mathieu Chartier02e25112013-08-14 16:14:24 -0700604 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800605 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
606
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700607 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
608 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700609
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700610 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700612
Mathieu Chartiereace4582014-11-24 18:29:54 -0800613 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
614 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
615#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
616 // Add 4 bytes if 64 bit, otherwise 0.
617 offset += pointer_size - sizeof(uint32_t);
618#endif
619 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800620 }
621
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800622 // Code points to the start of the quick code.
623 static uint32_t GetCodeSize(const void* code);
624
625 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
626 if (code == 0) {
627 return pc == 0;
628 }
629 /*
630 * During a stack walk, a return PC may point past-the-end of the code
631 * in the case that the last instruction is a call that isn't expected to
632 * return. Thus, we check <= code + GetCodeSize().
633 *
634 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
635 */
636 return code <= pc && pc <= code + GetCodeSize(
637 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
638 }
639
Brian Carlstromea46f952013-07-30 01:26:50 -0700640 friend struct art::ArtMethodOffsets; // for verifying offset information
641 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800642};
643
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800644} // namespace mirror
645} // namespace art
646
Brian Carlstromea46f952013-07-30 01:26:50 -0700647#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_