Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_ART_METHOD_H_ |
| 18 | #define ART_RUNTIME_MIRROR_ART_METHOD_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
| 20 | #include "class.h" |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 21 | #include "dex_file.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "invoke_type.h" |
| 23 | #include "locks.h" |
| 24 | #include "modifiers.h" |
| 25 | #include "object.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 29 | struct ArtMethodOffsets; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | struct ConstructorMethodOffsets; |
| 31 | union JValue; |
| 32 | struct MethodClassOffsets; |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 33 | class MethodHelper; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | class StringPiece; |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 35 | class ShadowFrame; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | |
| 37 | namespace mirror { |
| 38 | |
| 39 | class StaticStorageBase; |
| 40 | |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 41 | typedef void (EntryPointFromInterpreter)(Thread* self, MethodHelper& mh, |
| 42 | const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, JValue* result); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 43 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | // C++ mirror of java.lang.reflect.Method and java.lang.reflect.Constructor |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 45 | class MANAGED ArtMethod : public Object { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 46 | public: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | Class* GetDeclaringClass() const; |
| 48 | |
| 49 | void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 50 | |
| 51 | static MemberOffset DeclaringClassOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 52 | return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 55 | static MemberOffset EntryPointFromCompiledCodeOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 56 | return MemberOffset(OFFSETOF_MEMBER(ArtMethod, entry_point_from_compiled_code_)); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | uint32_t GetAccessFlags() const; |
| 60 | |
| 61 | void SetAccessFlags(uint32_t new_access_flags) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 62 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), new_access_flags, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Approximate what kind of method call would be used for this method. |
| 66 | InvokeType GetInvokeType() const; |
| 67 | |
| 68 | // Returns true if the method is declared public. |
| 69 | bool IsPublic() const { |
| 70 | return (GetAccessFlags() & kAccPublic) != 0; |
| 71 | } |
| 72 | |
| 73 | // Returns true if the method is declared private. |
| 74 | bool IsPrivate() const { |
| 75 | return (GetAccessFlags() & kAccPrivate) != 0; |
| 76 | } |
| 77 | |
| 78 | // Returns true if the method is declared static. |
| 79 | bool IsStatic() const { |
| 80 | return (GetAccessFlags() & kAccStatic) != 0; |
| 81 | } |
| 82 | |
| 83 | // Returns true if the method is a constructor. |
| 84 | bool IsConstructor() const { |
| 85 | return (GetAccessFlags() & kAccConstructor) != 0; |
| 86 | } |
| 87 | |
| 88 | // Returns true if the method is static, private, or a constructor. |
| 89 | bool IsDirect() const { |
| 90 | return IsDirect(GetAccessFlags()); |
| 91 | } |
| 92 | |
| 93 | static bool IsDirect(uint32_t access_flags) { |
| 94 | return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0; |
| 95 | } |
| 96 | |
| 97 | // Returns true if the method is declared synchronized. |
| 98 | bool IsSynchronized() const { |
| 99 | uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized; |
| 100 | return (GetAccessFlags() & synchonized) != 0; |
| 101 | } |
| 102 | |
| 103 | bool IsFinal() const { |
| 104 | return (GetAccessFlags() & kAccFinal) != 0; |
| 105 | } |
| 106 | |
| 107 | bool IsMiranda() const { |
| 108 | return (GetAccessFlags() & kAccMiranda) != 0; |
| 109 | } |
| 110 | |
| 111 | bool IsNative() const { |
| 112 | return (GetAccessFlags() & kAccNative) != 0; |
| 113 | } |
| 114 | |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame^] | 115 | bool IsFastNative() const { |
| 116 | return (GetAccessFlags() & kAccFastNative) != 0; |
| 117 | } |
| 118 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 119 | bool IsAbstract() const { |
| 120 | return (GetAccessFlags() & kAccAbstract) != 0; |
| 121 | } |
| 122 | |
| 123 | bool IsSynthetic() const { |
| 124 | return (GetAccessFlags() & kAccSynthetic) != 0; |
| 125 | } |
| 126 | |
| 127 | bool IsProxyMethod() const; |
| 128 | |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 129 | bool IsPreverified() const { |
| 130 | return (GetAccessFlags() & kAccPreverified) != 0; |
| 131 | } |
| 132 | |
| 133 | void SetPreverified() { |
| 134 | SetAccessFlags(GetAccessFlags() | kAccPreverified); |
| 135 | } |
| 136 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 137 | bool CheckIncompatibleClassChange(InvokeType type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 138 | |
| 139 | uint16_t GetMethodIndex() const; |
| 140 | |
| 141 | size_t GetVtableIndex() const { |
| 142 | return GetMethodIndex(); |
| 143 | } |
| 144 | |
| 145 | void SetMethodIndex(uint16_t new_method_index) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 146 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), new_method_index, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static MemberOffset MethodIndexOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 150 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | uint32_t GetCodeItemOffset() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 154 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, code_item_offset_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void SetCodeItemOffset(uint32_t new_code_off) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 158 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, code_item_offset_), new_code_off, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // Number of 32bit registers that would be required to hold all the arguments |
| 162 | static size_t NumArgRegisters(const StringPiece& shorty); |
| 163 | |
| 164 | uint32_t GetDexMethodIndex() const; |
| 165 | |
| 166 | void SetDexMethodIndex(uint32_t new_idx) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 167 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_dex_index_), new_idx, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | ObjectArray<String>* GetDexCacheStrings() const; |
| 171 | void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) |
| 172 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 173 | |
| 174 | static MemberOffset DexCacheStringsOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 175 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static MemberOffset DexCacheResolvedMethodsOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 179 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static MemberOffset DexCacheResolvedTypesOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 183 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static MemberOffset DexCacheInitializedStaticStorageOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 187 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 188 | dex_cache_initialized_static_storage_); |
| 189 | } |
| 190 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 191 | ObjectArray<ArtMethod>* GetDexCacheResolvedMethods() const; |
| 192 | void SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 193 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 194 | |
| 195 | ObjectArray<Class>* GetDexCacheResolvedTypes() const; |
| 196 | void SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_types) |
| 197 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 198 | |
| 199 | ObjectArray<StaticStorageBase>* GetDexCacheInitializedStaticStorage() const; |
| 200 | void SetDexCacheInitializedStaticStorage(ObjectArray<StaticStorageBase>* new_value) |
| 201 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 202 | |
| 203 | // Find the method that this method overrides |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 204 | ArtMethod* FindOverriddenMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 205 | |
Jeff Hao | 6474d19 | 2013-03-26 14:08:09 -0700 | [diff] [blame] | 206 | void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, char result_type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 207 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 208 | |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 209 | EntryPointFromInterpreter* GetEntryPointFromInterpreter() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 210 | return GetFieldPtr<EntryPointFromInterpreter*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_), false); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void SetEntryPointFromInterpreter(EntryPointFromInterpreter* entry_point_from_interpreter) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 214 | SetFieldPtr<EntryPointFromInterpreter*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_interpreter_), entry_point_from_interpreter, false); |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 217 | const void* GetEntryPointFromCompiledCode() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 218 | return GetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_compiled_code_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 221 | void SetEntryPointFromCompiledCode(const void* entry_point_from_compiled_code) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 222 | SetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_compiled_code_), entry_point_from_compiled_code, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | uint32_t GetCodeSize() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 226 | |
| 227 | bool IsWithinCode(uintptr_t pc) const |
| 228 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 229 | uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromCompiledCode()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 230 | if (code == 0) { |
| 231 | return pc == 0; |
| 232 | } |
| 233 | /* |
| 234 | * During a stack walk, a return PC may point to the end of the code + 1 |
| 235 | * (in the case that the last instruction is a call that isn't expected to |
| 236 | * return. Thus, we check <= code + GetCodeSize(). |
| 237 | */ |
| 238 | return (code <= pc && pc <= code + GetCodeSize()); |
| 239 | } |
| 240 | |
| 241 | void AssertPcIsWithinCode(uintptr_t pc) const |
| 242 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 243 | |
| 244 | uint32_t GetOatCodeOffset() const; |
| 245 | |
| 246 | void SetOatCodeOffset(uint32_t code_offset); |
| 247 | |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 248 | static MemberOffset GetEntryPointFromCompiledCodeOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 249 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_compiled_code_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 252 | // Callers should wrap the uint8_t* in a MappingTable instance for convenient access. |
| 253 | const uint8_t* GetMappingTable() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 254 | return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, mapping_table_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 257 | void SetMappingTable(const uint8_t* mapping_table) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 258 | SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, mapping_table_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 259 | mapping_table, false); |
| 260 | } |
| 261 | |
| 262 | uint32_t GetOatMappingTableOffset() const; |
| 263 | |
| 264 | void SetOatMappingTableOffset(uint32_t mapping_table_offset); |
| 265 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 266 | // Callers should wrap the uint8_t* in a VmapTable instance for convenient access. |
| 267 | const uint8_t* GetVmapTable() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 268 | return GetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, vmap_table_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 271 | void SetVmapTable(const uint8_t* vmap_table) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 272 | SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, vmap_table_), vmap_table, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | uint32_t GetOatVmapTableOffset() const; |
| 276 | |
| 277 | void SetOatVmapTableOffset(uint32_t vmap_table_offset); |
| 278 | |
| 279 | const uint8_t* GetNativeGcMap() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 280 | return GetFieldPtr<uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 281 | } |
| 282 | void SetNativeGcMap(const uint8_t* data) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 283 | SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), data, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // When building the oat need a convenient place to stuff the offset of the native GC map. |
| 287 | void SetOatNativeGcMapOffset(uint32_t gc_map_offset); |
| 288 | uint32_t GetOatNativeGcMapOffset() const; |
| 289 | |
| 290 | size_t GetFrameSizeInBytes() const { |
| 291 | DCHECK_EQ(sizeof(size_t), sizeof(uint32_t)); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 292 | size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, frame_size_in_bytes_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 293 | DCHECK_LE(static_cast<size_t>(kStackAlignment), result); |
| 294 | return result; |
| 295 | } |
| 296 | |
| 297 | void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) { |
| 298 | DCHECK_EQ(sizeof(size_t), sizeof(uint32_t)); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 299 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, frame_size_in_bytes_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 300 | new_frame_size_in_bytes, false); |
| 301 | } |
| 302 | |
| 303 | size_t GetReturnPcOffsetInBytes() const { |
| 304 | return GetFrameSizeInBytes() - kPointerSize; |
| 305 | } |
| 306 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 307 | size_t GetSirtOffsetInBytes() const { |
| 308 | CHECK(IsNative()); |
| 309 | return kPointerSize; |
| 310 | } |
| 311 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 312 | bool IsRegistered() const; |
| 313 | |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame^] | 314 | void RegisterNative(Thread* self, const void* native_method, bool is_fast) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 315 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 316 | |
| 317 | void UnregisterNative(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 318 | |
| 319 | static MemberOffset NativeMethodOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 320 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, native_method_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | const void* GetNativeMethod() const { |
| 324 | return reinterpret_cast<const void*>(GetField32(NativeMethodOffset(), false)); |
| 325 | } |
| 326 | |
| 327 | void SetNativeMethod(const void*); |
| 328 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 329 | static MemberOffset GetMethodIndexOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 330 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | uint32_t GetCoreSpillMask() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 334 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, core_spill_mask_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void SetCoreSpillMask(uint32_t core_spill_mask) { |
| 338 | // Computed during compilation |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 339 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, core_spill_mask_), core_spill_mask, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | uint32_t GetFpSpillMask() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 343 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, fp_spill_mask_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void SetFpSpillMask(uint32_t fp_spill_mask) { |
| 347 | // Computed during compilation |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 348 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, fp_spill_mask_), fp_spill_mask, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal |
| 352 | // conventions for a method of managed code. Returns false for Proxy methods. |
| 353 | bool IsRuntimeMethod() const; |
| 354 | |
| 355 | // Is this a hand crafted method used for something like describing callee saves? |
| 356 | bool IsCalleeSaveMethod() const; |
| 357 | |
| 358 | bool IsResolutionMethod() const; |
| 359 | |
| 360 | uintptr_t NativePcOffset(const uintptr_t pc) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 361 | |
| 362 | // Converts a native PC to a dex PC. |
| 363 | uint32_t ToDexPc(const uintptr_t pc) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 364 | |
| 365 | // Converts a dex PC to a native PC. |
| 366 | uintptr_t ToNativePc(const uint32_t dex_pc) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 367 | |
Ian Rogers | c449aa8 | 2013-07-29 14:35:46 -0700 | [diff] [blame] | 368 | // Find the catch block for the given exception type and dex_pc. When a catch block is found, |
| 369 | // indicates whether the found catch block is responsible for clearing the exception or whether |
| 370 | // a move-exception instruction is present. |
| 371 | uint32_t FindCatchBlock(Class* exception_type, uint32_t dex_pc, bool* has_no_move_exception) const |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 372 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 373 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 374 | static void SetClass(Class* java_lang_reflect_ArtMethod); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 375 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 376 | static Class* GetJavaLangReflectArtMethod() { |
| 377 | return java_lang_reflect_ArtMethod_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 380 | static void ResetClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 381 | |
| 382 | protected: |
| 383 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 384 | // The class we are a part of |
| 385 | Class* declaring_class_; |
| 386 | |
| 387 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 388 | ObjectArray<StaticStorageBase>* dex_cache_initialized_static_storage_; |
| 389 | |
| 390 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 391 | ObjectArray<ArtMethod>* dex_cache_resolved_methods_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 392 | |
| 393 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 394 | ObjectArray<Class>* dex_cache_resolved_types_; |
| 395 | |
| 396 | // short cuts to declaring_class_->dex_cache_ member for fast compiled code access |
| 397 | ObjectArray<String>* dex_cache_strings_; |
| 398 | |
| 399 | // Access flags; low 16 bits are defined by spec. |
| 400 | uint32_t access_flags_; |
| 401 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 402 | // Offset to the CodeItem. |
| 403 | uint32_t code_item_offset_; |
| 404 | |
| 405 | // Architecture-dependent register spill mask |
| 406 | uint32_t core_spill_mask_; |
| 407 | |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 408 | // Compiled code associated with this method for callers from managed code. |
| 409 | // May be compiled managed code or a bridge for invoking a native method. |
| 410 | // TODO: Break apart this into portable and quick. |
| 411 | const void* entry_point_from_compiled_code_; |
| 412 | |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 413 | // Called by the interpreter to execute this method. |
| 414 | EntryPointFromInterpreter* entry_point_from_interpreter_; |
| 415 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 416 | // Architecture-dependent register spill mask |
| 417 | uint32_t fp_spill_mask_; |
| 418 | |
| 419 | // Total size in bytes of the frame |
| 420 | size_t frame_size_in_bytes_; |
| 421 | |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 422 | // Garbage collection map of native PC offsets (quick) or dex PCs (portable) to reference bitmaps. |
| 423 | const uint8_t* gc_map_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 424 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 425 | // Mapping from native pc to dex pc |
| 426 | const uint32_t* mapping_table_; |
| 427 | |
| 428 | // Index into method_ids of the dex file associated with this method |
| 429 | uint32_t method_dex_index_; |
| 430 | |
| 431 | // For concrete virtual methods, this is the offset of the method in Class::vtable_. |
| 432 | // |
| 433 | // For abstract methods in an interface class, this is the offset of the method in |
| 434 | // "iftable_->Get(n)->GetMethodArray()". |
| 435 | // |
| 436 | // For static and direct methods this is the index in the direct methods table. |
| 437 | uint32_t method_index_; |
| 438 | |
| 439 | // The target native method registered with this method |
| 440 | const void* native_method_; |
| 441 | |
| 442 | // When a register is promoted into a register, the spill mask holds which registers hold dex |
| 443 | // registers. The first promoted register's corresponding dex register is vmap_table_[1], the Nth |
| 444 | // is vmap_table_[N]. vmap_table_[0] holds the length of the table. |
| 445 | const uint16_t* vmap_table_; |
| 446 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 447 | static Class* java_lang_reflect_ArtMethod_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 448 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 449 | private: |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 450 | friend struct art::ArtMethodOffsets; // for verifying offset information |
| 451 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 452 | }; |
| 453 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 454 | class MANAGED ArtMethodClass : public Class { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 455 | private: |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 456 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethodClass); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | } // namespace mirror |
| 460 | } // namespace art |
| 461 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 462 | #endif // ART_RUNTIME_MIRROR_ART_METHOD_H_ |