blob: e33de9c45a91da201369d27735399d2d287ed95f [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"
Ian Rogers450dcb52013-09-20 17:36:02 -070024#include "base/macros.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070025#include "base/mutex.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 Hodson75046d12018-05-10 08:22:46 +010037class MethodHandle;
Orion Hodsonb426afb2018-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.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +000052template <bool kInstrumented>
53ALWAYS_INLINE inline mirror::Object* AllocObjectFromCode(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080054 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>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080061ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
62 Thread* self,
63 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070064 REQUIRES_SHARED(Locks::mutator_lock_)
65 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080066
67// Given the context of a calling Method and an initialized class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080068template <bool kInstrumented>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070069ALWAYS_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 Yamauchibe1ca552014-01-15 11:46:48 -080075
76
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080077template <bool kAccessCheck>
Andreas Gampea5b09a62016-11-17 15:21:22 -080078ALWAYS_INLINE inline mirror::Class* CheckArrayAlloc(dex::TypeIndex type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080079 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070080 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080081 bool* slow_path)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070082 REQUIRES_SHARED(Locks::mutator_lock_)
83 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070084
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 Chartiercbb2d202013-11-14 17:45:16 -080089template <bool kAccessCheck, bool kInstrumented>
Andreas Gampea5b09a62016-11-17 15:21:22 -080090ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(dex::TypeIndex type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080091 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070092 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080093 Thread* self,
94 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070095 REQUIRES_SHARED(Locks::mutator_lock_)
96 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070097
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +000098template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080099ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800100 int32_t component_count,
101 Thread* self,
102 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700103 REQUIRES_SHARED(Locks::mutator_lock_)
104 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800105
Ian Rogers08f753d2012-08-24 14:35:25 -0700106// Type of find field operation for fast and slow case.
107enum FindFieldType {
108 InstanceObjectRead,
109 InstanceObjectWrite,
110 InstancePrimitiveRead,
111 InstancePrimitiveWrite,
112 StaticObjectRead,
113 StaticObjectWrite,
114 StaticPrimitiveRead,
115 StaticPrimitiveWrite,
116};
117
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200118template<FindFieldType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700119inline 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 Hertzd4beb6b2013-10-02 17:07:20 +0200125
126template<InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700127inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700128 ObjPtr<mirror::Object>* this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700129 ArtMethod* referrer,
130 Thread* self)
131 REQUIRES_SHARED(Locks::mutator_lock_)
132 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700133
Ian Rogers08f753d2012-08-24 14:35:25 -0700134// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700135inline ArtField* FindFieldFast(uint32_t field_idx,
136 ArtMethod* referrer,
137 FindFieldType type,
138 size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700139 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700140
Ian Rogers08f753d2012-08-24 14:35:25 -0700141// Fast path method resolution that can't throw exceptions.
Vladimir Markof79aa7f2017-07-04 16:58:55 +0100142template <InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700143inline ArtMethod* FindMethodFast(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700144 ObjPtr<mirror::Object> this_object,
Vladimir Markof79aa7f2017-07-04 16:58:55 +0100145 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700146 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700147
Vladimir Marko28e012a2017-12-07 11:22:59 +0000148inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx,
149 ArtMethod* referrer,
150 Thread* self,
151 bool can_run_clinit,
152 bool verify_access)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700153 REQUIRES_SHARED(Locks::mutator_lock_)
154 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700155
Orion Hodson75046d12018-05-10 08:22:46 +0100156ObjPtr<mirror::MethodHandle> ResolveMethodHandleFromCode(ArtMethod* referrer,
157 uint32_t method_handle_idx)
158 REQUIRES_SHARED(Locks::mutator_lock_)
159 REQUIRES(!Roles::uninterruptible_);
160
Orion Hodson16b2adf2018-05-14 08:53:38 +0100161ObjPtr<mirror::MethodType> ResolveMethodTypeFromCode(ArtMethod* referrer, dex::ProtoIndex proto_idx)
Orion Hodsonb426afb2018-04-12 11:18:23 +0100162 REQUIRES_SHARED(Locks::mutator_lock_)
163 REQUIRES(!Roles::uninterruptible_);
164
Vladimir Marko28e012a2017-12-07 11:22:59 +0000165inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer,
166 dex::StringIndex string_idx)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700167 REQUIRES_SHARED(Locks::mutator_lock_)
168 REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700169
Ian Rogerse5877a12014-07-16 12:06:35 -0700170// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800171inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700172 NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700173
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700174void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
175 REQUIRES_SHARED(Locks::mutator_lock_)
176 REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700177
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700178JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700179 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800180 std::vector<jvalue>& args)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700181 REQUIRES_SHARED(Locks::mutator_lock_)
182 REQUIRES(!Roles::uninterruptible_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800183
Mathieu Chartieref41db72016-10-25 15:08:01 -0700184bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700185 REQUIRES_SHARED(Locks::mutator_lock_)
186 REQUIRES(!Roles::uninterruptible_);
Ian Rogers832336b2014-10-08 15:35:22 -0700187
Ian Rogers450dcb52013-09-20 17:36:02 -0700188template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800189inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700190
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000191ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700192 CalleeSaveType type,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700193 bool do_caller_check = false)
194 REQUIRES_SHARED(Locks::mutator_lock_);
195
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000196struct CallerAndOuterMethod {
197 ArtMethod* caller;
198 ArtMethod* outer_method;
199};
200
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700201CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, CalleeSaveType type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700202 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000203
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700204ArtMethod* GetCalleeSaveOuterMethod(Thread* self, CalleeSaveType type)
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000205 REQUIRES_SHARED(Locks::mutator_lock_);
206
Shih-wei Liao2d831012011-09-28 22:06:53 -0700207} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700208
Ian Rogers7655f292013-07-29 11:07:13 -0700209#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_