blob: 04f8efc15137fd97fc9c20eede66a93077157100 [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "modifiers.h"
24#include "object.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080025#include "object_callbacks.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010026#include "quick/quick_method_frame_info.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "read_barrier_option.h"
Nicolas Geoffray39468442014-09-02 15:17:15 +010028#include "stack_map.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029
30namespace art {
31
Brian Carlstromea46f952013-07-30 01:26:50 -070032struct ArtMethodOffsets;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033struct ConstructorMethodOffsets;
34union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070035class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070037class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
39namespace mirror {
40
Ian Rogerse94652f2014-12-02 11:13:19 -080041typedef void (EntryPointFromInterpreter)(Thread* self, const DexFile::CodeItem* code_item,
42 ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070043
Mathieu Chartiereace4582014-11-24 18:29:54 -080044#define ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
45
Mingyao Yang98d1cc82014-05-15 17:02:16 -070046// C++ mirror of java.lang.reflect.ArtMethod.
47class MANAGED ArtMethod FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070049 // Size of java.lang.reflect.ArtMethod.class.
50 static uint32_t ClassSize();
51
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070052 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
53 jobject jlr_method)
Ian Rogers62f05122014-03-21 11:21:29 -070054 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
55
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070056 Class* GetDeclaringClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057
58 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
59
60 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070061 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062 }
63
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070064 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080065
Ian Rogersef7d42f2014-01-06 12:55:46 -080066 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010067 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070068 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069 }
70
71 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080072 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073
74 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080075 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 return (GetAccessFlags() & kAccPublic) != 0;
77 }
78
79 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080080 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081 return (GetAccessFlags() & kAccPrivate) != 0;
82 }
83
84 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080085 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086 return (GetAccessFlags() & kAccStatic) != 0;
87 }
88
89 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080090 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091 return (GetAccessFlags() & kAccConstructor) != 0;
92 }
93
Mathieu Chartierbfd9a432014-05-21 17:43:44 -070094 // Returns true if the method is a class initializer.
95 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
96 return IsConstructor() && IsStatic();
97 }
98
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800100 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 return IsDirect(GetAccessFlags());
102 }
103
104 static bool IsDirect(uint32_t access_flags) {
105 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
106 }
107
108 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800109 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800110 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
111 return (GetAccessFlags() & synchonized) != 0;
112 }
113
Ian Rogersef7d42f2014-01-06 12:55:46 -0800114 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115 return (GetAccessFlags() & kAccFinal) != 0;
116 }
117
Ian Rogersef7d42f2014-01-06 12:55:46 -0800118 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119 return (GetAccessFlags() & kAccMiranda) != 0;
120 }
121
Ian Rogersef7d42f2014-01-06 12:55:46 -0800122 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 return (GetAccessFlags() & kAccNative) != 0;
124 }
125
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800127 uint32_t mask = kAccFastNative | kAccNative;
128 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700129 }
130
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 return (GetAccessFlags() & kAccAbstract) != 0;
133 }
134
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 return (GetAccessFlags() & kAccSynthetic) != 0;
137 }
138
Ian Rogersef7d42f2014-01-06 12:55:46 -0800139 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800140
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200142 return (GetAccessFlags() & kAccPreverified) != 0;
143 }
144
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
146 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200147 SetAccessFlags(GetAccessFlags() | kAccPreverified);
148 }
149
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800150 bool IsOptimized(size_t pointer_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100151 // Temporary solution for detecting if a method has been optimized: the compiler
152 // does not create a GC map. Instead, the vmap table contains the stack map
153 // (as in stack_map.h).
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800154 return GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
155 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800156 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100157 }
158
Ian Rogersef7d42f2014-01-06 12:55:46 -0800159 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
160 return (GetAccessFlags() & kAccPortableCompiled) != 0;
161 }
162
163 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
164 DCHECK(!IsPortableCompiled());
165 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
166 }
167
168 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
169 DCHECK(IsPortableCompiled());
170 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
171 }
172
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
174
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700177 // Doesn't do erroneous / unresolved class checks.
178 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
179
Ian Rogersef7d42f2014-01-06 12:55:46 -0800180 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 return GetMethodIndex();
182 }
183
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100185 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700186 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 }
188
189 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700190 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 }
192
Ian Rogersef7d42f2014-01-06 12:55:46 -0800193 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700194 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 }
196
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700197 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100198 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700199 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201
202 // Number of 32bit registers that would be required to hold all the arguments
203 static size_t NumArgRegisters(const StringPiece& shorty);
204
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700205 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800206
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700207 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100208 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700209 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800210 }
211
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700213 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 }
215
216 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700217 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800218 }
219
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700220 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700221 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700222 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700224 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700226 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
227 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
228 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
229 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230
Andreas Gampe58a5af82014-07-31 16:23:49 -0700231 template <bool kWithCheck = true>
232 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700235 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
236 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
237 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
238 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800239
Ian Rogerse0a02da2014-12-02 14:10:53 -0800240 // Find the method that this method overrides.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800241 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242
Ian Rogerse0a02da2014-12-02 14:10:53 -0800243 // Find the method index for this method within other_dexfile. If this method isn't present then
244 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
245 // name and signature in the other_dexfile, such as the method index used to resolve this method
246 // in the other_dexfile.
247 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
248 uint32_t name_and_signature_idx)
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
250
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700251 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
252 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800253
Mathieu Chartier4e305412014-02-19 10:54:44 -0800254 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700255 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800257 CheckObjectSizeEqualsMirrorSize();
258 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
259 }
260 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
261 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
263 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
264 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700265 }
266
Mathieu Chartier2d721012014-11-10 11:08:06 -0800267 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700268 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800270 CheckObjectSizeEqualsMirrorSize();
271 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
272 }
273 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
274 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
275 size_t pointer_size)
276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
277 SetFieldPtrWithSize<false, true, kVerifyFlags>(
278 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700279 }
280
Mathieu Chartier2d721012014-11-10 11:08:06 -0800281 ALWAYS_INLINE static MemberOffset EntryPointFromPortableCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800282 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800283 PtrSizedFields, entry_point_from_portable_compiled_code_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800284 }
285
Mathieu Chartier2d721012014-11-10 11:08:06 -0800286 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
287 const void* GetEntryPointFromPortableCompiledCode()
288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
289 CheckObjectSizeEqualsMirrorSize();
290 return GetEntryPointFromPortableCompiledCodePtrSize(sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800291 }
292
Mathieu Chartier2d721012014-11-10 11:08:06 -0800293 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
294 ALWAYS_INLINE const void* GetEntryPointFromPortableCompiledCodePtrSize(size_t pointer_size)
295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
296 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
297 EntryPointFromPortableCompiledCodeOffset(pointer_size), pointer_size);
298 }
299
300 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700301 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code)
302 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800303 CheckObjectSizeEqualsMirrorSize();
304 return SetEntryPointFromPortableCompiledCodePtrSize(entry_point_from_portable_compiled_code,
305 sizeof(void*));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800306 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800307
Mathieu Chartier2d721012014-11-10 11:08:06 -0800308 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
309 void SetEntryPointFromPortableCompiledCodePtrSize(
310 const void* entry_point_from_portable_compiled_code, size_t pointer_size)
311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
312 SetFieldPtrWithSize<false, true, kVerifyFlags>(
313 EntryPointFromPortableCompiledCodeOffset(pointer_size),
314 entry_point_from_portable_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800315 }
316
Mathieu Chartier2d721012014-11-10 11:08:06 -0800317 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700318 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800319 CheckObjectSizeEqualsMirrorSize();
320 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
321 }
322 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
323 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
325 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
326 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800327 }
328
Mathieu Chartier2d721012014-11-10 11:08:06 -0800329 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700330 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800332 CheckObjectSizeEqualsMirrorSize();
333 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
334 sizeof(void*));
335 }
336 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
337 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
338 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
339 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
340 SetFieldPtrWithSize<false, true, kVerifyFlags>(
341 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
342 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800343 }
344
Ian Rogersef7d42f2014-01-06 12:55:46 -0800345 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
346
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700347 // Check whether the given PC is within the quick compiled code associated with this method's
348 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
349 // debug purposes.
350 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800351 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 if (code == 0) {
353 return pc == 0;
354 }
355 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100356 * During a stack walk, a return PC may point past-the-end of the code
357 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100359 *
360 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361 */
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700362 return code <= pc && pc <= code + GetCodeSize();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363 }
364
Ian Rogersef7d42f2014-01-06 12:55:46 -0800365 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700367 // Returns true if the entrypoint points to the interpreter, as
368 // opposed to the compiled code, that is, this method will be
369 // interpretered on invocation.
370 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
371
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700372 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
373 uint32_t GetPortableOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
374 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
375 void SetPortableOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800376
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700377 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100378 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700379 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
380 // least 2 byte aligned.
381 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100382 return reinterpret_cast<const void*>(code);
383 }
384
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800385 // Actual entry point pointer to compiled oat code or nullptr.
386 const void* GetQuickOatEntryPoint(size_t pointer_size)
387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko8a630572014-04-09 18:45:35 +0100388 // Actual pointer to compiled oat code or nullptr.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800389 const void* GetQuickOatCodePointer(size_t pointer_size)
390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
391 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700392 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100393
Ian Rogers1809a722013-08-09 22:05:32 -0700394 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800395 const uint8_t* GetMappingTable(size_t pointer_size)
396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
397 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399
Ian Rogers1809a722013-08-09 22:05:32 -0700400 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800401 const uint8_t* GetVmapTable(size_t pointer_size)
402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
403 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800405
Nicolas Geoffray39468442014-09-02 15:17:15 +0100406 StackMap GetStackMap(uint32_t native_pc_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100407 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100408
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800409 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
410 const uint8_t* GetNativeGcMap(size_t pointer_size)
411 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
412 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414
Andreas Gampe90546832014-03-12 18:07:19 -0700415 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700416 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100417 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700418 if (kCheckFrameSize) {
419 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
420 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421 return result;
422 }
423
Vladimir Marko7624d252014-05-02 14:40:15 +0100424 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100425 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700428 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
429 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100430 }
431
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700432 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
434 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700435 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436 }
437
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700438 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
439 DCHECK_LT(sizeof(void*), GetFrameSizeInBytes());
440 return FrameOffset(sizeof(void*));
Ian Rogers62d6c772013-02-27 08:32:07 -0800441 }
442
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700443 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
445
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700446 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447
Mathieu Chartier2d721012014-11-10 11:08:06 -0800448 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800449 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800450 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451 }
452
Mathieu Chartier2d721012014-11-10 11:08:06 -0800453 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800454 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800455 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456 }
457
Mathieu Chartier2d721012014-11-10 11:08:06 -0800458 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800459 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800460 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
461 }
462
Mathieu Chartier2d721012014-11-10 11:08:06 -0800463 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
464 CheckObjectSizeEqualsMirrorSize();
465 return GetEntryPointFromJniPtrSize(sizeof(void*));
466 }
467 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
468 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
469 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
470 }
471
472 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
473 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
474 CheckObjectSizeEqualsMirrorSize();
475 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
476 }
477 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
478 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
480 SetFieldPtrWithSize<false, true, kVerifyFlags>(
481 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
482 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800483
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700485 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800486 }
487
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
489 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800490 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491
492 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800493 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800494
Ian Rogersef7d42f2014-01-06 12:55:46 -0800495 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800496
Ian Rogersef7d42f2014-01-06 12:55:46 -0800497 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700498
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700499 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
500
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700501 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
502#ifdef NDEBUG
503 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
504 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
505 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
506 }
507#else
508 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100509 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700510#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800511
512 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800513 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800515
516 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000517 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800519
Ian Rogersc449aa82013-07-29 14:35:46 -0700520 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
521 // indicates whether the found catch block is responsible for clearing the exception or whether
522 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700523 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
524 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800525 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
526
Brian Carlstromea46f952013-07-30 01:26:50 -0700527 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800528
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700529 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700530 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800531
Brian Carlstromea46f952013-07-30 01:26:50 -0700532 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800534 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
536
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700537 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700538
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700539 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700540
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700541 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
542 uint32_t unused_length;
543 return GetShorty(&unused_length);
544 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700545
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700546 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700547
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700548 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700549
Ian Rogers1ff3c982014-08-12 02:30:58 -0700550 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700551
Ian Rogers6b14d552014-10-28 21:50:58 -0700552 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
553
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700554 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700555
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700556 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700557
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700558 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700559
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700560 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700561
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700562 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700563
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700564 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700565
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700566 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700567
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700568 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700569
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700570 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700571
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700572 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
573 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700574
Ian Rogersded66a02014-10-28 18:12:55 -0700575 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
576 // number of bugs at call sites.
577 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
578
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700579 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700580
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700581 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700582
Ian Rogers1ff3c982014-08-12 02:30:58 -0700583 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700584
Mathieu Chartiereace4582014-11-24 18:29:54 -0800585 static size_t SizeWithoutPointerFields(size_t pointer_size) {
586 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
587#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
588 // Add 4 bytes if 64 bit, otherwise 0.
589 total += pointer_size - sizeof(uint32_t);
590#endif
591 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800592 }
593
594 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
595 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800596 return SizeWithoutPointerFields(pointer_size) +
597 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800598 }
599
600 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800601 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800602 // The class we are a part of.
603 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800604
Ian Rogersef7d42f2014-01-06 12:55:46 -0800605 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700606 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800607
Ian Rogersef7d42f2014-01-06 12:55:46 -0800608 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700609 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800610
Ian Rogersef7d42f2014-01-06 12:55:46 -0800611 // Access flags; low 16 bits are defined by spec.
612 uint32_t access_flags_;
613
614 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
615
616 // Offset to the CodeItem.
617 uint32_t dex_code_item_offset_;
618
619 // Index into method_ids of the dex file associated with this method.
620 uint32_t dex_method_index_;
621
622 /* End of dex file fields. */
623
624 // Entry within a dispatch table for this method. For static/direct methods the index is into
625 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
626 // ifTable.
627 uint32_t method_index_;
628
Mathieu Chartiereace4582014-11-24 18:29:54 -0800629 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800630
631 // Must be the last fields in the method.
632 struct PACKED(4) PtrSizedFields {
633 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
634 // compiled code.
635 void* entry_point_from_interpreter_;
636
637 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
638 void* entry_point_from_jni_;
639
640 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
641 // portable compiled code or the interpreter.
642 void* entry_point_from_quick_compiled_code_;
643
Mathieu Chartier2d721012014-11-10 11:08:06 -0800644 // Method dispatch from portable compiled code invokes this pointer which may cause bridging
645 // into quick compiled code or the interpreter. Last to simplify entrypoint logic.
646 void* entry_point_from_portable_compiled_code_;
647 } ptr_sized_fields_;
648
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700649 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800650
Mathieu Chartier02e25112013-08-14 16:14:24 -0700651 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800652 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
653
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700654 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
655 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700656
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700657 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
658 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700659
Mathieu Chartiereace4582014-11-24 18:29:54 -0800660 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
661 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
662#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
663 // Add 4 bytes if 64 bit, otherwise 0.
664 offset += pointer_size - sizeof(uint32_t);
665#endif
666 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800667 }
668
Brian Carlstromea46f952013-07-30 01:26:50 -0700669 friend struct art::ArtMethodOffsets; // for verifying offset information
670 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800671};
672
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800673} // namespace mirror
674} // namespace art
675
Brian Carlstromea46f952013-07-30 01:26:50 -0700676#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_