blob: 6a04f20f3a2dc7d038030c9101b43c65c46c378b [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
Ian Rogers57b86d42012-03-27 16:05:41 -070048// Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it
49// cannot be resolved, throw an error. If it can, use it to create an instance.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +000050template <bool kInstrumented>
51ALWAYS_INLINE inline mirror::Object* AllocObjectFromCode(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080052 Thread* self,
53 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070054 REQUIRES_SHARED(Locks::mutator_lock_)
55 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070056
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080057// Given the context of a calling Method and a resolved class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080058template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080059ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
60 Thread* self,
61 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070062 REQUIRES_SHARED(Locks::mutator_lock_)
63 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080064
65// Given the context of a calling Method and an initialized class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080066template <bool kInstrumented>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070067ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(
68 mirror::Class* klass,
69 Thread* self,
70 gc::AllocatorType allocator_type)
71 REQUIRES_SHARED(Locks::mutator_lock_)
72 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080073
74
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080075template <bool kAccessCheck>
Andreas Gampea5b09a62016-11-17 15:21:22 -080076ALWAYS_INLINE inline mirror::Class* CheckArrayAlloc(dex::TypeIndex type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080077 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080079 bool* slow_path)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070080 REQUIRES_SHARED(Locks::mutator_lock_)
81 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070082
83// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
84// it cannot be resolved, throw an error. If it can, use it to create an array.
85// When verification/compiler hasn't been able to verify access, optionally perform an access
86// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080087template <bool kAccessCheck, bool kInstrumented>
Andreas Gampea5b09a62016-11-17 15:21:22 -080088ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(dex::TypeIndex type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080089 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070090 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080091 Thread* self,
92 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070093 REQUIRES_SHARED(Locks::mutator_lock_)
94 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -070095
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +000096template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080097ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080098 int32_t component_count,
99 Thread* self,
100 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700101 REQUIRES_SHARED(Locks::mutator_lock_)
102 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800103
Ian Rogers08f753d2012-08-24 14:35:25 -0700104// Type of find field operation for fast and slow case.
105enum FindFieldType {
106 InstanceObjectRead,
107 InstanceObjectWrite,
108 InstancePrimitiveRead,
109 InstancePrimitiveWrite,
110 StaticObjectRead,
111 StaticObjectWrite,
112 StaticPrimitiveRead,
113 StaticPrimitiveWrite,
114};
115
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200116template<FindFieldType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700117inline ArtField* FindFieldFromCode(uint32_t field_idx,
118 ArtMethod* referrer,
119 Thread* self,
120 size_t expected_size)
121 REQUIRES_SHARED(Locks::mutator_lock_)
122 REQUIRES(!Roles::uninterruptible_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200123
124template<InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700125inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700126 ObjPtr<mirror::Object>* this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700127 ArtMethod* referrer,
128 Thread* self)
129 REQUIRES_SHARED(Locks::mutator_lock_)
130 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700131
Ian Rogers08f753d2012-08-24 14:35:25 -0700132// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700133inline ArtField* FindFieldFast(uint32_t field_idx,
134 ArtMethod* referrer,
135 FindFieldType type,
136 size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700137 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700138
Ian Rogers08f753d2012-08-24 14:35:25 -0700139// Fast path method resolution that can't throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700140inline ArtMethod* FindMethodFast(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700141 ObjPtr<mirror::Object> this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700142 ArtMethod* referrer,
143 bool access_check,
144 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700145 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700146
Andreas Gampea5b09a62016-11-17 15:21:22 -0800147inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700148 ArtMethod* referrer,
149 Thread* self,
150 bool can_run_clinit,
151 bool verify_access)
152 REQUIRES_SHARED(Locks::mutator_lock_)
153 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700154
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800155inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700156 REQUIRES_SHARED(Locks::mutator_lock_)
157 REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700158
Ian Rogerse5877a12014-07-16 12:06:35 -0700159// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800160inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700161 NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700162
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700163void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
164 REQUIRES_SHARED(Locks::mutator_lock_)
165 REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700166
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700167JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700168 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800169 std::vector<jvalue>& args)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700170 REQUIRES_SHARED(Locks::mutator_lock_)
171 REQUIRES(!Roles::uninterruptible_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800172
Mathieu Chartieref41db72016-10-25 15:08:01 -0700173bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700174 REQUIRES_SHARED(Locks::mutator_lock_)
175 REQUIRES(!Roles::uninterruptible_);
Ian Rogers832336b2014-10-08 15:35:22 -0700176
Ian Rogers450dcb52013-09-20 17:36:02 -0700177template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800178inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700179
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000180ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
181 Runtime::CalleeSaveType type,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700182 bool do_caller_check = false)
183 REQUIRES_SHARED(Locks::mutator_lock_);
184
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000185struct CallerAndOuterMethod {
186 ArtMethod* caller;
187 ArtMethod* outer_method;
188};
189
190CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self,
191 Runtime::CalleeSaveType type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700192 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000193
Shih-wei Liao2d831012011-09-28 22:06:53 -0700194} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700195
Ian Rogers7655f292013-07-29 11:07:13 -0700196#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_