blob: bfa7cbe10fb8ba8563a768bfa14ec8cbb4f1b591 [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"
23#include "locks.h"
24#include "modifiers.h"
25#include "object.h"
Mathieu Chartierc528dba2013-11-26 12:00:11 -080026#include "root_visitor.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 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 Rogersef7d42f2014-01-06 12:55:46 -080048 Class* GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049
50 void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
51
52 static MemberOffset DeclaringClassOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070053 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054 }
55
Ian Rogersef7d42f2014-01-06 12:55:46 -080056 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao5d917302013-02-27 17:57:33 -080057
Ian Rogersef7d42f2014-01-06 12:55:46 -080058 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -070059 SetField32(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_) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700159 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 }
161
162 static MemberOffset MethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700163 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164 }
165
Ian Rogersef7d42f2014-01-06 12:55:46 -0800166 uint32_t GetCodeItemOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
167 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168 }
169
170 void SetCodeItemOffset(uint32_t new_code_off) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800171 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_code_item_offset_), new_code_off, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 }
173
174 // Number of 32bit registers that would be required to hold all the arguments
175 static size_t NumArgRegisters(const StringPiece& shorty);
176
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 uint32_t GetDexMethodIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178
179 void SetDexMethodIndex(uint32_t new_idx) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800180 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), new_idx, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 }
182
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
186
187 static MemberOffset DexCacheStringsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700188 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 }
190
191 static MemberOffset DexCacheResolvedMethodsOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700192 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 }
194
195 static MemberOffset DexCacheResolvedTypesOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700196 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197 }
198
Ian Rogersef7d42f2014-01-06 12:55:46 -0800199 ObjectArray<ArtMethod>* GetDexCacheResolvedMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700200 void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
202
Ian Rogersef7d42f2014-01-06 12:55:46 -0800203 ObjectArray<Class>* GetDexCacheResolvedTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types)
205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
206
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207 // Find the method that this method overrides
Ian Rogersef7d42f2014-01-06 12:55:46 -0800208 ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209
Jeff Hao6474d192013-03-26 14:08:09 -0700210 void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, char result_type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
212
Ian Rogersef7d42f2014-01-06 12:55:46 -0800213 EntryPointFromInterpreter* GetEntryPointFromInterpreter() {
214 return GetFieldPtr<EntryPointFromInterpreter*>(
215 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_), false);
Jeff Hao16743632013-05-08 10:59:04 -0700216 }
217
218 void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800219 SetFieldPtr<EntryPointFromInterpreter*>(
220 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_),
221 entry_point_from_interpreter, false);
Jeff Hao16743632013-05-08 10:59:04 -0700222 }
223
Ian Rogersef7d42f2014-01-06 12:55:46 -0800224 static MemberOffset EntryPointFromPortableCompiledCodeOffset() {
225 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_portable_compiled_code_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800226 }
227
Ian Rogersef7d42f2014-01-06 12:55:46 -0800228 const void* GetEntryPointFromPortableCompiledCode() {
229 return GetFieldPtr<const void*>(EntryPointFromPortableCompiledCodeOffset(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 }
231
Ian Rogersef7d42f2014-01-06 12:55:46 -0800232 void SetEntryPointFromPortableCompiledCode(const void* entry_point_from_portable_compiled_code) {
233 SetFieldPtr<const void*>(EntryPointFromPortableCompiledCodeOffset(),
234 entry_point_from_portable_compiled_code, false);
235 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800236
Ian Rogersef7d42f2014-01-06 12:55:46 -0800237 static MemberOffset EntryPointFromQuickCompiledCodeOffset() {
238 return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_quick_compiled_code_));
239 }
240
241 const void* GetEntryPointFromQuickCompiledCode() {
242 return GetFieldPtr<const void*>(EntryPointFromQuickCompiledCodeOffset(), false);
243 }
244
245 void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) {
246 SetFieldPtr<const void*>(EntryPointFromQuickCompiledCodeOffset(),
247 entry_point_from_quick_compiled_code, false);
248 }
249
250
251 uint32_t GetCodeSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
252
253 bool IsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
254 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255 if (code == 0) {
256 return pc == 0;
257 }
258 /*
259 * During a stack walk, a return PC may point to the end of the code + 1
260 * (in the case that the last instruction is a call that isn't expected to
261 * return. Thus, we check <= code + GetCodeSize().
262 */
263 return (code <= pc && pc <= code + GetCodeSize());
264 }
265
Ian Rogersef7d42f2014-01-06 12:55:46 -0800266 void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800267
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268 uint32_t GetQuickOatCodeOffset();
269 uint32_t GetPortableOatCodeOffset();
270 void SetQuickOatCodeOffset(uint32_t code_offset);
271 void SetPortableOatCodeOffset(uint32_t code_offset);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800272
Ian Rogers1809a722013-08-09 22:05:32 -0700273 // Callers should wrap the uint8_t* in a MappingTable instance for convenient access.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800274 const uint8_t* GetMappingTable() {
275 return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_mapping_table_),
276 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277 }
278
Ian Rogers1809a722013-08-09 22:05:32 -0700279 void SetMappingTable(const uint8_t* mapping_table) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800280 SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_mapping_table_),
281 mapping_table, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 }
283
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284 uint32_t GetOatMappingTableOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285
286 void SetOatMappingTableOffset(uint32_t mapping_table_offset);
287
Ian Rogers1809a722013-08-09 22:05:32 -0700288 // Callers should wrap the uint8_t* in a VmapTable instance for convenient access.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800289 const uint8_t* GetVmapTable() {
290 return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_vmap_table_),
291 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800292 }
293
Ian Rogers1809a722013-08-09 22:05:32 -0700294 void SetVmapTable(const uint8_t* vmap_table) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800295 SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_vmap_table_), vmap_table,
296 false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 }
298
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299 uint32_t GetOatVmapTableOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800300
301 void SetOatVmapTableOffset(uint32_t vmap_table_offset);
302
Ian Rogersef7d42f2014-01-06 12:55:46 -0800303 const uint8_t* GetNativeGcMap() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700304 return GetFieldPtr<uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800305 }
306 void SetNativeGcMap(const uint8_t* data) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700307 SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), data, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800308 }
309
310 // When building the oat need a convenient place to stuff the offset of the native GC map.
311 void SetOatNativeGcMapOffset(uint32_t gc_map_offset);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800312 uint32_t GetOatNativeGcMapOffset();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 size_t GetFrameSizeInBytes() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800315 DCHECK_EQ(sizeof(size_t), sizeof(uint32_t));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800316 size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800317 DCHECK_LE(static_cast<size_t>(kStackAlignment), result);
318 return result;
319 }
320
321 void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800322 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_frame_size_in_bytes_),
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800323 new_frame_size_in_bytes, false);
324 }
325
Ian Rogersef7d42f2014-01-06 12:55:46 -0800326 size_t GetReturnPcOffsetInBytes() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327 return GetFrameSizeInBytes() - kPointerSize;
328 }
329
Ian Rogersef7d42f2014-01-06 12:55:46 -0800330 size_t GetSirtOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800331 CHECK(IsNative());
332 return kPointerSize;
333 }
334
Ian Rogersef7d42f2014-01-06 12:55:46 -0800335 bool IsRegistered();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336
Ian Rogers1eb512d2013-10-18 15:42:20 -0700337 void RegisterNative(Thread* self, const void* native_method, bool is_fast)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
339
340 void UnregisterNative(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
341
342 static MemberOffset NativeMethodOffset() {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800343 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344 }
345
Ian Rogersef7d42f2014-01-06 12:55:46 -0800346 const void* GetNativeMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 return reinterpret_cast<const void*>(GetField32(NativeMethodOffset(), false));
348 }
349
350 void SetNativeMethod(const void*);
351
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 static MemberOffset GetMethodIndexOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -0700353 return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800354 }
355
Ian Rogersef7d42f2014-01-06 12:55:46 -0800356 uint32_t GetCoreSpillMask() {
357 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 }
359
360 void SetCoreSpillMask(uint32_t core_spill_mask) {
361 // Computed during compilation
Ian Rogersef7d42f2014-01-06 12:55:46 -0800362 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_core_spill_mask_), core_spill_mask, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363 }
364
Ian Rogersef7d42f2014-01-06 12:55:46 -0800365 uint32_t GetFpSpillMask() {
366 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 }
368
369 void SetFpSpillMask(uint32_t fp_spill_mask) {
370 // Computed during compilation
Ian Rogersef7d42f2014-01-06 12:55:46 -0800371 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, quick_fp_spill_mask_), fp_spill_mask, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372 }
373
374 // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal
375 // conventions for a method of managed code. Returns false for Proxy methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800376 bool IsRuntimeMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800377
378 // Is this a hand crafted method used for something like describing callee saves?
Ian Rogersef7d42f2014-01-06 12:55:46 -0800379 bool IsCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380
Ian Rogersef7d42f2014-01-06 12:55:46 -0800381 bool IsResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382
Ian Rogersef7d42f2014-01-06 12:55:46 -0800383 bool IsImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao88474b42013-10-23 16:24:40 -0700384
Ian Rogersef7d42f2014-01-06 12:55:46 -0800385 uintptr_t NativePcOffset(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386
387 // Converts a native PC to a dex PC.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800388 uint32_t ToDexPc(const uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389
390 // Converts a dex PC to a native PC.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800391 uintptr_t ToNativePc(const uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392
Ian Rogersc449aa82013-07-29 14:35:46 -0700393 // Find the catch block for the given exception type and dex_pc. When a catch block is found,
394 // indicates whether the found catch block is responsible for clearing the exception or whether
395 // a move-exception instruction is present.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800396 uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc, bool* has_no_move_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
398
Brian Carlstromea46f952013-07-30 01:26:50 -0700399 static void SetClass(Class* java_lang_reflect_ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800400
Brian Carlstromea46f952013-07-30 01:26:50 -0700401 static Class* GetJavaLangReflectArtMethod() {
402 return java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403 }
404
Brian Carlstromea46f952013-07-30 01:26:50 -0700405 static void ResetClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800407 static void VisitRoots(RootVisitor* visitor, void* arg)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
409
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410 protected:
411 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Ian Rogersef7d42f2014-01-06 12:55:46 -0800412 // The class we are a part of.
413 HeapReference<Class> declaring_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414
Ian Rogersef7d42f2014-01-06 12:55:46 -0800415 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
416 HeapReference<ObjectArray<ArtMethod> > dex_cache_resolved_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417
Ian Rogersef7d42f2014-01-06 12:55:46 -0800418 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
419 HeapReference<ObjectArray<Class> > dex_cache_resolved_types_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420
Ian Rogersef7d42f2014-01-06 12:55:46 -0800421 // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
422 HeapReference<ObjectArray<String> > dex_cache_strings_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800423
Ian Rogersef7d42f2014-01-06 12:55:46 -0800424 // Method dispatch from the interpreter invokes this pointer which may cause a bridge into
425 // compiled code.
426 uint64_t entry_point_from_interpreter_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427
Ian Rogersef7d42f2014-01-06 12:55:46 -0800428 // Pointer to JNI function registered to this method, or a function to resolve the JNI function.
429 uint64_t entry_point_from_jni_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430
Ian Rogersef7d42f2014-01-06 12:55:46 -0800431 // Method dispatch from portable compiled code invokes this pointer which may cause bridging into
432 // quick compiled code or the interpreter.
433 uint64_t entry_point_from_portable_compiled_code_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434
Ian Rogersef7d42f2014-01-06 12:55:46 -0800435 // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
436 // portable compiled code or the interpreter.
437 uint64_t entry_point_from_quick_compiled_code_;
Jeff Haoaa4a7932013-05-13 11:28:27 -0700438
Ian Rogersef7d42f2014-01-06 12:55:46 -0800439 // Pointer to a data structure created by the compiler and used by the garbage collector to
440 // determine which registers hold live references to objects within the heap. Keyed by native PC
441 // offsets for the quick compiler and dex PCs for the portable.
442 uint64_t gc_map_;
Jeff Hao16743632013-05-08 10:59:04 -0700443
Ian Rogersef7d42f2014-01-06 12:55:46 -0800444 // --- Quick compiler meta-data. ---
445 // TODO: merge and place in native heap, such as done with the code size.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800446
Ian Rogersef7d42f2014-01-06 12:55:46 -0800447 // Pointer to a data structure created by the quick compiler to map between dex PCs and native
448 // PCs, and vice-versa.
449 uint64_t quick_mapping_table_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450
451 // When a register is promoted into a register, the spill mask holds which registers hold dex
452 // registers. The first promoted register's corresponding dex register is vmap_table_[1], the Nth
453 // is vmap_table_[N]. vmap_table_[0] holds the length of the table.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 uint64_t quick_vmap_table_;
455
456 // --- End of quick compiler meta-data. ---
457
458 // Access flags; low 16 bits are defined by spec.
459 uint32_t access_flags_;
460
461 /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
462
463 // Offset to the CodeItem.
464 uint32_t dex_code_item_offset_;
465
466 // Index into method_ids of the dex file associated with this method.
467 uint32_t dex_method_index_;
468
469 /* End of dex file fields. */
470
471 // Entry within a dispatch table for this method. For static/direct methods the index is into
472 // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
473 // ifTable.
474 uint32_t method_index_;
475
476 // --- Quick compiler meta-data. ---
477 // TODO: merge and place in native heap, such as done with the code size.
478
479 // Bit map of spilled machine registers.
480 uint32_t quick_core_spill_mask_;
481
482 // Bit map of spilled floating point machine registers.
483 uint32_t quick_fp_spill_mask_;
484
485 // Fixed frame size for this method when executed.
486 uint32_t quick_frame_size_in_bytes_;
487
488 // --- End of quick compiler meta-data. ---
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800489
Brian Carlstromea46f952013-07-30 01:26:50 -0700490 static Class* java_lang_reflect_ArtMethod_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491
Mathieu Chartier02e25112013-08-14 16:14:24 -0700492 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700493 friend struct art::ArtMethodOffsets; // for verifying offset information
494 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800495};
496
Brian Carlstromea46f952013-07-30 01:26:50 -0700497class MANAGED ArtMethodClass : public Class {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700499 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethodClass);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800500};
501
502} // namespace mirror
503} // namespace art
504
Brian Carlstromea46f952013-07-30 01:26:50 -0700505#endif // ART_RUNTIME_MIRROR_ART_METHOD_H_