| Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | */ |
| buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame] | 16 | |
| Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_ |
| 18 | #define ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_ |
| Ian Rogers | 450dcb5 | 2013-09-20 17:36:02 -0700 | [diff] [blame] | 19 | |
| Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 20 | #include <jni.h> |
| 21 | #include <stdint.h> |
| 22 | |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 23 | #include "base/callee_save_type.h" |
| Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 24 | #include "base/locks.h" |
| Ian Rogers | 450dcb5 | 2013-09-20 17:36:02 -0700 | [diff] [blame] | 25 | #include "base/macros.h" |
| David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 26 | #include "dex/dex_file_types.h" |
| 27 | #include "dex/dex_instruction.h" |
| Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 28 | #include "gc/allocator_type.h" |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 29 | #include "handle.h" |
| Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 30 | #include "jvalue.h" |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 31 | |
| Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 32 | namespace art { |
| Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 33 | |
| Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | namespace mirror { |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 35 | class Array; |
| 36 | class Class; |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 37 | class MethodHandle; |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 38 | class MethodType; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 39 | class Object; |
| 40 | class String; |
| Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 41 | } // namespace mirror |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 42 | |
| Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 43 | class ArtField; |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 44 | class ArtMethod; |
| Andreas Gampe | 04c6ab9 | 2017-06-08 21:49:14 -0700 | [diff] [blame] | 45 | enum InvokeType : uint32_t; |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 46 | class OatQuickMethodHeader; |
| Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 47 | class ScopedObjectAccessAlreadyRunnable; |
| 48 | class Thread; |
| 49 | |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 50 | // Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it |
| 51 | // cannot be resolved, throw an error. If it can, use it to create an instance. |
| Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 52 | template <bool kInstrumented = true> |
| Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 53 | ALWAYS_INLINE inline ObjPtr<mirror::Object> AllocObjectFromCode(ObjPtr<mirror::Class> klass, |
| 54 | Thread* self, |
| 55 | gc::AllocatorType allocator_type) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 56 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 57 | REQUIRES(!Roles::uninterruptible_); |
| Hiroshi Yamauchi | 3b4c189 | 2013-09-12 21:33:12 -0700 | [diff] [blame] | 58 | |
| Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 59 | // Given the context of a calling Method and a resolved class, create an instance. |
| Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 60 | template <bool kInstrumented> |
| Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 61 | ALWAYS_INLINE |
| 62 | inline ObjPtr<mirror::Object> AllocObjectFromCodeResolved(ObjPtr<mirror::Class> klass, |
| 63 | Thread* self, |
| 64 | gc::AllocatorType allocator_type) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 65 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 66 | REQUIRES(!Roles::uninterruptible_); |
| Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 67 | |
| 68 | // Given the context of a calling Method and an initialized class, create an instance. |
| Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 69 | template <bool kInstrumented> |
| Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 70 | ALWAYS_INLINE |
| 71 | inline ObjPtr<mirror::Object> AllocObjectFromCodeInitialized(ObjPtr<mirror::Class> klass, |
| 72 | Thread* self, |
| 73 | gc::AllocatorType allocator_type) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 74 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 75 | REQUIRES(!Roles::uninterruptible_); |
| Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 76 | |
| 77 | |
| Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 78 | template <bool kAccessCheck> |
| Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 79 | ALWAYS_INLINE inline ObjPtr<mirror::Class> CheckArrayAlloc(dex::TypeIndex type_idx, |
| 80 | int32_t component_count, |
| 81 | ArtMethod* method, |
| 82 | bool* slow_path) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 83 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 84 | REQUIRES(!Roles::uninterruptible_); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 85 | |
| 86 | // Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If |
| 87 | // it cannot be resolved, throw an error. If it can, use it to create an array. |
| 88 | // When verification/compiler hasn't been able to verify access, optionally perform an access |
| 89 | // check. |
| Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 90 | template <bool kAccessCheck, bool kInstrumented = true> |
| Vladimir Marko | bcf1752 | 2018-06-01 13:14:32 +0100 | [diff] [blame] | 91 | ALWAYS_INLINE inline ObjPtr<mirror::Array> AllocArrayFromCode(dex::TypeIndex type_idx, |
| 92 | int32_t component_count, |
| 93 | ArtMethod* method, |
| 94 | Thread* self, |
| 95 | gc::AllocatorType allocator_type) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 96 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 97 | REQUIRES(!Roles::uninterruptible_); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 98 | |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 99 | template <bool kInstrumented> |
| Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 100 | ALWAYS_INLINE |
| 101 | inline ObjPtr<mirror::Array> AllocArrayFromCodeResolved(ObjPtr<mirror::Class> klass, |
| 102 | int32_t component_count, |
| 103 | Thread* self, |
| 104 | gc::AllocatorType allocator_type) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 105 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 106 | REQUIRES(!Roles::uninterruptible_); |
| Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 107 | |
| David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 108 | enum FindFieldFlags { |
| 109 | InstanceBit = 1 << 0, |
| 110 | StaticBit = 1 << 1, |
| 111 | ObjectBit = 1 << 2, |
| 112 | PrimitiveBit = 1 << 3, |
| 113 | ReadBit = 1 << 4, |
| 114 | WriteBit = 1 << 5, |
| 115 | }; |
| 116 | |
| Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 117 | // Type of find field operation for fast and slow case. |
| 118 | enum FindFieldType { |
| David Srbecky | ce32c10 | 2018-08-31 07:21:07 +0100 | [diff] [blame] | 119 | InstanceObjectRead = InstanceBit | ObjectBit | ReadBit, |
| 120 | InstanceObjectWrite = InstanceBit | ObjectBit | WriteBit, |
| 121 | InstancePrimitiveRead = InstanceBit | PrimitiveBit | ReadBit, |
| 122 | InstancePrimitiveWrite = InstanceBit | PrimitiveBit | WriteBit, |
| 123 | StaticObjectRead = StaticBit | ObjectBit | ReadBit, |
| 124 | StaticObjectWrite = StaticBit | ObjectBit | WriteBit, |
| 125 | StaticPrimitiveRead = StaticBit | PrimitiveBit | ReadBit, |
| 126 | StaticPrimitiveWrite = StaticBit | PrimitiveBit | WriteBit, |
| Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 129 | template<FindFieldType type, bool access_check> |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 130 | inline ArtField* FindFieldFromCode(uint32_t field_idx, |
| 131 | ArtMethod* referrer, |
| 132 | Thread* self, |
| 133 | size_t expected_size) |
| 134 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 135 | REQUIRES(!Roles::uninterruptible_); |
| Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 136 | |
| 137 | template<InvokeType type, bool access_check> |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 138 | inline ArtMethod* FindMethodFromCode(uint32_t method_idx, |
| Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 139 | ObjPtr<mirror::Object>* this_object, |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 140 | ArtMethod* referrer, |
| 141 | Thread* self) |
| 142 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 143 | REQUIRES(!Roles::uninterruptible_); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 144 | |
| Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 145 | // Fast path field resolution that can't initialize classes or throw exceptions. |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 146 | inline ArtField* FindFieldFast(uint32_t field_idx, |
| 147 | ArtMethod* referrer, |
| 148 | FindFieldType type, |
| 149 | size_t expected_size) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 150 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 151 | |
| Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 152 | // Fast path method resolution that can't throw exceptions. |
| Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 153 | template <InvokeType type, bool access_check> |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 154 | inline ArtMethod* FindMethodFast(uint32_t method_idx, |
| Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 155 | ObjPtr<mirror::Object> this_object, |
| Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 156 | ArtMethod* referrer) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 157 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 158 | |
| Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 159 | inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx, |
| 160 | ArtMethod* referrer, |
| 161 | Thread* self, |
| 162 | bool can_run_clinit, |
| 163 | bool verify_access) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 164 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 165 | REQUIRES(!Roles::uninterruptible_); |
| Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 166 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 167 | ObjPtr<mirror::MethodHandle> ResolveMethodHandleFromCode(ArtMethod* referrer, |
| 168 | uint32_t method_handle_idx) |
| 169 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 170 | REQUIRES(!Roles::uninterruptible_); |
| 171 | |
| Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 172 | ObjPtr<mirror::MethodType> ResolveMethodTypeFromCode(ArtMethod* referrer, dex::ProtoIndex proto_idx) |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 173 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 174 | REQUIRES(!Roles::uninterruptible_); |
| 175 | |
| Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 176 | // TODO: annotalysis disabled as monitor semantics are maintained in Java code. |
| Andreas Gampe | 9f612ff | 2014-11-24 13:42:22 -0800 | [diff] [blame] | 177 | inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 178 | NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_); |
| TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 179 | |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 180 | void CheckReferenceResult(Handle<mirror::Object> o, Thread* self) |
| 181 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 182 | REQUIRES(!Roles::uninterruptible_); |
| TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 183 | |
| Vladimir Marko | 4bb2af5 | 2019-03-22 11:09:19 +0000 | [diff] [blame] | 184 | JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, |
| 185 | const char* shorty, |
| 186 | jobject rcvr_jobj, |
| 187 | jobject interface_art_method_jobj, |
| Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 188 | std::vector<jvalue>& args) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 189 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 190 | REQUIRES(!Roles::uninterruptible_); |
| Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 191 | |
| Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 192 | bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 193 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 194 | REQUIRES(!Roles::uninterruptible_); |
| Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 195 | |
| Ian Rogers | 450dcb5 | 2013-09-20 17:36:02 -0700 | [diff] [blame] | 196 | template <typename INT_TYPE, typename FLOAT_TYPE> |
| Andreas Gampe | 9f612ff | 2014-11-24 13:42:22 -0800 | [diff] [blame] | 197 | inline INT_TYPE art_float_to_integral(FLOAT_TYPE f); |
| Ian Rogers | 450dcb5 | 2013-09-20 17:36:02 -0700 | [diff] [blame] | 198 | |
| Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 199 | ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp, |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 200 | CalleeSaveType type, |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 201 | bool do_caller_check = false) |
| 202 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 203 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 204 | struct CallerAndOuterMethod { |
| 205 | ArtMethod* caller; |
| 206 | ArtMethod* outer_method; |
| 207 | }; |
| 208 | |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 209 | CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, CalleeSaveType type) |
| Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 210 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 211 | |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 212 | ArtMethod* GetCalleeSaveOuterMethod(Thread* self, CalleeSaveType type) |
| Nicolas Geoffray | 5b3c6c0 | 2017-01-19 14:22:26 +0000 | [diff] [blame] | 213 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 214 | |
| Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 215 | } // namespace art |
| Ian Rogers | ad42e13 | 2011-09-17 20:23:33 -0700 | [diff] [blame] | 216 | |
| Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 217 | #endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_ |