blob: 9b982b769bffcb445a4e2ef1ea4715df8aedd9f9 [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"
Nicolas Geoffray39468442014-09-02 15:17:15 +010029#include "stack_map.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030
31namespace art {
32
Brian Carlstromea46f952013-07-30 01:26:50 -070033struct ArtMethodOffsets;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034struct ConstructorMethodOffsets;
35union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070036class ScopedObjectAccessAlreadyRunnable;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070038class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039
40namespace mirror {
41
Ian Rogerse94652f2014-12-02 11:13:19 -080042typedef void (EntryPointFromInterpreter)(Thread* self, const DexFile::CodeItem* code_item,
43 ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070044
Mathieu Chartiereace4582014-11-24 18:29:54 -080045#define ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
46
Mingyao Yang98d1cc82014-05-15 17:02:16 -070047// C++ mirror of java.lang.reflect.ArtMethod.
48class MANAGED ArtMethod FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070050 // Size of java.lang.reflect.ArtMethod.class.
51 static uint32_t ClassSize();
52
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070053 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
54 jobject jlr_method)
Ian Rogers62f05122014-03-21 11:21:29 -070055 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
56
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070057 Class* GetDeclaringClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058
59 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
60
61 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070062 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 }
64
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070065 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080066
Ian Rogersef7d42f2014-01-06 12:55:46 -080067 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010068 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070069 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070 }
71
72 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080073 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074
75 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080076 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 return (GetAccessFlags() & kAccPublic) != 0;
78 }
79
80 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080081 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 return (GetAccessFlags() & kAccPrivate) != 0;
83 }
84
85 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 return (GetAccessFlags() & kAccStatic) != 0;
88 }
89
90 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080091 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092 return (GetAccessFlags() & kAccConstructor) != 0;
93 }
94
Mathieu Chartierbfd9a432014-05-21 17:43:44 -070095 // Returns true if the method is a class initializer.
96 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
97 return IsConstructor() && IsStatic();
98 }
99
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800101 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800102 return IsDirect(GetAccessFlags());
103 }
104
105 static bool IsDirect(uint32_t access_flags) {
106 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
107 }
108
109 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800110 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
112 return (GetAccessFlags() & synchonized) != 0;
113 }
114
Ian Rogersef7d42f2014-01-06 12:55:46 -0800115 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800116 return (GetAccessFlags() & kAccFinal) != 0;
117 }
118
Ian Rogersef7d42f2014-01-06 12:55:46 -0800119 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120 return (GetAccessFlags() & kAccMiranda) != 0;
121 }
122
Ian Rogersef7d42f2014-01-06 12:55:46 -0800123 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124 return (GetAccessFlags() & kAccNative) != 0;
125 }
126
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800128 uint32_t mask = kAccFastNative | kAccNative;
129 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700130 }
131
Ian Rogersef7d42f2014-01-06 12:55:46 -0800132 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800133 return (GetAccessFlags() & kAccAbstract) != 0;
134 }
135
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 return (GetAccessFlags() & kAccSynthetic) != 0;
138 }
139
Ian Rogersef7d42f2014-01-06 12:55:46 -0800140 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800141
Ian Rogersef7d42f2014-01-06 12:55:46 -0800142 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200143 return (GetAccessFlags() & kAccPreverified) != 0;
144 }
145
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
147 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200148 SetAccessFlags(GetAccessFlags() | kAccPreverified);
149 }
150
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800151 bool IsOptimized(size_t pointer_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100152 // Temporary solution for detecting if a method has been optimized: the compiler
153 // does not create a GC map. Instead, the vmap table contains the stack map
154 // (as in stack_map.h).
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000155 return !IsNative()
156 && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800157 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800158 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100159 }
160
Ian Rogersef7d42f2014-01-06 12:55:46 -0800161 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
162 return (GetAccessFlags() & kAccPortableCompiled) != 0;
163 }
164
165 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
166 DCHECK(!IsPortableCompiled());
167 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
168 }
169
170 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
171 DCHECK(IsPortableCompiled());
172 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
173 }
174
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
176
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700179 // Doesn't do erroneous / unresolved class checks.
180 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
181
Ian Rogersef7d42f2014-01-06 12:55:46 -0800182 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183 return GetMethodIndex();
184 }
185
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 void SetMethodIndex(uint16_t new_method_index) 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, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 }
190
191 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700192 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 }
194
Ian Rogersef7d42f2014-01-06 12:55:46 -0800195 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700196 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197 }
198
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700199 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100200 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700201 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 }
203
204 // Number of 32bit registers that would be required to hold all the arguments
205 static size_t NumArgRegisters(const StringPiece& shorty);
206
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700207 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800208
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700209 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100210 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700211 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212 }
213
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700215 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216 }
217
218 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700219 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220 }
221
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700222 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
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 SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700225 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700226 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700228 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
229 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
230 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232
Andreas Gampe58a5af82014-07-31 16:23:49 -0700233 template <bool kWithCheck = true>
234 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800235 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
236 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700237 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
238 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
239 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
240 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241
Ian Rogersa0485602014-12-02 15:48:04 -0800242 // Get the Class* from the type index into this method's dex cache.
243 mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
245
Ian Rogerse0a02da2014-12-02 14:10:53 -0800246 // Find the method that this method overrides.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800247 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800248
Ian Rogerse0a02da2014-12-02 14:10:53 -0800249 // Find the method index for this method within other_dexfile. If this method isn't present then
250 // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same
251 // name and signature in the other_dexfile, such as the method index used to resolve this method
252 // in the other_dexfile.
253 uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
254 uint32_t name_and_signature_idx)
255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
256
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700257 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800259
Mathieu Chartier4e305412014-02-19 10:54:44 -0800260 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700261 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800263 CheckObjectSizeEqualsMirrorSize();
264 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
265 }
266 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
267 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
269 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
270 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700271 }
272
Mathieu Chartier2d721012014-11-10 11:08:06 -0800273 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700274 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800276 CheckObjectSizeEqualsMirrorSize();
277 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
278 }
279 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
280 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
281 size_t pointer_size)
282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
283 SetFieldPtrWithSize<false, true, kVerifyFlags>(
284 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700285 }
286
Mathieu Chartier2d721012014-11-10 11:08:06 -0800287 ALWAYS_INLINE static MemberOffset EntryPointFromPortableCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800288 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800289 PtrSizedFields, entry_point_from_portable_compiled_code_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800290 }
291
Mathieu Chartier2d721012014-11-10 11:08:06 -0800292 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
293 const void* GetEntryPointFromPortableCompiledCode()
294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
295 CheckObjectSizeEqualsMirrorSize();
296 return GetEntryPointFromPortableCompiledCodePtrSize(sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 }
298
Mathieu Chartier2d721012014-11-10 11:08:06 -0800299 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
300 ALWAYS_INLINE const void* GetEntryPointFromPortableCompiledCodePtrSize(size_t pointer_size)
301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
302 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
303 EntryPointFromPortableCompiledCodeOffset(pointer_size), pointer_size);
304 }
305
306 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700307 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code)
308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800309 CheckObjectSizeEqualsMirrorSize();
310 return SetEntryPointFromPortableCompiledCodePtrSize(entry_point_from_portable_compiled_code,
311 sizeof(void*));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800312 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313
Mathieu Chartier2d721012014-11-10 11:08:06 -0800314 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
315 void SetEntryPointFromPortableCompiledCodePtrSize(
316 const void* entry_point_from_portable_compiled_code, size_t pointer_size)
317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
318 SetFieldPtrWithSize<false, true, kVerifyFlags>(
319 EntryPointFromPortableCompiledCodeOffset(pointer_size),
320 entry_point_from_portable_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800321 }
322
Mathieu Chartier2d721012014-11-10 11:08:06 -0800323 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700324 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800325 CheckObjectSizeEqualsMirrorSize();
326 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
327 }
328 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
329 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
331 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
332 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800333 }
334
Mathieu Chartier2d721012014-11-10 11:08:06 -0800335 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700336 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800338 CheckObjectSizeEqualsMirrorSize();
339 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
340 sizeof(void*));
341 }
342 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
343 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
344 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
346 SetFieldPtrWithSize<false, true, kVerifyFlags>(
347 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
348 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800349 }
350
Ian Rogersef7d42f2014-01-06 12:55:46 -0800351 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
352
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700353 // Check whether the given PC is within the quick compiled code associated with this method's
354 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
355 // debug purposes.
356 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800357 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 if (code == 0) {
359 return pc == 0;
360 }
361 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100362 * During a stack walk, a return PC may point past-the-end of the code
363 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100365 *
366 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 */
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700368 return code <= pc && pc <= code + GetCodeSize();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800369 }
370
Ian Rogersef7d42f2014-01-06 12:55:46 -0800371 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700373 // Returns true if the entrypoint points to the interpreter, as
374 // opposed to the compiled code, that is, this method will be
375 // interpretered on invocation.
376 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
377
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700378 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
379 uint32_t GetPortableOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
380 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
381 void SetPortableOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700383 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100384 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700385 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
386 // least 2 byte aligned.
387 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100388 return reinterpret_cast<const void*>(code);
389 }
390
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800391 // Actual entry point pointer to compiled oat code or nullptr.
392 const void* GetQuickOatEntryPoint(size_t pointer_size)
393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko8a630572014-04-09 18:45:35 +0100394 // Actual pointer to compiled oat code or nullptr.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800395 const void* GetQuickOatCodePointer(size_t pointer_size)
396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
397 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700398 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100399
Ian Rogers1809a722013-08-09 22:05:32 -0700400 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800401 const uint8_t* GetMappingTable(size_t pointer_size)
402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
403 const uint8_t* GetMappingTable(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
Ian Rogers1809a722013-08-09 22:05:32 -0700406 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800407 const uint8_t* GetVmapTable(size_t pointer_size)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
409 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800411
Nicolas Geoffray39468442014-09-02 15:17:15 +0100412 StackMap GetStackMap(uint32_t native_pc_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100413 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100414
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800415 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
416 const uint8_t* GetNativeGcMap(size_t pointer_size)
417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
418 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
419 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420
Andreas Gampe90546832014-03-12 18:07:19 -0700421 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700422 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100423 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700424 if (kCheckFrameSize) {
425 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
426 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 return result;
428 }
429
Vladimir Marko7624d252014-05-02 14:40:15 +0100430 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100431 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700434 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
435 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100436 }
437
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700438 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100439 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
440 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700441 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442 }
443
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700444 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
445 DCHECK_LT(sizeof(void*), GetFrameSizeInBytes());
446 return FrameOffset(sizeof(void*));
Ian Rogers62d6c772013-02-27 08:32:07 -0800447 }
448
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700449 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
451
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700452 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453
Mathieu Chartier2d721012014-11-10 11:08:06 -0800454 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800455 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800456 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457 }
458
Mathieu Chartier2d721012014-11-10 11:08:06 -0800459 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800460 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800461 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800462 }
463
Mathieu Chartier2d721012014-11-10 11:08:06 -0800464 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800465 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800466 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
467 }
468
Mathieu Chartier2d721012014-11-10 11:08:06 -0800469 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
470 CheckObjectSizeEqualsMirrorSize();
471 return GetEntryPointFromJniPtrSize(sizeof(void*));
472 }
473 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
475 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
476 }
477
478 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
479 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
480 CheckObjectSizeEqualsMirrorSize();
481 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
482 }
483 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
484 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
486 SetFieldPtrWithSize<false, true, kVerifyFlags>(
487 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
488 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800489
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700491 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492 }
493
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800494 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
495 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800496 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800497
498 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800499 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800500
Ian Rogersef7d42f2014-01-06 12:55:46 -0800501 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800502
Ian Rogersef7d42f2014-01-06 12:55:46 -0800503 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700504
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700505 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
506
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700507 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
508#ifdef NDEBUG
509 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
511 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
512 }
513#else
514 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100515 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700516#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517
518 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800519 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
520 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800521
522 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000523 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800525
Mathieu Chartier36b58f52014-12-10 12:06:45 -0800526 MethodReference ToMethodReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
527 return MethodReference(GetDexFile(), GetDexMethodIndex());
528 }
529
Ian Rogersc449aa82013-07-29 14:35:46 -0700530 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
531 // indicates whether the found catch block is responsible for clearing the exception or whether
532 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700533 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
534 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
536
Brian Carlstromea46f952013-07-30 01:26:50 -0700537 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800538
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700539 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700540 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800541
Brian Carlstromea46f952013-07-30 01:26:50 -0700542 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800543
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800544 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700547 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700548
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700549 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700550
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700551 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
552 uint32_t unused_length;
553 return GetShorty(&unused_length);
554 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700555
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700556 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700557
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700558 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700559
Ian Rogers1ff3c982014-08-12 02:30:58 -0700560 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700561
Ian Rogers6b14d552014-10-28 21:50:58 -0700562 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
563
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700564 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700565
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700566 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700567
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700568 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700569
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700570 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700571
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700572 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700573
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700574 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700575
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700576 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700577
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700578 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700579
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700580 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700581
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700582 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
583 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700584
Ian Rogersded66a02014-10-28 18:12:55 -0700585 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
586 // number of bugs at call sites.
587 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
588
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700589 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700590
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700591 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700592
Ian Rogers1ff3c982014-08-12 02:30:58 -0700593 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700594
Mathieu Chartiereace4582014-11-24 18:29:54 -0800595 static size_t SizeWithoutPointerFields(size_t pointer_size) {
596 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
597#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
598 // Add 4 bytes if 64 bit, otherwise 0.
599 total += pointer_size - sizeof(uint32_t);
600#endif
601 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800602 }
603
604 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
605 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800606 return SizeWithoutPointerFields(pointer_size) +
607 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800608 }
609
610 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800611 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800612 // The class we are a part of.
613 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614
Ian Rogersef7d42f2014-01-06 12:55:46 -0800615 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700616 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800617
Ian Rogersef7d42f2014-01-06 12:55:46 -0800618 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700619 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800620
Ian Rogersef7d42f2014-01-06 12:55:46 -0800621 // Access flags; low 16 bits are defined by spec.
622 uint32_t access_flags_;
623
624 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
625
626 // Offset to the CodeItem.
627 uint32_t dex_code_item_offset_;
628
629 // Index into method_ids of the dex file associated with this method.
630 uint32_t dex_method_index_;
631
632 /* End of dex file fields. */
633
634 // Entry within a dispatch table for this method. For static/direct methods the index is into
635 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
636 // ifTable.
637 uint32_t method_index_;
638
Mathieu Chartiereace4582014-11-24 18:29:54 -0800639 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800640
641 // Must be the last fields in the method.
642 struct PACKED(4) PtrSizedFields {
643 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
644 // compiled code.
645 void* entry_point_from_interpreter_;
646
647 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
648 void* entry_point_from_jni_;
649
650 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
651 // portable compiled code or the interpreter.
652 void* entry_point_from_quick_compiled_code_;
653
Mathieu Chartier2d721012014-11-10 11:08:06 -0800654 // Method dispatch from portable compiled code invokes this pointer which may cause bridging
655 // into quick compiled code or the interpreter. Last to simplify entrypoint logic.
656 void* entry_point_from_portable_compiled_code_;
657 } ptr_sized_fields_;
658
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700659 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800660
Mathieu Chartier02e25112013-08-14 16:14:24 -0700661 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800662 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
663
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700664 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
665 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700666
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700667 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
668 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700669
Mathieu Chartiereace4582014-11-24 18:29:54 -0800670 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
671 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
672#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
673 // Add 4 bytes if 64 bit, otherwise 0.
674 offset += pointer_size - sizeof(uint32_t);
675#endif
676 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800677 }
678
Brian Carlstromea46f952013-07-30 01:26:50 -0700679 friend struct art::ArtMethodOffsets; // for verifying offset information
680 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800681};
682
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800683} // namespace mirror
684} // namespace art
685
Brian Carlstromea46f952013-07-30 01:26:50 -0700686#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_