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