blob: d878f25edd67653c23d32c7c4b549eeace915ffc [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
Ian Rogersef7d42f2014-01-06 12:55:46 -0800128 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800129 uint32_t mask = kAccFastNative | kAccNative;
130 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700131 }
132
Ian Rogersef7d42f2014-01-06 12:55:46 -0800133 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 return (GetAccessFlags() & kAccAbstract) != 0;
135 }
136
Ian Rogersef7d42f2014-01-06 12:55:46 -0800137 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800138 return (GetAccessFlags() & kAccSynthetic) != 0;
139 }
140
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142
Ian Rogersef7d42f2014-01-06 12:55:46 -0800143 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200144 return (GetAccessFlags() & kAccPreverified) != 0;
145 }
146
Ian Rogersef7d42f2014-01-06 12:55:46 -0800147 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
148 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200149 SetAccessFlags(GetAccessFlags() | kAccPreverified);
150 }
151
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800152 bool IsOptimized(size_t pointer_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100153 // Temporary solution for detecting if a method has been optimized: the compiler
154 // does not create a GC map. Instead, the vmap table contains the stack map
155 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000156 return !IsNative()
157 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800158 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800159 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100160 }
161
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
163
Ian Rogersef7d42f2014-01-06 12:55:46 -0800164 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700166 // Doesn't do erroneous / unresolved class checks.
167 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
168
Ian Rogersef7d42f2014-01-06 12:55:46 -0800169 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170 return GetMethodIndex();
171 }
172
Ian Rogersef7d42f2014-01-06 12:55:46 -0800173 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100174 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700175 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176 }
177
178 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700179 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180 }
181
Ian Rogersef7d42f2014-01-06 12:55:46 -0800182 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700183 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 }
185
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700186 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100187 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700188 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 }
190
191 // Number of 32bit registers that would be required to hold all the arguments
192 static size_t NumArgRegisters(const StringPiece& shorty);
193
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700194 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700196 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100197 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700198 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800199 }
200
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700202 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203 }
204
205 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700206 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 }
208
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700209 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700211 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700213 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700215 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
216 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
217 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219
Andreas Gampe58a5af82014-07-31 16:23:49 -0700220 template <bool kWithCheck = true>
221 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700224 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
225 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
226 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800228
Ian Rogersa0485602014-12-02 15:48:04 -0800229 // Get the Class* from the type index into this method's dex cache.
230 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
232
Ian Rogerse0a02da2014-12-02 14:10:53 -0800233 // Find the method that this method overrides.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800234 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800235
Ian Rogerse0a02da2014-12-02 14:10:53 -0800236 // Find the method index for this method within other_dexfile. If this method isn't present then
237 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
238 // name and signature in the other_dexfile, such as the method index used to resolve this method
239 // in the other_dexfile.
240 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
241 uint32_t name_and_signature_idx)
242 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
243
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700244 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246
Mathieu Chartier4e305412014-02-19 10:54:44 -0800247 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700248 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800250 CheckObjectSizeEqualsMirrorSize();
251 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
252 }
253 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
254 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
256 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
257 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700258 }
259
Mathieu Chartier2d721012014-11-10 11:08:06 -0800260 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700261 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800263 CheckObjectSizeEqualsMirrorSize();
264 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
265 }
266 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
267 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
268 size_t pointer_size)
269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
270 SetFieldPtrWithSize<false, true, kVerifyFlags>(
271 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, 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 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800276 CheckObjectSizeEqualsMirrorSize();
277 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
278 }
279 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
280 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
282 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
283 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284 }
285
Mathieu Chartier2d721012014-11-10 11:08:06 -0800286 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700287 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800289 CheckObjectSizeEqualsMirrorSize();
290 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
291 sizeof(void*));
292 }
293 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
294 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
295 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
297 SetFieldPtrWithSize<false, true, kVerifyFlags>(
298 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
299 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800300 }
301
Ian Rogersef7d42f2014-01-06 12:55:46 -0800302 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
303
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700304 // Check whether the given PC is within the quick compiled code associated with this method's
305 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
306 // debug purposes.
307 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800308 return PcIsWithinQuickCode(
309 reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800310 }
311
Ian Rogersef7d42f2014-01-06 12:55:46 -0800312 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700314 // Returns true if the entrypoint points to the interpreter, as
315 // opposed to the compiled code, that is, this method will be
316 // interpretered on invocation.
317 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
318
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700319 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700320 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700322 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100323 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700324 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
325 // least 2 byte aligned.
326 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100327 return reinterpret_cast<const void*>(code);
328 }
329
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800330 // Actual entry point pointer to compiled oat code or nullptr.
331 const void* GetQuickOatEntryPoint(size_t pointer_size)
332 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko8a630572014-04-09 18:45:35 +0100333 // Actual pointer to compiled oat code or nullptr.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800334 const void* GetQuickOatCodePointer(size_t pointer_size)
335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
336 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700337 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100338
Ian Rogers1809a722013-08-09 22:05:32 -0700339 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800340 const uint8_t* GetMappingTable(size_t pointer_size)
341 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
342 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344
Ian Rogers1809a722013-08-09 22:05:32 -0700345 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800346 const uint8_t* GetVmapTable(size_t pointer_size)
347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
348 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350
Nicolas Geoffray39468442014-09-02 15:17:15 +0100351 StackMap GetStackMap(uint32_t native_pc_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100352 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100353
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800354 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
355 const uint8_t* GetNativeGcMap(size_t pointer_size)
356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
357 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
358 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800359
Andreas Gampe90546832014-03-12 18:07:19 -0700360 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700361 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100362 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700363 if (kCheckFrameSize) {
364 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
365 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366 return result;
367 }
368
Vladimir Marko7624d252014-05-02 14:40:15 +0100369 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100370 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700373 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
374 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100375 }
376
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700377 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
379 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700380 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800381 }
382
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700383 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertze4b7c892014-12-17 20:02:50 +0100384 constexpr size_t handle_scope_offset = sizeof(StackReference<mirror::ArtMethod>);
385 DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes());
386 return FrameOffset(handle_scope_offset);
Ian Rogers62d6c772013-02-27 08:32:07 -0800387 }
388
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700389 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
391
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700392 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800393
Mathieu Chartier2d721012014-11-10 11:08:06 -0800394 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800395 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800396 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 }
398
Mathieu Chartier2d721012014-11-10 11:08:06 -0800399 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800400 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800401 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800402 }
403
Mathieu Chartier2d721012014-11-10 11:08:06 -0800404 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800405 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800406 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
407 }
408
Mathieu Chartier2d721012014-11-10 11:08:06 -0800409 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
410 CheckObjectSizeEqualsMirrorSize();
411 return GetEntryPointFromJniPtrSize(sizeof(void*));
412 }
413 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
415 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
416 }
417
418 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
419 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
420 CheckObjectSizeEqualsMirrorSize();
421 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
422 }
423 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
424 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
426 SetFieldPtrWithSize<false, true, kVerifyFlags>(
427 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
428 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800429
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700431 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432 }
433
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
435 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800436 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437
438 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800439 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440
Ian Rogersef7d42f2014-01-06 12:55:46 -0800441 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442
Ian Rogersef7d42f2014-01-06 12:55:46 -0800443 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700444
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700445 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
446
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700447 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
448#ifdef NDEBUG
449 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
451 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
452 }
453#else
454 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700456#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457
458 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800459 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
460 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461
462 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000463 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800465
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800466 MethodReference ToMethodReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
467 return MethodReference(GetDexFile(), GetDexMethodIndex());
468 }
469
Ian Rogersc449aa82013-07-29 14:35:46 -0700470 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
471 // indicates whether the found catch block is responsible for clearing the exception or whether
472 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700473 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
474 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800475 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
476
Brian Carlstromea46f952013-07-30 01:26:50 -0700477 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800478
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700479 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700480 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800481
Brian Carlstromea46f952013-07-30 01:26:50 -0700482 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800483
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800484 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
486
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700487 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700488
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700489 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700490
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700491 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
492 uint32_t unused_length;
493 return GetShorty(&unused_length);
494 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700495
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700496 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700497
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700498 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700499
Ian Rogers1ff3c982014-08-12 02:30:58 -0700500 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700501
Ian Rogers6b14d552014-10-28 21:50:58 -0700502 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
503
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700504 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700505
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700506 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700507
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700508 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700509
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700510 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700511
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700512 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700513
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700514 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700515
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700516 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700517
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700518 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700519
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700520 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700521
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700522 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700524
Ian Rogersded66a02014-10-28 18:12:55 -0700525 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
526 // number of bugs at call sites.
527 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700529 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700530
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700531 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700532
Ian Rogers1ff3c982014-08-12 02:30:58 -0700533 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700534
Mathieu Chartiereace4582014-11-24 18:29:54 -0800535 static size_t SizeWithoutPointerFields(size_t pointer_size) {
536 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
537#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
538 // Add 4 bytes if 64 bit, otherwise 0.
539 total += pointer_size - sizeof(uint32_t);
540#endif
541 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800542 }
543
544 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
545 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800546 return SizeWithoutPointerFields(pointer_size) +
547 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800548 }
549
550 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800551 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800552 // The class we are a part of.
553 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800554
Ian Rogersef7d42f2014-01-06 12:55:46 -0800555 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700556 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800557
Ian Rogersef7d42f2014-01-06 12:55:46 -0800558 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700559 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800560
Ian Rogersef7d42f2014-01-06 12:55:46 -0800561 // Access flags; low 16 bits are defined by spec.
562 uint32_t access_flags_;
563
564 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
565
566 // Offset to the CodeItem.
567 uint32_t dex_code_item_offset_;
568
569 // Index into method_ids of the dex file associated with this method.
570 uint32_t dex_method_index_;
571
572 /* End of dex file fields. */
573
574 // Entry within a dispatch table for this method. For static/direct methods the index is into
575 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
576 // ifTable.
577 uint32_t method_index_;
578
Mathieu Chartiereace4582014-11-24 18:29:54 -0800579 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800580
581 // Must be the last fields in the method.
582 struct PACKED(4) PtrSizedFields {
583 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
584 // compiled code.
585 void* entry_point_from_interpreter_;
586
587 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
588 void* entry_point_from_jni_;
589
590 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
Elliott Hughes956af0f2014-12-11 14:34:28 -0800591 // the interpreter.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800592 void* entry_point_from_quick_compiled_code_;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800593 } ptr_sized_fields_;
594
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700595 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800596
Mathieu Chartier02e25112013-08-14 16:14:24 -0700597 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800598 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
599
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700600 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
601 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700602
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700603 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
604 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700605
Mathieu Chartiereace4582014-11-24 18:29:54 -0800606 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
607 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
608#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
609 // Add 4 bytes if 64 bit, otherwise 0.
610 offset += pointer_size - sizeof(uint32_t);
611#endif
612 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800613 }
614
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800615 // Code points to the start of the quick code.
616 static uint32_t GetCodeSize(const void* code);
617
618 static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
619 if (code == 0) {
620 return pc == 0;
621 }
622 /*
623 * During a stack walk, a return PC may point past-the-end of the code
624 * in the case that the last instruction is a call that isn't expected to
625 * return. Thus, we check <= code + GetCodeSize().
626 *
627 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
628 */
629 return code <= pc && pc <= code + GetCodeSize(
630 EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
631 }
632
Brian Carlstromea46f952013-07-30 01:26:50 -0700633 friend struct art::ArtMethodOffsets; // for verifying offset information
634 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800635};
636
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800637} // namespace mirror
638} // namespace art
639
Brian Carlstromea46f952013-07-30 01:26:50 -0700640#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_