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