blob: bcddfb05086bbb2d0994589c3807f4c2184b80cc [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"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026#include "gc/allocator_type.h"
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070027#include "handle.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070028#include "invoke_type.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070029#include "jvalue.h"
Nicolas Geoffray1920c102015-09-29 18:00:03 +000030#include "runtime.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 {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070035 class Array;
Mathieu Chartierc7853442015-03-27 14:35:38 -070036 class Class;
Ian Rogers848871b2013-08-05 10:56:33 -070037 class Object;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070038 class String;
Ian Rogers848871b2013-08-05 10:56:33 -070039} // namespace mirror
Ian Rogers57b86d42012-03-27 16:05:41 -070040
Mathieu Chartierc7853442015-03-27 14:35:38 -070041class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070042class ArtMethod;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010043class OatQuickMethodHeader;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070044class ScopedObjectAccessAlreadyRunnable;
45class Thread;
46
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080047template <const bool kAccessCheck>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080048ALWAYS_INLINE inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -070049 ArtMethod* method,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070050 Thread* self,
51 bool* slow_path)
52 REQUIRES_SHARED(Locks::mutator_lock_)
53 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070054
Andreas Gampe9f612ff2014-11-24 13:42:22 -080055ALWAYS_INLINE inline mirror::Class* CheckClassInitializedForObjectAlloc(mirror::Class* klass,
56 Thread* self,
57 bool* slow_path)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070058 REQUIRES_SHARED(Locks::mutator_lock_)
59 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080060
Ian Rogers57b86d42012-03-27 16:05:41 -070061// Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it
62// cannot be resolved, throw an error. If it can, use it to create an instance.
63// When verification/compiler hasn't been able to verify access, optionally perform an access
64// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080065template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080066ALWAYS_INLINE inline mirror::Object* AllocObjectFromCode(uint32_t type_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -070067 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080068 Thread* self,
69 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070070 REQUIRES_SHARED(Locks::mutator_lock_)
71 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070072
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080073// Given the context of a calling Method and a resolved class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080074template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080075ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
76 Thread* self,
77 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070078 REQUIRES_SHARED(Locks::mutator_lock_)
79 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080080
81// Given the context of a calling Method and an initialized class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080082template <bool kInstrumented>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070083ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(
84 mirror::Class* klass,
85 Thread* self,
86 gc::AllocatorType allocator_type)
87 REQUIRES_SHARED(Locks::mutator_lock_)
88 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080089
90
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080091template <bool kAccessCheck>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080092ALWAYS_INLINE inline mirror::Class* CheckArrayAlloc(uint32_t type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080093 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070094 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080095 bool* slow_path)
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
99// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
100// it cannot be resolved, throw an error. If it can, use it to create an array.
101// When verification/compiler hasn't been able to verify access, optionally perform an access
102// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800103template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800104ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(uint32_t type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800105 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700106 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800107 Thread* self,
108 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700109 REQUIRES_SHARED(Locks::mutator_lock_)
110 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700111
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800112template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800113ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800114 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700115 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800116 Thread* self,
117 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700118 REQUIRES_SHARED(Locks::mutator_lock_)
119 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800120
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800121extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700122 ArtMethod* method, Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800123 bool access_check,
124 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700125 REQUIRES_SHARED(Locks::mutator_lock_)
126 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700127
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800128extern mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800129 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700130 ArtMethod* method,
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800131 Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800132 bool access_check,
133 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700134 REQUIRES_SHARED(Locks::mutator_lock_)
135 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700136
Ian Rogers08f753d2012-08-24 14:35:25 -0700137// Type of find field operation for fast and slow case.
138enum FindFieldType {
139 InstanceObjectRead,
140 InstanceObjectWrite,
141 InstancePrimitiveRead,
142 InstancePrimitiveWrite,
143 StaticObjectRead,
144 StaticObjectWrite,
145 StaticPrimitiveRead,
146 StaticPrimitiveWrite,
147};
148
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200149template<FindFieldType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700150inline ArtField* FindFieldFromCode(uint32_t field_idx,
151 ArtMethod* referrer,
152 Thread* self,
153 size_t expected_size)
154 REQUIRES_SHARED(Locks::mutator_lock_)
155 REQUIRES(!Roles::uninterruptible_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200156
157template<InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700158inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700159 ObjPtr<mirror::Object>* this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700160 ArtMethod* referrer,
161 Thread* self)
162 REQUIRES_SHARED(Locks::mutator_lock_)
163 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700164
Ian Rogers08f753d2012-08-24 14:35:25 -0700165// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700166inline ArtField* FindFieldFast(uint32_t field_idx,
167 ArtMethod* referrer,
168 FindFieldType type,
169 size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700170 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700171
Ian Rogers08f753d2012-08-24 14:35:25 -0700172// Fast path method resolution that can't throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700173inline ArtMethod* FindMethodFast(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700174 ObjPtr<mirror::Object> this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700175 ArtMethod* referrer,
176 bool access_check,
177 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700178 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700179
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700180inline mirror::Class* ResolveVerifyAndClinit(uint32_t type_idx,
181 ArtMethod* referrer,
182 Thread* self,
183 bool can_run_clinit,
184 bool verify_access)
185 REQUIRES_SHARED(Locks::mutator_lock_)
186 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700187
Mathieu Chartiere401d142015-04-22 13:56:20 -0700188inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, uint32_t string_idx)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700189 REQUIRES_SHARED(Locks::mutator_lock_)
190 REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700191
Ian Rogerse5877a12014-07-16 12:06:35 -0700192// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800193inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700194 NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700195
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700196void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
197 REQUIRES_SHARED(Locks::mutator_lock_)
198 REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700199
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700200JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700201 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800202 std::vector<jvalue>& args)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700203 REQUIRES_SHARED(Locks::mutator_lock_)
204 REQUIRES(!Roles::uninterruptible_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800205
Mathieu Chartieref41db72016-10-25 15:08:01 -0700206bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700207 REQUIRES_SHARED(Locks::mutator_lock_)
208 REQUIRES(!Roles::uninterruptible_);
Ian Rogers832336b2014-10-08 15:35:22 -0700209
Ian Rogers450dcb52013-09-20 17:36:02 -0700210template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800211inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700212
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000213ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
214 Runtime::CalleeSaveType type,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700215 bool do_caller_check = false)
216 REQUIRES_SHARED(Locks::mutator_lock_);
217
218ArtMethod* GetCalleeSaveMethodCaller(Thread* self, Runtime::CalleeSaveType type)
219 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000220
Shih-wei Liao2d831012011-09-28 22:06:53 -0700221} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700222
Ian Rogers7655f292013-07-29 11:07:13 -0700223#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_