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 | 75046d1 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 37 | class MethodHandle; |
Orion Hodson | b426afb | 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> |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 90 | ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(dex::TypeIndex type_idx, |
Andreas Gampe | 9f612ff | 2014-11-24 13:42:22 -0800 | [diff] [blame] | 91 | int32_t component_count, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 92 | ArtMethod* method, |
Andreas Gampe | 9f612ff | 2014-11-24 13:42:22 -0800 | [diff] [blame] | 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 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 106 | // Type of find field operation for fast and slow case. |
| 107 | enum FindFieldType { |
| 108 | InstanceObjectRead, |
| 109 | InstanceObjectWrite, |
| 110 | InstancePrimitiveRead, |
| 111 | InstancePrimitiveWrite, |
| 112 | StaticObjectRead, |
| 113 | StaticObjectWrite, |
| 114 | StaticPrimitiveRead, |
| 115 | StaticPrimitiveWrite, |
| 116 | }; |
| 117 | |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 118 | template<FindFieldType type, bool access_check> |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 119 | inline ArtField* FindFieldFromCode(uint32_t field_idx, |
| 120 | ArtMethod* referrer, |
| 121 | Thread* self, |
| 122 | size_t expected_size) |
| 123 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 124 | REQUIRES(!Roles::uninterruptible_); |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 125 | |
| 126 | template<InvokeType type, bool access_check> |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 127 | inline ArtMethod* FindMethodFromCode(uint32_t method_idx, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 128 | ObjPtr<mirror::Object>* this_object, |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 129 | ArtMethod* referrer, |
| 130 | Thread* self) |
| 131 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 132 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 133 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 134 | // Fast path field resolution that can't initialize classes or throw exceptions. |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 135 | inline ArtField* FindFieldFast(uint32_t field_idx, |
| 136 | ArtMethod* referrer, |
| 137 | FindFieldType type, |
| 138 | size_t expected_size) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 139 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 140 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 141 | // Fast path method resolution that can't throw exceptions. |
Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 142 | template <InvokeType type, bool access_check> |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 143 | inline ArtMethod* FindMethodFast(uint32_t method_idx, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 144 | ObjPtr<mirror::Object> this_object, |
Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 145 | ArtMethod* referrer) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 146 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 147 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 148 | inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx, |
| 149 | ArtMethod* referrer, |
| 150 | Thread* self, |
| 151 | bool can_run_clinit, |
| 152 | bool verify_access) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 153 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 154 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 155 | |
Orion Hodson | 75046d1 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 156 | ObjPtr<mirror::MethodHandle> ResolveMethodHandleFromCode(ArtMethod* referrer, |
| 157 | uint32_t method_handle_idx) |
| 158 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 159 | REQUIRES(!Roles::uninterruptible_); |
| 160 | |
Orion Hodson | 16b2adf | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 161 | ObjPtr<mirror::MethodType> ResolveMethodTypeFromCode(ArtMethod* referrer, dex::ProtoIndex proto_idx) |
Orion Hodson | b426afb | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 162 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 163 | REQUIRES(!Roles::uninterruptible_); |
| 164 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 165 | inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer, |
| 166 | dex::StringIndex string_idx) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 167 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 168 | REQUIRES(!Roles::uninterruptible_); |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 169 | |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 170 | // TODO: annotalysis disabled as monitor semantics are maintained in Java code. |
Andreas Gampe | 9f612ff | 2014-11-24 13:42:22 -0800 | [diff] [blame] | 171 | inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 172 | NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_); |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 173 | |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 174 | void CheckReferenceResult(Handle<mirror::Object> o, Thread* self) |
| 175 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 176 | REQUIRES(!Roles::uninterruptible_); |
TDYa127 | 3d71d80 | 2012-08-15 03:47:03 -0700 | [diff] [blame] | 177 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 178 | JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 179 | jobject rcvr_jobj, jobject interface_art_method_jobj, |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 180 | std::vector<jvalue>& args) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 181 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 182 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 183 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 184 | bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 185 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 186 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | 832336b | 2014-10-08 15:35:22 -0700 | [diff] [blame] | 187 | |
Ian Rogers | 450dcb5 | 2013-09-20 17:36:02 -0700 | [diff] [blame] | 188 | template <typename INT_TYPE, typename FLOAT_TYPE> |
Andreas Gampe | 9f612ff | 2014-11-24 13:42:22 -0800 | [diff] [blame] | 189 | inline INT_TYPE art_float_to_integral(FLOAT_TYPE f); |
Ian Rogers | 450dcb5 | 2013-09-20 17:36:02 -0700 | [diff] [blame] | 190 | |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 191 | ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp, |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 192 | CalleeSaveType type, |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 193 | bool do_caller_check = false) |
| 194 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 195 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 196 | struct CallerAndOuterMethod { |
| 197 | ArtMethod* caller; |
| 198 | ArtMethod* outer_method; |
| 199 | }; |
| 200 | |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 201 | CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, CalleeSaveType type) |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 202 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 1920c10 | 2015-09-29 18:00:03 +0000 | [diff] [blame] | 203 | |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 204 | ArtMethod* GetCalleeSaveOuterMethod(Thread* self, CalleeSaveType type) |
Nicolas Geoffray | 5b3c6c0 | 2017-01-19 14:22:26 +0000 | [diff] [blame] | 205 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 206 | |
Shih-wei Liao | 2d83101 | 2011-09-28 22:06:53 -0700 | [diff] [blame] | 207 | } // namespace art |
Ian Rogers | ad42e13 | 2011-09-17 20:23:33 -0700 | [diff] [blame] | 208 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 209 | #endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_ |