blob: 210794488da0d4a410bc25c7a1bf6f9a8a4fac54 [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 Rogersa0485602014-12-02 15:48:04 -0800240 // Get the Class* from the type index into this method's dex cache.
241 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
242 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
243
Ian Rogerse0a02da2014-12-02 14:10:53 -0800244 // Find the method that this method overrides.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800245 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246
Ian Rogerse0a02da2014-12-02 14:10:53 -0800247 // Find the method index for this method within other_dexfile. If this method isn't present then
248 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
249 // name and signature in the other_dexfile, such as the method index used to resolve this method
250 // in the other_dexfile.
251 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
252 uint32_t name_and_signature_idx)
253 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
254
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700255 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800257
Mathieu Chartier4e305412014-02-19 10:54:44 -0800258 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700259 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800261 CheckObjectSizeEqualsMirrorSize();
262 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
263 }
264 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
265 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
266 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
267 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
268 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700269 }
270
Mathieu Chartier2d721012014-11-10 11:08:06 -0800271 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700272 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
273 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800274 CheckObjectSizeEqualsMirrorSize();
275 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
276 }
277 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
278 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
279 size_t pointer_size)
280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
281 SetFieldPtrWithSize<false, true, kVerifyFlags>(
282 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700283 }
284
Mathieu Chartier2d721012014-11-10 11:08:06 -0800285 ALWAYS_INLINE static MemberOffset EntryPointFromPortableCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800286 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800287 PtrSizedFields, entry_point_from_portable_compiled_code_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800288 }
289
Mathieu Chartier2d721012014-11-10 11:08:06 -0800290 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
291 const void* GetEntryPointFromPortableCompiledCode()
292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
293 CheckObjectSizeEqualsMirrorSize();
294 return GetEntryPointFromPortableCompiledCodePtrSize(sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800295 }
296
Mathieu Chartier2d721012014-11-10 11:08:06 -0800297 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
298 ALWAYS_INLINE const void* GetEntryPointFromPortableCompiledCodePtrSize(size_t pointer_size)
299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
300 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
301 EntryPointFromPortableCompiledCodeOffset(pointer_size), pointer_size);
302 }
303
304 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700305 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800307 CheckObjectSizeEqualsMirrorSize();
308 return SetEntryPointFromPortableCompiledCodePtrSize(entry_point_from_portable_compiled_code,
309 sizeof(void*));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800310 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311
Mathieu Chartier2d721012014-11-10 11:08:06 -0800312 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
313 void SetEntryPointFromPortableCompiledCodePtrSize(
314 const void* entry_point_from_portable_compiled_code, size_t pointer_size)
315 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
316 SetFieldPtrWithSize<false, true, kVerifyFlags>(
317 EntryPointFromPortableCompiledCodeOffset(pointer_size),
318 entry_point_from_portable_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800319 }
320
Mathieu Chartier2d721012014-11-10 11:08:06 -0800321 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700322 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800323 CheckObjectSizeEqualsMirrorSize();
324 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
325 }
326 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
327 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
329 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
330 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800331 }
332
Mathieu Chartier2d721012014-11-10 11:08:06 -0800333 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700334 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800336 CheckObjectSizeEqualsMirrorSize();
337 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
338 sizeof(void*));
339 }
340 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
341 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
342 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
344 SetFieldPtrWithSize<false, true, kVerifyFlags>(
345 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
346 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800347 }
348
Ian Rogersef7d42f2014-01-06 12:55:46 -0800349 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
350
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700351 // Check whether the given PC is within the quick compiled code associated with this method's
352 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
353 // debug purposes.
354 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800355 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 if (code == 0) {
357 return pc == 0;
358 }
359 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100360 * During a stack walk, a return PC may point past-the-end of the code
361 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100363 *
364 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800365 */
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700366 return code <= pc && pc <= code + GetCodeSize();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 }
368
Ian Rogersef7d42f2014-01-06 12:55:46 -0800369 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800370
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700371 // Returns true if the entrypoint points to the interpreter, as
372 // opposed to the compiled code, that is, this method will be
373 // interpretered on invocation.
374 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
375
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700376 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
377 uint32_t GetPortableOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
378 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
379 void SetPortableOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700381 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100382 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700383 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
384 // least 2 byte aligned.
385 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100386 return reinterpret_cast<const void*>(code);
387 }
388
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800389 // Actual entry point pointer to compiled oat code or nullptr.
390 const void* GetQuickOatEntryPoint(size_t pointer_size)
391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko8a630572014-04-09 18:45:35 +0100392 // Actual pointer to compiled oat code or nullptr.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800393 const void* GetQuickOatCodePointer(size_t pointer_size)
394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
395 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700396 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100397
Ian Rogers1809a722013-08-09 22:05:32 -0700398 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800399 const uint8_t* GetMappingTable(size_t pointer_size)
400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
401 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403
Ian Rogers1809a722013-08-09 22:05:32 -0700404 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800405 const uint8_t* GetVmapTable(size_t pointer_size)
406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
407 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409
Nicolas Geoffray39468442014-09-02 15:17:15 +0100410 StackMap GetStackMap(uint32_t native_pc_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100411 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100412
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800413 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
414 const uint8_t* GetNativeGcMap(size_t pointer_size)
415 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
416 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418
Andreas Gampe90546832014-03-12 18:07:19 -0700419 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700420 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100421 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700422 if (kCheckFrameSize) {
423 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
424 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800425 return result;
426 }
427
Vladimir Marko7624d252014-05-02 14:40:15 +0100428 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100429 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
430 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700432 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
433 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100434 }
435
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700436 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100437 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
438 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700439 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 }
441
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700442 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
443 DCHECK_LT(sizeof(void*), GetFrameSizeInBytes());
444 return FrameOffset(sizeof(void*));
Ian Rogers62d6c772013-02-27 08:32:07 -0800445 }
446
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700447 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
449
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700450 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451
Mathieu Chartier2d721012014-11-10 11:08:06 -0800452 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800453 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800454 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800455 }
456
Mathieu Chartier2d721012014-11-10 11:08:06 -0800457 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800458 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800459 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800460 }
461
Mathieu Chartier2d721012014-11-10 11:08:06 -0800462 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800463 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800464 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
465 }
466
Mathieu Chartier2d721012014-11-10 11:08:06 -0800467 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
468 CheckObjectSizeEqualsMirrorSize();
469 return GetEntryPointFromJniPtrSize(sizeof(void*));
470 }
471 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
473 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
474 }
475
476 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
477 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
478 CheckObjectSizeEqualsMirrorSize();
479 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
480 }
481 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
482 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
483 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
484 SetFieldPtrWithSize<false, true, kVerifyFlags>(
485 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
486 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800487
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700489 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 }
491
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
493 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800494 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800495
496 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800497 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498
Ian Rogersef7d42f2014-01-06 12:55:46 -0800499 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800500
Ian Rogersef7d42f2014-01-06 12:55:46 -0800501 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700502
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700503 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
504
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700505 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
506#ifdef NDEBUG
507 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
508 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
509 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
510 }
511#else
512 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700514#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800515
516 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800517 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800519
520 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000521 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
522 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800523
Ian Rogersc449aa82013-07-29 14:35:46 -0700524 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
525 // indicates whether the found catch block is responsible for clearing the exception or whether
526 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700527 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
528 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
530
Brian Carlstromea46f952013-07-30 01:26:50 -0700531 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800532
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700533 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700534 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800535
Brian Carlstromea46f952013-07-30 01:26:50 -0700536 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800537
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800538 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
540
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700541 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700542
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700543 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700544
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700545 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
546 uint32_t unused_length;
547 return GetShorty(&unused_length);
548 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700549
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700550 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700551
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700552 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700553
Ian Rogers1ff3c982014-08-12 02:30:58 -0700554 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700555
Ian Rogers6b14d552014-10-28 21:50:58 -0700556 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
557
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700558 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700559
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700560 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700561
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700562 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700563
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700564 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700565
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700566 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700567
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700568 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700569
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700570 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700571
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700572 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700573
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700574 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700575
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700576 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
577 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700578
Ian Rogersded66a02014-10-28 18:12:55 -0700579 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
580 // number of bugs at call sites.
581 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
582
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700583 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700584
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700585 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700586
Ian Rogers1ff3c982014-08-12 02:30:58 -0700587 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700588
Mathieu Chartiereace4582014-11-24 18:29:54 -0800589 static size_t SizeWithoutPointerFields(size_t pointer_size) {
590 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
591#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
592 // Add 4 bytes if 64 bit, otherwise 0.
593 total += pointer_size - sizeof(uint32_t);
594#endif
595 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800596 }
597
598 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
599 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800600 return SizeWithoutPointerFields(pointer_size) +
601 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800602 }
603
604 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800606 // The class we are a part of.
607 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800608
Ian Rogersef7d42f2014-01-06 12:55:46 -0800609 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700610 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800611
Ian Rogersef7d42f2014-01-06 12:55:46 -0800612 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700613 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614
Ian Rogersef7d42f2014-01-06 12:55:46 -0800615 // Access flags; low 16 bits are defined by spec.
616 uint32_t access_flags_;
617
618 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
619
620 // Offset to the CodeItem.
621 uint32_t dex_code_item_offset_;
622
623 // Index into method_ids of the dex file associated with this method.
624 uint32_t dex_method_index_;
625
626 /* End of dex file fields. */
627
628 // Entry within a dispatch table for this method. For static/direct methods the index is into
629 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
630 // ifTable.
631 uint32_t method_index_;
632
Mathieu Chartiereace4582014-11-24 18:29:54 -0800633 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800634
635 // Must be the last fields in the method.
636 struct PACKED(4) PtrSizedFields {
637 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
638 // compiled code.
639 void* entry_point_from_interpreter_;
640
641 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
642 void* entry_point_from_jni_;
643
644 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
645 // portable compiled code or the interpreter.
646 void* entry_point_from_quick_compiled_code_;
647
Mathieu Chartier2d721012014-11-10 11:08:06 -0800648 // Method dispatch from portable compiled code invokes this pointer which may cause bridging
649 // into quick compiled code or the interpreter. Last to simplify entrypoint logic.
650 void* entry_point_from_portable_compiled_code_;
651 } ptr_sized_fields_;
652
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700653 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800654
Mathieu Chartier02e25112013-08-14 16:14:24 -0700655 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800656 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
657
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700658 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
659 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700660
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700661 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
662 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700663
Mathieu Chartiereace4582014-11-24 18:29:54 -0800664 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
665 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
666#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
667 // Add 4 bytes if 64 bit, otherwise 0.
668 offset += pointer_size - sizeof(uint32_t);
669#endif
670 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800671 }
672
Brian Carlstromea46f952013-07-30 01:26:50 -0700673 friend struct art::ArtMethodOffsets; // for verifying offset information
674 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800675};
676
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800677} // namespace mirror
678} // namespace art
679
Brian Carlstromea46f952013-07-30 01:26:50 -0700680#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_