blob: 4a7831fd62742c72d774fcb510bd7efa93fbe40e [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;
Jeff Hao790ad902013-05-22 15:02:08 -070035class MethodHelper;
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 Rogers6f3dbba2014-10-14 17:41:57 -070042typedef void (EntryPointFromInterpreter)(Thread* self, MethodHelper* mh,
Jeff Hao790ad902013-05-22 15:02:08 -070043 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070044
Mingyao Yang98d1cc82014-05-15 17:02:16 -070045// C++ mirror of java.lang.reflect.ArtMethod.
46class MANAGED ArtMethod FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070048 // Size of java.lang.reflect.ArtMethod.class.
49 static uint32_t ClassSize();
50
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070051 static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
52 jobject jlr_method)
Ian Rogers62f05122014-03-21 11:21:29 -070053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
54
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070055 Class* GetDeclaringClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056
57 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
58
59 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070060 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061 }
62
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070063 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080064
Ian Rogersef7d42f2014-01-06 12:55:46 -080065 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010066 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070067 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068 }
69
70 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080071 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072
73 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080074 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075 return (GetAccessFlags() & kAccPublic) != 0;
76 }
77
78 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080079 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080 return (GetAccessFlags() & kAccPrivate) != 0;
81 }
82
83 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080084 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085 return (GetAccessFlags() & kAccStatic) != 0;
86 }
87
88 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080089 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080090 return (GetAccessFlags() & kAccConstructor) != 0;
91 }
92
Mathieu Chartierbfd9a432014-05-21 17:43:44 -070093 // Returns true if the method is a class initializer.
94 bool IsClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
95 return IsConstructor() && IsStatic();
96 }
97
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080099 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100 return IsDirect(GetAccessFlags());
101 }
102
103 static bool IsDirect(uint32_t access_flags) {
104 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
105 }
106
107 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800108 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800109 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
110 return (GetAccessFlags() & synchonized) != 0;
111 }
112
Ian Rogersef7d42f2014-01-06 12:55:46 -0800113 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 return (GetAccessFlags() & kAccFinal) != 0;
115 }
116
Ian Rogersef7d42f2014-01-06 12:55:46 -0800117 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800118 return (GetAccessFlags() & kAccMiranda) != 0;
119 }
120
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122 return (GetAccessFlags() & kAccNative) != 0;
123 }
124
Ian Rogersef7d42f2014-01-06 12:55:46 -0800125 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800126 uint32_t mask = kAccFastNative | kAccNative;
127 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700128 }
129
Ian Rogersef7d42f2014-01-06 12:55:46 -0800130 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131 return (GetAccessFlags() & kAccAbstract) != 0;
132 }
133
Ian Rogersef7d42f2014-01-06 12:55:46 -0800134 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135 return (GetAccessFlags() & kAccSynthetic) != 0;
136 }
137
Ian Rogersef7d42f2014-01-06 12:55:46 -0800138 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139
Ian Rogersef7d42f2014-01-06 12:55:46 -0800140 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200141 return (GetAccessFlags() & kAccPreverified) != 0;
142 }
143
Ian Rogersef7d42f2014-01-06 12:55:46 -0800144 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
145 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200146 SetAccessFlags(GetAccessFlags() | kAccPreverified);
147 }
148
Nicolas Geoffray39468442014-09-02 15:17:15 +0100149 bool IsOptimized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
150 // Temporary solution for detecting if a method has been optimized: the compiler
151 // does not create a GC map. Instead, the vmap table contains the stack map
152 // (as in stack_map.h).
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100153 return (GetEntryPointFromQuickCompiledCode() != nullptr)
154 && (GetQuickOatCodePointer() != nullptr)
155 && (GetNativeGcMap() == nullptr);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100156 }
157
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
159 return (GetAccessFlags() & kAccPortableCompiled) != 0;
160 }
161
162 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
163 DCHECK(!IsPortableCompiled());
164 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
165 }
166
167 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
168 DCHECK(IsPortableCompiled());
169 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
170 }
171
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
173
Ian Rogersef7d42f2014-01-06 12:55:46 -0800174 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800175
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700176 // Doesn't do erroneous / unresolved class checks.
177 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
178
Ian Rogersef7d42f2014-01-06 12:55:46 -0800179 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180 return GetMethodIndex();
181 }
182
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100184 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700185 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 }
187
188 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700189 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 }
191
Ian Rogersef7d42f2014-01-06 12:55:46 -0800192 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700193 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 }
195
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700196 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100197 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700198 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800199 }
200
201 // Number of 32bit registers that would be required to hold all the arguments
202 static size_t NumArgRegisters(const StringPiece& shorty);
203
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700204 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700206 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100207 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700208 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 }
210
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
213 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
214
215 static MemberOffset DexCacheStringsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700216 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217 }
218
219 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700220 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221 }
222
223 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700224 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 }
226
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700227 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700228 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700229 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700231 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700233 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
234 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
235 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
236 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237
Andreas Gampe58a5af82014-07-31 16:23:49 -0700238 template <bool kWithCheck = true>
239 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700242 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
243 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
244 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800247 // Find the method that this method overrides
Ian Rogersef7d42f2014-01-06 12:55:46 -0800248 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800249
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700250 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800252
Mathieu Chartier4e305412014-02-19 10:54:44 -0800253 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700254 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800256 CheckObjectSizeEqualsMirrorSize();
257 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
258 }
259 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
260 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
261 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
262 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
263 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700264 }
265
Mathieu Chartier2d721012014-11-10 11:08:06 -0800266 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700267 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800269 CheckObjectSizeEqualsMirrorSize();
270 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
271 }
272 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
273 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
274 size_t pointer_size)
275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
276 SetFieldPtrWithSize<false, true, kVerifyFlags>(
277 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700278 }
279
Mathieu Chartier2d721012014-11-10 11:08:06 -0800280 ALWAYS_INLINE static MemberOffset EntryPointFromPortableCompiledCodeOffset(size_t pointer_size) {
281 return MemberOffset(PtrSizedFieldsOffset() + OFFSETOF_MEMBER(
282 PtrSizedFields, entry_point_from_portable_compiled_code_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800283 }
284
Mathieu Chartier2d721012014-11-10 11:08:06 -0800285 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
286 const void* GetEntryPointFromPortableCompiledCode()
287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
288 CheckObjectSizeEqualsMirrorSize();
289 return GetEntryPointFromPortableCompiledCodePtrSize(sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800290 }
291
Mathieu Chartier2d721012014-11-10 11:08:06 -0800292 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
293 ALWAYS_INLINE const void* GetEntryPointFromPortableCompiledCodePtrSize(size_t pointer_size)
294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
295 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
296 EntryPointFromPortableCompiledCodeOffset(pointer_size), pointer_size);
297 }
298
299 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700300 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code)
301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800302 CheckObjectSizeEqualsMirrorSize();
303 return SetEntryPointFromPortableCompiledCodePtrSize(entry_point_from_portable_compiled_code,
304 sizeof(void*));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800305 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306
Mathieu Chartier2d721012014-11-10 11:08:06 -0800307 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
308 void SetEntryPointFromPortableCompiledCodePtrSize(
309 const void* entry_point_from_portable_compiled_code, size_t pointer_size)
310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
311 SetFieldPtrWithSize<false, true, kVerifyFlags>(
312 EntryPointFromPortableCompiledCodeOffset(pointer_size),
313 entry_point_from_portable_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 }
315
Mathieu Chartier2d721012014-11-10 11:08:06 -0800316 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700317 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800318 CheckObjectSizeEqualsMirrorSize();
319 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
320 }
321 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
322 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
324 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
325 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800326 }
327
Mathieu Chartier2d721012014-11-10 11:08:06 -0800328 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700329 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800331 CheckObjectSizeEqualsMirrorSize();
332 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
333 sizeof(void*));
334 }
335 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
336 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
337 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
339 SetFieldPtrWithSize<false, true, kVerifyFlags>(
340 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
341 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800342 }
343
Ian Rogersef7d42f2014-01-06 12:55:46 -0800344 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
345
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700346 // Check whether the given PC is within the quick compiled code associated with this method's
347 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
348 // debug purposes.
349 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800350 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351 if (code == 0) {
352 return pc == 0;
353 }
354 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100355 * During a stack walk, a return PC may point past-the-end of the code
356 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800357 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100358 *
359 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800360 */
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700361 return code <= pc && pc <= code + GetCodeSize();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 }
363
Ian Rogersef7d42f2014-01-06 12:55:46 -0800364 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800365
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700366 // Returns true if the entrypoint points to the interpreter, as
367 // opposed to the compiled code, that is, this method will be
368 // interpretered on invocation.
369 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
370
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700371 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
372 uint32_t GetPortableOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
373 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
374 void SetPortableOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700376 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100377 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700378 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
379 // least 2 byte aligned.
380 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100381 return reinterpret_cast<const void*>(code);
382 }
383
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700384 // Actual entry point pointer to compiled oat code or nullptr if method has no compiled code.
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100385 const void* GetQuickOatEntryPoint() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700386
Vladimir Marko8a630572014-04-09 18:45:35 +0100387 // Actual pointer to compiled oat code or nullptr.
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700388 const void* GetQuickOatCodePointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
389 return EntryPointToCodePointer(GetQuickOatEntryPoint());
390 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100391
Ian Rogers1809a722013-08-09 22:05:32 -0700392 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Vladimir Marko8a630572014-04-09 18:45:35 +0100393 const uint8_t* GetMappingTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100394 const uint8_t* GetMappingTable(const void* code_pointer)
395 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800396
Ian Rogers1809a722013-08-09 22:05:32 -0700397 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Vladimir Marko8a630572014-04-09 18:45:35 +0100398 const uint8_t* GetVmapTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100399 const uint8_t* GetVmapTable(const void* code_pointer)
400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800401
Nicolas Geoffray39468442014-09-02 15:17:15 +0100402 StackMap GetStackMap(uint32_t native_pc_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100403 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100404
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700405 const uint8_t* GetNativeGcMap() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800406 CheckObjectSizeEqualsMirrorSize();
407 return GetNativeGcMapPtrSize(sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800408 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800409 ALWAYS_INLINE const uint8_t* GetNativeGcMapPtrSize(size_t pointer_size)
410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
411 return GetFieldPtrWithSize<uint8_t*>(GcMapOffset(pointer_size), pointer_size);
412 }
413 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700414 void SetNativeGcMap(const uint8_t* data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800415 CheckObjectSizeEqualsMirrorSize();
416 SetNativeGcMapPtrSize(data, sizeof(void*));
417 }
418 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
419 ALWAYS_INLINE void SetNativeGcMapPtrSize(const uint8_t* data, size_t pointer_size)
420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
421 SetFieldPtrWithSize<false, true, kVerifyFlags>(GcMapOffset(pointer_size), data,
422 pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800423 }
424
425 // When building the oat need a convenient place to stuff the offset of the native GC map.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700426 void SetOatNativeGcMapOffset(uint32_t gc_map_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
427 uint32_t GetOatNativeGcMapOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800428
Andreas Gampe90546832014-03-12 18:07:19 -0700429 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700430 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100431 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700432 if (kCheckFrameSize) {
433 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
434 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800435 return result;
436 }
437
Vladimir Marko7624d252014-05-02 14:40:15 +0100438 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100439 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
440 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800441
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700442 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
443 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100444 }
445
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700446 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
448 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700449 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450 }
451
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700452 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
453 DCHECK_LT(sizeof(void*), GetFrameSizeInBytes());
454 return FrameOffset(sizeof(void*));
Ian Rogers62d6c772013-02-27 08:32:07 -0800455 }
456
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700457 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800458 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
459
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700460 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800461
Mathieu Chartier2d721012014-11-10 11:08:06 -0800462 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
463 return MemberOffset(PtrSizedFieldsOffset() + OFFSETOF_MEMBER(
464 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800465 }
466
Mathieu Chartier2d721012014-11-10 11:08:06 -0800467 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
468 return MemberOffset(PtrSizedFieldsOffset() + OFFSETOF_MEMBER(
469 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800470 }
471
Mathieu Chartier2d721012014-11-10 11:08:06 -0800472 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
473 return MemberOffset(PtrSizedFieldsOffset() + OFFSETOF_MEMBER(
474 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
475 }
476
477 static MemberOffset GcMapOffset(size_t pointer_size) {
478 return MemberOffset(PtrSizedFieldsOffset() + OFFSETOF_MEMBER(
479 PtrSizedFields, gc_map_) / sizeof(void*) * pointer_size);
480 }
481
482 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
483 CheckObjectSizeEqualsMirrorSize();
484 return GetEntryPointFromJniPtrSize(sizeof(void*));
485 }
486 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
487 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
488 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
489 }
490
491 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
492 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
493 CheckObjectSizeEqualsMirrorSize();
494 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
495 }
496 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
497 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
499 SetFieldPtrWithSize<false, true, kVerifyFlags>(
500 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
501 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800502
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800503 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700504 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800505 }
506
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800507 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
508 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800509 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800510
511 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800512 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800513
Ian Rogersef7d42f2014-01-06 12:55:46 -0800514 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800515
Ian Rogersef7d42f2014-01-06 12:55:46 -0800516 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700517
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700518 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
519
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700520 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
521#ifdef NDEBUG
522 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
524 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
525 }
526#else
527 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100528 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700529#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530
531 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800532 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800534
535 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000536 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
537 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800538
Ian Rogersc449aa82013-07-29 14:35:46 -0700539 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
540 // indicates whether the found catch block is responsible for clearing the exception or whether
541 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700542 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
543 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800544 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
545
Brian Carlstromea46f952013-07-30 01:26:50 -0700546 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800547
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700548 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700549 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800550
Brian Carlstromea46f952013-07-30 01:26:50 -0700551 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800552
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800553 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800554 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
555
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700556 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700557
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700558 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700559
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700560 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
561 uint32_t unused_length;
562 return GetShorty(&unused_length);
563 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700564
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700565 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700566
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700567 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700568
Ian Rogers1ff3c982014-08-12 02:30:58 -0700569 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700570
Ian Rogers6b14d552014-10-28 21:50:58 -0700571 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
572
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700573 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700574
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700575 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700576
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700577 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700578
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700579 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700580
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700581 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700582
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700583 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700584
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700585 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700586
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700587 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700588
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700589 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700590
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700591 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
592 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700593
Ian Rogersded66a02014-10-28 18:12:55 -0700594 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
595 // number of bugs at call sites.
596 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
597
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700598 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700599
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700600 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700601
Ian Rogers1ff3c982014-08-12 02:30:58 -0700602 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700603
Mathieu Chartier2d721012014-11-10 11:08:06 -0800604 static size_t SizeWithoutPointerFields() {
605 return sizeof(ArtMethod) - sizeof(PtrSizedFields);
606 }
607
608 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
609 static size_t InstanceSize(size_t pointer_size) {
610 return SizeWithoutPointerFields() + (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
611 }
612
613 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800615 // The class we are a part of.
616 HeapReference<Class> declaring_class_;
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<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800620
Ian Rogersef7d42f2014-01-06 12:55:46 -0800621 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700622 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800623
Ian Rogersef7d42f2014-01-06 12:55:46 -0800624 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700625 HeapReference<ObjectArray<String>> dex_cache_strings_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800626
Ian Rogersef7d42f2014-01-06 12:55:46 -0800627 // Access flags; low 16 bits are defined by spec.
628 uint32_t access_flags_;
629
630 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
631
632 // Offset to the CodeItem.
633 uint32_t dex_code_item_offset_;
634
635 // Index into method_ids of the dex file associated with this method.
636 uint32_t dex_method_index_;
637
638 /* End of dex file fields. */
639
640 // Entry within a dispatch table for this method. For static/direct methods the index is into
641 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
642 // ifTable.
643 uint32_t method_index_;
644
Mathieu Chartier2d721012014-11-10 11:08:06 -0800645 // Add alignment word here if necessary.
646
647 // Must be the last fields in the method.
648 struct PACKED(4) PtrSizedFields {
649 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
650 // compiled code.
651 void* entry_point_from_interpreter_;
652
653 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
654 void* entry_point_from_jni_;
655
656 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
657 // portable compiled code or the interpreter.
658 void* entry_point_from_quick_compiled_code_;
659
660 // Pointer to a data structure created by the compiler and used by the garbage collector to
661 // determine which registers hold live references to objects within the heap. Keyed by native PC
662 // offsets for the quick compiler and dex PCs for the portable.
663 void* gc_map_;
664
665 // Method dispatch from portable compiled code invokes this pointer which may cause bridging
666 // into quick compiled code or the interpreter. Last to simplify entrypoint logic.
667 void* entry_point_from_portable_compiled_code_;
668 } ptr_sized_fields_;
669
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700670 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800671
Mathieu Chartier02e25112013-08-14 16:14:24 -0700672 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800673 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
674
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700675 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
676 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700677
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700678 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
679 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700680
Mathieu Chartier2d721012014-11-10 11:08:06 -0800681 static size_t PtrSizedFieldsOffset() {
682 return OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
683 }
684
Brian Carlstromea46f952013-07-30 01:26:50 -0700685 friend struct art::ArtMethodOffsets; // for verifying offset information
686 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800687};
688
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800689} // namespace mirror
690} // namespace art
691
Brian Carlstromea46f952013-07-30 01:26:50 -0700692#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_