blob: da494e0ec95ee1e4012d58dedf39c787f49bd7b9 [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
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).
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800155 return GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr
156 && GetQuickOatCodePointer(pointer_size) != nullptr
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800157 && GetNativeGcMap(pointer_size) == nullptr;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100158 }
159
Ian Rogersef7d42f2014-01-06 12:55:46 -0800160 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
161 return (GetAccessFlags() & kAccPortableCompiled) != 0;
162 }
163
164 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
165 DCHECK(!IsPortableCompiled());
166 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
167 }
168
169 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
170 DCHECK(IsPortableCompiled());
171 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
172 }
173
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
175
Ian Rogersef7d42f2014-01-06 12:55:46 -0800176 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177
Mathieu Chartier9f3629d2014-10-28 18:23:02 -0700178 // Doesn't do erroneous / unresolved class checks.
179 uint16_t GetMethodIndexDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
180
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800182 return GetMethodIndex();
183 }
184
Ian Rogersef7d42f2014-01-06 12:55:46 -0800185 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100186 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700187 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 }
189
190 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700191 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 }
193
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700195 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700198 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100199 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700200 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 }
202
203 // Number of 32bit registers that would be required to hold all the arguments
204 static size_t NumArgRegisters(const StringPiece& shorty);
205
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700206 ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700208 void SetDexMethodIndex(uint32_t new_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100209 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700210 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 }
212
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800213 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700214 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 }
216
217 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700218 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 }
220
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700221 ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700223 ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method)
Andreas Gampe58a5af82014-07-31 16:23:49 -0700224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700225 ALWAYS_INLINE void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700227 bool HasDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
228 bool HasSameDexCacheResolvedMethods(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
229 bool HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache)
230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231
Andreas Gampe58a5af82014-07-31 16:23:49 -0700232 template <bool kWithCheck = true>
233 Class* GetDexCacheResolvedType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800234 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
235 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700236 bool HasDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
237 bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
238 bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241 // Find the method that this method overrides
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700244 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty)
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246
Mathieu Chartier4e305412014-02-19 10:54:44 -0800247 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700248 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800250 CheckObjectSizeEqualsMirrorSize();
251 return GetEntryPointFromInterpreterPtrSize(sizeof(void*));
252 }
253 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
254 EntryPointFromInterpreter* GetEntryPointFromInterpreterPtrSize(size_t pointer_size)
255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
256 return GetFieldPtrWithSize<EntryPointFromInterpreter*, kVerifyFlags>(
257 EntryPointFromInterpreterOffset(pointer_size), pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700258 }
259
Mathieu Chartier2d721012014-11-10 11:08:06 -0800260 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700261 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800263 CheckObjectSizeEqualsMirrorSize();
264 SetEntryPointFromInterpreterPtrSize(entry_point_from_interpreter, sizeof(void*));
265 }
266 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
267 void SetEntryPointFromInterpreterPtrSize(EntryPointFromInterpreter* entry_point_from_interpreter,
268 size_t pointer_size)
269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
270 SetFieldPtrWithSize<false, true, kVerifyFlags>(
271 EntryPointFromInterpreterOffset(pointer_size), entry_point_from_interpreter, pointer_size);
Jeff Hao16743632013-05-08 10:59:04 -0700272 }
273
Mathieu Chartier2d721012014-11-10 11:08:06 -0800274 ALWAYS_INLINE static MemberOffset EntryPointFromPortableCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800275 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800276 PtrSizedFields, entry_point_from_portable_compiled_code_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277 }
278
Mathieu Chartier2d721012014-11-10 11:08:06 -0800279 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
280 const void* GetEntryPointFromPortableCompiledCode()
281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
282 CheckObjectSizeEqualsMirrorSize();
283 return GetEntryPointFromPortableCompiledCodePtrSize(sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800284 }
285
Mathieu Chartier2d721012014-11-10 11:08:06 -0800286 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
287 ALWAYS_INLINE const void* GetEntryPointFromPortableCompiledCodePtrSize(size_t pointer_size)
288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
289 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
290 EntryPointFromPortableCompiledCodeOffset(pointer_size), pointer_size);
291 }
292
293 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700294 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code)
295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800296 CheckObjectSizeEqualsMirrorSize();
297 return SetEntryPointFromPortableCompiledCodePtrSize(entry_point_from_portable_compiled_code,
298 sizeof(void*));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800300
Mathieu Chartier2d721012014-11-10 11:08:06 -0800301 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
302 void SetEntryPointFromPortableCompiledCodePtrSize(
303 const void* entry_point_from_portable_compiled_code, size_t pointer_size)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
305 SetFieldPtrWithSize<false, true, kVerifyFlags>(
306 EntryPointFromPortableCompiledCodeOffset(pointer_size),
307 entry_point_from_portable_compiled_code, pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800308 }
309
Mathieu Chartier2d721012014-11-10 11:08:06 -0800310 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700311 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800312 CheckObjectSizeEqualsMirrorSize();
313 return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*));
314 }
315 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
316 ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size)
317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
318 return GetFieldPtrWithSize<const void*, kVerifyFlags>(
319 EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800320 }
321
Mathieu Chartier2d721012014-11-10 11:08:06 -0800322 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700323 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800325 CheckObjectSizeEqualsMirrorSize();
326 SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code,
327 sizeof(void*));
328 }
329 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
330 ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize(
331 const void* entry_point_from_quick_compiled_code, size_t pointer_size)
332 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
333 SetFieldPtrWithSize<false, true, kVerifyFlags>(
334 EntryPointFromQuickCompiledCodeOffset(pointer_size), entry_point_from_quick_compiled_code,
335 pointer_size);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800336 }
337
Ian Rogersef7d42f2014-01-06 12:55:46 -0800338 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
339
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700340 // Check whether the given PC is within the quick compiled code associated with this method's
341 // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
342 // debug purposes.
343 bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800344 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800345 if (code == 0) {
346 return pc == 0;
347 }
348 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100349 * During a stack walk, a return PC may point past-the-end of the code
350 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100352 *
353 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800354 */
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700355 return code <= pc && pc <= code + GetCodeSize();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 }
357
Ian Rogersef7d42f2014-01-06 12:55:46 -0800358 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800359
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700360 // Returns true if the entrypoint points to the interpreter, as
361 // opposed to the compiled code, that is, this method will be
362 // interpretered on invocation.
363 bool IsEntrypointInterpreter() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
364
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700365 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
366 uint32_t GetPortableOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
367 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
368 void SetPortableOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800369
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700370 ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) {
Vladimir Marko8a630572014-04-09 18:45:35 +0100371 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700372 // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at
373 // least 2 byte aligned.
374 code &= ~0x1;
Vladimir Marko8a630572014-04-09 18:45:35 +0100375 return reinterpret_cast<const void*>(code);
376 }
377
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800378 // Actual entry point pointer to compiled oat code or nullptr.
379 const void* GetQuickOatEntryPoint(size_t pointer_size)
380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko8a630572014-04-09 18:45:35 +0100381 // Actual pointer to compiled oat code or nullptr.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800382 const void* GetQuickOatCodePointer(size_t pointer_size)
383 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
384 return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size));
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700385 }
Vladimir Marko8a630572014-04-09 18:45:35 +0100386
Ian Rogers1809a722013-08-09 22:05:32 -0700387 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800388 const uint8_t* GetMappingTable(size_t pointer_size)
389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
390 const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392
Ian Rogers1809a722013-08-09 22:05:32 -0700393 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800394 const uint8_t* GetVmapTable(size_t pointer_size)
395 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
396 const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800398
Nicolas Geoffray39468442014-09-02 15:17:15 +0100399 StackMap GetStackMap(uint32_t native_pc_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100400 CodeInfo GetOptimizedCodeInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100401
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800402 // Callers should wrap the uint8_t* in a GcMap instance for convenient access.
403 const uint8_t* GetNativeGcMap(size_t pointer_size)
404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
405 const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size)
406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407
Andreas Gampe90546832014-03-12 18:07:19 -0700408 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700409 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Vladimir Marko7624d252014-05-02 14:40:15 +0100410 uint32_t result = GetQuickFrameInfo().FrameSizeInBytes();
Andreas Gampe90546832014-03-12 18:07:19 -0700411 if (kCheckFrameSize) {
412 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
413 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414 return result;
415 }
416
Vladimir Marko7624d252014-05-02 14:40:15 +0100417 QuickMethodFrameInfo GetQuickFrameInfo() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100418 QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer)
419 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700421 FrameOffset GetReturnPcOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
422 return GetReturnPcOffset(GetFrameSizeInBytes());
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100423 }
424
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700425 FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
427 DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700428 return FrameOffset(frame_size_in_bytes - sizeof(void*));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800429 }
430
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700431 FrameOffset GetHandleScopeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
432 DCHECK_LT(sizeof(void*), GetFrameSizeInBytes());
433 return FrameOffset(sizeof(void*));
Ian Rogers62d6c772013-02-27 08:32:07 -0800434 }
435
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700436 void RegisterNative(const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
438
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700439 void UnregisterNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440
Mathieu Chartier2d721012014-11-10 11:08:06 -0800441 static MemberOffset EntryPointFromInterpreterOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800442 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800443 PtrSizedFields, entry_point_from_interpreter_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444 }
445
Mathieu Chartier2d721012014-11-10 11:08:06 -0800446 static MemberOffset EntryPointFromJniOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800447 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800448 PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449 }
450
Mathieu Chartier2d721012014-11-10 11:08:06 -0800451 static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800452 return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800453 PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size);
454 }
455
Mathieu Chartier2d721012014-11-10 11:08:06 -0800456 void* GetEntryPointFromJni() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
457 CheckObjectSizeEqualsMirrorSize();
458 return GetEntryPointFromJniPtrSize(sizeof(void*));
459 }
460 ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size)
461 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
462 return GetFieldPtrWithSize<void*>(EntryPointFromJniOffset(pointer_size), pointer_size);
463 }
464
465 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
466 void SetEntryPointFromJni(const void* entrypoint) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
467 CheckObjectSizeEqualsMirrorSize();
468 SetEntryPointFromJniPtrSize<kVerifyFlags>(entrypoint, sizeof(void*));
469 }
470 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
471 ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
473 SetFieldPtrWithSize<false, true, kVerifyFlags>(
474 EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size);
475 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800476
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700478 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800479 }
480
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800481 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
482 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800483 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484
485 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800486 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800487
Ian Rogersef7d42f2014-01-06 12:55:46 -0800488 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800489
Ian Rogersef7d42f2014-01-06 12:55:46 -0800490 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700491
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700492 bool IsImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
493
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700494 uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
495#ifdef NDEBUG
496 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
498 return pc - reinterpret_cast<uintptr_t>(quick_entry_point);
499 }
500#else
501 uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point)
Vladimir Marko4c1c5102014-05-14 16:51:16 +0100502 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700503#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800504
505 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800506 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800508
509 // Converts a dex PC to a native PC.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000510 uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true)
511 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800512
Ian Rogersc449aa82013-07-29 14:35:46 -0700513 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
514 // indicates whether the found catch block is responsible for clearing the exception or whether
515 // a move-exception instruction is present.
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700516 static uint32_t FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
517 uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
519
Brian Carlstromea46f952013-07-30 01:26:50 -0700520 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800521
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700522 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700523 static Class* GetJavaLangReflectArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524
Brian Carlstromea46f952013-07-30 01:26:50 -0700525 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800526
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800527 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800528 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
529
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700530 const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700531
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700532 const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700533
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700534 const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
535 uint32_t unused_length;
536 return GetShorty(&unused_length);
537 }
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700538
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700539 const char* GetShorty(uint32_t* out_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700540
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700541 const Signature GetSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700542
Ian Rogers1ff3c982014-08-12 02:30:58 -0700543 ALWAYS_INLINE const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700544
Ian Rogers6b14d552014-10-28 21:50:58 -0700545 mirror::String* GetNameAsString(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700547 const DexFile::CodeItem* GetCodeItem() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700548
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700549 bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700550
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700551 int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700552
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700553 const DexFile::ProtoId& GetPrototype() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700554
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700555 const DexFile::TypeList* GetParameterTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700556
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700557 const char* GetDeclaringClassSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700558
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700559 uint16_t GetClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700560
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700561 const DexFile::ClassDef& GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700562
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700563 const char* GetReturnTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700564
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700565 const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx)
566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700567
Ian Rogersded66a02014-10-28 18:12:55 -0700568 // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large
569 // number of bugs at call sites.
570 mirror::Class* GetReturnType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
571
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700572 mirror::ClassLoader* GetClassLoader() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700573
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700574 mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700575
Ian Rogers1ff3c982014-08-12 02:30:58 -0700576 ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700577
Mathieu Chartiereace4582014-11-24 18:29:54 -0800578 static size_t SizeWithoutPointerFields(size_t pointer_size) {
579 size_t total = sizeof(ArtMethod) - sizeof(PtrSizedFields);
580#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
581 // Add 4 bytes if 64 bit, otherwise 0.
582 total += pointer_size - sizeof(uint32_t);
583#endif
584 return total;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800585 }
586
587 // Size of an instance of java.lang.reflect.ArtMethod not including its value array.
588 static size_t InstanceSize(size_t pointer_size) {
Mathieu Chartiereace4582014-11-24 18:29:54 -0800589 return SizeWithoutPointerFields(pointer_size) +
590 (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800591 }
592
593 protected:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800594 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800595 // The class we are a part of.
596 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800597
Ian Rogersef7d42f2014-01-06 12:55:46 -0800598 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700599 HeapReference<ObjectArray<ArtMethod>> dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800600
Ian Rogersef7d42f2014-01-06 12:55:46 -0800601 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
Ian Rogers700a4022014-05-19 16:49:03 -0700602 HeapReference<ObjectArray<Class>> dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800603
Ian Rogersef7d42f2014-01-06 12:55:46 -0800604 // Access flags; low 16 bits are defined by spec.
605 uint32_t access_flags_;
606
607 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
608
609 // Offset to the CodeItem.
610 uint32_t dex_code_item_offset_;
611
612 // Index into method_ids of the dex file associated with this method.
613 uint32_t dex_method_index_;
614
615 /* End of dex file fields. */
616
617 // Entry within a dispatch table for this method. For static/direct methods the index is into
618 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
619 // ifTable.
620 uint32_t method_index_;
621
Mathieu Chartiereace4582014-11-24 18:29:54 -0800622 // Fake padding field gets inserted here.
Mathieu Chartier2d721012014-11-10 11:08:06 -0800623
624 // Must be the last fields in the method.
625 struct PACKED(4) PtrSizedFields {
626 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
627 // compiled code.
628 void* entry_point_from_interpreter_;
629
630 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
631 void* entry_point_from_jni_;
632
633 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
634 // portable compiled code or the interpreter.
635 void* entry_point_from_quick_compiled_code_;
636
Mathieu Chartier2d721012014-11-10 11:08:06 -0800637 // Method dispatch from portable compiled code invokes this pointer which may cause bridging
638 // into quick compiled code or the interpreter. Last to simplify entrypoint logic.
639 void* entry_point_from_portable_compiled_code_;
640 } ptr_sized_fields_;
641
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700642 static GcRoot<Class> java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800643
Mathieu Chartier02e25112013-08-14 16:14:24 -0700644 private:
Mathieu Chartier2d721012014-11-10 11:08:06 -0800645 ALWAYS_INLINE void CheckObjectSizeEqualsMirrorSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
646
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700647 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDexCacheResolvedMethods()
648 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700649
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700650 ALWAYS_INLINE ObjectArray<Class>* GetDexCacheResolvedTypes()
651 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700652
Mathieu Chartiereace4582014-11-24 18:29:54 -0800653 static size_t PtrSizedFieldsOffset(size_t pointer_size) {
654 size_t offset = OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_);
655#ifdef ART_METHOD_HAS_PADDING_FIELD_ON_64_BIT
656 // Add 4 bytes if 64 bit, otherwise 0.
657 offset += pointer_size - sizeof(uint32_t);
658#endif
659 return offset;
Mathieu Chartier2d721012014-11-10 11:08:06 -0800660 }
661
Brian Carlstromea46f952013-07-30 01:26:50 -0700662 friend struct art::ArtMethodOffsets; // for verifying offset information
663 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800664};
665
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800666} // namespace mirror
667} // namespace art
668
Brian Carlstromea46f952013-07-30 01:26:50 -0700669#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_