blob: 8d2c39cce5fb93528ac5f031a9a877d93fd62e1f [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"
Vladimir Marko8a630572014-04-09 18:45:35 +010024#include "oat.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "object.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080026#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027
28namespace art {
29
Brian Carlstromea46f952013-07-30 01:26:50 -070030struct ArtMethodOffsets;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031struct ConstructorMethodOffsets;
32union JValue;
33struct MethodClassOffsets;
Jeff Hao790ad902013-05-22 15:02:08 -070034class MethodHelper;
Ian Rogers62f05122014-03-21 11:21:29 -070035class ScopedObjectAccess;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070037class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
39namespace mirror {
40
41class StaticStorageBase;
42
Jeff Hao790ad902013-05-22 15:02:08 -070043typedef void (EntryPointFromInterpreter)(Thread* self, MethodHelper& mh,
44 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070045
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046// C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor
Brian Carlstromea46f952013-07-30 01:26:50 -070047class MANAGED ArtMethod : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 public:
Ian Rogers62f05122014-03-21 11:21:29 -070049 static ArtMethod* FromReflectedMethod(const ScopedObjectAccess& soa, jobject jlr_method)
50 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
51
Ian Rogersef7d42f2014-01-06 12:55:46 -080052 Class* GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053
54 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
55
56 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070057 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058 }
59
Ian Rogersef7d42f2014-01-06 12:55:46 -080060 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080061
Ian Rogersef7d42f2014-01-06 12:55:46 -080062 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010063 // Not called within a transaction.
64 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065 }
66
67 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080068 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069
70 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080071 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 return (GetAccessFlags() & kAccPublic) != 0;
73 }
74
75 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080076 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 return (GetAccessFlags() & kAccPrivate) != 0;
78 }
79
80 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080081 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 return (GetAccessFlags() & kAccStatic) != 0;
83 }
84
85 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 return (GetAccessFlags() & kAccConstructor) != 0;
88 }
89
90 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080091 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092 return IsDirect(GetAccessFlags());
93 }
94
95 static bool IsDirect(uint32_t access_flags) {
96 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
97 }
98
99 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800100 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
102 return (GetAccessFlags() & synchonized) != 0;
103 }
104
Ian Rogersef7d42f2014-01-06 12:55:46 -0800105 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800106 return (GetAccessFlags() & kAccFinal) != 0;
107 }
108
Ian Rogersef7d42f2014-01-06 12:55:46 -0800109 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800110 return (GetAccessFlags() & kAccMiranda) != 0;
111 }
112
Ian Rogersef7d42f2014-01-06 12:55:46 -0800113 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 return (GetAccessFlags() & kAccNative) != 0;
115 }
116
Ian Rogersef7d42f2014-01-06 12:55:46 -0800117 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800118 uint32_t mask = kAccFastNative | kAccNative;
119 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700120 }
121
Ian Rogersef7d42f2014-01-06 12:55:46 -0800122 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 return (GetAccessFlags() & kAccAbstract) != 0;
124 }
125
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 return (GetAccessFlags() & kAccSynthetic) != 0;
128 }
129
Ian Rogersef7d42f2014-01-06 12:55:46 -0800130 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131
Ian Rogersef7d42f2014-01-06 12:55:46 -0800132 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200133 return (GetAccessFlags() & kAccPreverified) != 0;
134 }
135
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
137 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200138 SetAccessFlags(GetAccessFlags() | kAccPreverified);
139 }
140
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
142 return (GetAccessFlags() & kAccPortableCompiled) != 0;
143 }
144
145 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
146 DCHECK(!IsPortableCompiled());
147 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
148 }
149
150 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
151 DCHECK(IsPortableCompiled());
152 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
153 }
154
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
156
Ian Rogersef7d42f2014-01-06 12:55:46 -0800157 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158
Ian Rogersef7d42f2014-01-06 12:55:46 -0800159 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 return GetMethodIndex();
161 }
162
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100164 // Not called within a transaction.
165 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 }
167
168 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700169 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170 }
171
Ian Rogersef7d42f2014-01-06 12:55:46 -0800172 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
173 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174 }
175
176 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100177 // Not called within a transaction.
178 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 }
180
181 // Number of 32bit registers that would be required to hold all the arguments
182 static size_t NumArgRegisters(const StringPiece& shorty);
183
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184 uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185
186 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100187 // Not called within a transaction.
188 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 }
190
Ian Rogersef7d42f2014-01-06 12:55:46 -0800191 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
193 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
194
195 static MemberOffset DexCacheStringsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700196 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197 }
198
199 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700200 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 }
202
203 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700204 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 }
206
Ian Rogersef7d42f2014-01-06 12:55:46 -0800207 ObjectArray<ArtMethod>* GetDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700208 void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
210
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211 ObjectArray<Class>* GetDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
213 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
214
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 // Find the method that this method overrides
Ian Rogersef7d42f2014-01-06 12:55:46 -0800216 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217
Ian Rogers0177e532014-02-11 16:30:46 -0800218 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result,
219 const char* shorty) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220
Mathieu Chartier4e305412014-02-19 10:54:44 -0800221 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800222 EntryPointFromInterpreter* GetEntryPointFromInterpreter() {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800223 return GetFieldPtr<EntryPointFromInterpreter*, kVerifyFlags>(
Ian Rogersef7d42f2014-01-06 12:55:46 -0800224 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_), false);
Jeff Hao16743632013-05-08 10:59:04 -0700225 }
226
Mathieu Chartier4e305412014-02-19 10:54:44 -0800227 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Jeff Hao16743632013-05-08 10:59:04 -0700228 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800229 SetFieldPtr<false, true, kVerifyFlags>(
230 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_),
231 entry_point_from_interpreter, false);
Jeff Hao16743632013-05-08 10:59:04 -0700232 }
233
Ian Rogersef7d42f2014-01-06 12:55:46 -0800234 static MemberOffset EntryPointFromPortableCompiledCodeOffset() {
235 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_portable_compiled_code_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236 }
237
Mathieu Chartier4e305412014-02-19 10:54:44 -0800238 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800239 const void* GetEntryPointFromPortableCompiledCode() {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800240 return GetFieldPtr<const void*, kVerifyFlags>(
241 EntryPointFromPortableCompiledCodeOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242 }
243
Mathieu Chartier4e305412014-02-19 10:54:44 -0800244 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800245 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800246 SetFieldPtr<false, true, kVerifyFlags>(
247 EntryPointFromPortableCompiledCodeOffset(), entry_point_from_portable_compiled_code, false);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800248 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800249
Ian Rogersef7d42f2014-01-06 12:55:46 -0800250 static MemberOffset EntryPointFromQuickCompiledCodeOffset() {
251 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_quick_compiled_code_));
252 }
253
Mathieu Chartier4e305412014-02-19 10:54:44 -0800254 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800255 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800256 return GetFieldPtr<const void*, kVerifyFlags>(EntryPointFromQuickCompiledCodeOffset(), false);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800257 }
258
Mathieu Chartier4e305412014-02-19 10:54:44 -0800259 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800260 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800261 SetFieldPtr<false, true, kVerifyFlags>(
262 EntryPointFromQuickCompiledCodeOffset(), entry_point_from_quick_compiled_code, false);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800263 }
264
Ian Rogersef7d42f2014-01-06 12:55:46 -0800265 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
266
267 bool IsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
268 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800269 if (code == 0) {
270 return pc == 0;
271 }
272 /*
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100273 * During a stack walk, a return PC may point past-the-end of the code
274 * in the case that the last instruction is a call that isn't expected to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800275 * return. Thus, we check <= code + GetCodeSize().
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100276 *
277 * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800278 */
279 return (code <= pc && pc <= code + GetCodeSize());
280 }
281
Ian Rogersef7d42f2014-01-06 12:55:46 -0800282 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800283
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284 uint32_t GetQuickOatCodeOffset();
285 uint32_t GetPortableOatCodeOffset();
286 void SetQuickOatCodeOffset(uint32_t code_offset);
287 void SetPortableOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800288
Vladimir Marko8a630572014-04-09 18:45:35 +0100289 static const void* EntryPointToCodePointer(const void* entry_point) ALWAYS_INLINE {
290 uintptr_t code = reinterpret_cast<uintptr_t>(entry_point);
291 code &= ~0x1; // TODO: Make this Thumb2 specific.
292 return reinterpret_cast<const void*>(code);
293 }
294
295 // Actual pointer to compiled oat code or nullptr.
296 const void* GetOatCodePointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
297
Ian Rogers1809a722013-08-09 22:05:32 -0700298 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Vladimir Marko8a630572014-04-09 18:45:35 +0100299 const uint8_t* GetMappingTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800300
Ian Rogers1809a722013-08-09 22:05:32 -0700301 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Vladimir Marko8a630572014-04-09 18:45:35 +0100302 const uint8_t* GetVmapTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303
Ian Rogersef7d42f2014-01-06 12:55:46 -0800304 const uint8_t* GetNativeGcMap() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700305 return GetFieldPtr<uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800307 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800308 void SetNativeGcMap(const uint8_t* data) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800309 SetFieldPtr<false, true, kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), data,
310 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311 }
312
313 // When building the oat need a convenient place to stuff the offset of the native GC map.
314 void SetOatNativeGcMapOffset(uint32_t gc_map_offset);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800315 uint32_t GetOatNativeGcMapOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800316
Andreas Gampe90546832014-03-12 18:07:19 -0700317 template <bool kCheckFrameSize = true>
Ian Rogers936b37f2014-02-14 00:52:24 -0800318 uint32_t GetFrameSizeInBytes() {
319 uint32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_),
320 false);
Andreas Gampe90546832014-03-12 18:07:19 -0700321 if (kCheckFrameSize) {
322 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
323 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800324 return result;
325 }
326
327 void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100328 // Not called within a transaction.
329 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_),
330 new_frame_size_in_bytes, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 }
332
Ian Rogersef7d42f2014-01-06 12:55:46 -0800333 size_t GetReturnPcOffsetInBytes() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800334 return GetFrameSizeInBytes() - kPointerSize;
335 }
336
Ian Rogersef7d42f2014-01-06 12:55:46 -0800337 size_t GetSirtOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800338 return kPointerSize;
339 }
340
Ian Rogersef7d42f2014-01-06 12:55:46 -0800341 bool IsRegistered();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800342
Ian Rogers1eb512d2013-10-18 15:42:20 -0700343 void RegisterNative(Thread* self, const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
345
346 void UnregisterNative(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
347
348 static MemberOffset NativeMethodOffset() {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800349 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350 }
351
Ian Rogersef7d42f2014-01-06 12:55:46 -0800352 const void* GetNativeMethod() {
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800353 return GetFieldPtr<const void*>(NativeMethodOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800354 }
355
Mathieu Chartier4e305412014-02-19 10:54:44 -0800356 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800357 void SetNativeMethod(const void*);
358
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800359 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700360 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361 }
362
Ian Rogersef7d42f2014-01-06 12:55:46 -0800363 uint32_t GetCoreSpillMask() {
364 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800365 }
366
367 void SetCoreSpillMask(uint32_t core_spill_mask) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100368 // Computed during compilation.
369 // Not called within a transaction.
370 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), core_spill_mask, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371 }
372
Ian Rogersef7d42f2014-01-06 12:55:46 -0800373 uint32_t GetFpSpillMask() {
374 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375 }
376
377 void SetFpSpillMask(uint32_t fp_spill_mask) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100378 // Computed during compilation.
379 // Not called within a transaction.
380 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), fp_spill_mask, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800381 }
382
383 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
384 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800385 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386
387 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800388 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389
Ian Rogersef7d42f2014-01-06 12:55:46 -0800390 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391
Ian Rogersef7d42f2014-01-06 12:55:46 -0800392 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700393
Ian Rogersef7d42f2014-01-06 12:55:46 -0800394 uintptr_t NativePcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800395
396 // Converts a native PC to a dex PC.
Dave Allisonb373e092014-02-20 16:06:36 -0800397 uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true)
398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399
400 // Converts a dex PC to a native PC.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800401 uintptr_t ToNativePc(const uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800402
Ian Rogersc449aa82013-07-29 14:35:46 -0700403 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
404 // indicates whether the found catch block is responsible for clearing the exception or whether
405 // a move-exception instruction is present.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800406 uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
408
Brian Carlstromea46f952013-07-30 01:26:50 -0700409 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410
Brian Carlstromea46f952013-07-30 01:26:50 -0700411 static Class* GetJavaLangReflectArtMethod() {
412 return java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413 }
414
Brian Carlstromea46f952013-07-30 01:26:50 -0700415 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800416
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800417 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
419
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420 protected:
421 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800422 // The class we are a part of.
423 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424
Ian Rogersef7d42f2014-01-06 12:55:46 -0800425 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
426 HeapReference<ObjectArray<ArtMethod> > dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427
Ian Rogersef7d42f2014-01-06 12:55:46 -0800428 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
429 HeapReference<ObjectArray<Class> > dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430
Ian Rogersef7d42f2014-01-06 12:55:46 -0800431 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
432 HeapReference<ObjectArray<String> > dex_cache_strings_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433
Ian Rogersef7d42f2014-01-06 12:55:46 -0800434 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
435 // compiled code.
436 uint64_t entry_point_from_interpreter_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437
Ian Rogersef7d42f2014-01-06 12:55:46 -0800438 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
439 uint64_t entry_point_from_jni_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440
Ian Rogersef7d42f2014-01-06 12:55:46 -0800441 // Method dispatch from portable compiled code invokes this pointer which may cause bridging into
442 // quick compiled code or the interpreter.
443 uint64_t entry_point_from_portable_compiled_code_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444
Ian Rogersef7d42f2014-01-06 12:55:46 -0800445 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
446 // portable compiled code or the interpreter.
447 uint64_t entry_point_from_quick_compiled_code_;
Jeff Haoaa4a7932013-05-13 11:28:27 -0700448
Ian Rogersef7d42f2014-01-06 12:55:46 -0800449 // Pointer to a data structure created by the compiler and used by the garbage collector to
450 // determine which registers hold live references to objects within the heap. Keyed by native PC
451 // offsets for the quick compiler and dex PCs for the portable.
452 uint64_t gc_map_;
Jeff Hao16743632013-05-08 10:59:04 -0700453
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 // Access flags; low 16 bits are defined by spec.
455 uint32_t access_flags_;
456
457 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
458
459 // Offset to the CodeItem.
460 uint32_t dex_code_item_offset_;
461
462 // Index into method_ids of the dex file associated with this method.
463 uint32_t dex_method_index_;
464
465 /* End of dex file fields. */
466
467 // Entry within a dispatch table for this method. For static/direct methods the index is into
468 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
469 // ifTable.
470 uint32_t method_index_;
471
472 // --- Quick compiler meta-data. ---
473 // TODO: merge and place in native heap, such as done with the code size.
474
475 // Bit map of spilled machine registers.
476 uint32_t quick_core_spill_mask_;
477
478 // Bit map of spilled floating point machine registers.
479 uint32_t quick_fp_spill_mask_;
480
481 // Fixed frame size for this method when executed.
482 uint32_t quick_frame_size_in_bytes_;
483
484 // --- End of quick compiler meta-data. ---
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800485
Brian Carlstromea46f952013-07-30 01:26:50 -0700486 static Class* java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800487
Mathieu Chartier02e25112013-08-14 16:14:24 -0700488 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700489 friend struct art::ArtMethodOffsets; // for verifying offset information
490 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491};
492
Brian Carlstromea46f952013-07-30 01:26:50 -0700493class MANAGED ArtMethodClass : public Class {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800494 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700495 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethodClass);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800496};
497
498} // namespace mirror
499} // namespace art
500
Brian Carlstromea46f952013-07-30 01:26:50 -0700501#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_