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 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ART_METHOD_H_ |
| 18 | #define ART_RUNTIME_ART_METHOD_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 20 | #include "dex_file.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 21 | #include "gc_root.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "invoke_type.h" |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 23 | #include "method_reference.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "modifiers.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 25 | #include "mirror/object.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 26 | #include "object_callbacks.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 27 | #include "quick/quick_method_frame_info.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 28 | #include "read_barrier_option.h" |
Sebastien Hertz | e4b7c89 | 2014-12-17 20:02:50 +0100 | [diff] [blame] | 29 | #include "stack.h" |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 30 | #include "stack_map.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "utils.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | union JValue; |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 36 | class ScopedObjectAccessAlreadyRunnable; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | class StringPiece; |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 38 | class ShadowFrame; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | |
| 40 | namespace mirror { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 41 | class Array; |
| 42 | class Class; |
| 43 | class PointerArray; |
| 44 | } // namespace mirror |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 45 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 46 | class ArtMethod FINAL { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | public: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 48 | ArtMethod() : access_flags_(0), dex_code_item_offset_(0), dex_method_index_(0), |
| 49 | method_index_(0) { } |
| 50 | |
| 51 | ArtMethod(const ArtMethod& src, size_t image_pointer_size) { |
| 52 | CopyFrom(&src, image_pointer_size); |
| 53 | } |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 54 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 55 | static ArtMethod* FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa, |
| 56 | jobject jlr_method) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 57 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 58 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 59 | ALWAYS_INLINE mirror::Class* GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 60 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 61 | ALWAYS_INLINE mirror::Class* GetDeclaringClassNoBarrier() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 62 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 63 | |
| 64 | ALWAYS_INLINE mirror::Class* GetDeclaringClassUnchecked() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 65 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 66 | |
| 67 | void SetDeclaringClass(mirror::Class *new_declaring_class) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 68 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | |
| 70 | static MemberOffset DeclaringClassOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 71 | return MemberOffset(OFFSETOF_MEMBER(ArtMethod, declaring_class_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 74 | ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_REQUIRES(Locks::mutator_lock_); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 75 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 76 | void SetAccessFlags(uint32_t new_access_flags) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 77 | // Not called within a transaction. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 78 | access_flags_ = new_access_flags; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // Approximate what kind of method call would be used for this method. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 82 | InvokeType GetInvokeType() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 83 | |
| 84 | // Returns true if the method is declared public. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 85 | bool IsPublic() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 86 | return (GetAccessFlags() & kAccPublic) != 0; |
| 87 | } |
| 88 | |
| 89 | // Returns true if the method is declared private. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 90 | bool IsPrivate() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 91 | return (GetAccessFlags() & kAccPrivate) != 0; |
| 92 | } |
| 93 | |
| 94 | // Returns true if the method is declared static. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 95 | bool IsStatic() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 96 | return (GetAccessFlags() & kAccStatic) != 0; |
| 97 | } |
| 98 | |
| 99 | // Returns true if the method is a constructor. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 100 | bool IsConstructor() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 101 | return (GetAccessFlags() & kAccConstructor) != 0; |
| 102 | } |
| 103 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 104 | // Returns true if the method is a class initializer. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 105 | bool IsClassInitializer() SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 106 | return IsConstructor() && IsStatic(); |
| 107 | } |
| 108 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 109 | // Returns true if the method is static, private, or a constructor. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 110 | bool IsDirect() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 111 | return IsDirect(GetAccessFlags()); |
| 112 | } |
| 113 | |
| 114 | static bool IsDirect(uint32_t access_flags) { |
| 115 | return (access_flags & (kAccStatic | kAccPrivate | kAccConstructor)) != 0; |
| 116 | } |
| 117 | |
| 118 | // Returns true if the method is declared synchronized. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 119 | bool IsSynchronized() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 120 | uint32_t synchonized = kAccSynchronized | kAccDeclaredSynchronized; |
| 121 | return (GetAccessFlags() & synchonized) != 0; |
| 122 | } |
| 123 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 124 | bool IsFinal() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 125 | return (GetAccessFlags() & kAccFinal) != 0; |
| 126 | } |
| 127 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 128 | bool IsMiranda() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 129 | return (GetAccessFlags() & kAccMiranda) != 0; |
| 130 | } |
| 131 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 132 | bool IsNative() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 133 | return (GetAccessFlags() & kAccNative) != 0; |
| 134 | } |
| 135 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 136 | bool ShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 137 | return (GetAccessFlags() & kAccDontInline) != 0; |
| 138 | } |
| 139 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 140 | void SetShouldNotInline() SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 141 | SetAccessFlags(GetAccessFlags() | kAccDontInline); |
| 142 | } |
| 143 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 144 | bool IsFastNative() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 16ce092 | 2014-01-10 14:59:36 -0800 | [diff] [blame] | 145 | uint32_t mask = kAccFastNative | kAccNative; |
| 146 | return (GetAccessFlags() & mask) == mask; |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 149 | bool IsAbstract() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 150 | return (GetAccessFlags() & kAccAbstract) != 0; |
| 151 | } |
| 152 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 153 | bool IsSynthetic() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 154 | return (GetAccessFlags() & kAccSynthetic) != 0; |
| 155 | } |
| 156 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 157 | bool IsProxyMethod() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 158 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 159 | bool IsPreverified() SHARED_REQUIRES(Locks::mutator_lock_) { |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 160 | return (GetAccessFlags() & kAccPreverified) != 0; |
| 161 | } |
| 162 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 163 | void SetPreverified() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 164 | DCHECK(!IsPreverified()); |
Sebastien Hertz | 233ea8e | 2013-06-06 11:57:09 +0200 | [diff] [blame] | 165 | SetAccessFlags(GetAccessFlags() | kAccPreverified); |
| 166 | } |
| 167 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 168 | bool IsOptimized(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 169 | // Temporary solution for detecting if a method has been optimized: the compiler |
| 170 | // does not create a GC map. Instead, the vmap table contains the stack map |
| 171 | // (as in stack_map.h). |
Nicolas Geoffray | 376b2bb | 2014-12-09 14:26:32 +0000 | [diff] [blame] | 172 | return !IsNative() |
| 173 | && GetEntryPointFromQuickCompiledCodePtrSize(pointer_size) != nullptr |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 174 | && GetQuickOatCodePointer(pointer_size) != nullptr |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 175 | && GetNativeGcMap(pointer_size) == nullptr; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 178 | bool CheckIncompatibleClassChange(InvokeType type) SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 179 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 180 | uint16_t GetMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 181 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 182 | // Doesn't do erroneous / unresolved class checks. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 183 | uint16_t GetMethodIndexDuringLinking() SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 184 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 185 | size_t GetVtableIndex() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 186 | return GetMethodIndex(); |
| 187 | } |
| 188 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 189 | void SetMethodIndex(uint16_t new_method_index) SHARED_REQUIRES(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 190 | // Not called within a transaction. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 191 | method_index_ = new_method_index; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Vladimir Marko | c136312 | 2015-04-09 14:13:13 +0100 | [diff] [blame] | 194 | static MemberOffset DexMethodIndexOffset() { |
| 195 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_); |
| 196 | } |
| 197 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 198 | static MemberOffset MethodIndexOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 199 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 202 | uint32_t GetCodeItemOffset() { |
| 203 | return dex_code_item_offset_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 206 | void SetCodeItemOffset(uint32_t new_code_off) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 207 | // Not called within a transaction. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 208 | dex_code_item_offset_ = new_code_off; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Number of 32bit registers that would be required to hold all the arguments |
| 212 | static size_t NumArgRegisters(const StringPiece& shorty); |
| 213 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 214 | ALWAYS_INLINE uint32_t GetDexMethodIndex() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 215 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 216 | void SetDexMethodIndex(uint32_t new_idx) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 217 | // Not called within a transaction. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 218 | dex_method_index_ = new_idx; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 221 | static MemberOffset DexCacheResolvedMethodsOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 222 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static MemberOffset DexCacheResolvedTypesOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 226 | return OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 229 | ALWAYS_INLINE mirror::PointerArray* GetDexCacheResolvedMethods() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 230 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 231 | ALWAYS_INLINE ArtMethod* GetDexCacheResolvedMethod(uint16_t method_idx, size_t ptr_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 232 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 233 | ALWAYS_INLINE void SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method, |
| 234 | size_t ptr_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 235 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 236 | ALWAYS_INLINE void SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 237 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 238 | bool HasDexCacheResolvedMethods() SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 239 | bool HasSameDexCacheResolvedMethods(ArtMethod* other) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 240 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 241 | bool HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 242 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 243 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 244 | template <bool kWithCheck = true> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 245 | mirror::Class* GetDexCacheResolvedType(uint32_t type_idx) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 246 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 247 | void SetDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* new_dex_cache_types) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 248 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 249 | bool HasDexCacheResolvedTypes() SHARED_REQUIRES(Locks::mutator_lock_); |
| 250 | bool HasSameDexCacheResolvedTypes(ArtMethod* other) SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 251 | bool HasSameDexCacheResolvedTypes(mirror::ObjectArray<mirror::Class>* other_cache) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 252 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 253 | |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 254 | // Get the Class* from the type index into this method's dex cache. |
| 255 | mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 256 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 257 | |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 258 | // Find the method that this method overrides. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 259 | ArtMethod* FindOverriddenMethod(size_t pointer_size) SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 260 | |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 261 | // Find the method index for this method within other_dexfile. If this method isn't present then |
| 262 | // return DexFile::kDexNoIndex. The name_and_signature_idx MUST refer to a MethodId with the same |
| 263 | // name and signature in the other_dexfile, such as the method index used to resolve this method |
| 264 | // in the other_dexfile. |
| 265 | uint32_t FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile, |
| 266 | uint32_t name_and_signature_idx) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 267 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 268 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 269 | void Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, const char* shorty) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 270 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 271 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 272 | const void* GetEntryPointFromQuickCompiledCode() { |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 273 | return GetEntryPointFromQuickCompiledCodePtrSize(sizeof(void*)); |
| 274 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 275 | ALWAYS_INLINE const void* GetEntryPointFromQuickCompiledCodePtrSize(size_t pointer_size) { |
| 276 | return GetEntryPoint<const void*>( |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 277 | EntryPointFromQuickCompiledCodeOffset(pointer_size), pointer_size); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 280 | void SetEntryPointFromQuickCompiledCode(const void* entry_point_from_quick_compiled_code) { |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 281 | SetEntryPointFromQuickCompiledCodePtrSize(entry_point_from_quick_compiled_code, |
| 282 | sizeof(void*)); |
| 283 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 284 | ALWAYS_INLINE void SetEntryPointFromQuickCompiledCodePtrSize( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 285 | const void* entry_point_from_quick_compiled_code, size_t pointer_size) { |
| 286 | SetEntryPoint(EntryPointFromQuickCompiledCodeOffset(pointer_size), |
| 287 | entry_point_from_quick_compiled_code, pointer_size); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 290 | uint32_t GetCodeSize() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 291 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 292 | // Check whether the given PC is within the quick compiled code associated with this method's |
| 293 | // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for |
| 294 | // debug purposes. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 295 | bool PcIsWithinQuickCode(uintptr_t pc) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 296 | return PcIsWithinQuickCode( |
| 297 | reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 300 | void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 301 | |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 302 | // Returns true if the entrypoint points to the interpreter, as |
| 303 | // opposed to the compiled code, that is, this method will be |
| 304 | // interpretered on invocation. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 305 | bool IsEntrypointInterpreter() SHARED_REQUIRES(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 306 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 307 | uint32_t GetQuickOatCodeOffset(); |
| 308 | void SetQuickOatCodeOffset(uint32_t code_offset); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 309 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 310 | ALWAYS_INLINE static const void* EntryPointToCodePointer(const void* entry_point) { |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 311 | uintptr_t code = reinterpret_cast<uintptr_t>(entry_point); |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 312 | // TODO: Make this Thumb2 specific. It is benign on other architectures as code is always at |
| 313 | // least 2 byte aligned. |
| 314 | code &= ~0x1; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 315 | return reinterpret_cast<const void*>(code); |
| 316 | } |
| 317 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 318 | // Actual entry point pointer to compiled oat code or null. |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 319 | const void* GetQuickOatEntryPoint(size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 320 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 321 | // Actual pointer to compiled oat code or null. |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 322 | const void* GetQuickOatCodePointer(size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 323 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 324 | return EntryPointToCodePointer(GetQuickOatEntryPoint(pointer_size)); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 325 | } |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 326 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 327 | // Callers should wrap the uint8_t* in a MappingTable instance for convenient access. |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 328 | const uint8_t* GetMappingTable(size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 329 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 330 | const uint8_t* GetMappingTable(const void* code_pointer, size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 331 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 332 | |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 333 | // Callers should wrap the uint8_t* in a VmapTable instance for convenient access. |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 334 | const uint8_t* GetVmapTable(size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 335 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 336 | const uint8_t* GetVmapTable(const void* code_pointer, size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 337 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 338 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 339 | const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_); |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 340 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 341 | CodeInfo GetOptimizedCodeInfo() SHARED_REQUIRES(Locks::mutator_lock_); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 342 | |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 343 | // Callers should wrap the uint8_t* in a GcMap instance for convenient access. |
| 344 | const uint8_t* GetNativeGcMap(size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 345 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 346 | const uint8_t* GetNativeGcMap(const void* code_pointer, size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 347 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 348 | |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 349 | template <bool kCheckFrameSize = true> |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 350 | uint32_t GetFrameSizeInBytes() SHARED_REQUIRES(Locks::mutator_lock_) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 351 | uint32_t result = GetQuickFrameInfo().FrameSizeInBytes(); |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 352 | if (kCheckFrameSize) { |
| 353 | DCHECK_LE(static_cast<size_t>(kStackAlignment), result); |
| 354 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 355 | return result; |
| 356 | } |
| 357 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 358 | QuickMethodFrameInfo GetQuickFrameInfo() SHARED_REQUIRES(Locks::mutator_lock_); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 359 | QuickMethodFrameInfo GetQuickFrameInfo(const void* code_pointer) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 360 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 361 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 362 | FrameOffset GetReturnPcOffset() SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 363 | return GetReturnPcOffset(GetFrameSizeInBytes()); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 366 | FrameOffset GetReturnPcOffset(uint32_t frame_size_in_bytes) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 367 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 368 | DCHECK_EQ(frame_size_in_bytes, GetFrameSizeInBytes()); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 369 | return FrameOffset(frame_size_in_bytes - sizeof(void*)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 372 | FrameOffset GetHandleScopeOffset() SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 373 | constexpr size_t handle_scope_offset = sizeof(ArtMethod*); |
Sebastien Hertz | e4b7c89 | 2014-12-17 20:02:50 +0100 | [diff] [blame] | 374 | DCHECK_LT(handle_scope_offset, GetFrameSizeInBytes()); |
| 375 | return FrameOffset(handle_scope_offset); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 378 | void RegisterNative(const void* native_method, bool is_fast) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 379 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 380 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 381 | void UnregisterNative() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 382 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 383 | static MemberOffset EntryPointFromJniOffset(size_t pointer_size) { |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 384 | return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER( |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 385 | PtrSizedFields, entry_point_from_jni_) / sizeof(void*) * pointer_size); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 388 | static MemberOffset EntryPointFromQuickCompiledCodeOffset(size_t pointer_size) { |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 389 | return MemberOffset(PtrSizedFieldsOffset(pointer_size) + OFFSETOF_MEMBER( |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 390 | PtrSizedFields, entry_point_from_quick_compiled_code_) / sizeof(void*) * pointer_size); |
| 391 | } |
| 392 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 393 | void* GetEntryPointFromJni() { |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 394 | return GetEntryPointFromJniPtrSize(sizeof(void*)); |
| 395 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 396 | ALWAYS_INLINE void* GetEntryPointFromJniPtrSize(size_t pointer_size) { |
| 397 | return GetEntryPoint<void*>(EntryPointFromJniOffset(pointer_size), pointer_size); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 400 | void SetEntryPointFromJni(const void* entrypoint) SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 401 | SetEntryPointFromJniPtrSize(entrypoint, sizeof(void*)); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 402 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 403 | ALWAYS_INLINE void SetEntryPointFromJniPtrSize(const void* entrypoint, size_t pointer_size) { |
| 404 | SetEntryPoint(EntryPointFromJniOffset(pointer_size), entrypoint, pointer_size); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 405 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 406 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 407 | // Is this a CalleSaveMethod or ResolutionMethod and therefore doesn't adhere to normal |
| 408 | // conventions for a method of managed code. Returns false for Proxy methods. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 409 | ALWAYS_INLINE bool IsRuntimeMethod(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 410 | |
| 411 | // Is this a hand crafted method used for something like describing callee saves? |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 412 | bool IsCalleeSaveMethod() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 413 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 414 | bool IsResolutionMethod() SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 415 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 416 | bool IsImtConflictMethod() SHARED_REQUIRES(Locks::mutator_lock_); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 417 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 418 | bool IsImtUnimplementedMethod() SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 419 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 420 | uintptr_t NativeQuickPcOffset(const uintptr_t pc) SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 421 | #ifdef NDEBUG |
| 422 | uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 423 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 424 | return pc - reinterpret_cast<uintptr_t>(quick_entry_point); |
| 425 | } |
| 426 | #else |
| 427 | uintptr_t NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 428 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 429 | #endif |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 430 | |
| 431 | // Converts a native PC to a dex PC. |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 432 | uint32_t ToDexPc(const uintptr_t pc, bool abort_on_failure = true) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 433 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 434 | |
| 435 | // Converts a dex PC to a native PC. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 436 | uintptr_t ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure = true) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 437 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 438 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 439 | MethodReference ToMethodReference() SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 440 | return MethodReference(GetDexFile(), GetDexMethodIndex()); |
| 441 | } |
| 442 | |
Ian Rogers | c449aa8 | 2013-07-29 14:35:46 -0700 | [diff] [blame] | 443 | // Find the catch block for the given exception type and dex_pc. When a catch block is found, |
| 444 | // indicates whether the found catch block is responsible for clearing the exception or whether |
| 445 | // a move-exception instruction is present. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 446 | uint32_t FindCatchBlock(Handle<mirror::Class> exception_type, uint32_t dex_pc, |
| 447 | bool* has_no_move_exception) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 448 | SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 449 | |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 450 | // NO_THREAD_SAFETY_ANALYSIS since we don't know what the callback requires. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 451 | template<typename RootVisitorType> |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 452 | void VisitRoots(RootVisitorType& visitor) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 453 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 454 | const DexFile* GetDexFile() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 455 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 456 | const char* GetDeclaringClassDescriptor() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 457 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 458 | const char* GetShorty() SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 459 | uint32_t unused_length; |
| 460 | return GetShorty(&unused_length); |
| 461 | } |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 462 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 463 | const char* GetShorty(uint32_t* out_length) SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 464 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 465 | const Signature GetSignature() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 466 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 467 | ALWAYS_INLINE const char* GetName() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 468 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 469 | mirror::String* GetNameAsString(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | 6b14d55 | 2014-10-28 21:50:58 -0700 | [diff] [blame] | 470 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 471 | const DexFile::CodeItem* GetCodeItem() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 472 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 473 | bool IsResolvedTypeIdx(uint16_t type_idx) SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 474 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 475 | int32_t GetLineNumFromDexPC(uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 476 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 477 | const DexFile::ProtoId& GetPrototype() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 478 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 479 | const DexFile::TypeList* GetParameterTypeList() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 480 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 481 | const char* GetDeclaringClassSourceFile() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 482 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 483 | uint16_t GetClassDefIndex() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 484 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 485 | const DexFile::ClassDef& GetClassDef() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 486 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 487 | const char* GetReturnTypeDescriptor() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 488 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 489 | const char* GetTypeDescriptorFromTypeIdx(uint16_t type_idx) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 490 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 491 | |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 492 | // May cause thread suspension due to GetClassFromTypeIdx calling ResolveType this caused a large |
| 493 | // number of bugs at call sites. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 494 | mirror::Class* GetReturnType(bool resolve = true) SHARED_REQUIRES(Locks::mutator_lock_); |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 495 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 496 | mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 497 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 498 | mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 499 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 500 | ALWAYS_INLINE ArtMethod* GetInterfaceMethodIfProxy(size_t pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 501 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 502 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 503 | // May cause thread suspension due to class resolution. |
| 504 | bool EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 505 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 506 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 507 | // Size of an instance of this object. |
| 508 | static size_t ObjectSize(size_t pointer_size) { |
| 509 | return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size) + |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 510 | (sizeof(PtrSizedFields) / sizeof(void*)) * pointer_size; |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 513 | void CopyFrom(const ArtMethod* src, size_t image_pointer_size) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 514 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 515 | |
| 516 | ALWAYS_INLINE mirror::ObjectArray<mirror::Class>* GetDexCacheResolvedTypes() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 517 | SHARED_REQUIRES(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 518 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 519 | protected: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 520 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 521 | // The class we are a part of. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 522 | GcRoot<mirror::Class> declaring_class_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 523 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 524 | // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 525 | GcRoot<mirror::PointerArray> dex_cache_resolved_methods_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 526 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 527 | // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 528 | GcRoot<mirror::ObjectArray<mirror::Class>> dex_cache_resolved_types_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 529 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 530 | // Access flags; low 16 bits are defined by spec. |
| 531 | uint32_t access_flags_; |
| 532 | |
| 533 | /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */ |
| 534 | |
| 535 | // Offset to the CodeItem. |
| 536 | uint32_t dex_code_item_offset_; |
| 537 | |
| 538 | // Index into method_ids of the dex file associated with this method. |
| 539 | uint32_t dex_method_index_; |
| 540 | |
| 541 | /* End of dex file fields. */ |
| 542 | |
| 543 | // Entry within a dispatch table for this method. For static/direct methods the index is into |
| 544 | // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the |
| 545 | // ifTable. |
| 546 | uint32_t method_index_; |
| 547 | |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 548 | // Fake padding field gets inserted here. |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 549 | |
| 550 | // Must be the last fields in the method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 551 | // PACKED(4) is necessary for the correctness of |
| 552 | // RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size). |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 553 | struct PACKED(4) PtrSizedFields { |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 554 | // Pointer to JNI function registered to this method, or a function to resolve the JNI function. |
| 555 | void* entry_point_from_jni_; |
| 556 | |
| 557 | // Method dispatch from quick compiled code invokes this pointer which may cause bridging into |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 558 | // the interpreter. |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 559 | void* entry_point_from_quick_compiled_code_; |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 560 | } ptr_sized_fields_; |
| 561 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 562 | private: |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 563 | static size_t PtrSizedFieldsOffset(size_t pointer_size) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 564 | // Round up to pointer size for padding field. |
| 565 | return RoundUp(OFFSETOF_MEMBER(ArtMethod, ptr_sized_fields_), pointer_size); |
| 566 | } |
| 567 | |
| 568 | template<typename T> |
| 569 | ALWAYS_INLINE T GetEntryPoint(MemberOffset offset, size_t pointer_size) const { |
| 570 | DCHECK(ValidPointerSize(pointer_size)) << pointer_size; |
| 571 | const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value(); |
| 572 | if (pointer_size == sizeof(uint32_t)) { |
| 573 | return reinterpret_cast<T>(*reinterpret_cast<const uint32_t*>(addr)); |
| 574 | } else { |
| 575 | auto v = *reinterpret_cast<const uint64_t*>(addr); |
| 576 | DCHECK_EQ(reinterpret_cast<uint64_t>(reinterpret_cast<T>(v)), v) << "Conversion lost bits"; |
| 577 | return reinterpret_cast<T>(v); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | template<typename T> |
| 582 | ALWAYS_INLINE void SetEntryPoint(MemberOffset offset, T new_value, size_t pointer_size) { |
| 583 | DCHECK(ValidPointerSize(pointer_size)) << pointer_size; |
| 584 | const auto addr = reinterpret_cast<uintptr_t>(this) + offset.Uint32Value(); |
| 585 | if (pointer_size == sizeof(uint32_t)) { |
| 586 | uintptr_t ptr = reinterpret_cast<uintptr_t>(new_value); |
| 587 | DCHECK_EQ(static_cast<uint32_t>(ptr), ptr) << "Conversion lost bits"; |
| 588 | *reinterpret_cast<uint32_t*>(addr) = static_cast<uint32_t>(ptr); |
| 589 | } else { |
| 590 | *reinterpret_cast<uint64_t*>(addr) = reinterpret_cast<uintptr_t>(new_value); |
| 591 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 594 | // Code points to the start of the quick code. |
| 595 | static uint32_t GetCodeSize(const void* code); |
| 596 | |
| 597 | static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) { |
| 598 | if (code == 0) { |
| 599 | return pc == 0; |
| 600 | } |
| 601 | /* |
| 602 | * During a stack walk, a return PC may point past-the-end of the code |
| 603 | * in the case that the last instruction is a call that isn't expected to |
| 604 | * return. Thus, we check <= code + GetCodeSize(). |
| 605 | * |
| 606 | * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state. |
| 607 | */ |
| 608 | return code <= pc && pc <= code + GetCodeSize( |
| 609 | EntryPointToCodePointer(reinterpret_cast<const void*>(code))); |
| 610 | } |
| 611 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 612 | DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 613 | }; |
| 614 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 615 | } // namespace art |
| 616 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 617 | #endif // ART_RUNTIME_ART_METHOD_H_ |