blob: a9da66c5357bbe8127bf80bdf9f41885def06a5d [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 Rogers2dd0e2c2013-01-24 12:42:14 -080034class StringPiece;
Jeff Hao16743632013-05-08 10:59:04 -070035class ShadowFrame;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036
37namespace mirror {
38
39class StaticStorageBase;
40
Jeff Hao790ad902013-05-22 15:02:08 -070041typedef void (EntryPointFromInterpreter)(Thread* self, MethodHelper& mh,
42 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, JValue* result);
Jeff Hao16743632013-05-08 10:59:04 -070043
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044// C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor
Brian Carlstromea46f952013-07-30 01:26:50 -070045class MANAGED ArtMethod : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046 public:
Ian Rogersef7d42f2014-01-06 12:55:46 -080047 Class* GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
49 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
50
51 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070052 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 }
54
Ian Rogersef7d42f2014-01-06 12:55:46 -080055 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080056
Ian Rogersef7d42f2014-01-06 12:55:46 -080057 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010058 // Not called within a transaction.
59 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060 }
61
62 // Approximate what kind of method call would be used for this method.
Ian Rogersef7d42f2014-01-06 12:55:46 -080063 InvokeType GetInvokeType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064
65 // Returns true if the method is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -080066 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067 return (GetAccessFlags() & kAccPublic) != 0;
68 }
69
70 // Returns true if the method is declared private.
Ian Rogersef7d42f2014-01-06 12:55:46 -080071 bool IsPrivate() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 return (GetAccessFlags() & kAccPrivate) != 0;
73 }
74
75 // Returns true if the method is declared static.
Ian Rogersef7d42f2014-01-06 12:55:46 -080076 bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 return (GetAccessFlags() & kAccStatic) != 0;
78 }
79
80 // Returns true if the method is a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080081 bool IsConstructor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 return (GetAccessFlags() & kAccConstructor) != 0;
83 }
84
85 // Returns true if the method is static, private, or a constructor.
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 bool IsDirect() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 return IsDirect(GetAccessFlags());
88 }
89
90 static bool IsDirect(uint32_t access_flags) {
91 return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0;
92 }
93
94 // Returns true if the method is declared synchronized.
Ian Rogersef7d42f2014-01-06 12:55:46 -080095 bool IsSynchronized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096 uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized;
97 return (GetAccessFlags() & synchonized) != 0;
98 }
99
Ian Rogersef7d42f2014-01-06 12:55:46 -0800100 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 return (GetAccessFlags() & kAccFinal) != 0;
102 }
103
Ian Rogersef7d42f2014-01-06 12:55:46 -0800104 bool IsMiranda() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 return (GetAccessFlags() & kAccMiranda) != 0;
106 }
107
Ian Rogersef7d42f2014-01-06 12:55:46 -0800108 bool IsNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800109 return (GetAccessFlags() & kAccNative) != 0;
110 }
111
Ian Rogersef7d42f2014-01-06 12:55:46 -0800112 bool IsFastNative() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800113 uint32_t mask = kAccFastNative | kAccNative;
114 return (GetAccessFlags() & mask) == mask;
Ian Rogers1eb512d2013-10-18 15:42:20 -0700115 }
116
Ian Rogersef7d42f2014-01-06 12:55:46 -0800117 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800118 return (GetAccessFlags() & kAccAbstract) != 0;
119 }
120
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122 return (GetAccessFlags() & kAccSynthetic) != 0;
123 }
124
Ian Rogersef7d42f2014-01-06 12:55:46 -0800125 bool IsProxyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200128 return (GetAccessFlags() & kAccPreverified) != 0;
129 }
130
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
132 DCHECK(!IsPreverified());
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200133 SetAccessFlags(GetAccessFlags() | kAccPreverified);
134 }
135
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 bool IsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
137 return (GetAccessFlags() & kAccPortableCompiled) != 0;
138 }
139
140 void SetIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
141 DCHECK(!IsPortableCompiled());
142 SetAccessFlags(GetAccessFlags() | kAccPortableCompiled);
143 }
144
145 void ClearIsPortableCompiled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
146 DCHECK(IsPortableCompiled());
147 SetAccessFlags(GetAccessFlags() & ~kAccPortableCompiled);
148 }
149
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
151
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152 uint16_t GetMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153
Ian Rogersef7d42f2014-01-06 12:55:46 -0800154 size_t GetVtableIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 return GetMethodIndex();
156 }
157
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 void SetMethodIndex(uint16_t new_method_index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100159 // Not called within a transaction.
160 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 }
162
163 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700164 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165 }
166
Ian Rogersef7d42f2014-01-06 12:55:46 -0800167 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
168 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800169 }
170
171 void SetCodeItemOffset(uint32_t new_code_off) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100172 // Not called within a transaction.
173 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174 }
175
176 // Number of 32bit registers that would be required to hold all the arguments
177 static size_t NumArgRegisters(const StringPiece& shorty);
178
Ian Rogersef7d42f2014-01-06 12:55:46 -0800179 uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180
181 void SetDexMethodIndex(uint32_t new_idx) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100182 // Not called within a transaction.
183 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 }
185
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
188 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
189
190 static MemberOffset DexCacheStringsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700191 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800192 }
193
194 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700195 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
198 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700199 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800200 }
201
Ian Rogersef7d42f2014-01-06 12:55:46 -0800202 ObjectArray<ArtMethod>* GetDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700203 void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
205
Ian Rogersef7d42f2014-01-06 12:55:46 -0800206 ObjectArray<Class>* GetDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
208 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
209
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800210 // Find the method that this method overrides
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212
Ian Rogers0177e532014-02-11 16:30:46 -0800213 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result,
214 const char* shorty) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800217 EntryPointFromInterpreter* GetEntryPointFromInterpreter() {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800218 return GetFieldPtr<EntryPointFromInterpreter*, kVerifyFlags>(
Ian Rogersef7d42f2014-01-06 12:55:46 -0800219 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_), false);
Jeff Hao16743632013-05-08 10:59:04 -0700220 }
221
Mathieu Chartier4e305412014-02-19 10:54:44 -0800222 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Jeff Hao16743632013-05-08 10:59:04 -0700223 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800224 SetFieldPtr<false, true, kVerifyFlags>(
225 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_),
226 entry_point_from_interpreter, false);
Jeff Hao16743632013-05-08 10:59:04 -0700227 }
228
Ian Rogersef7d42f2014-01-06 12:55:46 -0800229 static MemberOffset EntryPointFromPortableCompiledCodeOffset() {
230 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_portable_compiled_code_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 }
232
Mathieu Chartier4e305412014-02-19 10:54:44 -0800233 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800234 const void* GetEntryPointFromPortableCompiledCode() {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800235 return GetFieldPtr<const void*, kVerifyFlags>(
236 EntryPointFromPortableCompiledCodeOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 }
238
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800240 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800241 SetFieldPtr<false, true, kVerifyFlags>(
242 EntryPointFromPortableCompiledCodeOffset(), entry_point_from_portable_compiled_code, false);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800243 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800244
Ian Rogersef7d42f2014-01-06 12:55:46 -0800245 static MemberOffset EntryPointFromQuickCompiledCodeOffset() {
246 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_quick_compiled_code_));
247 }
248
Mathieu Chartier4e305412014-02-19 10:54:44 -0800249 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800250 const void* GetEntryPointFromQuickCompiledCode() {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800251 return GetFieldPtr<const void*, kVerifyFlags>(EntryPointFromQuickCompiledCodeOffset(), false);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800252 }
253
Mathieu Chartier4e305412014-02-19 10:54:44 -0800254 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800255 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800256 SetFieldPtr<false, true, kVerifyFlags>(
257 EntryPointFromQuickCompiledCodeOffset(), entry_point_from_quick_compiled_code, false);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800258 }
259
260
261 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
262
263 bool IsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
264 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265 if (code == 0) {
266 return pc == 0;
267 }
268 /*
269 * During a stack walk, a return PC may point to the end of the code + 1
270 * (in the case that the last instruction is a call that isn't expected to
271 * return. Thus, we check <= code + GetCodeSize().
272 */
273 return (code <= pc && pc <= code + GetCodeSize());
274 }
275
Ian Rogersef7d42f2014-01-06 12:55:46 -0800276 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278 uint32_t GetQuickOatCodeOffset();
279 uint32_t GetPortableOatCodeOffset();
280 void SetQuickOatCodeOffset(uint32_t code_offset);
281 void SetPortableOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282
Ian Rogers1809a722013-08-09 22:05:32 -0700283 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284 const uint8_t* GetMappingTable() {
285 return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_mapping_table_),
286 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 }
288
Mathieu Chartier4e305412014-02-19 10:54:44 -0800289 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers1809a722013-08-09 22:05:32 -0700290 void SetMappingTable(const uint8_t* mapping_table) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800291 SetFieldPtr<false, true, kVerifyFlags>(
292 OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_mapping_table_), mapping_table, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800293 }
294
Ian Rogersef7d42f2014-01-06 12:55:46 -0800295 uint32_t GetOatMappingTableOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800296
297 void SetOatMappingTableOffset(uint32_t mapping_table_offset);
298
Ian Rogers1809a722013-08-09 22:05:32 -0700299 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800300 const uint8_t* GetVmapTable() {
301 return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_vmap_table_),
302 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303 }
304
Mathieu Chartier4e305412014-02-19 10:54:44 -0800305 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers1809a722013-08-09 22:05:32 -0700306 void SetVmapTable(const uint8_t* vmap_table) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800307 SetFieldPtr<false, true, kVerifyFlags>(
308 OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_vmap_table_), vmap_table, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309 }
310
Ian Rogersef7d42f2014-01-06 12:55:46 -0800311 uint32_t GetOatVmapTableOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312
313 void SetOatVmapTableOffset(uint32_t vmap_table_offset);
314
Ian Rogersef7d42f2014-01-06 12:55:46 -0800315 const uint8_t* GetNativeGcMap() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700316 return GetFieldPtr<uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800317 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800318 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800319 void SetNativeGcMap(const uint8_t* data) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800320 SetFieldPtr<false, true, kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), data,
321 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800322 }
323
324 // When building the oat need a convenient place to stuff the offset of the native GC map.
325 void SetOatNativeGcMapOffset(uint32_t gc_map_offset);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800326 uint32_t GetOatNativeGcMapOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327
Ian Rogers936b37f2014-02-14 00:52:24 -0800328 uint32_t GetFrameSizeInBytes() {
329 uint32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_),
330 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
332 return result;
333 }
334
335 void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100336 // Not called within a transaction.
337 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_),
338 new_frame_size_in_bytes, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800339 }
340
Ian Rogersef7d42f2014-01-06 12:55:46 -0800341 size_t GetReturnPcOffsetInBytes() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800342 return GetFrameSizeInBytes() - kPointerSize;
343 }
344
Ian Rogersef7d42f2014-01-06 12:55:46 -0800345 size_t GetSirtOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800346 return kPointerSize;
347 }
348
Ian Rogersef7d42f2014-01-06 12:55:46 -0800349 bool IsRegistered();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350
Ian Rogers1eb512d2013-10-18 15:42:20 -0700351 void RegisterNative(Thread* self, const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
353
354 void UnregisterNative(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
355
356 static MemberOffset NativeMethodOffset() {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800357 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 }
359
Ian Rogersef7d42f2014-01-06 12:55:46 -0800360 const void* GetNativeMethod() {
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800361 return GetFieldPtr<const void*>(NativeMethodOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 }
363
Mathieu Chartier4e305412014-02-19 10:54:44 -0800364 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800365 void SetNativeMethod(const void*);
366
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700368 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800369 }
370
Ian Rogersef7d42f2014-01-06 12:55:46 -0800371 uint32_t GetCoreSpillMask() {
372 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 }
374
375 void SetCoreSpillMask(uint32_t core_spill_mask) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100376 // Computed during compilation.
377 // Not called within a transaction.
378 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), core_spill_mask, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379 }
380
Ian Rogersef7d42f2014-01-06 12:55:46 -0800381 uint32_t GetFpSpillMask() {
382 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800383 }
384
385 void SetFpSpillMask(uint32_t fp_spill_mask) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100386 // Computed during compilation.
387 // Not called within a transaction.
388 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), fp_spill_mask, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389 }
390
391 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
392 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800393 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800394
395 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800396 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397
Ian Rogersef7d42f2014-01-06 12:55:46 -0800398 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399
Ian Rogersef7d42f2014-01-06 12:55:46 -0800400 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700401
Ian Rogersef7d42f2014-01-06 12:55:46 -0800402 uintptr_t NativePcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403
404 // Converts a native PC to a dex PC.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800405 uint32_t ToDexPc(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406
407 // Converts a dex PC to a native PC.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800408 uintptr_t ToNativePc(const uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409
Ian Rogersc449aa82013-07-29 14:35:46 -0700410 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
411 // indicates whether the found catch block is responsible for clearing the exception or whether
412 // a move-exception instruction is present.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800413 uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
415
Brian Carlstromea46f952013-07-30 01:26:50 -0700416 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417
Brian Carlstromea46f952013-07-30 01:26:50 -0700418 static Class* GetJavaLangReflectArtMethod() {
419 return java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420 }
421
Brian Carlstromea46f952013-07-30 01:26:50 -0700422 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800423
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800424 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
426
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 protected:
428 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800429 // The class we are a part of.
430 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431
Ian Rogersef7d42f2014-01-06 12:55:46 -0800432 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
433 HeapReference<ObjectArray<ArtMethod> > dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434
Ian Rogersef7d42f2014-01-06 12:55:46 -0800435 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
436 HeapReference<ObjectArray<Class> > dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437
Ian Rogersef7d42f2014-01-06 12:55:46 -0800438 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
439 HeapReference<ObjectArray<String> > dex_cache_strings_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440
Ian Rogersef7d42f2014-01-06 12:55:46 -0800441 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
442 // compiled code.
443 uint64_t entry_point_from_interpreter_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444
Ian Rogersef7d42f2014-01-06 12:55:46 -0800445 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
446 uint64_t entry_point_from_jni_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447
Ian Rogersef7d42f2014-01-06 12:55:46 -0800448 // Method dispatch from portable compiled code invokes this pointer which may cause bridging into
449 // quick compiled code or the interpreter.
450 uint64_t entry_point_from_portable_compiled_code_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451
Ian Rogersef7d42f2014-01-06 12:55:46 -0800452 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
453 // portable compiled code or the interpreter.
454 uint64_t entry_point_from_quick_compiled_code_;
Jeff Haoaa4a7932013-05-13 11:28:27 -0700455
Ian Rogersef7d42f2014-01-06 12:55:46 -0800456 // Pointer to a data structure created by the compiler and used by the garbage collector to
457 // determine which registers hold live references to objects within the heap. Keyed by native PC
458 // offsets for the quick compiler and dex PCs for the portable.
459 uint64_t gc_map_;
Jeff Hao16743632013-05-08 10:59:04 -0700460
Ian Rogersef7d42f2014-01-06 12:55:46 -0800461 // --- Quick compiler meta-data. ---
462 // TODO: merge and place in native heap, such as done with the code size.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800463
Ian Rogersef7d42f2014-01-06 12:55:46 -0800464 // Pointer to a data structure created by the quick compiler to map between dex PCs and native
465 // PCs, and vice-versa.
466 uint64_t quick_mapping_table_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800467
468 // When a register is promoted into a register, the spill mask holds which registers hold dex
469 // registers. The first promoted register's corresponding dex register is vmap_table_[1], the Nth
470 // is vmap_table_[N]. vmap_table_[0] holds the length of the table.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800471 uint64_t quick_vmap_table_;
472
473 // --- End of quick compiler meta-data. ---
474
475 // Access flags; low 16 bits are defined by spec.
476 uint32_t access_flags_;
477
478 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
479
480 // Offset to the CodeItem.
481 uint32_t dex_code_item_offset_;
482
483 // Index into method_ids of the dex file associated with this method.
484 uint32_t dex_method_index_;
485
486 /* End of dex file fields. */
487
488 // Entry within a dispatch table for this method. For static/direct methods the index is into
489 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
490 // ifTable.
491 uint32_t method_index_;
492
493 // --- Quick compiler meta-data. ---
494 // TODO: merge and place in native heap, such as done with the code size.
495
496 // Bit map of spilled machine registers.
497 uint32_t quick_core_spill_mask_;
498
499 // Bit map of spilled floating point machine registers.
500 uint32_t quick_fp_spill_mask_;
501
502 // Fixed frame size for this method when executed.
503 uint32_t quick_frame_size_in_bytes_;
504
505 // --- End of quick compiler meta-data. ---
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800506
Brian Carlstromea46f952013-07-30 01:26:50 -0700507 static Class* java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800508
Mathieu Chartier02e25112013-08-14 16:14:24 -0700509 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700510 friend struct art::ArtMethodOffsets; // for verifying offset information
511 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800512};
513
Brian Carlstromea46f952013-07-30 01:26:50 -0700514class MANAGED ArtMethodClass : public Class {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800515 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700516 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethodClass);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517};
518
519} // namespace mirror
520} // namespace art
521
Brian Carlstromea46f952013-07-30 01:26:50 -0700522#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_