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