blob: f61a01d90e05e8ce095354ec0d5c2560fe5edbee [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
20#include "class.h"
Jeff Hao790ad902013-05-22 15:02:08 -070021#include "dex_file.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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026
27namespace art {
28
Brian Carlstromea46f952013-07-30 01:26:50 -070029struct ArtMethodOffsets;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030struct ConstructorMethodOffsets;
31union JValue;
32struct MethodClassOffsets;
Jeff Hao790ad902013-05-22 15:02:08 -070033class MethodHelper;
Ian Rogers62f05122014-03-21 11:21:29 -070034class ScopedObjectAccess;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070036class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037
38namespace mirror {
39
40class StaticStorageBase;
41
Jeff Hao790ad902013-05-22 15:02:08 -070042typedef void (EntryPointFromInterpreter)(Thread* self, MethodHelper& mh,
43 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070044
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045// C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor
Brian Carlstromea46f952013-07-30 01:26:50 -070046class MANAGED ArtMethod : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047 public:
Ian Rogers62f05122014-03-21 11:21:29 -070048 static ArtMethod* FromReflectedMethod(const ScopedObjectAccess& soa, jobject jlr_method)
49 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
50
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070051 Class* GetDeclaringClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052
53 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
54
55 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070056 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 }
58
Ian Rogersef7d42f2014-01-06 12:55:46 -080059 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080060
Ian Rogersef7d42f2014-01-06 12:55:46 -080061 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010062 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070063 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064 }
65
66 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080067 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068
69 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080070 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071 return (GetAccessFlags() & kAccPublic) != 0;
72 }
73
74 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080075 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 return (GetAccessFlags() & kAccPrivate) != 0;
77 }
78
79 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080080 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081 return (GetAccessFlags() & kAccStatic) != 0;
82 }
83
84 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080085 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086 return (GetAccessFlags() & kAccConstructor) != 0;
87 }
88
89 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080090 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091 return IsDirect(GetAccessFlags());
92 }
93
94 static bool IsDirect(uint32_t access_flags) {
95 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
96 }
97
98 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -080099 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
101 return (GetAccessFlags() & synchonized) != 0;
102 }
103
Ian Rogersef7d42f2014-01-06 12:55:46 -0800104 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 return (GetAccessFlags() & kAccFinal) != 0;
106 }
107
Ian Rogersef7d42f2014-01-06 12:55:46 -0800108 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800109 return (GetAccessFlags() & kAccMiranda) != 0;
110 }
111
Ian Rogersef7d42f2014-01-06 12:55:46 -0800112 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800113 return (GetAccessFlags() & kAccNative) != 0;
114 }
115
Ian Rogersef7d42f2014-01-06 12:55:46 -0800116 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800117 uint32_t mask = kAccFastNative | kAccNative;
118 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700119 }
120
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122 return (GetAccessFlags() & kAccAbstract) != 0;
123 }
124
Ian Rogersef7d42f2014-01-06 12:55:46 -0800125 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 return (GetAccessFlags() & kAccSynthetic) != 0;
127 }
128
Ian Rogersef7d42f2014-01-06 12:55:46 -0800129 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800130
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200132 return (GetAccessFlags() & kAccPreverified) != 0;
133 }
134
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
136 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200137 SetAccessFlags(GetAccessFlags() | kAccPreverified);
138 }
139
Ian Rogersef7d42f2014-01-06 12:55:46 -0800140 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
141 return (GetAccessFlags() & kAccPortableCompiled) != 0;
142 }
143
144 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
145 DCHECK(!IsPortableCompiled());
146 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
147 }
148
149 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
150 DCHECK(IsPortableCompiled());
151 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
152 }
153
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
155
Ian Rogersef7d42f2014-01-06 12:55:46 -0800156 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 return GetMethodIndex();
160 }
161
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100163 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700164 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165 }
166
167 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700168 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800169 }
170
Ian Rogersef7d42f2014-01-06 12:55:46 -0800171 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700172 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 }
174
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700175 void SetCodeItemOffset(uint32_t new_code_off) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100176 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700177 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 }
179
180 // Number of 32bit registers that would be required to hold all the arguments
181 static size_t NumArgRegisters(const StringPiece& shorty);
182
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700185 void SetDexMethodIndex(uint32_t new_idx) 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, dex_method_index_), new_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 }
189
Ian Rogersef7d42f2014-01-06 12:55:46 -0800190 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
192 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
193
194 static MemberOffset DexCacheStringsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700195 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
198 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700199 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201
202 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700203 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 }
205
Ian Rogersef7d42f2014-01-06 12:55:46 -0800206 ObjectArray<ArtMethod>* GetDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700207 void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800208 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
209
Ian Rogersef7d42f2014-01-06 12:55:46 -0800210 ObjectArray<Class>* GetDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
213
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 // Find the method that this method overrides
Ian Rogersef7d42f2014-01-06 12:55:46 -0800215 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216
Ian Rogers0177e532014-02-11 16:30:46 -0800217 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result,
218 const char* shorty) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219
Mathieu Chartier4e305412014-02-19 10:54:44 -0800220 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700221 EntryPointFromInterpreter* GetEntryPointFromInterpreter()
222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800223 return GetFieldPtr<EntryPointFromInterpreter*, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700224 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_));
Jeff Hao16743632013-05-08 10:59:04 -0700225 }
226
Mathieu Chartier4e305412014-02-19 10:54:44 -0800227 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700228 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter)
229 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800230 SetFieldPtr<false, true, kVerifyFlags>(
231 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700232 entry_point_from_interpreter);
Jeff Hao16743632013-05-08 10:59:04 -0700233 }
234
Ian Rogersef7d42f2014-01-06 12:55:46 -0800235 static MemberOffset EntryPointFromPortableCompiledCodeOffset() {
236 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_portable_compiled_code_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 }
238
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700240 const void* GetEntryPointFromPortableCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800241 return GetFieldPtr<const void*, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700242 EntryPointFromPortableCompiledCodeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800243 }
244
Mathieu Chartier4e305412014-02-19 10:54:44 -0800245 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700246 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code)
247 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800248 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700249 EntryPointFromPortableCompiledCodeOffset(), entry_point_from_portable_compiled_code);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800250 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800251
Ian Rogersef7d42f2014-01-06 12:55:46 -0800252 static MemberOffset EntryPointFromQuickCompiledCodeOffset() {
253 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_quick_compiled_code_));
254 }
255
Mathieu Chartier4e305412014-02-19 10:54:44 -0800256 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700257 const void* GetEntryPointFromQuickCompiledCode() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
258 return GetFieldPtr<const void*, kVerifyFlags>(EntryPointFromQuickCompiledCodeOffset());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800259 }
260
Mathieu Chartier4e305412014-02-19 10:54:44 -0800261 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700262 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code)
263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800264 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700265 EntryPointFromQuickCompiledCodeOffset(), entry_point_from_quick_compiled_code);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800266 }
267
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
269
270 bool IsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
271 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800272 if (code == 0) {
273 return pc == 0;
274 }
275 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100276 * During a stack walk, a return PC may point past-the-end of the code
277 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800278 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100279 *
280 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800281 */
282 return (code <= pc && pc <= code + GetCodeSize());
283 }
284
Ian Rogersef7d42f2014-01-06 12:55:46 -0800285 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700287 uint32_t GetQuickOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
288 uint32_t GetPortableOatCodeOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
289 void SetQuickOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
290 void SetPortableOatCodeOffset(uint32_t code_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800291
Vladimir Marko8a630572014-04-09 18:45:35 +0100292 static const void* EntryPointToCodePointer(const void* entry_point) ALWAYS_INLINE {
293 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
294 code &= ~0x1; // TODO: Make this Thumb2 specific.
295 return reinterpret_cast<const void*>(code);
296 }
297
298 // Actual pointer to compiled oat code or nullptr.
299 const void* GetOatCodePointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
300
Ian Rogers1809a722013-08-09 22:05:32 -0700301 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Vladimir Marko8a630572014-04-09 18:45:35 +0100302 const uint8_t* GetMappingTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303
Ian Rogers1809a722013-08-09 22:05:32 -0700304 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Vladimir Marko8a630572014-04-09 18:45:35 +0100305 const uint8_t* GetVmapTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700307 const uint8_t* GetNativeGcMap() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
308 return GetFieldPtr<uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800310 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700311 void SetNativeGcMap(const uint8_t* data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
312 SetFieldPtr<false, true, kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), data);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 }
314
315 // When building the oat need a convenient place to stuff the offset of the native GC map.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700316 void SetOatNativeGcMapOffset(uint32_t gc_map_offset) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317 uint32_t GetOatNativeGcMapOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318
Andreas Gampe90546832014-03-12 18:07:19 -0700319 template <bool kCheckFrameSize = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700320 uint32_t GetFrameSizeInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
321 uint32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_));
Andreas Gampe90546832014-03-12 18:07:19 -0700322 if (kCheckFrameSize) {
323 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
324 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800325 return result;
326 }
327
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700328 void SetFrameSizeInBytes(size_t new_frame_size_in_bytes)
329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100330 // Not called within a transaction.
331 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700332 new_frame_size_in_bytes);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333 }
334
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700335 size_t GetReturnPcOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 return GetFrameSizeInBytes() - kPointerSize;
337 }
338
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339 size_t GetSirtOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800340 return kPointerSize;
341 }
342
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700343 bool IsRegistered() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344
Ian Rogers1eb512d2013-10-18 15:42:20 -0700345 void RegisterNative(Thread* self, const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
347
348 void UnregisterNative(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
349
350 static MemberOffset NativeMethodOffset() {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800351 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 }
353
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700354 const void* GetNativeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
355 return GetFieldPtr<const void*>(NativeMethodOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 }
357
Mathieu Chartier4e305412014-02-19 10:54:44 -0800358 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700359 void SetNativeMethod(const void*) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800360
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700362 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363 }
364
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700365 uint32_t GetCoreSpillMask() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
366 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 }
368
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700369 void SetCoreSpillMask(uint32_t core_spill_mask) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100370 // Computed during compilation.
371 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700372 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), core_spill_mask);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 }
374
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700375 uint32_t GetFpSpillMask() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
376 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800377 }
378
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700379 void SetFpSpillMask(uint32_t fp_spill_mask) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100380 // Computed during compilation.
381 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700382 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), fp_spill_mask);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800383 }
384
385 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
386 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800387 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388
389 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800390 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391
Ian Rogersef7d42f2014-01-06 12:55:46 -0800392 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800393
Ian Rogersef7d42f2014-01-06 12:55:46 -0800394 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700395
Ian Rogersef7d42f2014-01-06 12:55:46 -0800396 uintptr_t NativePcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397
398 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800399 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800401
402 // Converts a dex PC to a native PC.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800403 uintptr_t ToNativePc(const uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800404
Ian Rogersc449aa82013-07-29 14:35:46 -0700405 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
406 // indicates whether the found catch block is responsible for clearing the exception or whether
407 // a move-exception instruction is present.
Jeff Haoaa961912014-04-22 13:54:32 -0700408 uint32_t FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc,
409 bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
411
Brian Carlstromea46f952013-07-30 01:26:50 -0700412 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700414 template <bool kDoReadBarrier = true>
Brian Carlstromea46f952013-07-30 01:26:50 -0700415 static Class* GetJavaLangReflectArtMethod() {
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700416 // This does not need a RB because it is a root.
Brian Carlstromea46f952013-07-30 01:26:50 -0700417 return java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418 }
419
Brian Carlstromea46f952013-07-30 01:26:50 -0700420 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800422 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
424
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800425 protected:
426 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800427 // The class we are a part of.
428 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800429
Ian Rogersef7d42f2014-01-06 12:55:46 -0800430 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
431 HeapReference<ObjectArray<ArtMethod> > dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432
Ian Rogersef7d42f2014-01-06 12:55:46 -0800433 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
434 HeapReference<ObjectArray<Class> > dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800435
Ian Rogersef7d42f2014-01-06 12:55:46 -0800436 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
437 HeapReference<ObjectArray<String> > dex_cache_strings_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438
Ian Rogersef7d42f2014-01-06 12:55:46 -0800439 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
440 // compiled code.
441 uint64_t entry_point_from_interpreter_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442
Ian Rogersef7d42f2014-01-06 12:55:46 -0800443 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
444 uint64_t entry_point_from_jni_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800445
Ian Rogersef7d42f2014-01-06 12:55:46 -0800446 // Method dispatch from portable compiled code invokes this pointer which may cause bridging into
447 // quick compiled code or the interpreter.
448 uint64_t entry_point_from_portable_compiled_code_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449
Ian Rogersef7d42f2014-01-06 12:55:46 -0800450 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
451 // portable compiled code or the interpreter.
452 uint64_t entry_point_from_quick_compiled_code_;
Jeff Haoaa4a7932013-05-13 11:28:27 -0700453
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 // Pointer to a data structure created by the compiler and used by the garbage collector to
455 // determine which registers hold live references to objects within the heap. Keyed by native PC
456 // offsets for the quick compiler and dex PCs for the portable.
457 uint64_t gc_map_;
Jeff Hao16743632013-05-08 10:59:04 -0700458
Ian Rogersef7d42f2014-01-06 12:55:46 -0800459 // Access flags; low 16 bits are defined by spec.
460 uint32_t access_flags_;
461
462 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
463
464 // Offset to the CodeItem.
465 uint32_t dex_code_item_offset_;
466
467 // Index into method_ids of the dex file associated with this method.
468 uint32_t dex_method_index_;
469
470 /* End of dex file fields. */
471
472 // Entry within a dispatch table for this method. For static/direct methods the index is into
473 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
474 // ifTable.
475 uint32_t method_index_;
476
477 // --- Quick compiler meta-data. ---
478 // TODO: merge and place in native heap, such as done with the code size.
479
480 // Bit map of spilled machine registers.
481 uint32_t quick_core_spill_mask_;
482
483 // Bit map of spilled floating point machine registers.
484 uint32_t quick_fp_spill_mask_;
485
486 // Fixed frame size for this method when executed.
487 uint32_t quick_frame_size_in_bytes_;
488
489 // --- End of quick compiler meta-data. ---
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490
Brian Carlstromea46f952013-07-30 01:26:50 -0700491 static Class* java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492
Mathieu Chartier02e25112013-08-14 16:14:24 -0700493 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700494 friend struct art::ArtMethodOffsets; // for verifying offset information
495 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800496};
497
Brian Carlstromea46f952013-07-30 01:26:50 -0700498class MANAGED ArtMethodClass : public Class {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800499 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700500 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethodClass);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800501};
502
503} // namespace mirror
504} // namespace art
505
Brian Carlstromea46f952013-07-30 01:26:50 -0700506#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_