blob: d87dc674bc989036fe2c0430193d05de781b80db [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
Ian Rogers450dcb52013-09-20 17:36:02 -070023#include "base/macros.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070024#include "base/mutex.h"
Ian Rogers832336b2014-10-08 15:35:22 -070025#include "dex_instruction.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080026#include "dex_file_types.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "gc/allocator_type.h"
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070028#include "handle.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070029#include "invoke_type.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070030#include "jvalue.h"
Nicolas Geoffray1920c102015-09-29 18:00:03 +000031#include "runtime.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070032
Shih-wei Liao2d831012011-09-28 22:06:53 -070033namespace art {
Ian Rogers848871b2013-08-05 10:56:33 -070034
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035namespace mirror {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070036 class Array;
Mathieu Chartierc7853442015-03-27 14:35:38 -070037 class Class;
Ian Rogers848871b2013-08-05 10:56:33 -070038 class Object;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070039 class String;
Ian Rogers848871b2013-08-05 10:56:33 -070040} // namespace mirror
Ian Rogers57b86d42012-03-27 16:05:41 -070041
Mathieu Chartierc7853442015-03-27 14:35:38 -070042class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070043class ArtMethod;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010044class OatQuickMethodHeader;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070045class ScopedObjectAccessAlreadyRunnable;
46class Thread;
47
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080048template <const bool kAccessCheck>
Andreas Gampea5b09a62016-11-17 15:21:22 -080049ALWAYS_INLINE inline mirror::Class* CheckObjectAlloc(dex::TypeIndex type_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -070050 ArtMethod* method,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070051 Thread* self,
52 bool* slow_path)
53 REQUIRES_SHARED(Locks::mutator_lock_)
54 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070055
Andreas Gampe9f612ff2014-11-24 13:42:22 -080056ALWAYS_INLINE inline mirror::Class* CheckClassInitializedForObjectAlloc(mirror::Class* klass,
57 Thread* self,
58 bool* slow_path)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070059 REQUIRES_SHARED(Locks::mutator_lock_)
60 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080061
Ian Rogers57b86d42012-03-27 16:05:41 -070062// Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it
63// cannot be resolved, throw an error. If it can, use it to create an instance.
64// When verification/compiler hasn't been able to verify access, optionally perform an access
65// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080066template <bool kAccessCheck, bool kInstrumented>
Andreas Gampea5b09a62016-11-17 15:21:22 -080067ALWAYS_INLINE inline mirror::Object* AllocObjectFromCode(dex::TypeIndex type_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -070068 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080069 Thread* self,
70 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070071 REQUIRES_SHARED(Locks::mutator_lock_)
72 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070073
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080074// Given the context of a calling Method and a resolved class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080075template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080076ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
77 Thread* self,
78 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070079 REQUIRES_SHARED(Locks::mutator_lock_)
80 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080081
82// Given the context of a calling Method and an initialized class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080083template <bool kInstrumented>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070084ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(
85 mirror::Class* klass,
86 Thread* self,
87 gc::AllocatorType allocator_type)
88 REQUIRES_SHARED(Locks::mutator_lock_)
89 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080090
91
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080092template <bool kAccessCheck>
Andreas Gampea5b09a62016-11-17 15:21:22 -080093ALWAYS_INLINE inline mirror::Class* CheckArrayAlloc(dex::TypeIndex type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080094 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070095 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080096 bool* slow_path)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070097 REQUIRES_SHARED(Locks::mutator_lock_)
98 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070099
100// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
101// it cannot be resolved, throw an error. If it can, use it to create an array.
102// When verification/compiler hasn't been able to verify access, optionally perform an access
103// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800104template <bool kAccessCheck, bool kInstrumented>
Andreas Gampea5b09a62016-11-17 15:21:22 -0800105ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(dex::TypeIndex type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800106 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700107 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800108 Thread* self,
109 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700110 REQUIRES_SHARED(Locks::mutator_lock_)
111 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700112
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800113template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800114ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800115 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700116 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800117 Thread* self,
118 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700119 REQUIRES_SHARED(Locks::mutator_lock_)
120 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800121
Andreas Gampea5b09a62016-11-17 15:21:22 -0800122mirror::Array* CheckAndAllocArrayFromCode(dex::TypeIndex type_idx,
123 int32_t component_count,
124 ArtMethod* method,
125 Thread* self,
126 bool access_check,
127 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700128 REQUIRES_SHARED(Locks::mutator_lock_)
129 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700130
Andreas Gampea5b09a62016-11-17 15:21:22 -0800131mirror::Array* CheckAndAllocArrayFromCodeInstrumented(dex::TypeIndex type_idx,
132 int32_t component_count,
133 ArtMethod* method,
134 Thread* self,
135 bool access_check,
136 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700137 REQUIRES_SHARED(Locks::mutator_lock_)
138 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700139
Ian Rogers08f753d2012-08-24 14:35:25 -0700140// Type of find field operation for fast and slow case.
141enum FindFieldType {
142 InstanceObjectRead,
143 InstanceObjectWrite,
144 InstancePrimitiveRead,
145 InstancePrimitiveWrite,
146 StaticObjectRead,
147 StaticObjectWrite,
148 StaticPrimitiveRead,
149 StaticPrimitiveWrite,
150};
151
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200152template<FindFieldType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700153inline ArtField* FindFieldFromCode(uint32_t field_idx,
154 ArtMethod* referrer,
155 Thread* self,
156 size_t expected_size)
157 REQUIRES_SHARED(Locks::mutator_lock_)
158 REQUIRES(!Roles::uninterruptible_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200159
160template<InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700161inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700162 ObjPtr<mirror::Object>* this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700163 ArtMethod* referrer,
164 Thread* self)
165 REQUIRES_SHARED(Locks::mutator_lock_)
166 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700167
Ian Rogers08f753d2012-08-24 14:35:25 -0700168// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700169inline ArtField* FindFieldFast(uint32_t field_idx,
170 ArtMethod* referrer,
171 FindFieldType type,
172 size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700173 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700174
Ian Rogers08f753d2012-08-24 14:35:25 -0700175// Fast path method resolution that can't throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700176inline ArtMethod* FindMethodFast(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700177 ObjPtr<mirror::Object> this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700178 ArtMethod* referrer,
179 bool access_check,
180 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700181 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700182
Andreas Gampea5b09a62016-11-17 15:21:22 -0800183inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700184 ArtMethod* referrer,
185 Thread* self,
186 bool can_run_clinit,
187 bool verify_access)
188 REQUIRES_SHARED(Locks::mutator_lock_)
189 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700190
Mathieu Chartiere401d142015-04-22 13:56:20 -0700191inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, uint32_t string_idx)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700192 REQUIRES_SHARED(Locks::mutator_lock_)
193 REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700194
Ian Rogerse5877a12014-07-16 12:06:35 -0700195// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800196inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700197 NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700198
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700199void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
200 REQUIRES_SHARED(Locks::mutator_lock_)
201 REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700202
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700203JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700204 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800205 std::vector<jvalue>& args)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700206 REQUIRES_SHARED(Locks::mutator_lock_)
207 REQUIRES(!Roles::uninterruptible_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800208
Mathieu Chartieref41db72016-10-25 15:08:01 -0700209bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700210 REQUIRES_SHARED(Locks::mutator_lock_)
211 REQUIRES(!Roles::uninterruptible_);
Ian Rogers832336b2014-10-08 15:35:22 -0700212
Ian Rogers450dcb52013-09-20 17:36:02 -0700213template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800214inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700215
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000216ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
217 Runtime::CalleeSaveType type,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700218 bool do_caller_check = false)
219 REQUIRES_SHARED(Locks::mutator_lock_);
220
221ArtMethod* GetCalleeSaveMethodCaller(Thread* self, Runtime::CalleeSaveType type)
222 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000223
Shih-wei Liao2d831012011-09-28 22:06:53 -0700224} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700225
Ian Rogers7655f292013-07-29 11:07:13 -0700226#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_