blob: 6e75a1eb63b025f41b4e441fdfd8714a12f64206 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
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 */
buzbee54330722011-08-23 16:46:55 -070016
Ian Rogers7655f292013-07-29 11:07:13 -070017#ifndef ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
18#define ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
Ian Rogers450dcb52013-09-20 17:36:02 -070019
Mingyao Yang98d1cc82014-05-15 17:02:16 -070020#include <jni.h>
21#include <stdint.h>
22
Andreas Gampe8228cdf2017-05-30 15:03:54 -070023#include "base/callee_save_type.h"
Andreas Gampe7fbc4a52018-11-28 08:26:47 -080024#include "base/locks.h"
Ian Rogers450dcb52013-09-20 17:36:02 -070025#include "base/macros.h"
David Sehr9e734c72018-01-04 17:56:19 -080026#include "dex/dex_file_types.h"
27#include "dex/dex_instruction.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070028#include "gc/allocator_type.h"
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070029#include "handle.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070030#include "jvalue.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070031
Shih-wei Liao2d831012011-09-28 22:06:53 -070032namespace art {
Ian Rogers848871b2013-08-05 10:56:33 -070033
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080035class Array;
36class Class;
Orion Hodsondbaa5c72018-05-10 08:22:46 +010037class MethodHandle;
Orion Hodson18259d72018-04-12 11:18:23 +010038class MethodType;
Igor Murashkin2ffb7032017-11-08 13:35:21 -080039class Object;
40class String;
Ian Rogers848871b2013-08-05 10:56:33 -070041} // namespace mirror
Ian Rogers57b86d42012-03-27 16:05:41 -070042
Mathieu Chartierc7853442015-03-27 14:35:38 -070043class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070044class ArtMethod;
Andreas Gampe04c6ab92017-06-08 21:49:14 -070045enum InvokeType : uint32_t;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010046class OatQuickMethodHeader;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070047class ScopedObjectAccessAlreadyRunnable;
48class Thread;
49
Ian Rogers57b86d42012-03-27 16:05:41 -070050// 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 Marko9b81ac32019-05-16 16:47:08 +010052template <bool kInstrumented = true>
Vladimir Marko4bb2af52019-03-22 11:09:19 +000053ALWAYS_INLINE inline ObjPtr<mirror::Object> AllocObjectFromCode(ObjPtr<mirror::Class> klass,
54 Thread* self,
55 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070056 REQUIRES_SHARED(Locks::mutator_lock_)
57 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070058
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080059// Given the context of a calling Method and a resolved class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080060template <bool kInstrumented>
Vladimir Marko4bb2af52019-03-22 11:09:19 +000061ALWAYS_INLINE
62inline ObjPtr<mirror::Object> AllocObjectFromCodeResolved(ObjPtr<mirror::Class> klass,
63 Thread* self,
64 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070065 REQUIRES_SHARED(Locks::mutator_lock_)
66 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080067
68// Given the context of a calling Method and an initialized class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080069template <bool kInstrumented>
Vladimir Marko4bb2af52019-03-22 11:09:19 +000070ALWAYS_INLINE
71inline ObjPtr<mirror::Object> AllocObjectFromCodeInitialized(ObjPtr<mirror::Class> klass,
72 Thread* self,
73 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070074 REQUIRES_SHARED(Locks::mutator_lock_)
75 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080076
77
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080078template <bool kAccessCheck>
Vladimir Marko4bb2af52019-03-22 11:09:19 +000079ALWAYS_INLINE inline ObjPtr<mirror::Class> CheckArrayAlloc(dex::TypeIndex type_idx,
80 int32_t component_count,
81 ArtMethod* method,
82 bool* slow_path)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070083 REQUIRES_SHARED(Locks::mutator_lock_)
84 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070085
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 Marko9b81ac32019-05-16 16:47:08 +010090template <bool kAccessCheck, bool kInstrumented = true>
Vladimir Markobcf17522018-06-01 13:14:32 +010091ALWAYS_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 Chartierbe08cf52016-09-13 13:41:24 -070096 REQUIRES_SHARED(Locks::mutator_lock_)
97 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070098
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +000099template <bool kInstrumented>
Vladimir Marko4bb2af52019-03-22 11:09:19 +0000100ALWAYS_INLINE
101inline ObjPtr<mirror::Array> AllocArrayFromCodeResolved(ObjPtr<mirror::Class> klass,
102 int32_t component_count,
103 Thread* self,
104 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700105 REQUIRES_SHARED(Locks::mutator_lock_)
106 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800107
David Srbeckyce32c102018-08-31 07:21:07 +0100108enum 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 Rogers08f753d2012-08-24 14:35:25 -0700117// Type of find field operation for fast and slow case.
118enum FindFieldType {
David Srbeckyce32c102018-08-31 07:21:07 +0100119 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 Rogers08f753d2012-08-24 14:35:25 -0700127};
128
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200129template<FindFieldType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700130inline 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 Hertzd4beb6b2013-10-02 17:07:20 +0200136
137template<InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700138inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700139 ObjPtr<mirror::Object>* this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700140 ArtMethod* referrer,
141 Thread* self)
142 REQUIRES_SHARED(Locks::mutator_lock_)
143 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700144
Ian Rogers08f753d2012-08-24 14:35:25 -0700145// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700146inline ArtField* FindFieldFast(uint32_t field_idx,
147 ArtMethod* referrer,
148 FindFieldType type,
149 size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700150 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700151
Ian Rogers08f753d2012-08-24 14:35:25 -0700152// Fast path method resolution that can't throw exceptions.
Vladimir Markof79aa7f2017-07-04 16:58:55 +0100153template <InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700154inline ArtMethod* FindMethodFast(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700155 ObjPtr<mirror::Object> this_object,
Vladimir Markof79aa7f2017-07-04 16:58:55 +0100156 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700157 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700158
Vladimir Marko28e012a2017-12-07 11:22:59 +0000159inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx,
160 ArtMethod* referrer,
161 Thread* self,
162 bool can_run_clinit,
163 bool verify_access)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700164 REQUIRES_SHARED(Locks::mutator_lock_)
165 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700166
Orion Hodsondbaa5c72018-05-10 08:22:46 +0100167ObjPtr<mirror::MethodHandle> ResolveMethodHandleFromCode(ArtMethod* referrer,
168 uint32_t method_handle_idx)
169 REQUIRES_SHARED(Locks::mutator_lock_)
170 REQUIRES(!Roles::uninterruptible_);
171
Orion Hodson06d10a72018-05-14 08:53:38 +0100172ObjPtr<mirror::MethodType> ResolveMethodTypeFromCode(ArtMethod* referrer, dex::ProtoIndex proto_idx)
Orion Hodson18259d72018-04-12 11:18:23 +0100173 REQUIRES_SHARED(Locks::mutator_lock_)
174 REQUIRES(!Roles::uninterruptible_);
175
Ian Rogerse5877a12014-07-16 12:06:35 -0700176// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800177inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700178 NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700179
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700180void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
181 REQUIRES_SHARED(Locks::mutator_lock_)
182 REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700183
Vladimir Marko4bb2af52019-03-22 11:09:19 +0000184JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa,
185 const char* shorty,
186 jobject rcvr_jobj,
187 jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800188 std::vector<jvalue>& args)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700189 REQUIRES_SHARED(Locks::mutator_lock_)
190 REQUIRES(!Roles::uninterruptible_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800191
Mathieu Chartieref41db72016-10-25 15:08:01 -0700192bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700193 REQUIRES_SHARED(Locks::mutator_lock_)
194 REQUIRES(!Roles::uninterruptible_);
Ian Rogers832336b2014-10-08 15:35:22 -0700195
Ian Rogers450dcb52013-09-20 17:36:02 -0700196template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800197inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700198
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000199ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700200 CalleeSaveType type,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700201 bool do_caller_check = false)
202 REQUIRES_SHARED(Locks::mutator_lock_);
203
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000204struct CallerAndOuterMethod {
205 ArtMethod* caller;
206 ArtMethod* outer_method;
207};
208
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700209CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, CalleeSaveType type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700210 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000211
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700212ArtMethod* GetCalleeSaveOuterMethod(Thread* self, CalleeSaveType type)
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000213 REQUIRES_SHARED(Locks::mutator_lock_);
214
Shih-wei Liao2d831012011-09-28 22:06:53 -0700215} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700216
Ian Rogers7655f292013-07-29 11:07:13 -0700217#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_