blob: b427c0717f3a76b1ba29c1ef5b42679f2946072f [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
Hiroshi Yamauchifee25502017-01-19 02:11:15 +000096template <bool kAccessCheck, 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,
Hiroshi Yamauchifee25502017-01-19 02:11:15 +000099 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800100 Thread* self,
101 gc::AllocatorType allocator_type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700102 REQUIRES_SHARED(Locks::mutator_lock_)
103 REQUIRES(!Roles::uninterruptible_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800104
Ian Rogers08f753d2012-08-24 14:35:25 -0700105// Type of find field operation for fast and slow case.
106enum FindFieldType {
107 InstanceObjectRead,
108 InstanceObjectWrite,
109 InstancePrimitiveRead,
110 InstancePrimitiveWrite,
111 StaticObjectRead,
112 StaticObjectWrite,
113 StaticPrimitiveRead,
114 StaticPrimitiveWrite,
115};
116
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200117template<FindFieldType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700118inline ArtField* FindFieldFromCode(uint32_t field_idx,
119 ArtMethod* referrer,
120 Thread* self,
121 size_t expected_size)
122 REQUIRES_SHARED(Locks::mutator_lock_)
123 REQUIRES(!Roles::uninterruptible_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200124
125template<InvokeType type, bool access_check>
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700126inline ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700127 ObjPtr<mirror::Object>* this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700128 ArtMethod* referrer,
129 Thread* self)
130 REQUIRES_SHARED(Locks::mutator_lock_)
131 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700132
Ian Rogers08f753d2012-08-24 14:35:25 -0700133// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700134inline ArtField* FindFieldFast(uint32_t field_idx,
135 ArtMethod* referrer,
136 FindFieldType type,
137 size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700138 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700139
Ian Rogers08f753d2012-08-24 14:35:25 -0700140// Fast path method resolution that can't throw exceptions.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700141inline ArtMethod* FindMethodFast(uint32_t method_idx,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700142 ObjPtr<mirror::Object> this_object,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700143 ArtMethod* referrer,
144 bool access_check,
145 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700146 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700147
Andreas Gampea5b09a62016-11-17 15:21:22 -0800148inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700149 ArtMethod* referrer,
150 Thread* self,
151 bool can_run_clinit,
152 bool verify_access)
153 REQUIRES_SHARED(Locks::mutator_lock_)
154 REQUIRES(!Roles::uninterruptible_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700155
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800156inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700157 REQUIRES_SHARED(Locks::mutator_lock_)
158 REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700159
Ian Rogerse5877a12014-07-16 12:06:35 -0700160// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800161inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700162 NO_THREAD_SAFETY_ANALYSIS REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700163
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700164void CheckReferenceResult(Handle<mirror::Object> o, Thread* self)
165 REQUIRES_SHARED(Locks::mutator_lock_)
166 REQUIRES(!Roles::uninterruptible_);
TDYa1273d71d802012-08-15 03:47:03 -0700167
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700168JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700169 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800170 std::vector<jvalue>& args)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700171 REQUIRES_SHARED(Locks::mutator_lock_)
172 REQUIRES(!Roles::uninterruptible_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800173
Mathieu Chartieref41db72016-10-25 15:08:01 -0700174bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700175 REQUIRES_SHARED(Locks::mutator_lock_)
176 REQUIRES(!Roles::uninterruptible_);
Ian Rogers832336b2014-10-08 15:35:22 -0700177
Ian Rogers450dcb52013-09-20 17:36:02 -0700178template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800179inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700180
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000181ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
182 Runtime::CalleeSaveType type,
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700183 bool do_caller_check = false)
184 REQUIRES_SHARED(Locks::mutator_lock_);
185
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000186struct CallerAndOuterMethod {
187 ArtMethod* caller;
188 ArtMethod* outer_method;
189};
190
191CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self,
192 Runtime::CalleeSaveType type)
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700193 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000194
Shih-wei Liao2d831012011-09-28 22:06:53 -0700195} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700196
Ian Rogers7655f292013-07-29 11:07:13 -0700197#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_